-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathoptimizeDataAccess.output.lua
73 lines (68 loc) · 1.8 KB
/
optimizeDataAccess.output.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
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
--[[============================================================
--=
--= LuaPreprocess example: Optimize data access.
--=
--= Here we have all data defined in one single place in the
--= metaprogram, then we export parts of the data into multiple
--= smaller tables that are easy and fast to access in the
--= final program.
--=
--============================================================]]
-- Array of character IDs, excluding special characters if we're not in developer mode.
CHARACTER_IDS = {
"war1",
"war2",
"mage1",
"mage2",
"arch1",
"arch2",
}
-- Maps between character IDs and other parameters.
CHARACTER_NAMES = {
war1 = "Steve",
war2 = "Bog",
mage1 = "Elise",
mage2 = "Cyan",
arch1 = "Di",
arch2 = "#&%€",
dev = "Dev",
}
CHARACTER_TYPES = {
war1 = "warrior",
war2 = "warrior",
mage1 = "mage",
mage2 = "mage",
arch1 = "archer",
arch2 = "archer",
dev = "dev",
}
CHARACTERS_UNLOCKED_BY_DEFAULT = {
war1 = true,
mage1 = true,
arch1 = true,
dev = true,
}
--
-- Instead of iterating over the CHARACTERS array until we find
-- the character with the specified ID, we use the maps above to
-- get the information we want through a single table lookup.
--
function getCharacterName(charId)
return CHARACTER_NAMES[charId]
end
function getCharacterType(charId)
return CHARACTER_TYPES[charId]
end
function isCharacterUnlockedByDefault(charId)
return CHARACTERS_UNLOCKED_BY_DEFAULT[charId] == true
end
function printCharacterInfo()
for _, charId in ipairs(CHARACTER_IDS) do
print(getCharacterName(charId))
print(" Type ...... "..getCharacterType(charId))
print(" Unlocked .. "..tostring(isCharacterUnlockedByDefault(charId)))
end
end
printCharacterInfo()
print("Type of 'war1': "..getCharacterType("war1"))
print("Is 'mage2' unlocked by default: "..tostring(isCharacterUnlockedByDefault("mage2")))