-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.lua
40 lines (33 loc) · 980 Bytes
/
api.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
local tilesets = {}
local categories = {}
function mapblock_tileset.register_tileset(name, tileset_def)
tileset_def.name = name
tileset_def.category = tileset_def.category or "default"
tilesets[name] = tileset_def
for _, c in ipairs(categories) do
if c == tileset_def.category then
-- category already exists
return
end
end
table.insert(categories, tileset_def.category)
end
function mapblock_tileset.get_categories()
return categories
end
function mapblock_tileset.get_tileset(name)
return tilesets[name]
end
function mapblock_tileset.get_tilesets()
return tilesets
end
function mapblock_tileset.get_tileset_list_by_category(category)
local list = {}
for _, tileset_def in pairs(tilesets) do
if tileset_def.category == category then
table.insert(list, tileset_def)
end
end
table.sort(list, function(a,b) return a.name < b.name end)
return list
end