Skip to content

Commit

Permalink
more stuff that will certainly work nocap
Browse files Browse the repository at this point in the history
  • Loading branch information
TheGoesen committed Jan 11, 2024
1 parent 3dfdc86 commit c550099
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 17 deletions.
26 changes: 26 additions & 0 deletions scripts/caravan/caravan-enable-gui.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
require 'caravan-gui-shared'
local Table = require('__stdlib__/stdlib/utils/table')

Caravan.events.on_gui_opened_enable = function(event)
local player = game.get_player(event.player_index)
local entity = event.entity
if not entity then
return
end
if entity.name == 'aerial-outpost' or entity.name == 'outpost' then
return
end
-- Caravan.events.on_close_outpost_gui(event)
if not Caravan.has_any_caravan(entity) then
return
end
local main_frame = player.gui.center
main_frame.add {
type = "sprite-button",
name = "open-caravan-list",
sprite = "utility/close_white",
style = "frame_action_button",
tags = { entity = entity }
}
end

22 changes: 22 additions & 0 deletions scripts/caravan/caravan-gui-shared.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
local function has_schedule(caravan_data, entity)
if not Caravan.validity_check(caravan_data) then
return
end
if not caravan_data.schedule then
return
end
return Table.any(caravan_data.schedule, function(schedule)
return schedule.entity == entity
end)
end

-- probably bad if you have 10 k caravans... but is that even remotely relevant?
function Caravan.has_any_caravan(entity)
return Table.any(global.caravans, function(caravan_data)
return has_schedule(caravan_data, entity)
end)
end




function Caravan.status_img(caravan_data)
local entity = caravan_data.entity
if caravan_data.is_aerial then
Expand Down
17 changes: 0 additions & 17 deletions scripts/caravan/caravan-outpost-gui.lua
Original file line number Diff line number Diff line change
@@ -1,24 +1,7 @@
require 'caravan-gui-shared'
local Table = require('__stdlib__/stdlib/utils/table')

local function has_schedule(caravan_data, entity)
if not Caravan.validity_check(caravan_data) then
return
end
if not caravan_data.schedule then
return
end
return Table.any(caravan_data.schedule, function(schedule)
return schedule.entity == entity
end)
end

-- probably bad if you have 10 k caravans... but is that even remotely relevant?
local function has_any_caravan(entity)
return Table.any(global.caravans, function(caravan_data)
return has_schedule(caravan_data, entity)
end)
end

Caravan.events.on_gui_opened_outpost = function(event)
local player = game.get_player(event.player_index)
Expand Down

0 comments on commit c550099

Please sign in to comment.