Skip to content

Commit

Permalink
Add test for logical OR expression in MOD_DEPENDENT
Browse files Browse the repository at this point in the history
  • Loading branch information
IhateTrains committed Sep 14, 2024
1 parent a99934a commit 8993761
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 14 deletions.
10 changes: 4 additions & 6 deletions ImperatorToCK3.UnitTests/CK3/ParserExtensionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class ParserExtensionsTests {
[Theory]
[InlineData(true, false, false, 0, 0)]
[InlineData(false, true, false, 1, 1)]
[InlineData(false, false, true, 2, 2)]
[InlineData(false, false, true, 2, 0)]
[InlineData(true, true, false, 0, 1)]
public void CorrectModDependentBranchesAreUsed(bool wtwsms, bool tfe, bool vanilla, int expectedValue1,
int expectedValue2) {
Expand All @@ -22,18 +22,16 @@ public void CorrectModDependentBranchesAreUsed(bool wtwsms, bool tfe, bool vanil
MOD_DEPENDENT = {
IF @wtwsms = { # Interpolated expression without brackets is valid, therefor should be supported.
value1 = 0
} ELSE_IF @[tfe] = {
} ELSE_IF tfe = {# Simple mod flag string should be supported as well.
value1 = 1
} ELSE = {
value1 = 2
}
IF wtwsms = { # Simple mod flag string should be supported as well.
IF @[wtwsms|vanilla|tfe] = { # Logical OR, example of more complex interpolated expression.
value2 = 0
} ELSE_IF @[vanilla] = {
value2 = 2
}
IF @[tfe] = { # will override the previous value2 assignment
IF @[tfe] = { # Will override the previous value2.
value2 = 1
}
}
Expand Down
4 changes: 4 additions & 0 deletions ImperatorToCK3/CK3/ParserExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ private static bool GetConditionValue(BufferedReader reader, IDictionary<string,
if (conditionToken == "True" || conditionToken == "False") {
// If the conditionToken is "True" or "False" it means the parser has already evaluated the expression.
return bool.Parse(conditionToken);
} else if (conditionToken == "1" || conditionToken == "0") {
// Parser evaluated the expression as a number.
// Convert to int and then to bool.
return int.Parse(conditionToken) != 0;
} else {
// Otherwise the token is expected to be a mod flag name.
return ck3ModFlags[conditionToken];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -462,9 +462,15 @@ language_messapic = {
vanilla = { language_messapic }
}

# TODO: add language_branch parameter for WtWSMS
# TODO: language_branch_italic = yes
# TODO: language_family_indo_european = yes
MOD_DEPENDENT = {
IF wtwsms = {
parameters = {
language_branch_italic = yes
language_family_indo_european = yes
}
}
}

# TODO: update ai_will_do

type = language
Expand All @@ -473,13 +479,18 @@ language_messapic = {
LANGUAGE = language_messapic
}
}
ai_will_do = {
value = 10
if = {
limit = { has_cultural_pillar = language_messapic }
multiply = 10
MOD_DEPENDENT = {
ELSE = {
ai_will_do = {
value = 10
if = {
limit = { has_cultural_pillar = language_messapic }
multiply = 10
}
}
}
}


color = { 5 52 113 }
}
Expand Down

0 comments on commit 8993761

Please sign in to comment.