diff --git a/changelog.txt b/changelog.txt index b87d132..aa13101 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,4 +1,9 @@ --------------------------------------------------------------------------------------------------- +Version: 2.0.0 +Date: 2024-11-19 + Features: + - Factorio 2.0 and Quality compatbility by Evilpla +--------------------------------------------------------------------------------------------------- Version: 1.6.7 Date: 2023-01-02 Features: diff --git a/control.lua b/control.lua index 8c9c67b..6b2ff78 100644 --- a/control.lua +++ b/control.lua @@ -53,7 +53,7 @@ script.on_event(defines.events.on_runtime_mod_setting_changed, function(event) end if event.setting == "ghost-scanner-show-hidden" then ShowHidden = settings.global["ghost-scanner-show-hidden"].value - global.Lookup_items_to_place_this = {} + storage.Lookup_items_to_place_this = {} end if event.setting == "ghost-scanner-negative-output" then InvertSign = settings.global["ghost-scanner-negative-output"].value @@ -73,385 +73,408 @@ end) ---- EVENTS ---- do -- create & remove -function OnEntityCreated(event) - local entity = event.created_entity or event.entity - if entity and entity.valid then - if entity.name == Scanner_Name then - global.GhostScanners = global.GhostScanners or {} + function OnEntityCreated(event) + local entity = event.created_entity or event.entity + if entity and entity.valid then + if entity.name == Scanner_Name then + storage.GhostScanners = storage.GhostScanners or {} - -- entity.operable = false - -- entity.rotatable = false + -- entity.operable = false + -- entity.rotatable = false - local ghostScanner = {} - ghostScanner.ID = entity.unit_number - ghostScanner.entity = entity - global.GhostScanners[#global.GhostScanners+1] = ghostScanner + local ghostScanner = {} + ghostScanner.ID = entity.unit_number + ghostScanner.entity = entity + storage.GhostScanners[#storage.GhostScanners + 1] = ghostScanner - UpdateEventHandlers() + UpdateEventHandlers() + end end - end -end - -function RemoveSensor(id) - for i=#global.GhostScanners, 1, -1 do - if id == global.GhostScanners[i].ID then - table.remove(global.GhostScanners,i) + function RemoveSensor(id) + for i = #storage.GhostScanners, 1, -1 do + if id == storage.GhostScanners[i].ID then + table.remove(storage.GhostScanners, i) + end end - end - UpdateEventHandlers() -end - -function OnEntityRemoved(event) --- script.on_event({defines.events.on_pre_player_mined_item, defines.events.on_robot_pre_mined, defines.events.on_entity_died}, function(event) - if event.entity.name == Scanner_Name then - RemoveSensor(event.entity.unit_number) + UpdateEventHandlers() end -end -end -do -- tick handlers -function UpdateEventHandlers() - -- unsubscribe tick handlers - script.on_nth_tick(nil) - script.on_event(defines.events.on_tick, nil) - - -- subcribe tick or nth_tick depending on number of scanners - local entity_count = #global.GhostScanners - if entity_count > 0 then - local nth_tick = UpdateInterval / entity_count - if nth_tick >= 2 then - script.on_nth_tick(math.floor(nth_tick), OnNthTick) - -- log("subscribed on_nth_tick = "..math.floor(nth_tick)) - else - script.on_event(defines.events.on_tick, OnTick) - -- log("subscribed on_tick") + function OnEntityRemoved(event) + -- script.on_event({defines.events.on_pre_player_mined_item, defines.events.on_robot_pre_mined, defines.events.on_entity_died}, function(event) + if event.entity.name == Scanner_Name then + RemoveSensor(event.entity.unit_number) end - - script.on_event({defines.events.on_pre_player_mined_item, defines.events.on_robot_pre_mined, defines.events.on_entity_died}, OnEntityRemoved) - else -- all sensors removed - script.on_event({defines.events.on_pre_player_mined_item, defines.events.on_robot_pre_mined, defines.events.on_entity_died}, nil) end end --- runs when #global.GhostScanners > UpdateInterval/2 -function OnTick(event) - local offset = event.tick % UpdateInterval - for i=#global.GhostScanners - offset, 1, -1 * UpdateInterval do - -- log( event.tick.." updating entity["..i.."]" ) - UpdateSensor(global.GhostScanners[i]) +do -- tick handlers + function UpdateEventHandlers() + -- unsubscribe tick handlers + script.on_nth_tick(nil) + script.on_event(defines.events.on_tick, nil) + + -- subcribe tick or nth_tick depending on number of scanners + local entity_count = #storage.GhostScanners + if entity_count > 0 then + local nth_tick = UpdateInterval / entity_count + if nth_tick >= 2 then + script.on_nth_tick(math.floor(nth_tick), OnNthTick) + -- log("subscribed on_nth_tick = "..math.floor(nth_tick)) + else + script.on_event(defines.events.on_tick, OnTick) + -- log("subscribed on_tick") + end + + script.on_event( + { defines.events.on_pre_player_mined_item, defines.events.on_robot_pre_mined, defines.events.on_entity_died }, + OnEntityRemoved) + else -- all sensors removed + script.on_event( + { defines.events.on_pre_player_mined_item, defines.events.on_robot_pre_mined, defines.events.on_entity_died }, + nil) + end end -end --- runs when #global.GhostScanners <= UpdateInterval/2 -function OnNthTick(NthTickEvent) - if global.UpdateIndex > #global.GhostScanners then - global.UpdateIndex = 1 + -- runs when #storage.GhostScanners > UpdateInterval/2 + function OnTick(event) + local offset = event.tick % UpdateInterval + for i = #storage.GhostScanners - offset, 1, -1 * UpdateInterval do + -- log( event.tick.." updating entity["..i.."]" ) + UpdateSensor(storage.GhostScanners[i]) + end end - -- log( NthTickEvent.tick.." updating entity["..global.UpdateIndex.."]" ) - UpdateSensor(global.GhostScanners[global.UpdateIndex]) + -- runs when #storage.GhostScanners <= UpdateInterval/2 + function OnNthTick(NthTickEvent) + if storage.UpdateIndex > #storage.GhostScanners then + storage.UpdateIndex = 1 + end - global.UpdateIndex = global.UpdateIndex + 1 -end + -- log( NthTickEvent.tick.." updating entity["..storage.UpdateIndex.."]" ) + UpdateSensor(storage.GhostScanners[storage.UpdateIndex]) + storage.UpdateIndex = storage.UpdateIndex + 1 + end end ---- update Sensor ---- do -local signals -local signal_indexes - -local function get_items_to_place(prototype) - if ShowHidden then - global.Lookup_items_to_place_this[prototype.name] = prototype.items_to_place_this - else - -- filter items flagged as hidden - local items_to_place_filtered = {} - for _, v in pairs (prototype.items_to_place_this) do - local item = v.name and game.item_prototypes[v.name] - if item and item.has_flag("hidden") == false then - items_to_place_filtered[#items_to_place_filtered+1] = v + local signals + local signal_indexes + + local function get_items_to_place(prototype) + if ShowHidden then + storage.Lookup_items_to_place_this[prototype.name] = prototype.items_to_place_this + else + -- filter items flagged as hidden + local items_to_place_filtered = {} + for _, v in pairs(prototype.items_to_place_this) do + local item = v.name and prototypes.item[v.name] + if item and item.hidden == false then + items_to_place_filtered[#items_to_place_filtered + 1] = v + end end + storage.Lookup_items_to_place_this[prototype.name] = items_to_place_filtered end - global.Lookup_items_to_place_this[prototype.name] = items_to_place_filtered + return storage.Lookup_items_to_place_this[prototype.name] end - return global.Lookup_items_to_place_this[prototype.name] -end -local function add_signal(name, count) - local signal_index = signal_indexes[name] - local s - if signal_index then - s = signals[signal_index] - else - signal_index = #signals+1 - signal_indexes[name] = signal_index - s = { signal = { type = "item", name = name }, count = 0, index = (signal_index) } - signals[signal_index] = s - end + local function add_signal(name, count, quality) + if quality == nil then + quality = "normal" + end + local index_key = name .. quality + local signal_index = signal_indexes[index_key] + local s + if signal_index then + s = signals[signal_index] + else + signal_index = #signals + 1 + signal_indexes[index_key] = signal_index + s = { value = { type = "item", name = name, quality = quality }, min = 0 } - if InvertSign then - s.count = s.count - count - else - s.count = s.count + count - end -end + signals[signal_index] = s + end -local function is_in_bbox(pos, area) - if pos.x >= area.left_top.x and pos.x <= area.right_bottom.x - and pos.y >= area.left_top.y and pos.y <= area.right_bottom.y then - return true + if InvertSign then + s.min = s.min - count + else + s.min = s.min + count + end end - return false -end ---- returns ghost requested items as signals or nil -local function get_ghosts_as_signals(logsiticNetwork) - if not (logsiticNetwork and logsiticNetwork.valid) then - return nil + local function is_in_bbox(pos, area) + if pos.x >= area.left_top.x and pos.x <= area.right_bottom.x + and pos.y >= area.left_top.y and pos.y <= area.right_bottom.y then + return true + end + return false end - local result_limit = MaxResults + --- returns ghost requested items as signals or nil + local function get_ghosts_as_signals(logsiticNetwork) + if not (logsiticNetwork and logsiticNetwork.valid) then + return nil + end - local search_areas = {} - local found_entities ={} -- store found unit_numbers to prevent duplicate entries - signals = {} - signal_indexes = {} + local result_limit = MaxResults - -- logistic networks don't have an id outside the gui, show the number of cells (roboports) to match the gui - if ShowCellCount then - signals[1] = { signal = { type = "virtual", name = "ghost-scanner-cell-count" }, count = table_size(logsiticNetwork.cells), index = (1) } - end + local search_areas = {} + local found_entities = {} -- store found unit_numbers to prevent duplicate entries + signals = {} + signal_indexes = {} - for _,cell in pairs(logsiticNetwork.cells) do - local pos = cell.owner.position - local r = cell.construction_radius - if r > 0 then - local bounds = { - left_top={ x=pos.x-r, y=pos.y-r, }, - right_bottom={ x=pos.x+r, y=pos.y+r } - } - local inner_bounds = { -- hack to skip checking if position is inside bounds for tiles - left_top={ x=pos.x-r+AreaReduction, y=pos.y-r+AreaReduction }, - right_bottom={ x=pos.x+r-AreaReduction, y=pos.y+r-AreaReduction } - } - search_areas[#search_areas+1] = { - bounds=bounds, - inner_bounds=inner_bounds, - force=logsiticNetwork.force, - surface=cell.owner.surface + -- logistic networks don't have an id outside the gui, show the number of cells (roboports) to match the gui + if ShowCellCount then + signals[1] = { + value = { type = "virtual", name = "ghost-scanner-cell-count", quality = "normal" }, + count = + table_size(logsiticNetwork.cells) } end - end - -- cliffs - for _, search_area in pairs(search_areas) do - local entities = search_area.surface.find_entities_filtered{area=search_area.inner_bounds, limit=result_limit, type="cliff"} - local count_unique_entities = 0 - for _, e in pairs(entities) do - local uid = e.unit_number or e.position - if not found_entities[uid] and e.to_be_deconstructed() and e.prototype.cliff_explosive_prototype then - found_entities[uid] = true - add_signal(e.prototype.cliff_explosive_prototype, 1) - count_unique_entities = count_unique_entities + 1 + for _, cell in pairs(logsiticNetwork.cells) do + local pos = cell.owner.position + local r = cell.construction_radius + if r > 0 then + local bounds = { + left_top = { x = pos.x - r, y = pos.y - r, }, + right_bottom = { x = pos.x + r, y = pos.y + r } + } + local inner_bounds = { -- hack to skip checking if position is inside bounds for tiles + left_top = { x = pos.x - r + AreaReduction, y = pos.y - r + AreaReduction }, + right_bottom = { x = pos.x + r - AreaReduction, y = pos.y + r - AreaReduction } + } + search_areas[#search_areas + 1] = { + bounds = bounds, + inner_bounds = inner_bounds, + force = logsiticNetwork.force, + surface = cell.owner.surface + } end end - if MaxResults then - result_limit = result_limit - count_unique_entities - if result_limit <= 0 then break end - end - end - -- upgrade requests (requires 0.17.69) - if MaxResults == nil or result_limit > 0 then + -- cliffs for _, search_area in pairs(search_areas) do - local entities = search_area.surface.find_entities_filtered{area=search_area.bounds, limit=result_limit, to_be_upgraded=true, force=search_area.force} + local entities = search_area.surface.find_entities_filtered { area = search_area.inner_bounds, limit = result_limit, type = "cliff" } local count_unique_entities = 0 for _, e in pairs(entities) do - local uid = e.unit_number - local upgrade_prototype = e.get_upgrade_target() - if not found_entities[uid] and upgrade_prototype and is_in_bbox(e.position, search_area.bounds) then + local uid = e.unit_number or e.position + if not found_entities[uid] and e.to_be_deconstructed() and e.prototype.cliff_explosive_prototype then found_entities[uid] = true - local items_to_place = global.Lookup_items_to_place_this[upgrade_prototype.name] or get_items_to_place(upgrade_prototype) - for _, item_stack in pairs(items_to_place) do - add_signal(item_stack.name, item_stack.count) - count_unique_entities = count_unique_entities + item_stack.count - end + add_signal(e.prototype.cliff_explosive_prototype, 1) + count_unique_entities = count_unique_entities + 1 end end - -- log("found "..tostring(count_unique_entities).."/"..tostring(result_limit).." upgrade requests." ) if MaxResults then result_limit = result_limit - count_unique_entities if result_limit <= 0 then break end end end - end - -- entity-ghost knows items_to_place_this and item_requests (modules) - if MaxResults == nil or result_limit > 0 then - for _, search_area in pairs(search_areas) do - local entities = search_area.surface.find_entities_filtered{area=search_area.bounds, limit=result_limit, type="entity-ghost", force=search_area.force} - local count_unique_entities = 0 - for _, e in pairs(entities) do - local uid = e.unit_number - if not found_entities[uid] and is_in_bbox(e.position, search_area.bounds) then - found_entities[uid] = true - for _, item_stack in pairs( - global.Lookup_items_to_place_this[e.ghost_name] or - get_items_to_place(e.ghost_prototype) - ) do - add_signal(item_stack.name, item_stack.count) - count_unique_entities = count_unique_entities + item_stack.count + -- upgrade requests (requires 0.17.69) + if MaxResults == nil or result_limit > 0 then + for _, search_area in pairs(search_areas) do + local entities = search_area.surface.find_entities_filtered { area = search_area.bounds, limit = result_limit, to_be_upgraded = true, force = search_area.force } + local count_unique_entities = 0 + for _, e in pairs(entities) do + local uid = e.unit_number + local upgrade_prototype, upgrade_quality = e.get_upgrade_target() + if not found_entities[uid] and upgrade_prototype and is_in_bbox(e.position, search_area.bounds) then + found_entities[uid] = true + local items_to_place = storage.Lookup_items_to_place_this[upgrade_prototype.name] or + get_items_to_place(upgrade_prototype) + for _, item_stack in pairs(items_to_place) do + add_signal(item_stack.name, item_stack.count, upgrade_quality.name) + count_unique_entities = count_unique_entities + item_stack.count + end end + end + -- log("found "..tostring(count_unique_entities).."/"..tostring(result_limit).." upgrade requests." ) + if MaxResults then + result_limit = result_limit - count_unique_entities + if result_limit <= 0 then break end + end + end + end - for request_item, count in pairs(e.item_requests) do - add_signal(request_item, count) - count_unique_entities = count_unique_entities + count + -- entity-ghost knows items_to_place_this and item_requests (modules) + if MaxResults == nil or result_limit > 0 then + for _, search_area in pairs(search_areas) do + local entities = search_area.surface.find_entities_filtered { area = search_area.bounds, limit = result_limit, type = "entity-ghost", force = search_area.force } + local count_unique_entities = 0 + for _, e in pairs(entities) do + local uid = e.unit_number + if not found_entities[uid] and is_in_bbox(e.position, search_area.bounds) then + found_entities[uid] = true + for _, item_stack in pairs( + storage.Lookup_items_to_place_this[e.ghost_name] or + get_items_to_place(e.ghost_prototype) + ) do + add_signal(item_stack.name, item_stack.count, e.quality.name) + count_unique_entities = count_unique_entities + item_stack.count + end + + for _, request in pairs(e.item_requests) do + add_signal(request.name, request.count, request.quality) + count_unique_entities = count_unique_entities + request.count + end end end - end - -- log("found "..tostring(count_unique_entities).."/"..tostring(result_limit).." ghosts." ) - if MaxResults then - result_limit = result_limit - count_unique_entities - if result_limit <= 0 then break end + -- log("found "..tostring(count_unique_entities).."/"..tostring(result_limit).." ghosts." ) + if MaxResults then + result_limit = result_limit - count_unique_entities + if result_limit <= 0 then break end + end end end - end - -- item-request-proxy holds item_requests (modules) for built entities - if MaxResults == nil or result_limit > 0 then - for _, search_area in pairs(search_areas) do - local entities = search_area.surface.find_entities_filtered{area=search_area.inner_bounds, limit=result_limit, type="item-request-proxy", force=search_area.force} - local count_unique_entities = 0 - for _, e in pairs(entities) do - local uid = script.register_on_entity_destroyed(e) -- abuse on_entity_destroyed to generate ids directly for proxies - if not found_entities[uid] then - found_entities[uid] = true - for request_item, count in pairs(e.item_requests) do - add_signal(request_item, count) - count_unique_entities = count_unique_entities + count + -- item-request-proxy holds item_requests (modules) for built entities + if MaxResults == nil or result_limit > 0 then + for _, search_area in pairs(search_areas) do + local entities = search_area.surface.find_entities_filtered { area = search_area.inner_bounds, limit = result_limit, type = "item-request-proxy", force = search_area.force } + local count_unique_entities = 0 + for _, e in pairs(entities) do + local uid = script.register_on_object_destroyed(e) -- abuse on_entity_destroyed to generate ids directly for proxies + if not found_entities[uid] then + found_entities[uid] = true + for _, request in pairs(e.item_requests) do + add_signal(request.name, request.count, request.quality) + count_unique_entities = count_unique_entities + request.count + end end end - end - -- log("found "..tostring(count_unique_entities).."/"..tostring(result_limit).." request proxies." ) - if MaxResults then - result_limit = result_limit - count_unique_entities - if result_limit <= 0 then break end + -- log("found "..tostring(count_unique_entities).."/"..tostring(result_limit).." request proxies." ) + if MaxResults then + result_limit = result_limit - count_unique_entities + if result_limit <= 0 then break end + end end end - end - -- tile-ghost knows only items_to_place_this - if MaxResults == nil or result_limit > 0 then - for _, search_area in pairs(search_areas) do - local entities = search_area.surface.find_entities_filtered{area=search_area.inner_bounds, limit=result_limit, type="tile-ghost", force=search_area.force} - local count_unique_entities = 0 - for _, e in pairs(entities) do - local uid = e.unit_number - if not found_entities[uid] then - found_entities[uid] = true - for _, item_stack in pairs( - global.Lookup_items_to_place_this[e.ghost_name] or - get_items_to_place(e.ghost_prototype) - ) do - add_signal(item_stack.name, item_stack.count) - count_unique_entities = count_unique_entities + item_stack.count + -- tile-ghost knows only items_to_place_this + if MaxResults == nil or result_limit > 0 then + for _, search_area in pairs(search_areas) do + local entities = search_area.surface.find_entities_filtered { area = search_area.inner_bounds, limit = result_limit, type = "tile-ghost", force = search_area.force } + local count_unique_entities = 0 + for _, e in pairs(entities) do + local uid = e.unit_number + if not found_entities[uid] then + found_entities[uid] = true + for _, item_stack in pairs( + storage.Lookup_items_to_place_this[e.ghost_name] or + get_items_to_place(e.ghost_prototype) + ) do + add_signal(item_stack.name, item_stack.count, e.quality.name) + count_unique_entities = count_unique_entities + item_stack.count + end end end - end - -- log("found "..tostring(count_unique_entities).."/"..tostring(result_limit).." tile-ghosts." ) - if MaxResults then - result_limit = result_limit - count_unique_entities - if result_limit <= 0 then break end + -- log("found "..tostring(count_unique_entities).."/"..tostring(result_limit).." tile-ghosts." ) + if MaxResults then + result_limit = result_limit - count_unique_entities + if result_limit <= 0 then break end + end end end - end - -- round signals to next stack size - -- signal = { type = "item", name = name }, count = 0, index = (signal_index) - if RoundToStack then - local round = math.ceil - if InvertSign then round = math.floor end - - for _, signal in pairs(signals) do - local prototype = game.item_prototypes[signal.signal.name] - if prototype then - local stack_size = prototype.stack_size - signal.count = round(signal.count / stack_size) * stack_size + -- round signals to next stack size + -- signal = { type = "item", name = name }, count = 0, index = (signal_index) + if RoundToStack then + local round = math.ceil + if InvertSign then round = math.floor end + + for _, signal in pairs(signals) do + local prototype = prototypes.item[signal.signal.name] + if prototype then + local stack_size = prototype.stack_size + signal.count = round(signal.count / stack_size) * stack_size + end end end - end - - return signals -end -function UpdateSensor(ghostScanner) - -- handle invalidated sensors - if not ghostScanner.entity.valid then - RemoveSensor(ghostScanner.ID) - return + return signals end - -- skip scanner if disabled - if not ghostScanner.entity.get_control_behavior().enabled then - ghostScanner.entity.get_control_behavior().parameters = nil - return - end + function UpdateSensor(ghostScanner) + -- handle invalidated sensors + if not ghostScanner.entity.valid then + RemoveSensor(ghostScanner.ID) + return + end - -- storing logistic network becomes problematic when roboports run out of energy - local logisticNetwork = ghostScanner.entity.surface.find_logistic_network_by_position(ghostScanner.entity.position, ghostScanner.entity.force ) - if not logisticNetwork then - ghostScanner.entity.get_control_behavior().parameters = nil - return - end + -- skip scanner if disabled + if not ghostScanner.entity.get_control_behavior().enabled then + --ghostScanner.entity.get_control_behavior().parameters = nil + local control_behavior = ghostScanner.entity.get_control_behavior() --[[@as LuaConstantCombinatorControlBehavior ]] + local section = control_behavior.get_section(1) + section.filters = {} + return + end - -- set signals - local signals = get_ghosts_as_signals(logisticNetwork) - if not signals then - ghostScanner.entity.get_control_behavior().parameters = nil - return - end - ghostScanner.entity.get_control_behavior().parameters = signals -end + -- storing logistic network becomes problematic when roboports run out of energy + local logisticNetwork = ghostScanner.entity.surface.find_logistic_network_by_position(ghostScanner.entity.position, + ghostScanner.entity.force) + if not logisticNetwork then + --ghostScanner.entity.get_control_behavior().parameters = nil + local control_behavior = ghostScanner.entity.get_control_behavior() --[[@as LuaConstantCombinatorControlBehavior ]] + local section = control_behavior.get_section(1) + section.filters = {} + return + end + -- set signals + local signals = get_ghosts_as_signals(logisticNetwork) + if not signals then + --ghostScanner.entity.get_control_behavior().parameters = nil + local control_behavior = ghostScanner.entity.get_control_behavior() --[[@as LuaConstantCombinatorControlBehavior ]] + local section = control_behavior.get_section(1) + section.filters = {} + return + end + --ghostScanner.entity.get_control_behavior().parameters = signals + local control_behavior = ghostScanner.entity.get_control_behavior() --[[@as LuaConstantCombinatorControlBehavior ]] + if control_behavior.sections_count < 1 then control_behavior.add_section() end + local section = control_behavior.get_section(1) + section.filters = signals + end end ---- INIT ---- do -local function init_events() - script.on_event({ - defines.events.on_built_entity, - defines.events.on_robot_built_entity, - defines.events.script_raised_built, - defines.events.script_raised_revive, - }, OnEntityCreated) - if global.GhostScanners then - UpdateEventHandlers() + local function init_events() + script.on_event({ + defines.events.on_built_entity, + defines.events.on_robot_built_entity, + defines.events.script_raised_built, + defines.events.script_raised_revive, + }, OnEntityCreated) + if storage.GhostScanners then + UpdateEventHandlers() + end end -end - -script.on_load(function() - init_events() -end) - -script.on_init(function() - global.GhostScanners = global.GhostScanners or {} - global.UpdateIndex = global.UpdateIndex or 1 - global.Lookup_items_to_place_this = {} - init_events() -end) - -script.on_configuration_changed(function(data) - global.GhostScanners = global.GhostScanners or {} - global.UpdateIndex = global.UpdateIndex or 1 - global.Lookup_items_to_place_this = {} - init_events() -end) + script.on_load(function() + init_events() + end) + + script.on_init(function() + storage.GhostScanners = storage.GhostScanners or {} + storage.UpdateIndex = storage.UpdateIndex or 1 + storage.Lookup_items_to_place_this = {} + init_events() + end) + + script.on_configuration_changed(function(data) + storage.GhostScanners = storage.GhostScanners or {} + storage.UpdateIndex = storage.UpdateIndex or 1 + storage.Lookup_items_to_place_this = {} + init_events() + end) end diff --git a/info.json b/info.json index faab5d8..384a5c1 100644 --- a/info.json +++ b/info.json @@ -1,11 +1,11 @@ { "name": "GhostScanner", - "version": "1.6.7", + "version": "2.0.0", "title": "Ghost Scanner", "author": "Optera", "contact": "https://forums.factorio.com/memberlist.php?mode=viewprofile&u=21729", "homepage": "https://mods.factorio.com/mod/GhostScanner", "description": "Adds a combinator reading ghost requests from the logistic network it's placed in.", - "factorio_version": "1.1", + "factorio_version": "2.0", "dependencies": ["base >= 1.1.0"] } diff --git a/prototypes/entity.lua b/prototypes/entity.lua index c4d4ccd..38cf53b 100644 --- a/prototypes/entity.lua +++ b/prototypes/entity.lua @@ -42,9 +42,7 @@ local scanner = table.deepcopy(data.raw["constant-combinator"]["constant-combina scanner.name = "ghost-scanner" scanner.icon = "__GhostScanner__/graphics/icons/ghost-scanner.png" scanner.icon_size = 32 -scanner.icon_mipmaps = 1 scanner.minable.result = "ghost-scanner" scanner.sprites = sprites -scanner.item_slot_count = 1000 data:extend({ scanner }) \ No newline at end of file diff --git a/prototypes/recipe.lua b/prototypes/recipe.lua index bb57f52..b44c7bd 100644 --- a/prototypes/recipe.lua +++ b/prototypes/recipe.lua @@ -4,12 +4,15 @@ data:extend({ name = "ghost-scanner", icon = "__GhostScanner__/graphics/icons/ghost-scanner.png", icon_size = 32, - enabled = "false", + enabled = false, ingredients = { - {"copper-cable", 5}, - {"electronic-circuit", 5}, + { type = "item", name = "copper-cable", amount = 5 }, + { type = "item", name = "electronic-circuit", amount = 5 }, }, - result = "ghost-scanner" + results = { + { type = "item", name = "ghost-scanner", amount = 1 }, + } + } }) diff --git a/prototypes/technology.lua b/prototypes/technology.lua index c803c1a..282eacf 100644 --- a/prototypes/technology.lua +++ b/prototypes/technology.lua @@ -8,7 +8,7 @@ else type = "technology", name = "circuit-network-2", icon = "__base__/graphics/technology/circuit-network.png", - icon_size = 256, icon_mipmaps = 4, + icon_size = 256, prerequisites = {"circuit-network"}, effects = {