cache block.index, block.name, item.index, item.name
This commit is contained in:
parent
913f942adb
commit
086c20c370
@ -7,7 +7,7 @@ local names = {
|
||||
"hidden", "draw-group", "picking-item", "surface-replacement", "script-name",
|
||||
"ui-layout", "inventory-size", "tick-interval", "overlay-texture",
|
||||
"translucent", "fields", "particles", "icon-type", "icon", "placing-block",
|
||||
"stack-size"
|
||||
"stack-size", "name"
|
||||
}
|
||||
for name, _ in pairs(user_props) do
|
||||
table.insert(names, name)
|
||||
@ -40,3 +40,24 @@ make_read_only(block.properties)
|
||||
for k,v in pairs(block.properties) do
|
||||
make_read_only(v)
|
||||
end
|
||||
|
||||
local function cache_names(library)
|
||||
local indices = {}
|
||||
local names = {}
|
||||
for id=0,library.defs_count()-1 do
|
||||
local name = library.properties[id].name
|
||||
indices[name] = id
|
||||
names[id] = name
|
||||
end
|
||||
|
||||
function library.name(id)
|
||||
return names[id]
|
||||
end
|
||||
|
||||
function library.index(name)
|
||||
return indices[name]
|
||||
end
|
||||
end
|
||||
|
||||
cache_names(block)
|
||||
cache_names(item)
|
||||
|
||||
@ -91,10 +91,18 @@ std::unique_ptr<Content> ContentBuilder::build() {
|
||||
for (Block* def : blockDefsIndices) {
|
||||
def->rt.pickingItem = content->items.require(def->pickingItem).rt.id;
|
||||
def->rt.surfaceReplacement = content->blocks.require(def->surfaceReplacement).rt.id;
|
||||
if (def->properties == nullptr) {
|
||||
def->properties = dv::object();
|
||||
}
|
||||
def->properties["name"] = def->name;
|
||||
}
|
||||
|
||||
for (ItemDef* def : itemDefsIndices) {
|
||||
def->rt.placingBlock = content->blocks.require(def->placingBlock).rt.id;
|
||||
if (def->properties == nullptr) {
|
||||
def->properties = dv::object();
|
||||
}
|
||||
def->properties["name"] = def->name;
|
||||
}
|
||||
|
||||
for (auto& [name, def] : content->generators.getDefs()) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user