Modify GUI tick rate to 10s from 1s and refactor some of the stations code with improvements from inventory

This commit is contained in:
Will Berry
2023-03-06 13:02:50 -05:00
parent af5f606cbb
commit 732d63d65b
2 changed files with 48 additions and 57 deletions

View File

@@ -92,36 +92,29 @@ function util.slot_table_build_from_station(station)
local item = v.signal local item = v.signal
local count = v.count local count = v.count
local name = item.name local name = item.name
local sprite local sprite = util.build_sprite_path(name)
local color if sprite ~= nil then
if count > 0 then local color
color = "green" if count > 0 then
else color = "green"
color = "red"
end
if item.type then
sprite = item.type .. "/" .. name
else
if name then
sprite = string.gsub(name, ",", "/")
else else
--idunno? color = "red"
end
if game.is_valid_sprite_path(sprite) then
children[#children + 1] = {
type = "sprite-button",
enabled = false,
style = "ltnm_small_slot_button_" .. color,
sprite = sprite,
tooltip = {
"",
"[img=" .. sprite .. "]",
{ "item-name." .. name },
"\n"..format.number(count),
},
number = count
}
end end
end
if game.is_valid_sprite_path(sprite) then
children[#children + 1] = {
type = "sprite-button",
enabled = false,
style = "ltnm_small_slot_button_" .. color,
sprite = sprite,
tooltip = {
"",
"[img=" .. sprite .. "]",
{ "item-name." .. name },
"\n"..format.number(count),
},
number = count
}
end end
end end
end end
@@ -132,33 +125,32 @@ function util.slot_table_build_from_deliveries(station)
---@type GuiElemDef[] ---@type GuiElemDef[]
local children = {} local children = {}
local deliveries = station.deliveries local deliveries = station.deliveries
local sprite = ""
for item, count in pairs(deliveries) do for item, count in pairs(deliveries) do
local color
if count > 0 then local sprite = util.build_sprite_path(item)
color = "green" if sprite ~= nil then
else local color
color = "blue" if count > 0 then
end color = "green"
if game.is_valid_sprite_path("item/" .. item) then else
sprite = "item/" .. item color = "blue"
elseif game.is_valid_sprite_path("fluid/" .. item) then end
sprite = "fluid/" .. item if game.is_valid_sprite_path(sprite) then
end children[#children + 1] = {
if game.is_valid_sprite_path(sprite) then type = "sprite-button",
children[#children + 1] = { enabled = false,
type = "sprite-button", style = "ltnm_small_slot_button_" .. color,
enabled = false, sprite = sprite,
style = "ltnm_small_slot_button_" .. color, tooltip = {
sprite = sprite, "",
tooltip = { "[img=" .. sprite .. "]",
"", { item },
"[img=" .. sprite .. "]", "\n"..format.number(count),
{ item }, },
"\n"..format.number(count), number = count
}, }
number = count end
}
end end
end end
return children return children
@@ -180,7 +172,6 @@ function util.slot_table_build_from_control_signals(station)
if item.type ~= "virtual" then if item.type ~= "virtual" then
goto continue goto continue
else else
-- don't know how to get the sprite path for signals like cybersyn-priority, so this fizzles
sprite = "virtual-signal" .. "/" .. name sprite = "virtual-signal" .. "/" .. name
end end
if game.is_valid_sprite_path(sprite) then if game.is_valid_sprite_path(sprite) then

View File

@@ -903,7 +903,7 @@ local function main()
end end
local MANAGER_ENABLED = true local MANAGER_ENABLED = true --convert to mod setting?
script.on_init(function() script.on_init(function()
local setting = settings.global["cybersyn-invert-sign"] local setting = settings.global["cybersyn-invert-sign"]
@@ -933,7 +933,7 @@ local function main()
script.on_event(defines.events.on_player_removed, manager.on_player_removed) script.on_event(defines.events.on_player_removed, manager.on_player_removed)
script.on_event(defines.events.on_player_created, manager.on_player_created) script.on_event(defines.events.on_player_created, manager.on_player_created)
script.on_event(defines.events.on_lua_shortcut, manager.on_lua_shortcut) script.on_event(defines.events.on_lua_shortcut, manager.on_lua_shortcut)
script.on_nth_tick(60, function() script.on_nth_tick(600, function() --TODO: tick value needs to be converted to mod setting
manager.tick(global) manager.tick(global)
end) end)
end end