From f9d8f4c053f609b84417980e3b5266cff8e37205 Mon Sep 17 00:00:00 2001 From: fed <58637860+fedddddd@users.noreply.github.com> Date: Tue, 27 Jun 2023 23:58:41 +0200 Subject: [PATCH] Some fixes --- src/client/component/mod_stats.cpp | 2 +- src/client/component/ui_scripting.cpp | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/client/component/mod_stats.cpp b/src/client/component/mod_stats.cpp index 70185fc2..814750df 100644 --- a/src/client/component/mod_stats.cpp +++ b/src/client/component/mod_stats.cpp @@ -171,7 +171,7 @@ namespace mod_stats return get_stats().access([&](mod_stats_t& stats) -> nlohmann::json { - if (!stats.is_object() || !stats[name].is_object() || stats[name].is_null()) + if (!stats.is_object() || !stats[name].is_object() || stats[name][field].is_null()) { return default_value; } diff --git a/src/client/component/ui_scripting.cpp b/src/client/component/ui_scripting.cpp index 2e4382ef..7683bc33 100644 --- a/src/client/component/ui_scripting.cpp +++ b/src/client/component/ui_scripting.cpp @@ -534,6 +534,13 @@ namespace ui_scripting return json_to_lua(mod_stats::get_struct(mapname, key)); }; + mods_stats_table["getstructor"] = [](const std::string& mapname, + const std::string& key, const script_value& default_value) + { + const auto json_default_value = lua_to_json(default_value); + return json_to_lua(mod_stats::get_struct(mapname, key, json_default_value)); + }; + mods_stats_table["save"] = mod_stats::write; mods_stats_table["getall"] = []() {