forked from jordanmchavez/kdm-tts
-
Notifications
You must be signed in to change notification settings - Fork 5
/
NamedObject.ttslua
181 lines (151 loc) · 8.02 KB
/
NamedObject.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
local Check = require("Kdm/Util/Check")
local Console = require("Kdm/Console")
local EventManager = require("Kdm/Util/EventManager")
local Expansion = require("Kdm/Expansion")
local log = require("Kdm/Log").ForModule("NamedObject")
---------------------------------------------------------------------------------------------------
local NamedObject = {}
NamedObject.data = {
["0b2ed0"] = { name = "Table", noninteractible = true },
["bafa19"] = { name = "Top Table", noninteractible = true },
["8bf5e2"] = { name = "Left Table", noninteractible = true },
["dff000"] = { name = "Bottom Table", noninteractible = true },
["f7805a"] = { name = "Right Table", noninteractible = true },
["da72c5"] = { name = "Abilities Archive" },
["0dc4b8"] = { name = "Fighting Arts Archive" },
["13a43d"] = { name = "Secret Fighting Arts Archive" },
["590a4f"] = { name = "Disorders Archive" },
["1d3367"] = { name = "Severe Injuries Archive" },
["379dcf"] = { name = "Tactics Archive" },
["a80b96"] = { name = "Weapon Proficiencies Archive" },
["d843fb"] = { name = "Armor Sets Archive" },
["43ac01"] = { name = "Vermin Archive" },
["dd76f7"] = { name = "Strange Resources Archive" },
["57a8b5"] = { name = "Basic Resources Archive" },
["7223e1"] = { name = "Terrain Archive" },
["2551b1"] = { name = "Terrain Tiles Archive" },
["916de5"] = { name = "Settlement Events Archive" },
["7a04ec"] = { name = "Rare Gear Archive" },
["166a4f"] = { name = "Gear Archive" },
["26dc61"] = { name = "Monster Resources Archive" },
["5d72f3"] = { name = "Hunt Events Archive" },
["fdb47b"] = { name = "Survivor Sheets Archive" },
["174926"] = { name = "Survivor Boxes Archive" },
["54abe6"] = { name = "Dodge Tokens" },
["046b7f"] = { name = "Encourage Tokens" },
["692b54"] = { name = "Embolden Tokens" },
["417446"] = { name = "Dash Tokens" },
["64a148"] = { name = "Surge Tokens" },
["740242"] = { name = "Overcharge Tokens" },
["97f88b"] = { name = "Endure Tokens" },
["437cd7"] = { name = "Showdown Board", noninteractible = true }, --(make false to change image)
["51a21e"] = { name = "Hunt Board", noninteractible = true },
["226d8a"] = { name = "Settlement Board", noninteractible = true },
["456dc5"] = { name = "Rules Board", noninteractible = true },
["58f2b5"] = { name = "Rules Navigation Board", noninteractible = true },
["4ff505"] = { name = "Milestone Board", noninteractible = true },
["05e4ab"] = { name = "Export/Import Board", noninteractible = true },
["d2a564"] = { name = "Survivor Board", noninteractible = true },
["b9c2e9"] = { name = "Survivor Board Cell 1", noninteractible = true },
["a56349"] = { name = "Survivor Board Cell 2", noninteractible = true },
["89842b"] = { name = "Survivor Board Cell 3", noninteractible = true },
["e0af8f"] = { name = "Survivor Board Cell 4", noninteractible = true },
["951600"] = { name = "Survivor Board Cell 5", noninteractible = true },
["1d1ccc"] = { name = "Survivor Board Cell 6", noninteractible = true },
["bea4c0"] = { name = "Survivor Board Cell 7", noninteractible = true },
["142a23"] = { name = "Survivor Board Cell 8", noninteractible = true },
["8a4bfd"] = { name = "Survivor Board Cell 9", noninteractible = true },
["484be9"] = { name = "Survivor Board Cell 10", noninteractible = true },
["bf278c"] = { name = "Survivor Board Cell 11", noninteractible = true },
["076ed5"] = { name = "Survivor Board Cell 12", noninteractible = true },
["385d8a"] = { name = "Survivor Board Cell 13", noninteractible = true },
["efc41f"] = { name = "Survivor Board Cell 14", noninteractible = true },
["a98661"] = { name = "Survivor Board Cell 15", noninteractible = true },
["40baee"] = { name = "Survivor Board Cell 16", noninteractible = true },
["d57548"] = { name = "Survivor Board Cell 17", noninteractible = true },
["411c2f"] = { name = "Survivor Board Cell 18", noninteractible = true },
["fecd6f"] = { name = "Survivor Board Cell 19", noninteractible = true },
["a61dd0"] = { name = "Survivor Board Cell 20", noninteractible = true },
["34bfdb"] = { name = "Player 1 Board", noninteractible = true },
["61f946"] = { name = "Player 2 Board", noninteractible = true },
["4f139d"] = { name = "Player 3 Board", noninteractible = true },
["276ea7"] = { name = "Player 4 Board", noninteractible = true },
["9380cb"] = { name = "Player 1 Marker" },
["ed7b20"] = { name = "Player 2 Marker" },
["7f1cde"] = { name = "Player 3 Marker" },
["9a6e00"] = { name = "Player 4 Marker" },
["b07b40"] = { name = "Overlay", noninteractible = true },
["18a13f"] = { name = "Allister Archive" },
["590a94"] = { name = "Ezra Archive" },
["962317"] = { name = "Lucy Archive" },
["0a73fe"] = { name = "Zachary Archive" },
["966a53"] = { name = "Patterns Archive" },
}
---------------------------------------------------------------------------------------------------
function NamedObject.Init()
NamedObject.objectsByName = {}
NamedObject.guids = {}
for guid, data in pairs(NamedObject.data) do
NamedObject.Set(data.name, guid)
end
for _, expansion in ipairs(Expansion.All()) do
for guid, name in pairs(expansion.guidNames or {}) do
NamedObject.Set(name, guid)
end
end
NamedObject.SetInteractable(false)
EventManager.AddHandler("onObjectDestroy", function(object)
if NamedObject.guids[object.getGUID()] then
log:Broadcastf("A critical game component '%s' (GUID %s) was just deleted. This may cause the mod to malfunction. Please restore an earlier save game.", object.getName(), object.getGUID())
end
end)
EventManager.AddHandler("tryObjectEnterContainer", function(container, object, previousReturnValue)
if previousReturnValue == false then
return false
end
if NamedObject.guids[object.getGUID()] then
log:Broadcastf("%s (%s) is a critical game component. The mod will break if it's put in a container.", object.getName(), object.getGUID())
return false
end
return true
end)
Console.AddCommand("interact", function(args)
if #args != 2 or (args[2] != "on" and args[2] != "off") then
Console.Printf("Usage: interact <on|off>")
return
end
local interactible = args[2] == "on"
NamedObject.SetInteractable(interactible)
Console.Printf("Set critical game objects to %s", interactible and "interactible" or "non-interactible")
end, "Toggles whether critical game objects are interactible")
end
---------------------------------------------------------------------------------------------------
function NamedObject.SetInteractable(interactible)
for _, data in pairs(NamedObject.data) do
if data.noninteractible then
NamedObject.Get(data.name).interactable = interactible
end
end
end
---------------------------------------------------------------------------------------------------
function NamedObject.Set(name, guid)
local object = getObjectFromGUID(guid)
assert(Check(object != nil, "Couldn't find critical component '%s' with guid %s. If you accidentally deleted this object, then you may need to restore an earlier save.", name, guid))
local existing = NamedObject.objectsByName[name]
if existing then
assert(Check.Fail("Tried to add object '%s' with guid %s, but already exists with guid %s", name, existing.getGUID(), guid))
end
NamedObject.objectsByName[name] = object
NamedObject.guids[guid] = true
end
---------------------------------------------------------------------------------------------------
function NamedObject.Get(name)
local object = NamedObject.objectsByName[name]
assert(Check(object, "Unknown object '%s'", name))
return object
end
---------------------------------------------------------------------------------------------------
return {
Init = NamedObject.Init,
Get = NamedObject.Get,
}