Skip to content

Commit

Permalink
(Aegis) move SplitDefinition to agrf
Browse files Browse the repository at this point in the history
  • Loading branch information
ahyangyi committed Nov 14, 2023
1 parent bafeb7c commit 4f94a45
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
1 change: 1 addition & 0 deletions agrf/split_action/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .split_definition import SplitDefinition
12 changes: 12 additions & 0 deletions agrf/split_action/split_definition.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class SplitDefinition:
def __init__(self, variables, branches):
self.variables = variables
self.branches = branches

def fixup(self, parameter_list):
if isinstance(self.variables[0], str):
self.variables = tuple(parameter_list.index(idx) for idx in self.variables)
self.branches = {
tuple(parameter_list.parameters[idx].enum_index(s) for idx, s in zip(self.variables, i)): b
for i, b in self.branches.items()
}
19 changes: 3 additions & 16 deletions industry/lib/industry/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from .transcriber import transcribe
from .symmetrizer import symmetrize
from agrf.strings import get_translation
from agrf.split_action import SplitDefinition


def props_hash(parameters):
Expand All @@ -16,20 +17,6 @@ def props_hash(parameters):
return hash(tuple(ret))


class SplitDefinition:
def __init__(self, variables, branches):
self.variables = variables
self.branches = branches

def fixup(self):
if isinstance(self.variables[0], str):
self.variables = tuple(parameter_list.index(idx) for idx in self.variables)
self.branches = {
tuple(parameter_list.parameters[idx].enum_index(s) for idx, s in zip(self.variables, i)): b
for i, b in self.branches.items()
}


class AIndustry(grf.SpriteGenerator):
def __init__(self, *, translation_name, id=None, callbacks={}, **props):
super().__init__()
Expand All @@ -50,7 +37,7 @@ def dynamic_prop_variables(self):
ret = set()
for p in self._props.values():
if isinstance(p, SplitDefinition):
p.fixup()
p.fixup(parameter_list)
for v in p.variables:
ret.add(v)
return list(sorted(ret))
Expand All @@ -60,7 +47,7 @@ def resolve_props(self, parameters):
miss = False
for k, v in self._props.items():
while isinstance(v, SplitDefinition):
v.fixup()
v.fixup(parameter_list)
branch_key = tuple(parameters[var] for var in v.variables)
if branch_key in v.branches:
v = v.branches[branch_key]
Expand Down

0 comments on commit 4f94a45

Please sign in to comment.