forked from jordanmchavez/kdm-tts
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Global.ttslua
105 lines (94 loc) · 3.15 KB
/
Global.ttslua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
KDM_VERSION = "1.2"
GLOBAL_OBJECT = self
local Armor = require("Kdm/Armor")
local Archive = require("Kdm/Archive")
local BattleUi = require("Kdm/BattleUi")
local Campaign = require("Kdm/Campaign")
local Console = require("Kdm/Console")
local Deck = require("Kdm/Deck")
local Expansion = require("Kdm/Expansion")
local GlobalUi = require("Kdm/GlobalUi")
local Hunt = require("Kdm/Hunt")
local Location = require("Kdm/Location")
local Log = require("Kdm/Log")
local log = Log.ForModule("G")
local MessageBox = require("Kdm/MessageBox")
local MilestoneBoard = require("Kdm/MilestoneBoard")
local Monster = require("Kdm/Monster")
local NamedObject = require("Kdm/NamedObject")
local Player = require("Kdm/Player")
local Rules = require("Kdm/Rules")
local Settlement = require("Kdm/Settlement")
local Showdown = require("Kdm/Showdown")
local Survivor = require("Kdm/Survivor")
local Terrain = require("Kdm/Terrain")
local Timeline = require("Kdm/Timeline")
local Ui = require("Kdm/Ui")
local Weapon = require("Kdm/Weapon")
---------------------------------------------------------------------------------------------------
function onSave()
local saveState = {
Campaign = Campaign.Save(),
Expansion = Expansion.Save(),
Monster = Monster.Save(),
Player = Player.Save(),
Survivor = Survivor.Save(),
Timeline = Timeline.Save(),
BattleUi = BattleUi.Save(),
}
return JSON.encode(saveState)
end
---------------------------------------------------------------------------------------------------
function onLoad(saveJson)
local saveState = JSON.decode(saveJson) or {}
-- Init() = everything before the UI is first rendered (includes UI setup)
--
Console.Init()
Expansion.Init(saveState.Expansion or {})
--
Log.Init(e)
log:Printf("Misterslack's Kingdom Death: Monster Mod v%s", KDM_VERSION)
--
Armor.Init(e)
NamedObject.Init(e)
Terrain.Init(e)
Ui.Init(e)
Weapon.Init(e)
--
Archive.Init(e)
Location.Init(e)
--
Deck.Init()
Hunt.Init()
Monster.Init(saveState.Monster or {})
Rules.Init()
Settlement.Init()
--
Survivor.Init(saveState.Survivor or {})
--
Player.Init(saveState.Player or {})
--
Showdown.Init()
BattleUi.Init()
--
GlobalUi.Init()
Timeline.Init(saveState.Timeline or {})
--
Campaign.Init(saveState.Campaign or {})
--
MilestoneBoard.Init()
-- mad sketchy that initialization order for MessageBox doesn't match include order, but this must be *after* all 2d UIs since we want this to display *over*
-- all other 2d UIs, and 2d UI display order is solely based on the order of the XML elements (last is on top of everything else)
MessageBox.Init()
Ui.Get2d():ApplyToObject()
-- PostInit() = register event handlers and code that depends on the UI elements actually being instantiated
Wait.frames(function()
Log.PostInit()
Monster.PostInit()
Survivor.PostInit()
Player.PostInit()
Timeline.PostInit()
BattleUi.PostInit()
end, 20)
end
---------------------------------------------------------------------------------------------------