From e861eeb20583173bb147ac56891d7945274a844b Mon Sep 17 00:00:00 2001 From: ZwerOxotnik Date: Tue, 22 Oct 2024 13:11:57 +0300 Subject: [PATCH] Update to 0.12.0 --- .editorconfig | 4 +-- .github/ISSUE_TEMPLATE/bug_report.md | 8 ++--- .vscode/settings.json | 2 +- changelog.txt | 5 +++ compiler.lua | 4 +-- constants.lua | 10 +++--- control.lua | 46 +++++++++++++------------ data.lua | 51 ++++++++++++++++------------ info.json | 4 +-- microcontroller.lua | 4 +-- stdlib/area/chunk.lua | 26 +++++++------- stdlib/area/tile.lua | 16 ++++----- stdlib/config/config.lua | 12 +++---- stdlib/entity/entity.lua | 20 +++++------ 14 files changed, 113 insertions(+), 99 deletions(-) diff --git a/.editorconfig b/.editorconfig index 1a20351..4da8392 100644 --- a/.editorconfig +++ b/.editorconfig @@ -13,7 +13,7 @@ trim_trailing_whitespace = true indent_style = tab insert_final_newline = true -[*.{txt,yml}] +[*.{txt,yml,json}] indent_style = space indent_size = 2 insert_final_newline = false @@ -24,7 +24,7 @@ indent_size = 2 insert_final_newline = true trim_trailing_whitespace = false -[*.{json,md}] +[*.md] indent_style = tab indent_size = 2 insert_final_newline = false diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index 6fa3409..c8d6954 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -7,17 +7,15 @@ assignees: ZwerOxotnik --- -Usually any information is enough to fix a bug, but, please, consider to provide more information now or **later**. - Please drop the `factorio-current.log` file or `factorio-previous.log` here **Describe the bug** **Steps to reproduce** -1. -2. -3. +1. +2. +3. **Expected behavior** diff --git a/.vscode/settings.json b/.vscode/settings.json index 7a847af..d68e41c 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -39,7 +39,7 @@ "table": "enable", "math": "enable", "string": "enable", - "package": "enable", + "package": "disable", "debug": "enable", "bit32": "disable", "io": "disable", diff --git a/changelog.txt b/changelog.txt index 8e6f713..f56f9b5 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,4 +1,9 @@ --------------------------------------------------------------------------------------------------- +Version: 0.12.0 +Date: 22. 10. 2024 + Bugfixes: + - Updated for Factorio 2.0 +--------------------------------------------------------------------------------------------------- Version: 0.11.2 Date: 06. 05. 2023 Bugfixes: diff --git a/compiler.lua b/compiler.lua index ee68a95..e46975a 100644 --- a/compiler.lua +++ b/compiler.lua @@ -119,8 +119,8 @@ end --- Evaluates an AST. local function eval( ast, control, memory, modules, program_counter, clock ) local wires = {} - wires.red = control.get_circuit_network(defines.wire_type.red, defines.circuit_connector_id.combinator_input) - wires.green = control.get_circuit_network(defines.wire_type.green, defines.circuit_connector_id.combinator_input) + wires.red = control.get_circuit_network(defines.wire_connector_id.combinator_input_red) + wires.green = control.get_circuit_network(defines.wire_connector_id.combinator_input_green) local node, num -- Assertion Helper Functions diff --git a/constants.lua b/constants.lua index c928995..39c3433 100644 --- a/constants.lua +++ b/constants.lua @@ -1,9 +1,9 @@ -NULL_SIGNAL = {signal = { type = "virtual", name = "signal-black" }, count = 0} -HALT_SIGNAL = {signal = { type = "virtual", name = "signal-mc-halt"}, count = 1} -RUN_SIGNAL = {signal = { type = "virtual", name = "signal-mc-run"}, count = 1} -STEP_SIGNAL = {signal = { type = "virtual", name = "signal-mc-step"}, count = 1} +NULL_SIGNAL = {signal = { type = "virtual", name = "signal-black" }, count = 0} +HALT_SIGNAL = {signal = { type = "virtual", name = "signal-mc-halt"} , count = 1} +RUN_SIGNAL = {signal = { type = "virtual", name = "signal-mc-run"}, count = 1} +STEP_SIGNAL = {signal = { type = "virtual", name = "signal-mc-step"}, count = 1} SLEEP_SIGNAL = {signal = { type = "virtual", name = "signal-mc-sleep"}, count = 1} -JUMP_SIGNAL = {signal = { type = "virtual", name = "signal-mc-jump"}, count = 1} +JUMP_SIGNAL = {signal = { type = "virtual", name = "signal-mc-jump"}, count = 1} OP_NOP = {type = 'nop'} -- {type = "instruction", name = ""} diff --git a/control.lua b/control.lua index 49e7ba3..91c2f96 100644 --- a/control.lua +++ b/control.lua @@ -9,12 +9,12 @@ require('stdlib/area/tile') function get_player_data(player_index) - local player_data = global.player_data[player_index] or {} + local player_data = storage.player_data[player_index] or {} return player_data end function set_player_data(player_index, data) - global.player_data[player_index] = data + storage.player_data[player_index] = data end @@ -78,20 +78,20 @@ end -- Handle Entity built event. script.on_event({defines.events.on_built_entity, defines.events.on_robot_built_entity}, function(event) - local entity = event.created_entity + local entity = event.entity if not (entity and entity.valid) then return end if entity.name == "microcontroller" then -- Init and insert new microcontroller to global state. microcontroller.init(entity, {}) local didFind = false - for _, mc in ipairs(global.microcontrollers) do + for _, mc in ipairs(storage.microcontrollers) do if mc == entity then didFind = true end end if not didFind then - table.insert(global.microcontrollers, entity) + table.insert(storage.microcontrollers, entity) end attach_microcontroller(entity) @@ -290,7 +290,9 @@ script.on_event(microcontroller.event_halt, function(event) end) local function signalToSpritePath(signal) - if signal.type == "virtual" then + if signal.type == nil then + return "item/" .. signal.name + elseif signal.type == "virtual" then return "virtual-signal/" .. signal.name else return signal.type .. '/' .. signal.name @@ -305,8 +307,8 @@ script.on_nth_tick(update_tick_time, function() end -- Iterate through all stored microcontrollers. - for i = #global.microcontrollers, 1, -1 do - local mc = global.microcontrollers[i] + for i = #storage.microcontrollers, 1, -1 do + local mc = storage.microcontrollers[i] if mc.valid then local mc_state = Entity.get_data(mc) if mc_state then @@ -333,19 +335,19 @@ script.on_nth_tick(update_tick_time, function() -- Update the inspector GUI. if mc_state.inspector and mc_state.inspector.valid then - for i = 1, 4 do -- TODO: check with various entites - mc_state.inspector['mem'..i..'-inspect'].sprite = signalToSpritePath( mc_state.memory[i].signal) - mc_state.inspector['mem'..i..'-inspect'].number = mc_state.memory[i].count + for j = 1, 4 do -- TODO: check with various entites + mc_state.inspector['mem'..j..'-inspect'].sprite = signalToSpritePath(mc_state.memory[j].signal) + mc_state.inspector['mem'..j..'-inspect'].number = mc_state.memory[j].count end end end -- Check adjacent modules still exists. if mc_state.adjacent_modules ~= nil then - for i = 4, 1, -1 do - local module = mc_state.adjacent_modules[i] + for j = 4, 1, -1 do + local module = mc_state.adjacent_modules[j] if module and not module.valid then - mc_state.adjacent_modules[i] = nil + mc_state.adjacent_modules[j] = nil end end end @@ -365,7 +367,7 @@ script.on_nth_tick(update_tick_time, function() end set_player_data(player_index, player_data) end - table.remove(global.microcontrollers, i) + table.remove(storage.microcontrollers, i) end end end) @@ -400,10 +402,10 @@ function microcontrollerGui( player, entity ) local outerflow = gWindow.add{type = "table", name = "outer", column_count = 1} local buttons_row = outerflow.add{type = "flow", name = "buttons_row", column_count = 1} - state.gui_run_button = buttons_row.add{type = "sprite-button", name = "run-program", sprite = "microcontroller-play-sprite"} - state.gui_step_button = buttons_row.add{type = "sprite-button", name = "step-program", sprite = "microcontroller-next-sprite"} - state.gui_halt_button = buttons_row.add{type = "sprite-button", name = "halt-program", sprite = "microcontroller-stop-sprite"} - state.gui_copy_button = buttons_row.add{type = "sprite-button", name = "copy-program", sprite = "microcontroller-copy-sprite"} + state.gui_run_button = buttons_row.add{type = "sprite-button", name = "run-program", sprite = "microcontroller-play-sprite"} + state.gui_step_button = buttons_row.add{type = "sprite-button", name = "step-program", sprite = "microcontroller-next-sprite"} + state.gui_halt_button = buttons_row.add{type = "sprite-button", name = "halt-program", sprite = "microcontroller-stop-sprite"} + state.gui_copy_button = buttons_row.add{type = "sprite-button", name = "copy-program", sprite = "microcontroller-copy-sprite"} state.gui_paste_button = buttons_row.add{type = "sprite-button", name = "paste-program", sprite = "microcontroller-paste-sprite"} buttons_row.add{type = "sprite-button", name = "mc-help-button", sprite = "microcontroller-info-sprite"} state.gui_exit_button = buttons_row.add{type = "sprite-button", name = "close-microcontroller-window", sprite = "microcontroller-exit-sprite"} @@ -452,8 +454,8 @@ function microcontrollerGui( player, entity ) end function update_global_data() - global.microcontrollers = global.microcontrollers or {} - global.player_data = global.player_data or {} + storage.microcontrollers = storage.microcontrollers or {} + storage.player_data = storage.player_data or {} end Event.register(Event.core_events.init, update_global_data) @@ -466,7 +468,7 @@ script.on_configuration_changed(function(event) local version = tonumber(string.gmatch(mod_changes.old_version, "%d+.%d+")()) if version <= 0.9 then - for _, mc in pairs(global.microcontrollers) do + for _, mc in pairs(storage.microcontrollers) do if mc.valid then local control_behavior = mc.get_control_behavior() if control_behavior.parameters.second_constant == 0 then diff --git a/data.lua b/data.lua index d8ef852..7093158 100644 --- a/data.lua +++ b/data.lua @@ -60,7 +60,7 @@ data:extend{ {type = "unlock-recipe", recipe = "microcontroller"}, {type = "unlock-recipe", recipe = "microcontroller-ram"} }, - prerequisites = {"circuit-network", "advanced-electronics"}, + prerequisites = {"circuit-network", "advanced-circuit"}, unit = { count = 250, ingredients = { @@ -73,25 +73,34 @@ data:extend{ }, { type = "recipe", name = "microcontroller", + icon = "__m-microcontroller__/graphics/microchip.png", + icon_size = 32, enabled = false, - ingredients = {{"arithmetic-combinator", 3}, {"decider-combinator", 3}}, + ingredients = { + {type = "item", name = "arithmetic-combinator", amount = 3}, + {type = "item", name = "decider-combinator", amount = 3}, + }, energy_required = 1, - results = {{"microcontroller", 1}} + results = {{type = "item", name = "microcontroller", amount = 1}}, }, { type = "recipe", name = "microcontroller-ram", + icon = "__m-microcontroller__/graphics/ram.png", + icon_size = 32, enabled = false, - ingredients = {{"arithmetic-combinator", 3}, {"advanced-circuit", 2}}, + ingredients = { + {type = "item", name = "arithmetic-combinator", amount = 3}, + {type = "item", name = "advanced-circuit", amount = 2}, + }, energy_required = 1, - results = {{"microcontroller-ram", 1}} + results = {{type = "item", name = "microcontroller-ram", amount = 1}}, }, {type = "custom-input", name = "microcontroller-close", key_sequence = "E"}, {type = "font", name = "default-mono", from = "default-mono", size = 16} } -local function gen_tech(no,nb_packs_type,nb_packs,time,prerequisites) +local function gen_tech(no, nb_packs_type, nb_packs, time, prerequisites) local ingredients = { - {"automation-science-pack", 1}, {"logistic-science-pack", 1}, {"chemical-science-pack", 1}, {"production-science-pack", 1}, @@ -99,12 +108,12 @@ local function gen_tech(no,nb_packs_type,nb_packs,time,prerequisites) {"space-science-pack", 1} } while(#ingredients > nb_packs_type) do - table.remove(ingredients,#ingredients) + table.remove(ingredients, #ingredients) end local unit={ - count=nb_packs, - time=time, - ingredients=ingredients + count = nb_packs, + time = time, + ingredients = ingredients } local name="microcontroller-program-size-" .. no local order="c-g-b-" .. string.char(96+no) @@ -114,24 +123,24 @@ local function gen_tech(no,nb_packs_type,nb_packs,time,prerequisites) return { type = "technology", name = name, - icon_size=128, + icon_size = 128, icon="__m-microcontroller__/graphics/microchip_large.png", prerequisites = prerequisites, effects = {}, + upgrade = true, unit = unit, - order = order + order = order, } end -local infinite_tech=gen_tech(4,6,0,60,{"space-science-pack"}) -infinite_tech.unit.count_formula="(L-3)*1000" -infinite_tech.unit.count=nil -infinite_tech.max_level="infinite" -infinite_tech.upgrade="true" +local infinite_tech = gen_tech(4,6,0,60, {"space-science-pack"}) +infinite_tech.unit.count_formula = "(L-3)*1000" +infinite_tech.unit.count = nil +infinite_tech.max_level = "infinite" data:extend{ - gen_tech(1,3,300,40,{"microcontroller","chemical-science-pack"}), - gen_tech(2,4,500,45,{"production-science-pack"}), - gen_tech(3,5,750,50,{"utility-science-pack"}), + gen_tech(1,3,300,40, {"microcontroller","chemical-science-pack"}), + gen_tech(2,4,500,45, {"production-science-pack"}), + gen_tech(3,5,750,50, {"utility-science-pack"}), infinite_tech } diff --git a/info.json b/info.json index 462a22b..8cbce53 100644 --- a/info.json +++ b/info.json @@ -1,7 +1,7 @@ { "name": "m-microcontroller", - "version": "0.11.2", - "factorio_version": "1.1", + "version": "0.12.0", + "factorio_version": "2.0", "title": "MicroController", "author": "Luke Perkin", "contact": "zweroxotnik@gmail.com, lukeperkin@gmail.com", diff --git a/microcontroller.lua b/microcontroller.lua index eaf8c2c..8ca7302 100644 --- a/microcontroller.lua +++ b/microcontroller.lua @@ -133,8 +133,8 @@ function microcontroller.tick( mc, state ) -- Interrupts local control = mc.get_control_behavior() - local red_input = control.get_circuit_network(defines.wire_type.red, defines.circuit_connector_id.combinator_input) - local green_input = control.get_circuit_network(defines.wire_type.green, defines.circuit_connector_id.combinator_input) + local red_input = control.get_circuit_network(defines.wire_connector_id.combinator_input_red) + local green_input = control.get_circuit_network(defines.wire_connector_id.combinator_input_green) local get_signal = function(signal) if red_input then local result = red_input.get_signal(signal.signal) diff --git a/stdlib/area/chunk.lua b/stdlib/area/chunk.lua index c8e7b55..4980b3f 100644 --- a/stdlib/area/chunk.lua +++ b/stdlib/area/chunk.lua @@ -48,15 +48,15 @@ end function Chunk.get_data(surface, chunk_pos, default_value) fail_if_missing(surface, "missing surface argument") fail_if_missing(chunk_pos, "missing chunk_pos argument") - if not global._chunk_data then + if not storage._chunk_data then if not default_value then return nil end - global._chunk_data = {} + storage._chunk_data = {} end local idx = Chunk.get_index(surface, chunk_pos) - local val = global._chunk_data[idx] + local val = storage._chunk_data[idx] if not val then - global._chunk_data[idx] = default_value + storage._chunk_data[idx] = default_value val = default_value end @@ -72,11 +72,11 @@ end function Chunk.set_data(surface, chunk_pos, data) fail_if_missing(surface, "missing surface argument") fail_if_missing(chunk_pos, "missing chunk_pos argument") - if not global._chunk_data then global._chunk_data = {} end + if not storage._chunk_data then storage._chunk_data = {} end local idx = Chunk.get_index(surface, chunk_pos) - local prev = global._chunk_data[idx] - global._chunk_data[idx] = data + local prev = storage._chunk_data[idx] + storage._chunk_data[idx] = data return prev end @@ -88,20 +88,20 @@ end function Chunk.get_index(surface, chunk_pos) fail_if_missing(surface, "missing surface argument") fail_if_missing(chunk_pos, "missing chunk_pos argument") - if not global._next_chunk_index then global._next_chunk_index = 0 end - if not global._chunk_indexes then global._chunk_indexes = {} end + if not storage._next_chunk_index then storage._next_chunk_index = 0 end + if not storage._chunk_indexes then storage._chunk_indexes = {} end if type(surface) == "string" then surface = game.surfaces[surface] end local surface_idx = surface.index - if not global._chunk_indexes[surface_idx] then global._chunk_indexes[surface_idx] = {} end + if not storage._chunk_indexes[surface_idx] then storage._chunk_indexes[surface_idx] = {} end - local surface_chunks = global._chunk_indexes[surface_idx] + local surface_chunks = storage._chunk_indexes[surface_idx] if not surface_chunks[chunk_pos.x] then surface_chunks[chunk_pos.x] = {} end if not surface_chunks[chunk_pos.x][chunk_pos.y] then - surface_chunks[chunk_pos.x][chunk_pos.y] = global._next_chunk_index - global._next_chunk_index = global._next_chunk_index + 1 + surface_chunks[chunk_pos.x][chunk_pos.y] = storage._next_chunk_index + storage._next_chunk_index = storage._next_chunk_index + 1 end return surface_chunks[chunk_pos.x][chunk_pos.y] diff --git a/stdlib/area/tile.lua b/stdlib/area/tile.lua index cd40630..d8e0eea 100644 --- a/stdlib/area/tile.lua +++ b/stdlib/area/tile.lua @@ -65,17 +65,17 @@ end function Tile.get_data(surface, tile_pos, default_value) fail_if_missing(surface, "missing surface argument") fail_if_missing(tile_pos, "missing tile_pos argument") - if not global._tile_data then + if not storage._tile_data then if not default_value then return nil end - global._tile_data = {} + storage._tile_data = {} end local chunk_idx = Chunk.get_index(surface, Chunk.from_position(tile_pos)) - if not global._tile_data[chunk_idx] then + if not storage._tile_data[chunk_idx] then if not default_value then return nil end - global._tile_data[chunk_idx] = {} + storage._tile_data[chunk_idx] = {} end - local chunk_tiles = global._tile_data[chunk_idx] + local chunk_tiles = storage._tile_data[chunk_idx] if not chunk_tiles then return nil end local idx = Tile.get_index(tile_pos) @@ -97,12 +97,12 @@ end function Tile.set_data(surface, tile_pos, data) fail_if_missing(surface, "missing surface argument") fail_if_missing(tile_pos, "missing tile_pos argument") - if not global._tile_data then global._tile_data = {} end + if not storage._tile_data then storage._tile_data = {} end local chunk_idx = Chunk.get_index(surface, Chunk.from_position(tile_pos)) - if not global._tile_data[chunk_idx] then global._tile_data[chunk_idx] = {} end + if not storage._tile_data[chunk_idx] then storage._tile_data[chunk_idx] = {} end - local chunk_tiles = global._tile_data[chunk_idx] + local chunk_tiles = storage._tile_data[chunk_idx] local idx = Tile.get_index(tile_pos) local prev = chunk_tiles[idx] chunk_tiles[idx] = data diff --git a/stdlib/config/config.lua b/stdlib/config/config.lua index c9fd0bd..40741cf 100644 --- a/stdlib/config/config.lua +++ b/stdlib/config/config.lua @@ -27,29 +27,29 @@ Config = {} -- @return the Config instance for managing config_table -- -- @usage --[Use a global table for config that persists across game save/loads] ---CONFIG = Config.new(global.testtable) +--CONFIG = Config.new(storage.testtable) -- -- @usage --[You can also create a temporary scratch pad config] --CONFIG = Config.new({}) -- Temporary scratch pad -- -- @usage --[Setting data in Config] ---CONFIG = Config.new(global.testtable) +--CONFIG = Config.new(storage.testtable) --CONFIG.set("your.path.here", "myvalue") -- -- @usage --[Getting data out of Config] ---CONFIG = Config.new(global.testtable) +--CONFIG = Config.new(storage.testtable) --my_data = CONFIG.get("your.path.here") -- -- @usage --[Getting data out of Config with a default to use if path is not found in Config] ---CONFIG = Config.new(global.testtable) +--CONFIG = Config.new(storage.testtable) --my_data = CONFIG.get("your.path.here", "Your Default here") -- -- @usage --[Deleting a path from Config] ---CONFIG = Config.new(global.testtable) +--CONFIG = Config.new(storage.testtable) --CONFIG.delete("your.path.here") -- -- @usage --[Checking if a path exists in Config] ---CONFIG = Config.new(global.testtable) +--CONFIG = Config.new(storage.testtable) --CONFIG.is_set("your.path.here") function Config.new(config_table) if not config_table then diff --git a/stdlib/entity/entity.lua b/stdlib/entity/entity.lua index 9c371d6..5ec9f74 100644 --- a/stdlib/entity/entity.lua +++ b/stdlib/entity/entity.lua @@ -47,16 +47,16 @@ end -- @return the data, or nil if no data exists for the entity function Entity.get_data(entity) fail_if_missing(entity, "missing entity argument") - if not global._entity_data then return nil end + if not storage._entity_data then return nil end local unit_number = entity.unit_number if unit_number then - return global._entity_data[unit_number] + return storage._entity_data[unit_number] else local entity_name = entity.name - if not global._entity_data[entity_name] then return nil end + if not storage._entity_data[entity_name] then return nil end - local entity_category = global._entity_data[entity_name] + local entity_category = storage._entity_data[entity_name] for _, entity_data in pairs(entity_category) do if Entity._are_equal(entity_data.entity, entity) then return entity_data.data @@ -74,20 +74,20 @@ end function Entity.set_data(entity, data) fail_if_missing(entity, "missing entity argument") - if not global._entity_data then global._entity_data = {} end + if not storage._entity_data then storage._entity_data = {} end local unit_number = entity.unit_number if unit_number then - local prev = global._entity_data[unit_number] - global._entity_data[unit_number] = data + local prev = storage._entity_data[unit_number] + storage._entity_data[unit_number] = data return prev else local entity_name = entity.name - if not global._entity_data[entity_name] then - global._entity_data[entity_name] = {} + if not storage._entity_data[entity_name] then + storage._entity_data[entity_name] = {} end - local entity_category = global._entity_data[entity_name] + local entity_category = storage._entity_data[entity_name] for i = #entity_category, 1, -1 do local entity_data = entity_category[i]