Skip to content

Commit

Permalink
new state idle
Browse files Browse the repository at this point in the history
  • Loading branch information
TheGoesen committed Jan 11, 2024
1 parent e5b769b commit 9004520
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 16 deletions.
1 change: 1 addition & 0 deletions locale/en/caravan.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ outpost-aerial=Item and food storage for aerial caravans.
healthy=Healthy
starved=Starved
wounded=Wounded
idle=Idle

[caravan-global-gui]
caption=Caravan organizer
Expand Down
22 changes: 9 additions & 13 deletions scripts/caravan/caravan-gui-shared.lua
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
function Caravan.status_img(caravan_data)
local status, img
local entity = caravan_data.entity
if caravan_data.is_aerial then
status = { 'entity-status.working' }
img = 'utility/status_working'
return { 'entity-status.working' }, 'utility/status_working'
elseif caravan_data.fuel_bar == 0 and caravan_data.fuel_inventory.is_empty() then
status = { 'entity-status.starved' }
img = 'utility/status_not_working'
return { 'entity-status.starved' }, 'utility/status_not_working'
elseif entity.health ~= entity.prototype.max_health then
status = { 'entity-status.wounded' }
img = 'utility/status_yellow'
return { 'entity-status.wounded' }, 'utility/status_yellow'
elseif not Caravan.is_automated(caravan_data) then
return { 'entity-status.idle' }, 'utility/status_yellow'
else
status = { 'entity-status.healthy' }
img = 'utility/status_working'
return { 'entity-status.healthy' }, 'utility/status_working'
end
return { status = status, img = img }
end

function Caravan.add_gui_row(caravan_data, key, table)
Expand All @@ -31,7 +27,7 @@ function Caravan.add_gui_row(caravan_data, key, table)
status_sprite.style.size = { 16, 16 }
local status_text = status_flow.add { type = 'label' }
status_flow.add { type = 'empty-widget', style = 'py_empty_widget' }
local state = Caravan.status_img(caravan_data)
status_text.caption = state.status
status_sprite.sprite = state.img
local state, img = Caravan.status_img(caravan_data)
status_text.caption = state
status_sprite.sprite = img
end
6 changes: 3 additions & 3 deletions scripts/caravan/caravan-gui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,9 @@ function Caravan.update_gui(gui, weak)
local caravan_data = global.caravans[gui.tags.unit_number]
if not Caravan.validity_check(caravan_data) then gui.destroy() return end
local content_flow = gui.content_frame.content_flow
local state = Caravan.status_img(caravan_data)
content_flow.status_flow.status_text.caption = state.status
content_flow.status_flow.status_sprite.sprite = state.img
local state, img = Caravan.status_img(caravan_data)
content_flow.status_flow.status_text.caption = state
content_flow.status_flow.status_sprite.sprite = img
if caravan_data.fuel_inventory then
for i = 1, #caravan_data.fuel_inventory do
local stack = caravan_data.fuel_inventory[i]
Expand Down
4 changes: 4 additions & 0 deletions scripts/caravan/caravan.lua
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ Caravan.events.used_capsule = function(event)
Caravan.build_gui(player, caravan_data.entity)
end

Caravan.is_automated = function(caravan_data)
return caravan_data.schedule_id and caravan_data.schedule_id >= 0
end

local function eat(caravan_data)
if caravan_data.fuel_bar == 0 then
local fuel = caravan_data.fuel_inventory
Expand Down

0 comments on commit 9004520

Please sign in to comment.