From ee9df6e9bf659d731b68b013d70c9c7c22fad408 Mon Sep 17 00:00:00 2001 From: yairm210 Date: Thu, 1 May 2025 23:45:40 +0300 Subject: [PATCH] Better Expression documentation --- .../com/unciv/models/ruleset/unique/Countables.kt | 5 +++-- .../models/ruleset/unique/UniqueParameterType.kt | 3 ++- docs/Modders/Unique-parameters.md | 12 ++++++------ docs/Modders/uniques.md | 2 +- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/core/src/com/unciv/models/ruleset/unique/Countables.kt b/core/src/com/unciv/models/ruleset/unique/Countables.kt index 9057f5a491..ecfe100659 100644 --- a/core/src/com/unciv/models/ruleset/unique/Countables.kt +++ b/core/src/com/unciv/models/ruleset/unique/Countables.kt @@ -179,8 +179,9 @@ enum class Countables( override val documentationHeader = "Evaluate expressions!" override val documentationStrings = listOf( - "Expressions support arbitrary math operations, and can include other countables", - "For example, something like: `([[Melee] units] + 1) / [Cities]`", + "Expressions support arbitrary math operations, and can include other countables, when surrounded by square brackets.", + "For example, since `Cities` is a countable, and `[Melee] units` is a countable, " + + "you can have something like: `([[Melee] units] + 1) / [Cities]` (the whitespace is optional but helps readability)", "Since on translation, the brackets are removed, the expression will be displayed as `(Melee units + 1) / Cities`", "Supported operations between 2 values are: "+ Operator.BinaryOperators.entries.joinToString { it.symbol }, "Supported operations on 1 value are: " + Operator.UnaryOperators.entries.joinToString { it.symbol+" (${it.description})" }, diff --git a/core/src/com/unciv/models/ruleset/unique/UniqueParameterType.kt b/core/src/com/unciv/models/ruleset/unique/UniqueParameterType.kt index e64f71d979..5d9c7a1f34 100644 --- a/core/src/com/unciv/models/ruleset/unique/UniqueParameterType.kt +++ b/core/src/com/unciv/models/ruleset/unique/UniqueParameterType.kt @@ -69,7 +69,8 @@ enum class UniqueParameterType( parameterText.getInvariantSeverityUnless { toIntOrNull() != null } }, - Countable("countable", "1000", "This indicates a number or a numeric variable") { + Countable("countable", "1000", "This indicates a number or a numeric variable." + + "They can be tested in the developer console with `civ checkcountable` - for example, `civ checkcountable \"[Iron]+2\"`") { override fun isKnownValue(parameterText: String, ruleset: Ruleset) = Countables.isKnownValue(parameterText, ruleset) diff --git a/docs/Modders/Unique-parameters.md b/docs/Modders/Unique-parameters.md index 70baab4e39..09243e3f5c 100644 --- a/docs/Modders/Unique-parameters.md +++ b/docs/Modders/Unique-parameters.md @@ -342,13 +342,13 @@ Allowed values: [//]: # (Countables automatically generated BEGIN) - Integer constant - any positive or negative integer number - `turns` - Number of turns played - - (Always starts at zero irrespective of game speed or start era) + - Always starts at zero irrespective of game speed or start era - `year` - The current year - - (Depends on game speed or start era, negative for years BC) + - Depends on game speed or start era, negative for years BC - `Cities` - The number of cities the relevant Civilization owns - `Units` - The number of units the relevant Civilization owns - Stat name (`Production`, `Food`, `Gold`, `Science`, `Culture`, `Happiness` or `Faith`) - - gets the stat *reserve*, not the amount per turn (can be city stats or civilization stats, depending on where the unique is used) + - Gets the stat *reserve*, not the amount per turn (can be city stats or civilization stats, depending on where the unique is used) - `Completed Policy branches` - `[cityFilter] Cities` - `[mapUnitFilter] Units` @@ -356,12 +356,12 @@ Allowed values: - `Remaining [civFilter] Civilizations` - `Owned [tileFilter] Tiles` - Resource name - From [TileResources.json](3-Map-related-JSON-files.md#tileresourcesjson) - - (can be city stats or civilization stats, depending on where the unique is used) + - Can be city stats or civilization stats, depending on where the unique is used - For example: If a unique is placed on a building, then the retrieved resources will be of the city. If placed on a policy, they will be of the civilization. - This can make a difference for e.g. local resources, which are counted per city. - Evaluate expressions! - - Expressions support arbitrary math operations, and can include other countables - - For example, something like: `([[Melee] units] + 1) / [Cities]` + - Expressions support arbitrary math operations, and can include other countables, when surrounded by square brackets. + - For example, since `Cities` is a countable, and `[Melee] units` is a countable, you can have something like: `([[Melee] units] + 1) / [Cities]` (the whitespace is optional but helps readability) - Since on translation, the brackets are removed, the expression will be displayed as `(Melee units + 1) / Cities` - Supported operations between 2 values are: +, -, *, /, %, ^ - Supported operations on 1 value are: - (negation), √ (square root), abs (absolute value - turns negative into positive), sqrt (square root), floor (round down), ceil (round up) diff --git a/docs/Modders/uniques.md b/docs/Modders/uniques.md index 1dee729b1b..4e2f228bba 100644 --- a/docs/Modders/uniques.md +++ b/docs/Modders/uniques.md @@ -3531,7 +3531,7 @@ Simple unique parameters are explained by mouseover. Complex parameters are expl *[civWideStat]: All the following stats have civ-wide fields: `Gold`, `Science`, `Culture`, `Faith`. *[combatantFilter]: This indicates a combatant, which can either be a unit or a city (when bombarding). Must either be `City` or a `mapUnitFilter`. *[costOrStrength]: `Cost` or `Strength`. -*[countable]: This indicates a number or a numeric variable. +*[countable]: This indicates a number or a numeric variable.They can be tested in the developer console with `civ checkcountable` - for example, `civ checkcountable "[Iron]+2"`. *[difficulty]: The name of any difficulty. *[era]: The name of any era. *[event]: The name of any event.