add Factorio world gen settings
This commit is contained in:
parent
eee6fc0f10
commit
0a64caf4c5
1
Utils.py
1
Utils.py
|
@ -12,6 +12,7 @@ class Version(typing.NamedTuple):
|
||||||
minor: int
|
minor: int
|
||||||
build: int
|
build: int
|
||||||
|
|
||||||
|
|
||||||
__version__ = "0.1.4"
|
__version__ = "0.1.4"
|
||||||
version_tuple = tuplize_version(__version__)
|
version_tuple = tuplize_version(__version__)
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
{% from "macros.lua" import dict_to_lua %}
|
||||||
|
data.raw["map-gen-presets"].default["archipelago"] = {{ dict_to_lua({"default": False, "order": "a", "basic_settings": world_gen}) }}
|
|
@ -1,3 +1,8 @@
|
||||||
|
[map-gen-preset-name]
|
||||||
|
archipelago=Archipelago
|
||||||
|
|
||||||
|
[map-gen-preset-description]
|
||||||
|
archipelago=World preset created by the Archipelago Randomizer. World may or may not contain actual archipelagos.
|
||||||
|
|
||||||
[technology-name]
|
[technology-name]
|
||||||
{% for original_tech_name, item_name, receiving_player, advancement in locations %}
|
{% for original_tech_name, item_name, receiving_player, advancement in locations %}
|
||||||
|
|
|
@ -1,10 +1,17 @@
|
||||||
{% macro dict_to_lua(dict) -%}
|
{% macro dict_to_lua(dict) -%}
|
||||||
{
|
{
|
||||||
{%- for key, value in dict.items() -%}
|
{%- for key, value in dict.items() -%}
|
||||||
["{{ key }}"] = {% if value is mapping %}{{ dict_to_lua(value) }}{% else %}{{ value | safe }}{% endif %}{% if not loop.last %},{% endif %}
|
["{{ key }}"] = {{ variable_to_lua(value) }}{% if not loop.last %},{% endif %}
|
||||||
{% endfor -%}
|
{% endfor -%}
|
||||||
}
|
}
|
||||||
{%- endmacro %}
|
{%- endmacro %}
|
||||||
|
{%- macro variable_to_lua(value) %}
|
||||||
|
{%- if value is mapping -%}{{ dict_to_lua(value) }}
|
||||||
|
{%- elif value is boolean -%}{{ value | string | lower }}
|
||||||
|
{%- elif value is string -%} "{{ value | safe }}"
|
||||||
|
{%- else -%} {{ value | safe }}
|
||||||
|
{%- endif -%}
|
||||||
|
{%- endmacro -%}
|
||||||
{% macro dict_to_recipe(dict) -%}
|
{% macro dict_to_recipe(dict) -%}
|
||||||
{
|
{
|
||||||
{%- for key, value in dict.items() -%}
|
{%- for key, value in dict.items() -%}
|
||||||
|
|
|
@ -15,7 +15,8 @@ from .Technologies import tech_table, rocket_recipes, recipes, free_sample_black
|
||||||
|
|
||||||
template_env: Optional[jinja2.Environment] = None
|
template_env: Optional[jinja2.Environment] = None
|
||||||
|
|
||||||
template: Optional[jinja2.Template] = None
|
data_template: Optional[jinja2.Template] = None
|
||||||
|
data_final_template: Optional[jinja2.Template] = None
|
||||||
locale_template: Optional[jinja2.Template] = None
|
locale_template: Optional[jinja2.Template] = None
|
||||||
control_template: Optional[jinja2.Template] = None
|
control_template: Optional[jinja2.Template] = None
|
||||||
|
|
||||||
|
@ -43,14 +44,14 @@ recipe_time_scales = {
|
||||||
|
|
||||||
|
|
||||||
def generate_mod(world: MultiWorld, player: int):
|
def generate_mod(world: MultiWorld, player: int):
|
||||||
global template, locale_template, control_template
|
global data_final_template, locale_template, control_template, data_template
|
||||||
with template_load_lock:
|
with template_load_lock:
|
||||||
if not template:
|
if not data_final_template:
|
||||||
mod_template_folder = Utils.local_path("data", "factorio", "mod_template")
|
mod_template_folder = Utils.local_path("data", "factorio", "mod_template")
|
||||||
template_env: Optional[jinja2.Environment] = \
|
template_env: Optional[jinja2.Environment] = \
|
||||||
jinja2.Environment(loader=jinja2.FileSystemLoader([mod_template_folder]))
|
jinja2.Environment(loader=jinja2.FileSystemLoader([mod_template_folder]))
|
||||||
|
data_template = template_env.get_template("data.lua")
|
||||||
template = template_env.get_template("data-final-fixes.lua")
|
data_final_template = template_env.get_template("data-final-fixes.lua")
|
||||||
locale_template = template_env.get_template(r"locale/en/locale.cfg")
|
locale_template = template_env.get_template(r"locale/en/locale.cfg")
|
||||||
control_template = template_env.get_template("control.lua")
|
control_template = template_env.get_template("control.lua")
|
||||||
# get data for templates
|
# get data for templates
|
||||||
|
@ -83,16 +84,19 @@ def generate_mod(world: MultiWorld, player: int):
|
||||||
template_data[factorio_option] = getattr(world, factorio_option)[player].value
|
template_data[factorio_option] = getattr(world, factorio_option)[player].value
|
||||||
|
|
||||||
control_code = control_template.render(**template_data)
|
control_code = control_template.render(**template_data)
|
||||||
data_final_fixes_code = template.render(**template_data)
|
data_template_code = data_template.render(**template_data)
|
||||||
|
data_final_fixes_code = data_final_template.render(**template_data)
|
||||||
|
|
||||||
mod_dir = Utils.output_path(mod_name) + "_" + Utils.__version__
|
mod_dir = Utils.output_path(mod_name) + "_" + Utils.__version__
|
||||||
en_locale_dir = os.path.join(mod_dir, "locale", "en")
|
en_locale_dir = os.path.join(mod_dir, "locale", "en")
|
||||||
os.makedirs(en_locale_dir, exist_ok=True)
|
os.makedirs(en_locale_dir, exist_ok=True)
|
||||||
shutil.copytree(Utils.local_path("data", "factorio", "mod"), mod_dir, dirs_exist_ok=True)
|
shutil.copytree(Utils.local_path("data", "factorio", "mod"), mod_dir, dirs_exist_ok=True)
|
||||||
|
with open(os.path.join(mod_dir, "data.lua"), "wt") as f:
|
||||||
|
f.write(data_template_code)
|
||||||
with open(os.path.join(mod_dir, "data-final-fixes.lua"), "wt") as f:
|
with open(os.path.join(mod_dir, "data-final-fixes.lua"), "wt") as f:
|
||||||
f.write(data_final_fixes_code)
|
f.write(data_final_fixes_code)
|
||||||
with open(os.path.join(mod_dir, "control.lua"), "wt") as f:
|
with open(os.path.join(mod_dir, "control.lua"), "wt") as f:
|
||||||
f.write(control_code)
|
f.write(control_code)
|
||||||
locale_content = locale_template.render(**template_data)
|
locale_content = locale_template.render(**template_data)
|
||||||
with open(os.path.join(en_locale_dir, "locale.cfg"), "wt") as f:
|
with open(os.path.join(en_locale_dir, "locale.cfg"), "wt") as f:
|
||||||
f.write(locale_content)
|
f.write(locale_content)
|
||||||
|
|
|
@ -73,6 +73,20 @@ class FactorioStartItems(OptionDict):
|
||||||
default = {"burner-mining-drill": 19, "stone-furnace": 19}
|
default = {"burner-mining-drill": 19, "stone-furnace": 19}
|
||||||
|
|
||||||
|
|
||||||
|
class FactorioWorldGen(OptionDict):
|
||||||
|
default = {"terrain_segmentation": 0.5, "water": 1.5,
|
||||||
|
"autoplace_controls": {"coal": {"frequency": 1, "size": 3, "richness": 6},
|
||||||
|
"copper-ore": {"frequency": 1, "size": 3, "richness": 6},
|
||||||
|
"crude-oil": {"frequency": 1, "size": 3, "richness": 6},
|
||||||
|
"enemy-base": {"frequency": 1, "size": 1, "richness": 1},
|
||||||
|
"iron-ore": {"frequency": 1, "size": 3, "richness": 6},
|
||||||
|
"stone": {"frequency": 1, "size": 3, "richness": 6},
|
||||||
|
"trees": {"frequency": 1, "size": 1, "richness": 1},
|
||||||
|
"uranium-ore": {"frequency": 1, "size": 3, "richness": 6}},
|
||||||
|
"starting_area": 1, "peaceful_mode": False,
|
||||||
|
"cliff_settings": {"name": "cliff", "cliff_elevation_0": 10, "cliff_elevation_interval": 40,
|
||||||
|
"richness": 1}}
|
||||||
|
|
||||||
factorio_options: typing.Dict[str, type(Option)] = {
|
factorio_options: typing.Dict[str, type(Option)] = {
|
||||||
"max_science_pack": MaxSciencePack,
|
"max_science_pack": MaxSciencePack,
|
||||||
"tech_tree_layout": TechTreeLayout,
|
"tech_tree_layout": TechTreeLayout,
|
||||||
|
@ -82,4 +96,5 @@ factorio_options: typing.Dict[str, type(Option)] = {
|
||||||
"starting_items": FactorioStartItems,
|
"starting_items": FactorioStartItems,
|
||||||
"recipe_time": RecipeTime,
|
"recipe_time": RecipeTime,
|
||||||
"imported_blueprints": DefaultOnToggle,
|
"imported_blueprints": DefaultOnToggle,
|
||||||
|
"world_gen": FactorioWorldGen
|
||||||
}
|
}
|
|
@ -23,6 +23,9 @@ class Factorio(World):
|
||||||
self.world.get_location(tech_name, self.player).place_locked_item(tech_item)
|
self.world.get_location(tech_name, self.player).place_locked_item(tech_item)
|
||||||
else:
|
else:
|
||||||
self.world.itempool.append(tech_item)
|
self.world.itempool.append(tech_item)
|
||||||
|
world_gen = self.world.world_gen[self.player].value
|
||||||
|
if world_gen.get("seed", None) is None: # allow seed 0
|
||||||
|
world_gen["seed"] = self.world.slot_seeds[self.player].randint(0, 2**32-1) # 32 bit uint
|
||||||
|
|
||||||
def generate_output(self):
|
def generate_output(self):
|
||||||
generate_mod(self.world, self.player)
|
generate_mod(self.world, self.player)
|
||||||
|
|
Loading…
Reference in New Issue