inventory convert fix (items count)

This commit is contained in:
MihailRis 2024-05-05 17:49:17 +03:00
parent bad871b0a2
commit 2a77c24414
5 changed files with 16 additions and 4 deletions

View File

@ -6,8 +6,9 @@ add_packs = {}
rem_packs = {}
function apply()
core.reconfig_packs(add_packs, rem_packs)
menu:back()
if not core.reconfig_packs(add_packs, rem_packs) then
menu:back()
end
end
function refresh_changes()

View File

@ -335,6 +335,10 @@ Map& Map::put(std::string key, std::unique_ptr<Value> value) {
return *this;
}
void Map::remove(const std::string& key) {
values.erase(key);
}
List& Map::putList(std::string key) {
List* arr = new List();
put(key, arr);

View File

@ -118,6 +118,8 @@ namespace dynamic {
Map& put(std::string key, bool value);
Map& put(std::string key, std::unique_ptr<Value> value);
void remove(const std::string& key);
List& putList(std::string key);
Map& putMap(std::string key);

View File

@ -88,7 +88,11 @@ void Inventory::convert(dynamic::Map* data, const ContentLUT* lut) {
for (size_t i = 0; i < slotsarr->size(); i++) {
auto item = slotsarr->map(i);
itemid_t id = item->getInt("id", ITEM_EMPTY);
item->put("id", lut->getItemId(id));
itemid_t replacement = lut->getItemId(id);
item->put("id", replacement);
if (replacement == 0 && item->has("count")) {
item->remove("count");
}
}
}

View File

@ -91,7 +91,8 @@ static int l_reconfig_packs(lua_State* L) {
}
auto controller = scripting::engine->getController();
controller->reconfigPacks(scripting::controller, addPacks, remPacks);
return 0;
lua_pushboolean(L, scripting::controller != nullptr);
return 1;
}
static int l_get_bindings(lua_State* L) {