@@ -3,22 +3,19 @@ require "config"
3
3
local mod_version = " 0.0.2"
4
4
local mod_data_version = " 0.0.2"
5
5
6
- termbelts = {}
7
- curvebelts = {}
6
+ local termbelts = {}
7
+ local curvebelts = {}
8
8
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 )
10
10
11
11
local polling_cycles = math.floor (60 / belt_polling_rate )
12
12
13
- --- [[
14
- local function print (...)
15
- return game .player .print (... )
16
- end
17
- -- ]]
18
-
19
- -- swap comment to toggle debug prints
20
13
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
22
19
23
20
local function pos2s (pos )
24
21
if pos then
@@ -85,8 +82,10 @@ local function terminal_belt_lines(entity,entity_to_ignore)
85
82
-- following code originally copied from https://github.com/sparr/factorio-mod-belt-combinators
86
83
for _ ,check in pairs (to_check ) do
87
84
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 })
90
89
local target = nil
91
90
for _ ,candidate in pairs (entities ) do
92
91
if candidate ~= entity_to_ignore then
@@ -175,6 +174,7 @@ local function onTick(event)
175
174
if event .tick % polling_cycles == 0 then
176
175
for y ,row in pairs (termbelts ) do
177
176
for x ,belt in pairs (row ) do
177
+ debug (x .. ' ,' .. y )
178
178
if not belt .entity or not belt .entity .valid then
179
179
termbelts [y ][x ]= nil
180
180
else
@@ -336,9 +336,11 @@ local function find_all_entities(args)
336
336
return entities
337
337
end
338
338
339
- local function refreshGlobalData ()
339
+ local function refreshData ()
340
340
global .terminal_belts = {}
341
341
global .curve_belts = {}
342
+ curvebelts = global .curve_belts
343
+ termbelts = global .terminal_belts
342
344
for _ ,type in pairs ({" transport-belt" ," transport-belt-to-ground" ," splitter" }) do
343
345
for _ ,e in pairs (find_all_entities {type = type }) do
344
346
check_and_update (e ,false ,true )
@@ -353,29 +355,29 @@ end
353
355
local function checkForDataMigration (old_data_version , new_data_version )
354
356
-- TODO: when a migration is necessary, trigger it here or set a flag.
355
357
if old_data_version ~= new_data_version then
356
- refreshGlobalData ()
358
+ refreshData ()
357
359
end
358
360
end
359
361
360
362
local function onLoad ()
361
363
-- 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 )
368
366
369
367
-- After these lines, we can no longer check for migration.
370
368
global .version = mod_version
371
369
global .data_version = mod_data_version
372
370
373
371
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
375
379
end
376
380
377
- curvebelts = global .curve_belts
378
- termbelts = global .terminal_belts
379
381
end
380
382
381
383
script .on_init (onLoad )
0 commit comments