Skip to content

Commit b54deb7

Browse files
committed
bugfixes
1 parent 0b099e5 commit b54deb7

File tree

1 file changed

+26
-24
lines changed

1 file changed

+26
-24
lines changed

Diff for: control.lua

+26-24
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,19 @@ require "config"
33
local mod_version="0.0.2"
44
local mod_data_version="0.0.2"
55

6-
termbelts = {}
7-
curvebelts = {}
6+
local termbelts = {}
7+
local curvebelts = {}
88

9-
belt_polling_rate = math.max(math.min(belt_polling_rate,60),1)
9+
local belt_polling_rate = math.max(math.min(belt_polling_rate,60),1)
1010

1111
local polling_cycles = math.floor(60/belt_polling_rate)
1212

13-
---[[
14-
local function print(...)
15-
return game.player.print(...)
16-
end
17-
--]]
18-
19-
--swap comment to toggle debug prints
2013
local function debug() end
21-
-- local debug = print
14+
-- local function debug(...)
15+
-- if game.players[1] then
16+
-- game.players[1].print(...)
17+
-- end
18+
-- end
2219

2320
local function pos2s(pos)
2421
if pos then
@@ -85,8 +82,10 @@ local function terminal_belt_lines(entity,entity_to_ignore)
8582
-- following code originally copied from https://github.com/sparr/factorio-mod-belt-combinators
8683
for _,check in pairs(to_check) do
8784
debug("checking "..pos2s(check.pos))
88-
local tpos = rotate_pos({x=check.pos.x,y=check.pos.y-1},dir)
89-
local entities = game.get_surface(entity.surface.index).find_entities({{0,0},{0,0}})
85+
local delta = rotate_pos({0,-1},dir)
86+
local tpos = {x=check.pos.x+delta.x,y=check.pos.y+delta.y}
87+
debug("tpos "..pos2s(tpos))
88+
local entities = game.get_surface(entity.surface.index).find_entities({tpos,tpos})
9089
local target = nil
9190
for _,candidate in pairs(entities) do
9291
if candidate ~= entity_to_ignore then
@@ -175,6 +174,7 @@ local function onTick(event)
175174
if event.tick%polling_cycles == 0 then
176175
for y,row in pairs(termbelts) do
177176
for x,belt in pairs(row) do
177+
debug(x..','..y)
178178
if not belt.entity or not belt.entity.valid then
179179
termbelts[y][x]=nil
180180
else
@@ -336,9 +336,11 @@ local function find_all_entities(args)
336336
return entities
337337
end
338338

339-
local function refreshGlobalData()
339+
local function refreshData()
340340
global.terminal_belts={}
341341
global.curve_belts={}
342+
curvebelts = global.curve_belts
343+
termbelts = global.terminal_belts
342344
for _,type in pairs({"transport-belt","transport-belt-to-ground","splitter"}) do
343345
for _,e in pairs(find_all_entities{type=type}) do
344346
check_and_update(e,false,true)
@@ -353,29 +355,29 @@ end
353355
local function checkForDataMigration(old_data_version, new_data_version)
354356
-- TODO: when a migration is necessary, trigger it here or set a flag.
355357
if old_data_version ~= new_data_version then
356-
refreshGlobalData()
358+
refreshData()
357359
end
358360
end
359361

360362
local function onLoad()
361363
-- The only reason to have version/data_version is to trigger migrations, so do that here.
362-
if global.version then
363-
checkForMigration(global.version, mod_version)
364-
end
365-
if global.data_version then
366-
checkForDataMigration(global.data_version, mod_data_version)
367-
end
364+
checkForMigration(global.version, mod_version)
365+
checkForDataMigration(global.data_version, mod_data_version)
368366

369367
-- After these lines, we can no longer check for migration.
370368
global.version=mod_version
371369
global.data_version=mod_data_version
372370

373371
if global.terminal_belts==nil then
374-
refreshGlobalData()
372+
refreshData()
373+
end
374+
375+
for y,row in pairs(termbelts) do
376+
for x,belt in pairs(row) do
377+
debug(x..','..y)
378+
end
375379
end
376380

377-
curvebelts = global.curve_belts
378-
termbelts = global.terminal_belts
379381
end
380382

381383
script.on_init(onLoad)

0 commit comments

Comments
 (0)