Overrides!
This commit is contained in:
parent
fcb420c4c7
commit
8b949c4c9a
@ -32,8 +32,8 @@ void ContentBuilder::add(ContentPackRuntime* pack) {
|
||||
Block& ContentBuilder::createBlock(std::string id) {
|
||||
auto found = blockDefs.find(id);
|
||||
if (found != blockDefs.end()) {
|
||||
//return found->second;
|
||||
throw namereuse_error("name "+id+" is already used", contenttype::item);
|
||||
return *found->second;
|
||||
// throw namereuse_error("name "+id+" is already used", contenttype::item);
|
||||
}
|
||||
Block* block = new Block(id);
|
||||
add(block);
|
||||
@ -43,10 +43,10 @@ Block& ContentBuilder::createBlock(std::string id) {
|
||||
ItemDef& ContentBuilder::createItem(std::string id) {
|
||||
auto found = itemDefs.find(id);
|
||||
if (found != itemDefs.end()) {
|
||||
if (found->second->generated) {
|
||||
return *found->second;
|
||||
}
|
||||
throw namereuse_error("name "+id+" is already used", contenttype::item);
|
||||
// if (found->second->generated) {
|
||||
return *found->second;
|
||||
// }
|
||||
// throw namereuse_error("name "+id+" is already used", contenttype::item);
|
||||
}
|
||||
ItemDef* item = new ItemDef(id);
|
||||
add(item);
|
||||
|
||||
@ -36,6 +36,19 @@ bool ContentLoader::fixPackIndices(fs::path folder,
|
||||
if (name[0] == '_')
|
||||
continue;
|
||||
detected.push_back(name);
|
||||
} else if (fs::is_directory(file)) {
|
||||
std::string space = file.stem().string();
|
||||
if (space[0] == '_')
|
||||
continue;
|
||||
for (auto entry : fs::directory_iterator(file)) {
|
||||
fs::path file = entry.path();
|
||||
if (fs::is_regular_file(file) && file.extension() == ".json") {
|
||||
std::string name = file.stem().string();
|
||||
if (name[0] == '_')
|
||||
continue;
|
||||
detected.push_back(space + ':' + name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -268,7 +281,7 @@ void ContentLoader::loadBlock(Block& def, std::string full, std::string name) {
|
||||
auto folder = pack->folder;
|
||||
|
||||
fs::path configFile = folder/fs::path("blocks/"+name+".json");
|
||||
loadBlock(def, full, configFile);
|
||||
if (fs::exists(configFile)) loadBlock(def, full, configFile);
|
||||
|
||||
fs::path scriptfile = folder/fs::path("scripts/"+def.scriptName+".lua");
|
||||
if (fs::is_regular_file(scriptfile)) {
|
||||
@ -280,7 +293,7 @@ void ContentLoader::loadItem(ItemDef& def, std::string full, std::string name) {
|
||||
auto folder = pack->folder;
|
||||
|
||||
fs::path configFile = folder/fs::path("items/"+name+".json");
|
||||
loadItem(def, full, configFile);
|
||||
if (fs::exists(configFile)) loadItem(def, full, configFile);
|
||||
|
||||
fs::path scriptfile = folder/fs::path("scripts/"+def.scriptName+".lua");
|
||||
if (fs::is_regular_file(scriptfile)) {
|
||||
@ -313,8 +326,11 @@ void ContentLoader::load(ContentBuilder& builder) {
|
||||
if (blocksarr) {
|
||||
for (uint i = 0; i < blocksarr->size(); i++) {
|
||||
std::string name = blocksarr->str(i);
|
||||
std::string full = pack->id+":"+name;
|
||||
auto colon = name.find(':');
|
||||
std::string full = colon == std::string::npos ? pack->id + ":" + name : name;
|
||||
if (colon != std::string::npos) name[colon] = '/';
|
||||
auto& def = builder.createBlock(full);
|
||||
if (colon != std::string::npos) def.scriptName = name.substr(0, colon) + '/' + def.scriptName;
|
||||
loadBlock(def, full, name);
|
||||
stats.totalBlocks++;
|
||||
if (!def.hidden) {
|
||||
@ -336,8 +352,12 @@ void ContentLoader::load(ContentBuilder& builder) {
|
||||
if (itemsarr) {
|
||||
for (uint i = 0; i < itemsarr->size(); i++) {
|
||||
std::string name = itemsarr->str(i);
|
||||
std::string full = pack->id+":"+name;
|
||||
loadItem(builder.createItem(full), full, name);
|
||||
auto colon = name.find(':');
|
||||
std::string full = colon == std::string::npos ? pack->id + ":" + name : name;
|
||||
if (colon != std::string::npos) name[colon] = '/';
|
||||
auto& def = builder.createItem(full);
|
||||
if (colon != std::string::npos) def.scriptName = name.substr(0, colon) + '/' + def.scriptName;
|
||||
loadItem(def, full, name);
|
||||
stats.totalItems++;
|
||||
}
|
||||
}
|
||||
|
||||
@ -30,13 +30,13 @@ void scripting::on_frontend_init(Hud* hud) {
|
||||
}
|
||||
|
||||
void scripting::on_frontend_close() {
|
||||
scripting::hud = nullptr;
|
||||
for (auto& pack : scripting::engine->getContentPacks()) {
|
||||
emit_event(pack.id + ".hudclose", [&] (lua::LuaState* state) {
|
||||
state->pushinteger(hud->getPlayer()->getId());
|
||||
return 1;
|
||||
});
|
||||
}
|
||||
scripting::hud = nullptr;
|
||||
}
|
||||
|
||||
void scripting::load_hud_script(int env, std::string packid, fs::path file) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user