Skip to content

Commit

Permalink
save changes
Browse files Browse the repository at this point in the history
  • Loading branch information
bengardner committed Nov 8, 2023
1 parent ac7aa8a commit 136d26a
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 29 deletions.
2 changes: 2 additions & 0 deletions locale/en/config.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ network-chest-provider=Network Provider Chest
network-loader=Network Loader
network-tank=Network Tank
network-sensor=Network Sensor
network-limit-sensor=Network Limit Sensor

[item-name]
network-chest=Network Chest
Expand All @@ -13,6 +14,7 @@ network-chest-provider=Network Provider Chest
network-loader=Network Loader
network-tank=Network Tank
network-sensor=Network Sensor
network-limit-sensor=Network Limit Sensor

[item-description]
network-chest=A chest used to access the network.
Expand Down
19 changes: 15 additions & 4 deletions src/GlobalState.lua
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ end
-- scan existing tanks and chests and use the max "give" limit as the item limit
function M.limit_scan(item)
local limits = global.mod.item_limits
local unlimited = 5000000000 -- "5G"
local unlimited = 2000000000 -- "2G"

for _, info in pairs(global.mod.chests) do
if info.requests ~= nil then
Expand Down Expand Up @@ -200,9 +200,13 @@ function M.set_limit(item_name, value)
-- don't use get_limit()
local old_value = global.mod.item_limits[item_name]
value = tonumber(value)
if value ~= nil and value ~= old_value then
global.mod.item_limits[item_name] = value
return true
if value ~= nil then
-- some game code paths use a int32 for the item count
value = math.min(value, 2000000000)
if value ~= old_value then
global.mod.item_limits[item_name] = value
return true
end
end
end
return false
Expand Down Expand Up @@ -483,6 +487,13 @@ function M.register_tank_entity(entity, config)
if global.mod.tanks[entity.unit_number] ~= nil then
return
end
if config == nil then
config = {
type = "give",
limit = 0,
no_limit = true,
}
end

Queue.push(global.mod.scan_queue, entity.unit_number)
global.mod.tanks[entity.unit_number] = {
Expand Down
4 changes: 2 additions & 2 deletions src/NetworkChest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -899,8 +899,8 @@ end
local function update_tank(info)
local status = GlobalState.UPDATE_STATUS.NOT_UPDATED
local type = info.config.type
local limit = info.config.limit
local buffer = info.config.buffer
local limit = info.config.limit or 5000
local buffer = info.config.buffer or 1000
local fluid = info.config.fluid
local temp = info.config.temperature
local no_limit = (info.config.no_limit == true)
Expand Down
58 changes: 54 additions & 4 deletions src/NetworkSensor.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,48 @@ function M.get_parameters()
count = count,
})
end
for fluid_name, fluid_temps in pairs(GlobalState.get_fluids()) do
if game.fluid_prototypes[fluid_name] ~= nil then
local max_temp
local max_count
for temp, count in pairs(fluid_temps) do
if max_temp == nil or max_temp < temp then
max_temp = temp
max_count = count
end
end
if max_count ~= nil then
table.insert(params, {
signal = { type = "fluid", name = fluid_name },
count = max_count,
})
end
end
end
-- have to set the index after sorting
table.sort(params, compare_control_params)
for index, param in ipairs(params) do
param.index = index
end
return params
end

function M.get_limit_parameters()
local params = {}
for item, count in pairs(GlobalState.get_limits()) do
local name, temp = GlobalState.fluid_temp_key_decode(item)
if temp == nil then
table.insert(params, {
signal = { type = "item", name = name },
count = math.min(count, 2000000000),
})
else
table.insert(params, {
signal = { type = "fluid", name = name },
count = math.min(count, 2000000000),
})
end
end
-- have to set the index after sorting
table.sort(params, compare_control_params)
for index, param in ipairs(params) do
Expand All @@ -34,16 +76,24 @@ end

function M.service_sensors()
local params
local params_limit
local to_del = {}
-- all sensors get the same parameters, so handle them all in one tick
for unit_number, entity in pairs(GlobalState.sensor_get_list()) do
if entity.valid then
local cb = entity.get_control_behavior()
if cb ~= nil then
if params == nil then
params = M.get_parameters()
if entity.name == "network-sensor" then
if params == nil then
params = M.get_parameters()
end
cb.parameters = params
else
if params_limit == nil then
params_limit = M.get_limit_parameters()
end
cb.parameters = params_limit
end
cb.parameters = params
end
else
table.insert(to_del, unit_number)
Expand All @@ -56,7 +106,7 @@ end

function M.register_entity(event)
local entity = event.created_entity or event.entity or event.destination
if entity ~= nil and entity.name == "network-sensor" then
if entity ~= nil and (entity.name == "network-sensor" or entity.name == "network-limit-sensor") then
GlobalState.sensor_add(entity)
end
end
Expand Down
2 changes: 1 addition & 1 deletion src/UiNetworkShortages.lua
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ function NetLimits:refresh()
total_count = total_count + item.count
end

self.elems.title.caption = string.format("Network Shortages - %s types, %s total", total_items, total_count)
self.elems.title.caption = string.format("Network Shortages - %.0f types, %.0f total", total_items, total_count)
end

return M
41 changes: 23 additions & 18 deletions src/prototypes/network-sensor.lua
Original file line number Diff line number Diff line change
@@ -1,23 +1,28 @@

local name = "network-sensor"
local override_item_name = "constant-combinator"
local override_prototype = "constant-combinator"

local entity = table.deepcopy(data.raw[override_prototype][override_item_name])
entity.name = name
entity.minable.result = name
-- Need enough to hold every item we might build
-- We could scan in data-final-fixes to get a more accurate count, but that is ~1700 items.
entity.item_slot_count = 1000
local function extend_one(name)
local override_item_name = "constant-combinator"
local override_prototype = "constant-combinator"

local item = table.deepcopy(data.raw["item"][override_item_name])
item.name = name
item.place_result = name
item.order = item.order .. "2"
local entity = table.deepcopy(data.raw[override_prototype][override_item_name])
entity.name = name
entity.minable.result = name
-- Need enough to hold every item we might build
-- We could scan in data-final-fixes to get a more accurate count, but that is ~1700 items.
entity.item_slot_count = 1000

local recipe = table.deepcopy(data.raw["recipe"][override_item_name])
recipe.name = name
recipe.result = name
recipe.enabled = true
local item = table.deepcopy(data.raw["item"][override_item_name])
item.name = name
item.place_result = name
item.order = item.order .. name

data:extend({ entity, item, recipe })
local recipe = table.deepcopy(data.raw["recipe"][override_item_name])
recipe.name = name
recipe.result = name
recipe.enabled = true

data:extend({ entity, item, recipe })
end

extend_one("network-sensor")
extend_one("network-limit-sensor")

0 comments on commit 136d26a

Please sign in to comment.