Skip to content

Commit

Permalink
(Aegis) support string-tuple SplitDefinition format
Browse files Browse the repository at this point in the history
  • Loading branch information
ahyangyi committed Nov 6, 2023
1 parent 89b9078 commit 67ee455
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
3 changes: 3 additions & 0 deletions agrf/parameters/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ def range(self):
def set_index(self, index):
self.index = index

def enum_index(self, name):
return [k for k, v in self.enum.items() if v == name][0]


class ParameterList:
def __init__(self, parameters):
Expand Down
6 changes: 3 additions & 3 deletions industry/aegis_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ def initialize_metadata():
all_cargos.append(cargo)

for industry in all_industries:
industry._props["exists"] = SplitDefinition((0,), {})
industry._props["production_types"] = SplitDefinition((0,), {})
industry._props["acceptance_types"] = SplitDefinition((0,), {})
industry._props["exists"] = SplitDefinition(("ECONOMY",), {})
industry._props["production_types"] = SplitDefinition(("ECONOMY",), {})
industry._props["acceptance_types"] = SplitDefinition(("ECONOMY",), {})

for i, meta_economy in enumerate(all_economies):
for variation in parameter_choices.iterate_variations():
Expand Down
10 changes: 8 additions & 2 deletions industry/lib/industry/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,17 @@ def __init__(self, variables, branches):
# Legacy format
variables = (variables,)
branches = {(i,): b for i, b in branches.items()}
if isinstance(variables, str):
elif isinstance(variables, str):
idx = parameter_list.index(variables)
p = parameter_list.parameters[idx]
variables = (idx,)
branches = {(next(k for k, v in p.enum.items() if v == i),): b for i, b in branches.items()}
branches = {(p.enum_index(i),): b for i, b in branches.items()}
elif isinstance(variables[0], str):
variables = tuple(parameter_list.index(idx) for idx in variables)
branches = {
tuple(parameter_list.index(idx).enum_index(s) for idx, s in zip(variables, i)): b
for i, b in branches.items()
}
self.variables = variables
self.branches = branches

Expand Down

0 comments on commit 67ee455

Please sign in to comment.