mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-11-20 09:29:44 +00:00
replace 'units' with 'blocks', 'items' for some reason
This commit is contained in:
parent
8268118735
commit
ecc4c1794e
4 changed files with 39 additions and 16 deletions
|
|
@ -1,12 +1,19 @@
|
|||
content_report = nil
|
||||
|
||||
function delete_content()
|
||||
local units = {}
|
||||
local blocks = {}
|
||||
local items = {}
|
||||
for i, entry in ipairs(content_report.content) do
|
||||
table.insert(units, entry.name)
|
||||
local type = entry.type
|
||||
if type == "block" then
|
||||
table.insert(blocks, entry.name)
|
||||
elseif type == "item" then
|
||||
table.insert(items, entry.name)
|
||||
end
|
||||
end
|
||||
local request = {
|
||||
units = units
|
||||
blocks = blocks,
|
||||
items = items
|
||||
}
|
||||
app.delete_world_content(content_report.world, request, true)
|
||||
end
|
||||
|
|
|
|||
|
|
@ -328,21 +328,34 @@ static int l_delete_world(lua::State* L) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static ContentRemovalRequest parse_content_removal_request(lua::State* L, int idx) {
|
||||
static ContentRemovalRequest parse_content_removal_request(
|
||||
lua::State* L, int idx
|
||||
) {
|
||||
ContentRemovalRequest request;
|
||||
if (!lua::istable(L, idx)) {
|
||||
throw std::runtime_error("table expected as argument");
|
||||
}
|
||||
if (!lua::getfield(L, "units", idx)) {
|
||||
throw std::runtime_error("table with 'units' field expected");
|
||||
}
|
||||
if (!lua::istable(L, -1)) {
|
||||
throw std::runtime_error("'units' field must be a table");
|
||||
}
|
||||
int len = lua::objlen(L, -1);
|
||||
for (int i = 0; i < len; i++) {
|
||||
lua::rawgeti(L, i + 1);
|
||||
request.units.emplace_back(lua::require_lstring(L, -1));
|
||||
lua::pushnil(L);
|
||||
while (lua::next(L, idx)) {
|
||||
auto key = lua::require_lstring(L, -2);
|
||||
int len = lua::objlen(L, -1);
|
||||
|
||||
for (int i = 0; i < len; i++) {
|
||||
lua::rawgeti(L, i + 1);
|
||||
auto value = lua::require_lstring(L, -1);
|
||||
|
||||
if (key == "blocks") {
|
||||
request.blocks.emplace_back(value);
|
||||
} else if (key == "items") {
|
||||
request.items.emplace_back(value);
|
||||
} else {
|
||||
throw std::runtime_error(
|
||||
"invalid key in content removal request: " +
|
||||
std::string(key)
|
||||
);
|
||||
}
|
||||
lua::pop(L);
|
||||
}
|
||||
lua::pop(L);
|
||||
}
|
||||
return request;
|
||||
|
|
|
|||
|
|
@ -249,8 +249,10 @@ static void replace_all(
|
|||
|
||||
void WorldFiles::deleteContent(const ContentRemovalRequest& request) {
|
||||
auto root = io::read_json(getIndicesFile());
|
||||
for (const auto& unit : request.units) {
|
||||
for (const auto& unit : request.blocks) {
|
||||
replace_all(root["blocks"], unit, CORE_AIR);
|
||||
}
|
||||
for (const auto& unit : request.items) {
|
||||
replace_all(root["items"], unit, CORE_EMPTY);
|
||||
}
|
||||
io::write_json(getIndicesFile(), root);
|
||||
|
|
|
|||
|
|
@ -24,7 +24,8 @@ struct WorldInfo;
|
|||
struct DebugSettings;
|
||||
|
||||
struct ContentRemovalRequest {
|
||||
std::vector<std::string> units;
|
||||
std::vector<std::string> blocks;
|
||||
std::vector<std::string> items;
|
||||
};
|
||||
|
||||
class WorldFiles {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue