diff --git a/src/client/component/ui_scripting.cpp b/src/client/component/ui_scripting.cpp index 44937a20..09cb740a 100644 --- a/src/client/component/ui_scripting.cpp +++ b/src/client/component/ui_scripting.cpp @@ -389,7 +389,7 @@ namespace ui_scripting } const auto folder = globals.in_require_script.substr(0, globals.in_require_script.find_last_of("/\\")); - const std::string name_ = name; + std::string name_ = utils::string::replace(name, "~", "."); const std::string target_script = folder + "/" + name_ + ".lua"; if (utils::io::file_exists(target_script)) diff --git a/src/client/game/scripting/lua/context.cpp b/src/client/game/scripting/lua/context.cpp index 8f1a83ff..c636128a 100644 --- a/src/client/game/scripting/lua/context.cpp +++ b/src/client/game/scripting/lua/context.cpp @@ -10,14 +10,19 @@ #include "../../../component/scripting.hpp" #include "../../../component/command.hpp" #include "../../../component/fastfiles.hpp" +#include "../../../component/mods.hpp" +#include "../../../component/localized_strings.hpp" #include #include +#include namespace scripting::lua { namespace { + const auto json_script = utils::nt::load_resource(LUA_JSON); + vector normalize_vector(const vector& vec) { const auto length = sqrt((vec.get_x() * vec.get_x()) + (vec.get_y() * vec.get_y()) + (vec.get_z() * vec.get_z())); @@ -29,6 +34,13 @@ namespace scripting::lua ); } + void setup_json(sol::state& state) + { + const auto json = state.safe_script(json_script, &sol::script_pass_on_error); + handle_error(json); + state["json"] = json; + } + void setup_io(sol::state& state) { state["io"]["fileexists"] = utils::io::file_exists; @@ -738,6 +750,17 @@ namespace scripting::lua } return count; }; + + game_type["getloadedmod"] = [](const game&) + { + return mods::mod_path; + }; + + game_type["addlocalizedstring"] = [](const game&, const std::string& string, + const std::string& value) + { + localized_strings::override(string, value); + }; } } @@ -773,6 +796,7 @@ namespace scripting::lua }; setup_io(this->state_); + setup_json(this->state_); setup_vector_type(this->state_); setup_entity_type(this->state_, this->event_handler_, this->scheduler_); setup_game_type(this->state_, this->event_handler_, this->scheduler_); @@ -804,6 +828,7 @@ namespace scripting::lua }; setup_io(this->state_); + setup_json(this->state_); setup_vector_type(this->state_); setup_entity_type(this->state_, this->event_handler_, this->scheduler_); setup_game_type(this->state_, this->event_handler_, this->scheduler_);