Move Factorio data from /data/factorio to /worlds/factorio/data, to contain it in its world folder

This commit is contained in:
Fabian Dill
2021-07-31 15:13:55 +02:00
parent 7f8617d639
commit abf4e82737
18 changed files with 5 additions and 4 deletions

View File

@@ -1 +0,0 @@
{"stone-furnace":{"smelting":true},"steel-furnace":{"smelting":true},"electric-furnace":{"smelting":true},"assembling-machine-1":{"crafting":true,"basic-crafting":true,"advanced-crafting":true},"assembling-machine-2":{"basic-crafting":true,"crafting":true,"advanced-crafting":true,"crafting-with-fluid":true},"assembling-machine-3":{"basic-crafting":true,"crafting":true,"advanced-crafting":true,"crafting-with-fluid":true},"oil-refinery":{"oil-processing":true},"chemical-plant":{"chemistry":true},"centrifuge":{"centrifuging":true},"rocket-silo":{"rocket-building":true},"character":{"crafting":true}}

View File

@@ -1,22 +0,0 @@
The MIT License (MIT)
Copyright (c) 2021 Berserker55 and Dewiniaid
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 31 KiB

View File

@@ -1,9 +0,0 @@
{
"name": "archipelago-client",
"version": "0.0.1",
"title": "Archipelago",
"author": "Berserker and Dewiniaid",
"homepage": "https://archipelago.gg",
"description": "Integration client for the Archipelago Randomizer",
"factorio_version": "1.1"
}

View File

