tag api
This commit is contained in:
parent
9eda9b2203
commit
8e46bb1fc3
21
api.lua
21
api.lua
@ -3,13 +3,28 @@
|
|||||||
local buildings = {}
|
local buildings = {}
|
||||||
local building_categories = {}
|
local building_categories = {}
|
||||||
|
|
||||||
|
-- string -> { building_def, building_def, ... }
|
||||||
|
local building_tags = {}
|
||||||
|
|
||||||
function building_lib.register_building(name, def)
|
function building_lib.register_building(name, def)
|
||||||
def.name = name
|
def.name = name
|
||||||
def.placement = def.placement or "mapblock_lib"
|
def.placement = def.placement or "mapblock_lib"
|
||||||
def.category = def.category or "_uncategorized"
|
|
||||||
|
|
||||||
|
def.category = def.category or "_uncategorized"
|
||||||
building_categories[def.category] = true
|
building_categories[def.category] = true
|
||||||
|
|
||||||
|
-- populate tags
|
||||||
|
if type(def.tags) == "table" then
|
||||||
|
for _, tag in ipairs(def.tags) do
|
||||||
|
local building_list = building_tags[tag]
|
||||||
|
if not building_list then
|
||||||
|
building_list = {}
|
||||||
|
building_tags[tag] = building_list
|
||||||
|
end
|
||||||
|
table.insert(building_list, def)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
-- try to validate the building/placement combo
|
-- try to validate the building/placement combo
|
||||||
local placement = building_lib.get_placement(def.placement)
|
local placement = building_lib.get_placement(def.placement)
|
||||||
assert(placement, "placement not found: " .. def.placement)
|
assert(placement, "placement not found: " .. def.placement)
|
||||||
@ -44,6 +59,10 @@ function building_lib.get_building(name)
|
|||||||
return buildings[name]
|
return buildings[name]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function building_lib.get_building_tags()
|
||||||
|
return building_tags
|
||||||
|
end
|
||||||
|
|
||||||
function building_lib.get_buildings()
|
function building_lib.get_buildings()
|
||||||
return buildings
|
return buildings
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user