From 254fc5a90c699fa0deb326b59e1111becda126a4 Mon Sep 17 00:00:00 2001 From: Someone Date: Tue, 22 Oct 2024 12:42:51 +0200 Subject: [PATCH] RELEASE 2.0.0 - Initial compatibility with Factorio 2.0 --- changelog.txt | 7 ++++++ control.lua | 53 ++++++++++++++++++++++++-------------------- data-final-fixes.lua | 10 ++++----- info.json | 6 ++--- settings.lua | 4 ++-- 5 files changed, 46 insertions(+), 34 deletions(-) diff --git a/changelog.txt b/changelog.txt index 6606a68..83f1c2b 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,3 +1,10 @@ +--------------------------------------------------------------------------------------------------- +Version: 2.0.0 +Date: 2024-10-21 + + Changed: + - Initial compatibility with Factorio 2.0 + --------------------------------------------------------------------------------------------------- Version: 1.1.4 Date: 2024-01-06 diff --git a/control.lua b/control.lua index 5758fbb..e34ea1c 100644 --- a/control.lua +++ b/control.lua @@ -1,15 +1,13 @@ -function getConfig(force, config_changed) - if not global.auto_research_config then - global.auto_research_config = {} +local auto_research_config = {} - -- Disable Research Queue popup - if remote.interfaces.RQ and remote.interfaces.RQ["popup"] then - remote.call("RQ", "popup", false) - end +function getConfig(force, config_changed) + -- Disable Research Queue popup + if remote.interfaces.RQ and remote.interfaces.RQ["popup"] then + remote.call("RQ", "popup", false) end - if not global.auto_research_config[force.name] then - global.auto_research_config[force.name] = { + if not auto_research_config[force.name] then + auto_research_config[force.name] = { prioritized_techs = {}, -- "prioritized" is "queued". kept for backwards compatability (because i'm lazy and don't want migration code) deprioritized_techs = {} -- "deprioritized" is "blacklisted". kept for backwards compatability (because i'm lazy and don't want migration code) } @@ -27,27 +25,27 @@ function getConfig(force, config_changed) end -- set research strategy - global.auto_research_config[force.name].research_strategy = global.auto_research_config[force.name].research_strategy or "balanced" + auto_research_config[force.name].research_strategy = auto_research_config[force.name].research_strategy or "balanced" - if config_changed or not global.auto_research_config[force.name].allowed_ingredients or not global.auto_research_config[force.name].infinite_research then + if config_changed or not auto_research_config[force.name].allowed_ingredients or not auto_research_config[force.name].infinite_research then -- remember any old ingredients local old_ingredients = {} - if global.auto_research_config[force.name].allowed_ingredients then - for name, enabled in pairs(global.auto_research_config[force.name].allowed_ingredients) do + if auto_research_config[force.name].allowed_ingredients then + for name, enabled in pairs(auto_research_config[force.name].allowed_ingredients) do old_ingredients[name] = enabled end end -- find all possible tech ingredients -- also scan for research that are infinite: techs that have no successor and tech.research_unit_count_formula is not nil - global.auto_research_config[force.name].allowed_ingredients = {} - global.auto_research_config[force.name].infinite_research = {} + auto_research_config[force.name].allowed_ingredients = {} + auto_research_config[force.name].infinite_research = {} local finite_research = {} for _, tech in pairs(force.technologies) do for _, ingredient in pairs(tech.research_unit_ingredients) do - global.auto_research_config[force.name].allowed_ingredients[ingredient.name] = (old_ingredients[ingredient.name] == nil or old_ingredients[ingredient.name]) + auto_research_config[force.name].allowed_ingredients[ingredient.name] = (old_ingredients[ingredient.name] == nil or old_ingredients[ingredient.name]) end if tech.research_unit_count_formula then - global.auto_research_config[force.name].infinite_research[tech.name] = tech + auto_research_config[force.name].infinite_research[tech.name] = tech end for _, pretech in pairs(tech.prerequisites) do if pretech.enabled and not pretech.researched then @@ -56,11 +54,11 @@ function getConfig(force, config_changed) end end for techname, _ in pairs(finite_research) do - global.auto_research_config[force.name].infinite_research[techname] = nil + auto_research_config[force.name].infinite_research[techname] = nil end end - return global.auto_research_config[force.name] + return auto_research_config[force.name] end function setAutoResearch(force, enabled) @@ -69,7 +67,6 @@ function setAutoResearch(force, enabled) end local config = getConfig(force) config.enabled = enabled - force.research_queue_enabled = not enabled if enabled then -- start new research @@ -219,7 +216,15 @@ function startNextResearch(force, override_spam_detection) end if next_research then - force.add_research(next_research) + local rq = {} + table.insert(rq, next_research) + + for i=1,6 do + if force.research_queue[i] == nil then break end + table.insert(rq, force.research_queue[i]) + end + + force.research_queue = rq end end @@ -502,7 +507,7 @@ gui = { } end local sprite = "auto_research_tool_" .. ingredientname - if not player.gui.is_valid_sprite_path(sprite) then + if not helpers.is_valid_sprite_path(sprite) then sprite = "auto_research_unknown" end ingredientflow.add{type = "sprite-button", style = "auto_research_sprite_button_toggle" .. (allowed and "_pressed" or ""), name = "auto_research_allow_ingredient-" .. ingredientname, tooltip = {"item-name." .. ingredientname}, sprite = sprite} @@ -533,7 +538,7 @@ gui = { entryflow.add{type = "label", style = "auto_research_tech_label", caption = tech.localised_name} for _, ingredient in pairs(tech.research_unit_ingredients) do local sprite = "auto_research_tool_" .. ingredient.name - if not player.gui.is_valid_sprite_path(sprite) then + if not helpers.is_valid_sprite_path(sprite) then sprite = "auto_research_unknown" end entryflow.add{type = "sprite", style = "auto_research_sprite", sprite = sprite} @@ -659,7 +664,7 @@ gui = { entryflow.add{type = "label", style = "auto_research_tech_label", name = name, caption = tech.localised_name} for _, ingredient in pairs(tech.research_unit_ingredients) do local sprite = "auto_research_tool_" .. ingredient.name - if not player.gui.is_valid_sprite_path(sprite) then + if not helpers.is_valid_sprite_path(sprite) then sprite = "auto_research_unknown" end entryflow.add{type = "sprite", style = "auto_research_sprite", sprite = sprite} diff --git a/data-final-fixes.lua b/data-final-fixes.lua index c565c7e..9993d3b 100644 --- a/data-final-fixes.lua +++ b/data-final-fixes.lua @@ -1,15 +1,15 @@ -- dynamically add sprites for tools (to display research ingredients) for _, tool in pairs(data.raw.tool) do - if tool.icon or tool.icons then + if tool.icon then data:extend({ { type = "sprite", name = "auto_research_tool_" .. tool.name, - filename = tool.icon or (tool.icons[1] and tool.icons[1].icon) or nil, + filename = tool.icon or nil, priority = "extra-high-no-scale", - width = tool.icon_size or (tool.icons[1].icon_size) or 32, - height = tool.icon_size or (tool.icons[1].icon_size) or 32, - scale = 32/(tool.icon_size or (tool.icons[1].icon_size) or 32) + width = tool.icon_size or 64, + height = tool.icon_size or 64, + scale = 64/(tool.icon_size or 64) } }) end diff --git a/info.json b/info.json index e9d5b1c..1b0508f 100644 --- a/info.json +++ b/info.json @@ -1,13 +1,13 @@ { "name": "some-autoresearch", - "version": "1.1.4", + "version": "2.0.0", "title": "Auto Research (fixed + re-published)", "author": "Someone (originally canidae)", "homepage": "https://git.somenet.org/factorio/some-autoresearch.git", "description": "Automates research. Toggle GUI with Shift+T (customizable).", - "factorio_version": "1.1", + "factorio_version": "2.0", "dependencies": [ - "base>=1.1.0", + "base>=2.0.0", "! factorio-research-queue", "! sonaxaton-research-queue" diff --git a/settings.lua b/settings.lua index b1c66cd..20e2008 100644 --- a/settings.lua +++ b/settings.lua @@ -1,7 +1,7 @@ data:extend({ { type = "string-setting", - allow_blank = "true", + allow_blank = true, name = "queued-tech-setting", setting_type = "runtime-per-user", default_value = "", @@ -9,7 +9,7 @@ data:extend({ }, { type = "string-setting", - allow_blank = "true", + allow_blank = true, name = "blacklisted-tech-setting", setting_type = "runtime-per-user", default_value = "", -- 2.43.0