Factorio: move info dump to https://mods.factorio.com/mod/archipelago-extractor
This commit is contained in:
parent
b7327138f3
commit
4fe10b88b3
|
@ -77,22 +77,23 @@ class FactorioContext(CommonContext):
|
|||
|
||||
|
||||
async def game_watcher(ctx: FactorioContext):
|
||||
research_logger = logging.getLogger("FactorioWatcher")
|
||||
researches_done_file = os.path.join(script_folder, "research_done.json")
|
||||
if os.path.exists(researches_done_file):
|
||||
os.remove(researches_done_file)
|
||||
bridge_logger = logging.getLogger("FactorioWatcher")
|
||||
bridge_file = os.path.join(script_folder, "ap_bridge.json")
|
||||
if os.path.exists(bridge_file):
|
||||
os.remove(bridge_file)
|
||||
from worlds.factorio.Technologies import lookup_id_to_name
|
||||
bridge_counter = 0
|
||||
try:
|
||||
while 1:
|
||||
if os.path.exists(researches_done_file):
|
||||
research_logger.info("Found Factorio Bridge file.")
|
||||
if os.path.exists(bridge_file):
|
||||
bridge_logger.info("Found Factorio Bridge file.")
|
||||
while 1:
|
||||
with open(researches_done_file) as f:
|
||||
with open(bridge_file) as f:
|
||||
data = json.load(f)
|
||||
research_data = {int(tech_name.split("-")[1]) for tech_name in data if tech_name.startswith("ap-")}
|
||||
research_data = data["research_done"]
|
||||
research_data = {int(tech_name.split("-")[1]) for tech_name in research_data}
|
||||
if ctx.locations_checked != research_data:
|
||||
research_logger.info(f"New researches done: "
|
||||
bridge_logger.info(f"New researches done: "
|
||||
f"{[lookup_id_to_name[rid] for rid in research_data - ctx.locations_checked]}")
|
||||
ctx.locations_checked = research_data
|
||||
await ctx.send_msgs([{"cmd": 'LocationChecks', "locations": tuple(research_data)}])
|
||||
|
@ -100,8 +101,8 @@ async def game_watcher(ctx: FactorioContext):
|
|||
else:
|
||||
bridge_counter += 1
|
||||
if bridge_counter >= 60:
|
||||
research_logger.info("Did not find Factorio Bridge file, waiting for mod to run.")
|
||||
bridge_counter = 1
|
||||
bridge_logger.info("Did not find Factorio Bridge file, waiting for mod to run, which requires the server to run, which requires a player to be connected.")
|
||||
bridge_counter = 0
|
||||
await asyncio.sleep(1)
|
||||
except Exception as e:
|
||||
logging.exception(e)
|
||||
|
|
|
@ -1,6 +1,11 @@
|
|||
require "lib"
|
||||
script.on_event(defines.events.on_player_created, function(event)
|
||||
game.players[event.player_index].force.research_queue_enabled = true
|
||||
local player = game.players[event.player_index]
|
||||
player.force.research_queue_enabled = true
|
||||
{% if free_samples %}
|
||||
player.insert({count=19, name="burner-mining-drill"})
|
||||
player.insert({count=19, name="stone-furnace"})
|
||||
{% endif %}
|
||||
end)
|
||||
|
||||
-- for testing
|
||||
|
@ -42,80 +47,23 @@ script.on_event(defines.events.on_research_finished, function(event)
|
|||
end)
|
||||
|
||||
function dumpTech(force)
|
||||
local data_collection = {}
|
||||
local research_done = {}
|
||||
local data_collection = {["research_done"] = research_done}
|
||||
|
||||
for tech_name, tech in pairs(force.technologies) do
|
||||
if tech.researched and string.find(tech_name, "ap-") == 1 then
|
||||
data_collection[tech_name] = tech.researched
|
||||
end
|
||||
end
|
||||
game.write_file("research_done.json", game.table_to_json(data_collection), false)
|
||||
game.write_file("ap_bridge.json", game.table_to_json(data_collection), false)
|
||||
-- game.write_file("research_done.json", game.table_to_json(data_collection), false, 0)
|
||||
-- game.print("Sent progress to Archipelago.")
|
||||
end
|
||||
|
||||
function dumpGameInfo()
|
||||
-- dump Game Information that the Archipelago Randomizer needs.
|
||||
local data_collection = {}
|
||||
local force = game.forces["player"]
|
||||
for tech_name, tech in pairs(force.technologies) do
|
||||
if tech.enabled and tech.research_unit_count_formula == nil then
|
||||
local tech_data = {}
|
||||
local unlocks = {}
|
||||
tech_data["unlocks"] = unlocks
|
||||
local requires = {}
|
||||
tech_data["requires"] = requires
|
||||
local ingredients = {}
|
||||
tech_data["ingredients"] = ingredients
|
||||
for tech_requirement, _ in pairs(tech.prerequisites) do
|
||||
table.insert(requires, tech_requirement)
|
||||
end
|
||||
for _, modifier in pairs(tech.effects) do
|
||||
if modifier.type == "unlock-recipe" then
|
||||
table.insert(unlocks, modifier.recipe)
|
||||
end
|
||||
end
|
||||
for _, ingredient in pairs(tech.research_unit_ingredients) do
|
||||
table.insert(ingredients, ingredient.name)
|
||||
end
|
||||
data_collection[tech_name] = tech_data
|
||||
|
||||
end
|
||||
game.write_file("techs.json", game.table_to_json(data_collection), false)
|
||||
game.print("Exported Tech Data")
|
||||
end
|
||||
data_collection = {}
|
||||
for recipe_name, recipe in pairs(force.recipes) do
|
||||
local recipe_data = {}
|
||||
recipe_data["ingredients"] = {}
|
||||
recipe_data["products"] = {}
|
||||
recipe_data["category"] = recipe.category
|
||||
for _, ingredient in pairs(recipe.ingredients) do
|
||||
table.insert(recipe_data["ingredients"], ingredient.name)
|
||||
end
|
||||
for _, product in pairs(recipe.products) do
|
||||
table.insert(recipe_data["products"], product.name)
|
||||
end
|
||||
data_collection[recipe_name] = recipe_data
|
||||
end
|
||||
game.write_file("recipes.json", game.table_to_json(data_collection), false)
|
||||
game.print("Exported Recipe Data")
|
||||
-- data.raw can't be accessed from control.lua, need to find a better method
|
||||
-- data_collection = {}
|
||||
-- for machine_name, machine in pairs(data.raw["assembling_machine"]) do
|
||||
-- local machine_data = {}
|
||||
-- machine_data["categories"] = table.deepcopy(machine.crafting_categories)
|
||||
-- data_collection[machine.name] = machine_data
|
||||
-- end
|
||||
-- game.write_file("machines.json", game.table_to_json(data_collection), false)
|
||||
-- game.print("Exported Machine Data")
|
||||
end
|
||||
|
||||
-- add / commands
|
||||
|
||||
commands.add_command("ap-get-info-dump", "Dump Game Info, used by Archipelago.", function(call)
|
||||
dumpGameInfo()
|
||||
end)
|
||||
|
||||
commands.add_command("ap-sync", "Run manual Research Sync with Archipelago.", function(call)
|
||||
dumpTech(game.players[call.player_index].force)
|
||||
game.print("Wrote bridge file.")
|
||||
|
|
Loading…
Reference in New Issue