Skip to content

Commit

Permalink
Make fomod selection flag matching case insensitive
Browse files Browse the repository at this point in the history
Also add "action" to the list of values that should be interpreted as
True. Note that this doesn't make the actual flag names case
insensitive, just their values.
  • Loading branch information
cyberrumor committed Apr 1, 2024
1 parent c48b51a commit ca74581
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions ammo/fomod_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,14 +161,13 @@ def _get_pages(self) -> list[Page]:
# but fits into the "each step is a page" paradigm better.
if visible := step.find("visible"):
if dependencies := visible.find("dependencies"):
dep_op = dependencies.get("operator")
if dep_op:
dep_op = dep_op.lower()
dep_op = dependencies.get("operator", "").lower()
visibility_conditions["operator"] = dep_op
for xml_flag in dependencies:
visibility_conditions[xml_flag.get("flag")] = (
xml_flag.get("value") in ["On", "1"]
)
if flag := xml_flag.get("flag"):
visibility_conditions[flag] = xml_flag.get(
"value", ""
).lower() in ["on", "1", "active"]

page = Page(
name=group.get("name"),
Expand All @@ -192,10 +191,11 @@ def _get_pages(self) -> list[Page]:
if conditional_flags := plugin.find("conditionFlags"):
for flag in conditional_flags:
# People use arbitrary flags here.
# Most commonly "On" or "1".
flags[flag.get("name")] = flag.text in [
"On",
# Most commonly "On", "1" or "active".
flags[flag.get("name")] = (flag.text or "").lower() in [
"on",
"1",
"active",
]
conditional = True

Expand Down Expand Up @@ -318,15 +318,15 @@ def _get_nodes(self) -> list[ElementTree.Element]:
)
for pattern in patterns:
dependencies = pattern.find("dependencies")
dep_op = dependencies.get("operator")
if dep_op:
dep_op = dep_op.lower()
dep_op = dependencies.get("operator", "").lower()
expected_flags = {"operator": dep_op}
for xml_flag in dependencies:
expected_flags[xml_flag.get("flag")] = xml_flag.get("value") in [
"On",
"1",
]
if flag := xml_flag.get("flag"):
expected_flags[flag] = xml_flag.get("value", "").lower() in [
"on",
"1",
"active",
]

# xml_files is a list of folders. The folder objects contain the paths.
xml_files = pattern.find("files")
Expand Down

0 comments on commit ca74581

Please sign in to comment.