forked from jordanmchavez/kdm-tts
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Terrain.ttslua
50 lines (39 loc) · 1.71 KB
/
Terrain.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
local Check = require("Kdm/Util/Check")
local Expansion = require("Kdm/Expansion")
local log = require("Kdm/Log").ForModule("Terrain")
local Util = require("Kdm/Util/Util")
---------------------------------------------------------------------------------------------------
local Terrain = {}
---------------------------------------------------------------------------------------------------
function Terrain.Init()
Terrain.dataByName = {}
Terrain.tileSizesByName = {}
for _, expansion in ipairs(Expansion.All()) do
for name, data in pairs(expansion.terrain or {}) do
assert(Check(not Terrain.dataByName[name], "Terrain %s is already registered", name))
Terrain.dataByName[name] = data
end
for terrainTile, size in pairs(expansion.terrainTileSizes or {}) do
assert(Check, not Terrain.tileSizesByName[terrainTile], "Terrain tile %s is already registered", terrainTile)
Terrain.tileSizesByName[terrainTile] = size
end
end
end
---------------------------------------------------------------------------------------------------
function Terrain.Data(name)
local data = Terrain.dataByName[name]
assert(Check(data, "Unrecognized terrain '%s", name))
return data
end
---------------------------------------------------------------------------------------------------
function Terrain.TileSize(name)
local tileSize = Terrain.tileSizesByName[name]
assert(Check(tileSize, "Unrecognized terrain tile '%s'", name))
return tileSize
end
---------------------------------------------------------------------------------------------------
return {
Init = Terrain.Init,
Data = Terrain.Data,
TileSize = Terrain.TileSize
}