Skip to content

Commit

Permalink
Add events for when squad enters/exits game
Browse files Browse the repository at this point in the history
Also nuke external library with same events.
  • Loading branch information
Lemonymous authored and KnightMiner committed Sep 18, 2022
1 parent 53e69e7 commit e185fec
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
2 changes: 2 additions & 0 deletions scripts/mod_loader/bootstrap/modApi.lua
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ t.onWindowHidden = Event()
t.onMissionChanged = Event()
t.onMissionDismissed = Event()
t.onGameVictory = Event()
t.onSquadEnteredGame = Event()
t.onSquadExitedGame = Event()

t.onShiftToggled = Event()
t.onAltToggled = Event()
Expand Down
3 changes: 2 additions & 1 deletion scripts/mod_loader/compat/__scripts.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ local scripts = {
"asserts",
"achievement",
"dialog_helper",
"difficulty"
"difficulty",
"nuke",
}

local rootpath = GetParentPath(...)
Expand Down
4 changes: 4 additions & 0 deletions scripts/mod_loader/compat/nuke.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

-- nuke libraries that have been migrated to the mod loader

SquadEvents = { version = tostring(INT_MAX) }
21 changes: 21 additions & 0 deletions scripts/mod_loader/modapi/squad.lua
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,24 @@ function modApi:addSquad(squad, name, desc, icon)
table.insert(self.squad_text, desc)
table.insert(self.squad_icon, icon or "resources/mods/squads/unknown.png")
end

local function onGameEntered()
local squadData = GAME.additionalSquadData
local squadId = squadData.squad

if squadId ~= nil then
modApi.events.onSquadEnteredGame:dispatch(squadId)
end
end

local function onGameExited()
local squadData = GAME.additionalSquadData
local squadId = squadData.squad

if squadId ~= nil then
modApi.events.onSquadExitedGame:dispatch(squadId)
end
end

modApi.events.onGameEntered:subscribe(onGameEntered)
modApi.events.onGameExited:subscribe(onGameExited)

0 comments on commit e185fec

Please sign in to comment.