Skip to content

Commit

Permalink
Add event for when difficulty changes
Browse files Browse the repository at this point in the history
Also nuke external library with the same event.
Add compatibility for event `onRealDifficultyChanged`, referencing `onDifficultyChanged`.
  • Loading branch information
Lemonymous authored and KnightMiner committed Sep 18, 2022
1 parent e185fec commit 9b950b4
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions scripts/mod_loader/bootstrap/modApi.lua
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ t.onSettingsInitialized = Event()
t.onProfileChanged = Event()
t.onProfileCreated = Event()
t.onProfileDeleted = Event()
t.onDifficultyChanged = Event()

t.onHangarUiShown = Event()
t.onHangarUiHidden = Event()
Expand Down
17 changes: 17 additions & 0 deletions scripts/mod_loader/compat/difficulty.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@

-- EVENTS
---------

local difficulty

modApi.events.onFrameDrawStart:subscribe(function()
local prev_difficulty = difficulty

difficulty = GetDifficulty()

if difficulty ~= prev_difficulty then
modApi.events.onDifficultyChanged:dispatch(difficulty, prev_difficulty)
end
end)


-- Legacy: originally GetDifficulty() returned the custom difficulty while GetRealDifficulty() returned vanilla
GetRealDifficulty = GetDifficulty

Expand Down
3 changes: 3 additions & 0 deletions scripts/mod_loader/compat/nuke.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
-- nuke libraries that have been migrated to the mod loader

SquadEvents = { version = tostring(INT_MAX) }
DifficultyEvents = { version = tostring(INT_MAX) }

modApi.events.onRealDifficultyChanged = modApi.events.onDifficultyChanged

0 comments on commit 9b950b4

Please sign in to comment.