early return

This commit is contained in:
phidias authored and GitHub committed 2026-11-10 14:17:46 +09:00
1 parent 2dade8224d
commit 086af3cb78
1 file changed
+10 -8
+10 -8
View File
@@ -242,7 +242,8 @@ end
local function get_remaining_surface_area(s_index) local function get_remaining_surface_area(s_index)
local properties = assert(vlayer_data[s_index]).properties local properties = assert(vlayer_data[s_index]).properties
local remaining = properties.total_surface_area - properties.used_surface_area local remaining = properties.total_surface_area - properties.used_surface_area
for name, qnc in pairs(assert(vlayer_data[s_index]).storage.unallocated) do local unallocated = assert(vlayer_data[s_index]).storage.unallocated
for name, qnc in pairs(unallocated) do
for _, count in pairs(qnc) do for _, count in pairs(qnc) do
remaining = remaining - allowed_items[name].required_area * count remaining = remaining - allowed_items[name].required_area * count
end end
@@ -351,6 +352,7 @@ end
function Vlayer.insert_item(s_index, name, count, quality_level) function Vlayer.insert_item(s_index, name, count, quality_level)
local item = assert(allowed_items[name], "Item not allowed in the vlayer: " .. name) local item = assert(allowed_items[name], "Item not allowed in the vlayer: " .. name)
local storage = assert(vlayer_data[s_index]).storage local storage = assert(vlayer_data[s_index]).storage
if not storage.items[name] then storage.items[name] = {} end
storage.items[name][quality_level] = storage.items[name][quality_level] + count storage.items[name][quality_level] = storage.items[name][quality_level] + count
if config.unlimited_surface_area or item.required_area == 0 then if config.unlimited_surface_area or item.required_area == 0 then
@@ -366,6 +368,7 @@ function Vlayer.insert_item(s_index, name, count, quality_level)
end end
local unallocated = count - allocated local unallocated = count - allocated
if not storage.unallocated[name] then storage.unallocated[name] = {} end
storage.unallocated[name][quality_level] = storage.unallocated[name][quality_level] + unallocated storage.unallocated[name][quality_level] = storage.unallocated[name][quality_level] + unallocated
count_unallocated_production(s_index, name, unallocated, quality_level) count_unallocated_production(s_index, name, unallocated, quality_level)
end end
@@ -376,7 +379,7 @@ end
--- @param count number --- @param count number
--- @param quality_level number --- @param quality_level number
--- @return number # The count actually removed --- @return number # The count actually removed
function Vlayer.remove_item(s_index, name, wanted, quality_level) function Vlayer.remove_item(s_index, name, count, quality_level)
local item = assert(allowed_items[name], "Item not allowed in the vlayer: " .. name) local item = assert(allowed_items[name], "Item not allowed in the vlayer: " .. name)
local storage = assert(vlayer_data[s_index]).storage local storage = assert(vlayer_data[s_index]).storage
local properties = assert(vlayer_data[s_index]).properties local properties = assert(vlayer_data[s_index]).properties
@@ -603,8 +606,7 @@ local function handle_unallocated()
unallocated_area = unallocated_area + allowed_items[name].required_area * count unallocated_area = unallocated_area + allowed_items[name].required_area * count
end end
end end
if unallocated_area == 0 then return end if unallocated_area > 0 then
local properties = prop.properties local properties = prop.properties
local surplus_area = properties.total_surface_area - properties.used_surface_area local surplus_area = properties.total_surface_area - properties.used_surface_area
for name, qnc in pairs(prop.storage.unallocated) do for name, qnc in pairs(prop.storage.unallocated) do
@@ -619,14 +621,14 @@ local function handle_unallocated()
end end
end end
end end
end
--- Set the signals of the circuit interfaces to the statistics and stored items --- Set the signals of the circuit interfaces to the statistics and stored items
local function handle_circuit_interfaces() local function handle_circuit_interfaces()
for s_index, prop in pairs(vlayer_data) do for s_index, prop in pairs(vlayer_data) do
local interfaces = prop.interfaces.circuit local interfaces = prop.interfaces.circuit
prune_interfaces(interfaces) prune_interfaces(interfaces)
if #interfaces == 0 then return end if #interfaces > 0 then
local stats = Vlayer.get_statistics(s_index) local stats = Vlayer.get_statistics(s_index)
for _, interface in ipairs(interfaces) do for _, interface in ipairs(interfaces) do
local control = interface.get_or_create_control_behavior() --[[@as LuaConstantCombinatorControlBehavior]] local control = interface.get_or_create_control_behavior() --[[@as LuaConstantCombinatorControlBehavior]]
@@ -663,6 +665,7 @@ local function handle_circuit_interfaces()
end end
end end
end end
end
--- Produce energy, share it between the energy interfaces, and burn fuel when storage runs low --- Produce energy, share it between the energy interfaces, and burn fuel when storage runs low
local function handle_energy_interfaces() local function handle_energy_interfaces()
@@ -693,7 +696,6 @@ local function handle_energy_interfaces()
local capacity = properties.capacity * mega local capacity = properties.capacity * mega
if not config.unlimited_capacity and storage.energy > capacity then if not config.unlimited_capacity and storage.energy > capacity then
storage.energy = capacity storage.energy = capacity
return
end end
end end
end end
@@ -751,7 +753,7 @@ end
local e = defines.events local e = defines.events
Vlayer.on_init = function() Vlayer.on_init = function()
default_surface(1) update_surface({surface_index=game.surfaces["nauvis"].index})
end -- The default surface exists before on_surface_created can fire end -- The default surface exists before on_surface_created can fire
Vlayer.events[e.on_surface_created] = update_surface Vlayer.events[e.on_surface_created] = update_surface
Vlayer.events[e.on_surface_renamed] = update_surface Vlayer.events[e.on_surface_renamed] = update_surface