Skip to content

Commit a548d9e

Browse files
committed
add the ability to check whether an entry is contained in a variable contition
1 parent 9db4e7e commit a548d9e

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

worlds/crosscode/codegen/parse.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from ..types.locations import AccessInfo, Condition
1515
from ..types.regions import RegionConnection, RegionsData
1616
from ..types.condition import ChestKeyCondition, ItemCondition, LocationCondition, NeverCondition, QuestCondition, RegionCondition, AnyElementCondition, \
17-
OrCondition, ShopSlotCondition, VariableCondition
17+
OrCondition, ShopSlotCondition, VariableCondition, VariableEntryCondition
1818

1919
class JsonParserError(Exception):
2020
"""
@@ -112,6 +112,8 @@ def parse_condition(self, raw: list[typing.Any]) -> list[Condition]:
112112
elif cond[0] == "var":
113113
if num_args == 1:
114114
result.append(VariableCondition(cond[1]))
115+
elif num_args == 2:
116+
result.append(VariableEntryCondition(cond[1], cond[2]))
115117
else:
116118
raise JsonParserError(
117119
raw,

worlds/crosscode/types/condition.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,16 @@ def satisfied(self, state: CollectionState, player: int, location: int | None, a
108108

109109
return True
110110

111+
@dataclass
112+
class VariableEntryCondition(Condition):
113+
name: str
114+
value: str
115+
116+
def satisfied(self, state: CollectionState, player: int, location: int | None, args: LogicDict) -> bool:
117+
variables = args["variables"]
118+
119+
return self.value in variables[self.name]
120+
111121
@dataclass
112122
class ChestKeyCondition(Condition):
113123
default_level: str
@@ -160,6 +170,7 @@ def satisfied(self, state: CollectionState, player: int, location: int | None, a
160170
"AnyElementCondition",
161171
"OrCondition",
162172
"VariableCondition",
173+
"VariableEntryCondition",
163174
"ChestKeyCondition",
164175
"ShopSlotCondition",
165176
"NeverCondition"

0 commit comments

Comments
 (0)