-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathequipslotutil.lua
45 lines (35 loc) · 1.29 KB
/
equipslotutil.lua
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
--------------------------------------------------------------------------
-- Initialize should be called once only during world initializtion
-- after MODs have finished loading and modifying GLOBAL.EQUIPSLOTS
local EQUIPSLOT_NAMES, EQUIPSLOT_IDS
local function InitializeSlots()
assert(EQUIPSLOT_NAMES == nil and EQUIPSLOT_IDS == nil, "Equip slots already initialized")
EQUIPSLOT_NAMES = {}
for k, v in pairs(EQUIPSLOTS) do
table.insert(EQUIPSLOT_NAMES, v)
end
assert(#EQUIPSLOT_NAMES <= 63, "Too many equip slots!")
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_NAMES
end
--------------------------------------------------------------------------
return
{
--Internal use
Initialize = InitializeSlots,
--Valid only after initialization
ToID = EquipSlotToID,
FromID = EquipSlotFromID,
Count = GetCount,
}