@@ -1,35 +0,0 @@
function filter_ingredients(ingredients, ingredient_filter)
local new_ingredient_list = {}
for _, ingredient_table in pairs(ingredients) do
if ingredient_filter[ingredient_table[1]] then -- name of ingredient_table
table.insert(new_ingredient_list, ingredient_table)
end
end
return new_ingredient_list
end
function get_any_stack_size(name)
local item = game.item_prototypes[name]
if item ~= nil then
return item.stack_size
end
item = game.equipment_prototypes[name]
if item ~= nil then
return item.stack_size
end
-- failsafe
return 1
end
-- from https://stackoverflow.com/a/40180465
-- split("a,b,c", ",") => {"a", "b", "c"}
function split(s, sep)
local fields = {}
sep = sep or " "
local pattern = string.format("([^%s]+)", sep)
string.gsub(s, pattern, function(c) fields[#fields + 1] = c end)
return fields
end

Binary file not shown.

Before

Width:  |  Height:  |  Size: 34 KiB

View File

@@ -1,272 +0,0 @@
{% from "macros.lua" import dict_to_lua %}
-- this file gets written automatically by the Archipelago Randomizer and is in its raw form a Jinja2 Template
require "lib"
require "util"
FREE_SAMPLES = {{ free_samples }}
SLOT_NAME = "{{ slot_name }}"
SEED_NAME = "{{ seed_name }}"
FREE_SAMPLE_BLACKLIST = {{ dict_to_lua(free_sample_blacklist) }}
{% if not imported_blueprints -%}
function set_permissions()
local group = game.permissions.get_group("Default")
group.set_allows_action(defines.input_action.open_blueprint_library_gui, false)
group.set_allows_action(defines.input_action.import_blueprint, false)
group.set_allows_action(defines.input_action.import_blueprint_string, false)
group.set_allows_action(defines.input_action.import_blueprints_filtered, false)
end
{%- endif %}
-- Initialize force data, either from it being created or already being part of the game when the mod was added.
function on_force_created(event)
--event.force appears to be LuaForce.name, not LuaForce
game.forces[event.force].research_queue_enabled = true
local data = {}
data['earned_samples'] = {{ dict_to_lua(starting_items) }}
data["victory"] = 0
global.forcedata[event.force] = data
end
script.on_event(defines.events.on_force_created, on_force_created)
-- Destroy force data. This doesn't appear to be currently possible with the Factorio API, but here for completeness.
function on_force_destroyed(event)
global.forcedata[event.force.name] = nil
end
-- Initialize player data, either from them joining the game or them already being part of the game when the mod was
-- added.`
function on_player_created(event)
local player = game.players[event.player_index]
-- FIXME: This (probably) fires before any other mod has a chance to change the player's force
-- For now, they will (probably) always be on the 'player' force when this event fires.
local data = {}
data['pending_samples'] = table.deepcopy(global.forcedata[player.force.name]['earned_samples'])
global.playerdata[player.index] = data
update_player(player.index) -- Attempt to send pending free samples, if relevant.
end
script.on_event(defines.events.on_player_created, on_player_created)
function on_player_removed(event)
global.playerdata[event.player_index] = nil
end
script.on_event(defines.events.on_player_removed, on_player_removed)
function on_rocket_launched(event)
global.forcedata[event.rocket.force.name]['victory'] = 1
dumpInfo(event.rocket.force)
end
script.on_event(defines.events.on_rocket_launched, on_rocket_launched)
-- Updates a player, attempting to send them any pending samples (if relevant)
function update_player(index)
local player = game.players[index]
if not player or not player.valid then -- Do nothing if we reference an invalid player somehow
return
end
local character = player.character or player.cutscene_character
if not character or not character.valid then
return
end
local data = global.playerdata[index]
local samples = data['pending_samples']
local sent
--player.print(serpent.block(data['pending_samples']))
local stack = {}
for name, count in pairs(samples) do
stack.name = name
stack.count = count
if character.can_insert(stack) then
sent = character.insert(stack)
else
sent = 0
end
if sent > 0 then
player.print("Received " .. sent .. "x [item=" .. name .. "]")
data.suppress_full_inventory_message = false
end
if sent ~= count then -- Couldn't full send.
if not data.suppress_full_inventory_message then
player.print("Additional items will be sent when inventory space is available.", {r=1, g=1, b=0.25})
end
data.suppress_full_inventory_message = true -- Avoid spamming them with repeated full inventory messages.
samples[name] = count - sent -- Buffer the remaining items
break -- Stop trying to send other things
else
samples[name] = nil -- Remove from the list
end
end
end
-- Update players upon them connecting, since updates while they're offline are suppressed.
script.on_event(defines.events.on_player_joined_game, function(event) update_player(event.player_index) end)
function update_player_event(event)
update_player(event.player_index)
end
script.on_event(defines.events.on_player_main_inventory_changed, update_player_event)
function add_samples(force, name, count)
local function add_to_table(t)
t[name] = (t[name] or 0) + count
end
-- Add to global table of earned samples for future new players
add_to_table(global.forcedata[force.name]['earned_samples'])
-- Add to existing players
for _, player in pairs(force.players) do
add_to_table(global.playerdata[player.index]['pending_samples'])
update_player(player.index)
end
end
script.on_init(function()
{% if not imported_blueprints %}set_permissions(){% endif %}
global.forcedata = {}
global.playerdata = {}
-- Fire dummy events for all currently existing forces.
local e = {}
for name, _ in pairs(game.forces) do
e.force = name
on_force_created(e)
end
e.force = nil
-- Fire dummy events for all currently existing players.
for index, _ in pairs(game.players) do
e.player_index = index
on_player_created(e)
end
end)
-- hook into researches done
script.on_event(defines.events.on_research_finished, function(event)
local technology = event.research
if technology.researched and string.find(technology.name, "ap%-") == 1 then
dumpInfo(technology.force) --is sendable
else
if FREE_SAMPLES == 0 then
return -- Nothing else to do
end
if not technology.effects then
return -- No technology effects, so nothing to do.
end
for _, effect in pairs(technology.effects) do
if effect.type == "unlock-recipe" then
local recipe = game.recipe_prototypes[effect.recipe]
for _, result in pairs(recipe.products) do
if result.type == "item" and result.amount then
local name = result.name
if FREE_SAMPLE_BLACKLIST[name] ~= 1 then
local count
if FREE_SAMPLES == 1 then
count = result.amount
else
count = get_any_stack_size(result.name)
if FREE_SAMPLES == 2 then
count = math.ceil(count / 2)
end
end
add_samples(technology.force, name, count)
end
end
end
end
end
end
end)
function dumpInfo(force)
log("Archipelago Bridge Data available for game tick ".. game.tick .. ".") -- notifies client
end
function chain_lookup(table, ...)
for _, k in ipairs{...} do
table = table[k]
if not table then
return nil
end
end
return table
end
-- add / commands
commands.add_command("ap-sync", "Used by the Archipelago client to get progress information", function(call)
local force
if call.player_index == nil then
force = game.forces.player
else
force = game.players[call.player_index].force
end
local research_done = {}
local data_collection = {
["research_done"] = research_done,
["victory"] = chain_lookup(global, "forcedata", force.name, "victory"),
}
for tech_name, tech in pairs(force.technologies) do
if tech.researched and string.find(tech_name, "ap%-") == 1 then
research_done[tech_name] = tech.researched
end
end
rcon.print(game.table_to_json({["slot_name"] = SLOT_NAME, ["seed_name"] = SEED_NAME, ["info"] = data_collection}))
end)
commands.add_command("ap-print", "Used by the Archipelago client to print messages", function (call)
game.print(call.parameter)
end)
commands.add_command("ap-get-technology", "Grant a technology, used by the Archipelago Client.", function(call)
if global.index_sync == nil then
global.index_sync = {}
end
local tech
local force = game.forces["player"]
chunks = split(call.parameter, "\t")
local tech_name = chunks[1]
local index = chunks[2]
local source = chunks[3] or "Archipelago"
if progressive_technologies[tech_name] ~= nil then
if global.index_sync[index] == nil then -- not yet received prog item
global.index_sync[index] = tech_name
local tech_stack = progressive_technologies[tech_name]
for _, tech_name in ipairs(tech_stack) do
tech = force.technologies[tech_name]
if tech.researched ~= true then
game.print({"", "Received [technology=" .. tech.name .. "] from ", source})
game.play_sound({path="utility/research_completed"})
tech.researched = true
return
end
end
end
elseif force.technologies[tech_name] ~= nil then
tech = force.technologies[tech_name]
if tech ~= nil then
if global.index_sync[index] ~= nil and global.index_sync[index] ~= tech then
game.print("Warning: Desync Detected. Duplicate/Missing items may occur.")
end
global.index_sync[index] = tech
if tech.researched ~= true then
game.print({"", "Received [technology=" .. tech.name .. "] from ", source})
game.play_sound({path="utility/research_completed"})
tech.researched = true
end
end
else
game.print("Unknown Technology " .. tech_name)
end
end)
commands.add_command("ap-rcon-info", "Used by the Archipelago client to get information", function(call)
rcon.print(game.table_to_json({["slot_name"] = SLOT_NAME, ["seed_name"] = SEED_NAME}))
end)
-- data
progressive_technologies = {{ dict_to_lua(progressive_technology_table) }}

View File

@@ -1,109 +0,0 @@
{% from "macros.lua" import dict_to_recipe %}
-- this file gets written automatically by the Archipelago Randomizer and is in its raw form a Jinja2 Template
require('lib')
{%- for recipe_name, recipe in custom_recipes.items() %}
data.raw["recipe"]["{{recipe_name}}"].ingredients = {{ dict_to_recipe(recipe.ingredients) }}
{%- endfor %}
local technologies = data.raw["technology"]
local original_tech
local new_tree_copy
allowed_ingredients = {}
{%- for tech_name, technology in custom_technologies.items() %}
allowed_ingredients["{{ tech_name }}"] = {
{%- for ingredient in technology.ingredients %}
["{{ingredient}}"] = 1,
{%- endfor %}
}
{% endfor %}
local template_tech = table.deepcopy(technologies["automation"])
{#- ensure the copy unlocks nothing #}
template_tech.unlocks = {}
template_tech.upgrade = false
template_tech.effects = {}
template_tech.prerequisites = {}
function prep_copy(new_copy, old_tech)
old_tech.hidden = true
new_copy.unit = table.deepcopy(old_tech.unit)
local ingredient_filter = allowed_ingredients[old_tech.name]
if ingredient_filter ~= nil then
new_copy.unit.ingredients = filter_ingredients(new_copy.unit.ingredients, ingredient_filter)
end
end
function set_ap_icon(tech)
tech.icon = "__{{ mod_name }}__/graphics/icons/ap.png"
tech.icons = nil
tech.icon_size = 128
end
function set_ap_unimportant_icon(tech)
tech.icon = "__{{ mod_name }}__/graphics/icons/ap_unimportant.png"
tech.icons = nil
tech.icon_size = 128
end
function copy_factorio_icon(tech, tech_source)
tech.icon = table.deepcopy(technologies[tech_source].icon)
tech.icons = table.deepcopy(technologies[tech_source].icons)
tech.icon_size = table.deepcopy(technologies[tech_source].icon_size)
end
function adjust_energy(recipe_name, factor)
local recipe = data.raw.recipe[recipe_name]
local energy = recipe.energy_required
if (energy ~= nil) then
data.raw.recipe[recipe_name].energy_required = energy * factor
end
if (recipe.normal ~= nil and recipe.normal.energy_required ~= nil) then
energy = recipe.normal.energy_required
recipe.normal.energy_required = energy * factor
end
if (recipe.expensive ~= nil and recipe.expensive.energy_required ~= nil) then
energy = recipe.expensive.energy_required
recipe.expensive.energy_required = energy * factor
end
end
data.raw["assembling-machine"]["assembling-machine-1"].crafting_categories = table.deepcopy(data.raw["assembling-machine"]["assembling-machine-3"].crafting_categories)
data.raw["assembling-machine"]["assembling-machine-2"].crafting_categories = table.deepcopy(data.raw["assembling-machine"]["assembling-machine-3"].crafting_categories)
data.raw["assembling-machine"]["assembling-machine-1"].fluid_boxes = table.deepcopy(data.raw["assembling-machine"]["assembling-machine-2"].fluid_boxes)
data.raw["ammo"]["artillery-shell"].stack_size = 10
{# each randomized tech gets set to be invisible, with new nodes added that trigger those #}
{%- for original_tech_name, item_name, receiving_player, advancement in locations %}
original_tech = technologies["{{original_tech_name}}"]
{#- the tech researched by the local player #}
new_tree_copy = table.deepcopy(template_tech)
new_tree_copy.name = "ap-{{ tech_table[original_tech_name] }}-"{# use AP ID #}
prep_copy(new_tree_copy, original_tech)
{% if tech_cost_scale != 1 %}
new_tree_copy.unit.count = math.max(1, math.floor(new_tree_copy.unit.count * {{ tech_cost_scale }}))
{% endif %}
{%- if (tech_tree_information == 2 or original_tech_name in static_nodes) and item_name in base_tech_table -%}
{#- copy Factorio Technology Icon -#}
copy_factorio_icon(new_tree_copy, "{{ item_name }}")
{%- elif (tech_tree_information == 2 or original_tech_name in static_nodes) and item_name in progressive_technology_table -%}
copy_factorio_icon(new_tree_copy, "{{ progressive_technology_table[item_name][0] }}")
{%- else -%}
{#- use default AP icon if no Factorio graphics exist -#}
{% if advancement or not tech_tree_information %}set_ap_icon(new_tree_copy){% else %}set_ap_unimportant_icon(new_tree_copy){% endif %}
{%- endif -%}
{#- connect Technology #}
{%- if original_tech_name in tech_tree_layout_prerequisites %}
{%- for prerequesite in tech_tree_layout_prerequisites[original_tech_name] %}
table.insert(new_tree_copy.prerequisites, "ap-{{ tech_table[prerequesite] }}-")
{% endfor %}
{% endif -%}
{#- add new Technology to game #}
data:extend{new_tree_copy}
{% endfor %}
{% if recipe_time_scale %}
{%- for recipe_name, recipe in recipes.items() %}
{%- if recipe.category != "mining" %}
adjust_energy("{{ recipe_name }}", {{ random.triangular(*recipe_time_scale) }})
{%- endif %}
{%- endfor -%}
{% endif %}

View File

@@ -1,2 +0,0 @@
{% 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["basic"], "advanced_settings": world_gen["advanced"]}) }}

View File

@@ -1,25 +0,0 @@
[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]
{% for original_tech_name, item_name, receiving_player, advancement in locations %}
{%- if tech_tree_information == 2 or original_tech_name in static_nodes %}
ap-{{ tech_table[original_tech_name] }}-={{ player_names[receiving_player] }}'s {{ item_name }}
{%- else %}
ap-{{ tech_table[original_tech_name] }}-=An Archipelago Sendable
{%- endif -%}
{% endfor %}
[technology-description]
{% for original_tech_name, item_name, receiving_player, advancement in locations %}
{%- if tech_tree_information == 2 or original_tech_name in static_nodes %}
ap-{{ tech_table[original_tech_name] }}-=Researching this technology sends {{ item_name }} to {{ player_names[receiving_player] }}{% if advancement %}, which is considered a logical advancement{% endif %}.
{%- elif tech_tree_information == 1 and advancement %}
ap-{{ tech_table[original_tech_name] }}-=Researching this technology sends something to someone, which is considered a logical advancement. For purposes of hints, this location is called "{{ original_tech_name }}".
{%- else %}
ap-{{ tech_table[original_tech_name] }}-=Researching this technology sends something to someone. For purposes of hints, this location is called "{{ original_tech_name }}".
{%- endif -%}
{% endfor %}

View File

@@ -1,29 +0,0 @@
{% macro dict_to_lua(dict) -%}
{
{%- for key, value in dict.items() -%}
["{{ key }}"] = {{ variable_to_lua(value) }}{% if not loop.last %},{% endif %}
{% endfor -%}
}
{%- endmacro %}
{% macro list_to_lua(list) -%}
{
{%- for key in list -%}
{{ variable_to_lua(key) }}{% if not loop.last %},{% endif %}
{% endfor -%}
}
{%- 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 }}"
{%- elif value is iterable -%}{{ list_to_lua(value) }}
{%- else -%} {{ value | safe }}
{%- endif -%}
{%- endmacro -%}
{% macro dict_to_recipe(dict) -%}
{
{%- for key, value in dict.items() -%}
{"{{ key }}", {{ value | safe }}}{% if not loop.last %},{% endif %}
{% endfor -%}
}
{%- endmacro %}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long