Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions crates/workshop-rs/src/actions/emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,24 @@ impl EmitContext<'_> {
if index > 0 {
args_text.push_str(", ");
}
// The frontend merges the leading `player, name` pair of
// the indexed player-variable actions into one
// player-variable value; split it back.
if index == 0
&& matches!(
name.as_str(),
"setPlayerVariableAtIndex" | "modifyPlayerVariableAtIndex"
)
{
if let Some(wir::Value::PlayerVariable { player, variable }) =
self.program.values.get(*arg).map(|node| &node.value)
{
self.value(*player, &mut args_text)?;
args_text.push_str(", ");
args_text.push_str(self.player_name(*variable)?);
continue;
}
}
let variable_position = match name.as_str() {
"setGlobalVariableAtIndex" | "modifyGlobalVariableAtIndex" => {
index == 0
Expand Down
1 change: 0 additions & 1 deletion crates/workshop-rs/src/actions/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ fn action_width_wir(
locale: locale.clone(),
fallback: None,
fallback_ids: Vec::new(),
force_hero_constructors: false,
out: String::new(),
line_count: 0,
};
Expand Down
1 change: 1 addition & 0 deletions crates/workshop-rs/src/bin/workshop-catalog-gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,7 @@ mod corpus {
let tokens = [
("token.on", "On"),
("token.off", "Off"),
("token.yes", "Yes"),
("token.no", "No"),
("token.disabled", "disabled"),
]
Expand Down
46 changes: 23 additions & 23 deletions crates/workshop-rs/src/catalog/data/catalog.json
Original file line number Diff line number Diff line change
Expand Up @@ -3796,8 +3796,8 @@
"th-TH": "เปิดใช้งานเสียงเพลงโหมดเกมในตัว",
"tr-TR": "Dâhilî Oyun Modu Müziğini Etkinleştir",
"zh-CN": [
"启用内置游戏模式音乐",
"开启游戏预设音乐模式"
"开启游戏预设音乐模式",
"启用内置游戏模式音乐"
],
"zh-TW": "Enable Built-In Game Mode Music"
},
Expand All @@ -3821,8 +3821,8 @@
"th-TH": "ทำลายข้อความในโลกทั้งหมด",
"tr-TR": "Tüm Oyun İçi Metinleri Yok Et",
"zh-CN": [
"摧毁所有世界内文本",
"消除所有地图文本"
"消除所有地图文本",
"摧毁所有世界内文本"
],
"zh-TW": "Destroy All In-World Text"
},
Expand All @@ -3846,8 +3846,8 @@
"th-TH": "ทำลายไอคอนทั้งหมด",
"tr-TR": "Tüm Simgeleri Yok Et",
"zh-CN": [
"摧毁所有图标",
"消除所有图标"
"消除所有图标",
"摧毁所有图标"
],
"zh-TW": "Destroy All Icons"
},
Expand All @@ -3871,8 +3871,8 @@
"th-TH": "ทำลายข้อความ HUD ทั้งหมด",
"tr-TR": "Tüm Ekran Göstergeleri Metinlerini Yok Et",
"zh-CN": [
"摧毁所有HUD文本",
"消除所有HUD文本"
"消除所有HUD文本",
"摧毁所有HUD文本"
],
"zh-TW": "Destroy All HUD Text"
},
Expand All @@ -3896,8 +3896,8 @@
"th-TH": "ทําลายเอฟเฟกต์ทั้งหมด",
"tr-TR": "Tüm Efektleri Yok Et",
"zh-CN": [
"摧毁所有效果",
"消除所有效果"
"消除所有效果",
"摧毁所有效果"
],
"zh-TW": "Destroy All Effects"
},
Expand All @@ -3921,8 +3921,8 @@
"th-TH": "ปิดใช้งานเพลงโหมดเกมในตัว",
"tr-TR": "Dâhilî Oyun Modu Müziğini Devre Dışı Bırak",
"zh-CN": [
"禁用内置游戏模式音乐",
"关闭游戏预设音乐模式"
"关闭游戏预设音乐模式",
"禁用内置游戏模式音乐"
],
"zh-TW": "Disable Built-In Game Mode Music"
},
Expand Down Expand Up @@ -3971,8 +3971,8 @@
"th-TH": "ปิดใช้งานการจบโหมดเกมในตัว",
"tr-TR": "Dâhilî Oyun Modu Sonuçlandırma'yı Devre Dışı Bırak",
"zh-CN": [
"禁用内置游戏模式完成",
"关闭游戏预设完成条件"
"关闭游戏预设完成条件",
"禁用内置游戏模式完成"
],
"zh-TW": "Disable Built-In Game Mode Completion"
},
Expand All @@ -3996,8 +3996,8 @@
"th-TH": "ปิดใช้งานผู้ประกาศโหมดเกมในตัว",
"tr-TR": "Dâhilî Oyun Modu Anonsçusunu Devre Dışı Bırak",
"zh-CN": [
"禁用内置游戏模式播报员",
"关闭游戏预设通告模式"
"关闭游戏预设通告模式",
"禁用内置游戏模式播报员"
],
"zh-TW": "Disable Built-In Game Mode Announcer"
},
Expand All @@ -4021,8 +4021,8 @@
"th-TH": "ปิดใช้งานการให้คะแนนโหมดเกมในตัว",
"tr-TR": "Dâhilî Oyun Modu Puanlama'yı Devre Dışı Bırak",
"zh-CN": [
"禁用内置游戏模式计分",
"关闭游戏预设计分模式"
"关闭游戏预设计分模式",
"禁用内置游戏模式计分"
],
"zh-TW": "Disable Built-In Game Mode Scoring"
},
Expand All @@ -4046,8 +4046,8 @@
"th-TH": "เลิกหยุดเวลาแมตช์ชั่วคราว",
"tr-TR": "Maç Süresini Sürdür",
"zh-CN": [
"继续比赛时间",
"比赛时间继续"
"比赛时间继续",
"继续比赛时间"
],
"zh-TW": "Unpause Match Time"
},
Expand Down Expand Up @@ -7888,7 +7888,7 @@
]
}
],
"digest": "e022d56f95c4870a4e1abfeb82b33674da3a8e983f9aed986b21285e181a404d",
"digest": "d9cca56119ddb28dbb9363ca1a2a22db2efb70c9bcd7ac738a7fd985099b7e9a",
"enums": [
{
"domain": "Impulse",
Expand Down Expand Up @@ -14694,8 +14694,8 @@
{
"aliases": {
"en-US": [
"Jinyu",
"Domina"
"Domina",
"Jinyu"
],
"zh-CN": "金驭",
"zh-TW": "多米娜"
Expand Down
9 changes: 9 additions & 0 deletions crates/workshop-rs/src/core/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ pub fn format_number(value: f64) -> String {
}
}

/// Format a settings number: the shortest decimal that round-trips, so a
/// value read from a project is written back unchanged.
pub fn format_setting_number(value: f64) -> String {
if value.fract() == 0.0 && value.abs() < 1e15 {
return format_number(value);
}
format!("{value}")
}

/// Keep at most `max_digits` significant digits of a decimal string,
/// truncating (not rounding) and expanding any exponent form.
fn truncate_significant(text: &str, max_digits: usize) -> String {
Expand Down
2 changes: 1 addition & 1 deletion crates/workshop-rs/src/output/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ pub fn convert_with_context(
let emit_options = EmitOptions {
fallback_locale: options.fallback_locale.clone(),
};
let output = emitter::emit_with_options_for_conversion(&program, catalog, to, &emit_options)?;
let output = emitter::emit_with_options(&program, catalog, to, &emit_options)?;
Ok(Conversion {
text: output.text,
fallback_ids: output.fallback_ids,
Expand Down
21 changes: 3 additions & 18 deletions crates/workshop-rs/src/output/emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ pub(crate) use std::fmt::Write;

pub(crate) use crate::catalog::{Catalog, Kind, Locale};
pub(crate) use crate::core::error::{Result, WorkshopError};
pub(crate) use crate::core::format::format_number;
pub(crate) use crate::settings::table::KeyKind;
pub(crate) use crate::settings::{PathPart, table};
pub(crate) use crate::settings::{Settings as SettingsTree, SettingsNode};
Expand Down Expand Up @@ -51,8 +50,7 @@ pub(crate) fn emit_wir(
catalog: &Catalog,
locale: &Locale,
) -> Result<String> {
emit_with_options_inner(program, catalog, locale, &EmitOptions::default(), false)
.map(|out| out.text)
emit_with_options_inner(program, catalog, locale, &EmitOptions::default()).map(|out| out.text)
}

/// Emit a public Workshop program as localized Workshop text with emission
Expand All @@ -64,17 +62,7 @@ pub fn emit_with_options(
options: &EmitOptions,
) -> Result<EmitOutput> {
let storage = program.to_wir()?;
emit_with_options_inner(&storage, catalog, locale, options, false)
}

pub(crate) fn emit_with_options_for_conversion(
program: &crate::Program,
catalog: &Catalog,
locale: &Locale,
options: &EmitOptions,
) -> Result<EmitOutput> {
let storage = program.to_wir()?;
emit_with_options_inner(&storage, catalog, locale, options, true)
emit_with_options_inner(&storage, catalog, locale, options)
}

#[cfg(test)]
Expand All @@ -84,22 +72,20 @@ pub(crate) fn emit_wir_with_options(
locale: &Locale,
options: &EmitOptions,
) -> Result<EmitOutput> {
emit_with_options_inner(program, catalog, locale, options, false)
emit_with_options_inner(program, catalog, locale, options)
}

fn emit_with_options_inner(
program: &wir::Program,
catalog: &Catalog,
locale: &Locale,
options: &EmitOptions,
force_hero_constructors: bool,
) -> Result<EmitOutput> {
let mut emitter = EmitContext {
program,
catalog,
locale: locale.clone(),
fallback: options.fallback_locale.clone(),
force_hero_constructors,
fallback_ids: Vec::new(),
out: String::new(),
line_count: 0,
Expand All @@ -119,7 +105,6 @@ pub(crate) struct EmitContext<'a> {
pub(crate) fallback: Option<Locale>,
/// Canonical ids emitted with a fallback-locale spelling.
pub(crate) fallback_ids: Vec<String>,
pub(crate) force_hero_constructors: bool,
pub(crate) out: String,
pub(crate) line_count: usize,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{ "hero": "roadhog", "key": "secondaryFireCooldown%", "locale": "en-US", "display": "secondaryFireCooldown%" },
{ "hero": "roadhog", "key": "secondaryFireCooldown%", "locale": "zh-CN", "display": "secondaryFireCooldown%" },
{ "hero": "sojourn", "key": "secondaryFireEnergyChargeRate%", "locale": "zh-CN", "display": "充能速度 充能射击" },
{ "hero": "roadhog", "key": "secondaryFireRechargeRate%", "locale": "zh-CN", "display": "secondaryFireRechargeRate%" },
{ "hero": "roadhog", "key": "secondaryFireRechargeRate%", "locale": "zh-CN", "display": "呼吸器充能速度" },
{ "hero": "hazard", "key": "secondaryFireRegen%", "locale": "zh-CN", "display": "尖刺护体资源恢复" },
{ "hero": "hazard", "key": "secondaryFireCost%", "locale": "zh-CN", "display": "尖刺护体资源消耗" }
Expand Down
24 changes: 22 additions & 2 deletions crates/workshop-rs/src/settings/data/locales.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
"total": 3
},
"tokens": {
"matched": 4,
"total": 4
"matched": 5,
"total": 5
}
},
"enums": {
Expand Down Expand Up @@ -9370,6 +9370,26 @@
"zh-CN": "开启",
"zh-TW": "開啟"
},
"Yes": {
"de-DE": "Ja",
"en-US": "Yes",
"es-ES": "Sí",
"es-MX": "Sí",
"fr-FR": "Oui",
"it-IT": "Sì",
"ja-JP": "はい",
"ko-KR": "네",
"pl-PL": "Tak",
"pt-BR": "Sim",
"ru-RU": "Да",
"sources": [
"other.customGameSettings.__yes__"
],
"th-TH": "ใช่",
"tr-TR": "Evet",
"zh-CN": "是",
"zh-TW": "是"
},
"disabled": {
"de-DE": "Deaktiviert",
"en-US": "disabled",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
{ "path": "heroes.<team>.<hero>.enableAbility2", "fixture": { "name": "Ability 2", "kind": "bool" }, "generated": { "name": "%1$s", "kind": "bool" } },
{ "path": "heroes.<team>.<hero>.enableSecondaryFire", "fixture": { "name": "Secondary Fire", "kind": "bool" }, "generated": { "name": "%1$s", "kind": "bool" } },
{ "path": "heroes.<team>.<hero>.passiveUltGen%", "fixture": { "name": "Ultimate Generation - Passive Blizzard", "kind": "percent" }, "generated": { "name": "Ultimate Generation - Passive %1$s", "kind": "percent" } },
{ "path": "lobby.allowPlayersInQueue", "fixture": { "name": "Allow Players Who Are In Queue", "kind": "yesNo" }, "generated": { "name": "Allow Players Who Are In Queue", "kind": "bool" } },
{ "path": "lobby.enableMatchVoiceChat", "fixture": { "name": "Match Voice Chat", "kind": "boolEnum", "domain": "matchVoiceChat" }, "generated": { "name": "Match Voice Chat", "kind": "bool" } },
{ "path": "lobby.mapRotation", "fixture": { "name": "Map Rotation", "kind": "enum", "domain": "mapRotation" }, "generated": { "name": "Map Rotation", "kind": "enum", "domain": "setting_lobby_mapRotation" } },
{ "path": "lobby.returnToLobby", "fixture": { "name": "Return To Lobby", "kind": "enum", "domain": "returnToLobby" }, "generated": { "name": "Return To Lobby", "kind": "enum", "domain": "setting_lobby_returnToLobby" } },
{ "path": "lobby.swapTeamsAfterMatch", "fixture": { "name": "Swap Teams After Match", "kind": "yesNo" }, "generated": { "name": "Swap Teams After Match", "kind": "bool" } },
{ "path": "lobby.team1Slots", "fixture": { "name": "Max Team 1 Players", "kind": "number" }, "generated": { "name": "Max %1$s Players", "kind": "number" } },
{ "path": "lobby.team2Slots", "fixture": { "name": "Max Team 2 Players", "kind": "number" }, "generated": { "name": "Max %1$s Players", "kind": "number" } }
],
Expand Down
21 changes: 19 additions & 2 deletions crates/workshop-rs/src/settings/emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,12 +236,21 @@ impl EmitContext<'_> {
self.line(level, &format!("{display_name}: {display}"))?;
}
(SettingsNode::Number { value, .. }, KeyKind::Number) => {
self.line(level, &format!("{display_name}: {}", format_number(*value)))?;
self.line(
level,
&format!(
"{display_name}: {}",
crate::format::format_setting_number(*value)
),
)?;
}
(SettingsNode::Number { value, .. }, KeyKind::Percent) => {
self.line(
level,
&format!("{display_name}: {}%", format_number(*value)),
&format!(
"{display_name}: {}%",
crate::format::format_setting_number(*value)
),
)?;
}
(SettingsNode::Bool { value, .. }, KeyKind::Bool) => {
Expand All @@ -252,6 +261,14 @@ impl EmitContext<'_> {
)?;
self.line(level, &format!("{display_name}: {rendered}"))?;
}
(SettingsNode::Bool { value, .. }, KeyKind::YesNo) => {
let rendered = self.setting_name(
"tokens",
if *value { "Yes" } else { "No" },
if *value { "token.yes" } else { "token.no" },
)?;
self.line(level, &format!("{display_name}: {rendered}"))?;
}
(SettingsNode::Bool { value, .. }, KeyKind::BoolEnum(domain)) => {
if !*value {
return Err(self
Expand Down
2 changes: 1 addition & 1 deletion crates/workshop-rs/src/settings/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ impl ParseContext<'_> {
span: Some(Span::new(self.file(), start, self.previous_span().1)),
})
}
KeyKind::Bool => {
KeyKind::Bool | KeyKind::YesNo => {
let value = self.settings_bool()?;
Ok(SettingsNode::Bool {
name: name.to_string(),
Expand Down
Loading
Loading