mirror of
https://github.com/MarioSpore/Grinch-AP.git
synced 2025-10-21 20:21:32 -06:00
Factorio:
add visibility option fix tech_cost using the wrong variable name fix yaml defaults not init'ing the Option class LttP: fix potential pathing confusion in maseya palette shuffler Server: Minimum version per team made no sense, removed
This commit is contained in:
@@ -6,12 +6,13 @@ import Utils
|
||||
factorio_id = 2 ** 17
|
||||
|
||||
source_file = Utils.local_path("data", "factorio", "techs.json")
|
||||
|
||||
recipe_source_file = Utils.local_path("data", "factorio", "recipes.json")
|
||||
with open(source_file) as f:
|
||||
raw = json.load(f)
|
||||
with open(recipe_source_file) as f:
|
||||
raw_recipes = json.load(f)
|
||||
tech_table = {}
|
||||
technology_table = {}
|
||||
requirements = {} # tech_name -> Set[required_technologies]
|
||||
|
||||
|
||||
class Technology(): # maybe make subclass of Location?
|
||||
@@ -25,13 +26,28 @@ class Technology(): # maybe make subclass of Location?
|
||||
def get_required_technologies(self):
|
||||
requirements = set()
|
||||
for ingredient in self.ingredients:
|
||||
if ingredient in recipe_sources: # no source likely means starting item
|
||||
requirements |= recipe_sources[ingredient] # technically any, not all, need to improve later
|
||||
if ingredient in recipe_sources: # no source likely means starting item
|
||||
requirements |= recipe_sources[ingredient] # technically any, not all, need to improve later
|
||||
return requirements
|
||||
|
||||
def build_rule(self):
|
||||
ingredient_rules = []
|
||||
for ingredient in self.ingredients:
|
||||
if ingredient in recipe_sources:
|
||||
technologies = recipe_sources[ingredient] # technologies that unlock the recipe
|
||||
ingredient_rules.append(lambda state, technologies=technologies: any(state.has(technology) for technology in technologies))
|
||||
ingredient_rules = frozenset(ingredient_rules)
|
||||
return lambda state: all(rule(state) for rule in ingredient_rules)
|
||||
|
||||
def __hash__(self):
|
||||
return self.factorio_id
|
||||
|
||||
class Recipe():
|
||||
def __init__(self, name, category, ingredients, products):
|
||||
self.name = name
|
||||
self.category = category
|
||||
self.products = ingredients
|
||||
self.ingredients = products
|
||||
|
||||
# recipes and technologies can share names in Factorio
|
||||
for technology_name in sorted(raw):
|
||||
@@ -56,3 +72,10 @@ for technology, data in raw.items():
|
||||
|
||||
del (raw)
|
||||
lookup_id_to_name: Dict[int, str] = {item_id: item_name for item_name, item_id in tech_table.items()}
|
||||
|
||||
|
||||
all_recipes = set()
|
||||
for recipe_name, recipe_data in raw_recipes.items():
|
||||
# example:
|
||||
# "accumulator":{"ingredients":["iron-plate","battery"],"products":["accumulator"],"category":"crafting"}
|
||||
all_recipes.add(Recipe(recipe_name, recipe_data["category"], set(recipe_data["ingredients"]), set(recipe_data["products"])))
|
||||
|
Reference in New Issue
Block a user