Skip to content

Commit ac3e7f6

Browse files
committed
shift selecting an area removes pending insertion jobs
reset insertion jobs when updating to 0.1.4
1 parent ca6a379 commit ac3e7f6

2 files changed

Lines changed: 48 additions & 3 deletions

File tree

control.lua

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ function remove_ghost(key)
104104
end
105105
end
106106

107-
script.on_event({defines.events.on_player_selected_area,defines.events.on_player_alt_selected_area}, function(event)
107+
function on_player_selected_area(event)
108108
--log(serpent.block(event, {comment=false}))
109109
local status, err = pcall(function()
110110
if not event.player_index then return end
@@ -205,7 +205,37 @@ script.on_event({defines.events.on_player_selected_area,defines.events.on_player
205205
if not status then
206206
debugDump(err, true)
207207
end
208-
end)
208+
end
209+
210+
function on_player_alt_selected_area(event)
211+
--log(serpent.block(event, {comment=false}))
212+
local status, err = pcall(function()
213+
if not event.player_index then return end
214+
local player = game.players[event.player_index]
215+
216+
for _, entity in pairs(event.entities) do
217+
if entity.type == "entity-ghost" and entity.ghost_name == "module-inserter-proxy" then
218+
log(entity.ghost_name)
219+
220+
local key = entityKey(entity)
221+
if global.entitiesToInsert[key] then
222+
global.entitiesToInsert[key] = nil
223+
if player.get_item_count("module-inserter-proxy") > 0 then
224+
player.remove_item{name="module-inserter-proxy", count=1}
225+
end
226+
remove_ghost(key)
227+
entity.destroy()
228+
end
229+
end
230+
end
231+
end)
232+
if not status then
233+
debugDump(err, true)
234+
end
235+
end
236+
237+
script.on_event(defines.events.on_player_selected_area, on_player_selected_area)
238+
script.on_event(defines.events.on_player_alt_selected_area, on_player_alt_selected_area)
209239

210240
local function getMetaItemData()
211241
local metaitem = game.forces.player.recipes["mi-meta"].ingredients
@@ -385,8 +415,19 @@ local function on_configuration_changed(data)
385415
cleanup(true)
386416
end
387417
if oldVersion < "0.1.4" then
418+
for _, ent in pairs(global.entitiesToInsert) do
419+
if ent.ghost and ent.ghost.valid then
420+
ent.ghost.destroy()
421+
end
422+
end
388423
global.entitiesToInsert = {}
389424
global.removeTicks = {}
425+
for _, p in pairs(game.players) do
426+
local c = p.get_item_count("module-inserter-proxy")
427+
if c > 0 then
428+
p.remove_item{name = "module-inserter-proxy", count = c}
429+
end
430+
end
390431
on_load()
391432
end
392433
global.version = newVersion

prototypes/item.lua

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,15 @@ local mi_planner = {
99
selection_color = { r = 0, g = 1, b = 0 },
1010
alt_selection_color = { r = 0, g = 0, b = 1 },
1111
selection_mode = {"matches-force", "buildable-type"},
12-
alt_selection_mode = {"matches-force", "buildable-type"},
12+
alt_selection_mode = {"matches-force", "any-entity"},
1313
selection_cursor_box_type = "copy",
1414
alt_selection_cursor_box_type = "copy"
1515
}
1616

17+
--Error while loading item prototype "module-inserter" (selection-tool): Missing selection_mode in module-inserter item definition.
18+
--Valid values are: blueprint, deconstruct, cancel-deconstruct, items, trees, buildable-type, tiles, items-to-place, any-entity, any-tile, matches-force.
19+
20+
1721
local mi_proxy = copyPrototype("container","wooden-chest","module-inserter-proxy")
1822
mi_proxy.icon = "__ModuleInserter__/graphics/module-inserter-icon.png"
1923
table.insert(mi_proxy.flags, "placeable-off-grid")

0 commit comments

Comments
 (0)