mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-11-21 18:09:46 +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
|
content_report = nil
|
||||||
|
|
||||||
function delete_content()
|
function delete_content()
|
||||||
local units = {}
|
local blocks = {}
|
||||||
|
local items = {}
|
||||||
for i, entry in ipairs(content_report.content) do
|
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
|
end
|
||||||
local request = {
|
local request = {
|
||||||
units = units
|
blocks = blocks,
|
||||||
|
items = items
|
||||||
}
|
}
|
||||||
app.delete_world_content(content_report.world, request, true)
|
app.delete_world_content(content_report.world, request, true)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -328,21 +328,34 @@ static int l_delete_world(lua::State* L) {
|
||||||
return 0;
|
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;
|
ContentRemovalRequest request;
|
||||||
if (!lua::istable(L, idx)) {
|
if (!lua::istable(L, idx)) {
|
||||||
throw std::runtime_error("table expected as argument");
|
throw std::runtime_error("table expected as argument");
|
||||||
}
|
}
|
||||||
if (!lua::getfield(L, "units", idx)) {
|
lua::pushnil(L);
|
||||||
throw std::runtime_error("table with 'units' field expected");
|
while (lua::next(L, idx)) {
|
||||||
}
|
auto key = lua::require_lstring(L, -2);
|
||||||
if (!lua::istable(L, -1)) {
|
int len = lua::objlen(L, -1);
|
||||||
throw std::runtime_error("'units' field must be a table");
|
|
||||||
}
|
for (int i = 0; i < len; i++) {
|
||||||
int len = lua::objlen(L, -1);
|
lua::rawgeti(L, i + 1);
|
||||||
for (int i = 0; i < len; i++) {
|
auto value = lua::require_lstring(L, -1);
|
||||||
lua::rawgeti(L, i + 1);
|
|
||||||
request.units.emplace_back(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);
|
lua::pop(L);
|
||||||
}
|
}
|
||||||
return request;
|
return request;
|
||||||
|
|
|
||||||
|
|
@ -249,8 +249,10 @@ static void replace_all(
|
||||||
|
|
||||||
void WorldFiles::deleteContent(const ContentRemovalRequest& request) {
|
void WorldFiles::deleteContent(const ContentRemovalRequest& request) {
|
||||||
auto root = io::read_json(getIndicesFile());
|
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);
|
replace_all(root["blocks"], unit, CORE_AIR);
|
||||||
|
}
|
||||||
|
for (const auto& unit : request.items) {
|
||||||
replace_all(root["items"], unit, CORE_EMPTY);
|
replace_all(root["items"], unit, CORE_EMPTY);
|
||||||
}
|
}
|
||||||
io::write_json(getIndicesFile(), root);
|
io::write_json(getIndicesFile(), root);
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,8 @@ struct WorldInfo;
|
||||||
struct DebugSettings;
|
struct DebugSettings;
|
||||||
|
|
||||||
struct ContentRemovalRequest {
|
struct ContentRemovalRequest {
|
||||||
std::vector<std::string> units;
|
std::vector<std::string> blocks;
|
||||||
|
std::vector<std::string> items;
|
||||||
};
|
};
|
||||||
|
|
||||||
class WorldFiles {
|
class WorldFiles {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue