-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathequipslotutil.lua
More file actions
50 lines (40 loc) · 1.69 KB
/
equipslotutil.lua
File metadata and controls
50 lines (40 loc) · 1.69 KB
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
--------------------------------------------------------------------------
-- Initialize should be called once only during world initializtion
-- after MODs have finished loading and modifying GLOBAL.EQUIPSLOTS
local EQUIPSLOT_NAMES, EQUIPSLOT_IDS, EQUIPSLOT_COUNT
local function InitializeSlots()
assert(EQUIPSLOT_NAMES == nil and EQUIPSLOT_IDS == nil, "Equip slots already initialized")
EQUIPSLOT_NAMES = {}
for k, v in orderedPairs(EQUIPSLOTS) do
table.insert(EQUIPSLOT_NAMES, v)
end
EQUIPSLOT_COUNT = #EQUIPSLOT_NAMES
assert(EQUIPSLOT_COUNT <= 63, "Too many equip slots!")
-- NOTES(JBK): The orderedPairs iterator above forces this sort so it is deterministic for all platforms.
-- I am reversing the sort so that coincidentally the names will be good for priorities when using deterministic checks.
-- {"head", "hands", "body", "beard"} is the expected output.
table.reverse_inplace(EQUIPSLOT_NAMES)
EQUIPSLOT_IDS = table.invert(EQUIPSLOT_NAMES)
end
--------------------------------------------------------------------------
-- These are meant for networking, and can be used in prefab or
-- component logic. They are not valid when modmain is loading.
local function EquipSlotToID(eslot)
return EQUIPSLOT_IDS[eslot]
end
local function EquipSlotFromID(eslotid)
return EQUIPSLOT_NAMES[eslotid]
end
local function GetCount()
return EQUIPSLOT_COUNT
end
--------------------------------------------------------------------------
return
{
--Internal use
Initialize = InitializeSlots,
--Valid only after initialization
ToID = EquipSlotToID,
FromID = EquipSlotFromID,
Count = GetCount,
}