Skip to content

Commit cba9408

Browse files
committed
fix gui update
1 parent 6cf2299 commit cba9408

File tree

2 files changed

+23
-29
lines changed

2 files changed

+23
-29
lines changed

control.lua

+22-29
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ function entityKey(ent)
4444
end
4545
return false
4646
end
47+
4748
--/c game.player.print(serpent.dump(game.player.surface.find_logistic_network_by_position(game.player.position, game.player.force.name).find_cell_closest_to(game.player.position)))
4849
function hasPocketBots(player)
4950
local logisticCell = player.character.logistic_cell
@@ -235,30 +236,10 @@ local function initGlob()
235236
global.version = "0.0.7"
236237
end
237238

238-
if global.version < "0.0.8" then
239-
local toDelete = {}
240-
for k, e in pairs(global.entitiesToInsert) do
241-
if e.entity.valid then
242-
for _, g in pairs(e.entity.surface.find_entities_filtered{area=expandPos(e.position), type="entity-ghost"}) do
243-
if g.ghost_name == "module-inserter-proxy" then
244-
e.ghost = g
245-
end
246-
end
247-
if not e.ghost then
248-
table.insert(toDelete, k)
249-
end
250-
else
251-
table.insert(toDelete, k)
252-
end
253-
end
254-
for _, key in pairs(toDelete) do
255-
global.entitiesToInsert[key] = nil
256-
end
257-
global.version = "0.0.8"
258-
end
259239
if global.version < "0.0.9" then
260240
global.entitiesToInsert = {}
261241
global.removeTicks = {}
242+
global.guiVersion = {}
262243
global.version = "0.0.9"
263244
end
264245
global.version = "0.0.9"
@@ -277,15 +258,21 @@ end
277258
function update_gui(player)
278259
local status, err = pcall(function()
279260
if player then
280-
if global.guiVersion[player.name] and global.guiVersion[player.name] < "0.0.7" and player.gui.top["module-inserter-config-button"] then
261+
if not global.guiVersion[player.name] then
262+
global.guiVersion[player.name] = "0.0.0"
263+
end
264+
if global.guiVersion[player.name] < "0.0.7" and player.gui.top["module-inserter-config-button"] then
281265
player.gui.top["module-inserter-config-button"].destroy()
282266
global.guiVersion[player.name] = "0.0.7"
283267
end
284268
gui_init(player)
285269
else
286270
for i,player in pairs(game.players) do
287271
if player.valid and player.connected then
288-
if global.guiVersion[player.name] and global.guiVersion[player.name] < "0.0.7" and player.gui.top["module-inserter-config-button"] then
272+
if not global.guiVersion[player.name] then
273+
global.guiVersion[player.name] = "0.0.0"
274+
end
275+
if global.guiVersion[player.name] < "0.0.7" and player.gui.top["module-inserter-config-button"] then
289276
player.gui.top["module-inserter-config-button"].destroy()
290277
global.guiVersion[player.name] = "0.0.7"
291278
end
@@ -324,13 +311,18 @@ game.on_load(onload)
324311

325312
function on_tick(event)
326313
if global.removeTicks[event.tick] then
327-
for _, g in pairs(global.removeTicks[event.tick]) do
328-
if not g.g.valid and g.p.get_item_count("module-inserter-proxy") > 0 then
329-
g.p.remove_item{name="module-inserter-proxy", count = 1}
330-
global.entitiesToInsert[g.key] = nil
314+
local status, err = pcall(function()
315+
for _, g in pairs(global.removeTicks[event.tick]) do
316+
if not g.g.valid and g.p.get_item_count("module-inserter-proxy") > 0 then
317+
g.p.remove_item{name="module-inserter-proxy", count = 1}
318+
global.entitiesToInsert[g.key] = nil
319+
end
331320
end
321+
global.removeTicks[event.tick] = nil
322+
end)
323+
if not status then
324+
debugDump(err, true)
332325
end
333-
global.removeTicks[event.tick] = nil
334326
end
335327
end
336328

@@ -382,7 +374,8 @@ game.on_event(defines.events.on_robot_built_entity, function(event)
382374
end
383375
end
384376
end
385-
global.entitiesToInsert[entityKey(entity)] = nil
377+
local key = entityKey(entity)
378+
global.entitiesToInsert[key] = nil
386379
end
387380
entity.destroy()
388381
end

gui.lua

+1
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ function gui_init(player, after_research)
133133
name = "module-inserter-config-button",
134134
style = "module-inserter-button"
135135
}
136+
global.guiVersion[player.name] = "0.0.9"
136137
end
137138
end
138139

0 commit comments

Comments
 (0)