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