-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindexNameHandler.lua
More file actions
75 lines (60 loc) · 1.72 KB
/
indexNameHandler.lua
File metadata and controls
75 lines (60 loc) · 1.72 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
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
local IterableMap = require("include/IterableMap")
local util = require("include/util")
local Font = require("include/font")
local self = {}
local api = {}
local function InitIndexData(defaultPrefix)
return {
usedNames = {},
indexToName = {},
defaultPrefix = defaultPrefix,
}
end
local function GetNewName(data, prefix)
local nameIndex = 1
local name = prefix .. tostring(nameIndex)
while data.usedNames[name] do
nameIndex = nameIndex + 1
name = prefix .. tostring(nameIndex)
end
data.usedNames[name] = true
return name
end
local function GetOrMakeName(data, index, prefix)
if not data.indexToName[index] then
prefix = prefix or data.defaultPrefix
data.indexToName[index] = GetNewName(data, prefix)
end
return data.indexToName[index]
end
function api.GetNewTriggerName(prefix)
return GetNewName(self.triggerData, prefix)
end
function api.GetOrMakeTriggerName(triggerID, prefix)
return GetOrMakeName(self.triggerData, triggerID, prefix)
end
function api.GetNewPlatformName(prefix)
return GetNewName(self.platformData, prefix)
end
function api.GetOrMakePlatformName(platformID, prefix)
return GetOrMakeName(self.platformData, platformID, prefix)
end
function api.GetNewPortalName(prefix)
return GetNewName(self.portalData, prefix)
end
function api.GetOrMakePortalName(portalID, prefix)
return GetOrMakeName(self.portalData, portalID, prefix)
end
function api.Update(dt)
end
function api.Draw(drawQueue)
end
function api.Initialize(world, levelIndex, mapDataOverride)
self = {
world = world,
triggerData = InitIndexData("trigger"),
platformData = InitIndexData("platform"),
portalData = InitIndexData("portal"),
}
end
return api