Skip to content

Commit

Permalink
Update to 0.12.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ZwerOxotnik committed Oct 22, 2024
1 parent fcdc088 commit e861eeb
Show file tree
Hide file tree
Showing 14 changed files with 113 additions and 99 deletions.
4 changes: 2 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
8 changes: 3 additions & 5 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -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**

Expand Down
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"table": "enable",
"math": "enable",
"string": "enable",
"package": "enable",
"package": "disable",
"debug": "enable",
"bit32": "disable",
"io": "disable",
Expand Down
5 changes: 5 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
4 changes: 2 additions & 2 deletions compiler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions constants.lua
Original file line number Diff line number Diff line change
@@ -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 = ""}
Expand Down
46 changes: 24 additions & 22 deletions control.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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"}
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down
51 changes: 30 additions & 21 deletions data.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -73,38 +73,47 @@ 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},
{"utility-science-pack", 1},
{"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)
Expand All @@ -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
}

Expand Down
4 changes: 2 additions & 2 deletions info.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
4 changes: 2 additions & 2 deletions microcontroller.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
26 changes: 13 additions & 13 deletions stdlib/area/chunk.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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]
Expand Down
Loading

0 comments on commit e861eeb

Please sign in to comment.