commit 3
This commit is contained in:
parent
5fae85dd35
commit
cef4cbc5b9
@ -29,11 +29,7 @@ namespace images
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (data.empty()
|
if (data.empty() && !utils::io::read_file(utils::string::va("images/%s.png", image->name), &data))
|
||||||
&& !utils::io::read_file(utils::string::va("images/%s.png", image->name), &data)
|
|
||||||
&& game::mod_folder.empty() && !utils::io::read_file(utils::string::va("%s/images/%s.png",
|
|
||||||
game::mod_folder.data(), image->name), &data)
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
#include <utils/nt.hpp>
|
#include <utils/nt.hpp>
|
||||||
#include <utils/io.hpp>
|
#include <utils/io.hpp>
|
||||||
#include <utils/http.hpp>
|
#include <utils/http.hpp>
|
||||||
|
#include <utils/cryptography.hpp>
|
||||||
|
|
||||||
namespace ui_scripting::lua
|
namespace ui_scripting::lua
|
||||||
{
|
{
|
||||||
@ -710,7 +711,7 @@ namespace ui_scripting::lua
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setup_game_type(sol::state& state, event_handler& handler, scheduler& scheduler, bool safe_mode)
|
void setup_game_type(sol::state& state, event_handler& handler, scheduler& scheduler)
|
||||||
{
|
{
|
||||||
struct game
|
struct game
|
||||||
{
|
{
|
||||||
@ -1103,35 +1104,37 @@ namespace ui_scripting::lua
|
|||||||
return ::game::mod_folder;
|
return ::game::mod_folder;
|
||||||
};
|
};
|
||||||
|
|
||||||
if (/*!safe_mode*/true)
|
static int request_id{};
|
||||||
|
game_type["httpget"] = [](const game&, const std::string& url)
|
||||||
{
|
{
|
||||||
static int request_id{};
|
const auto id = request_id++;
|
||||||
game_type["httpget"] = [](const game&, const std::string& url)
|
::scheduler::once([url, id]()
|
||||||
{
|
{
|
||||||
const auto id = request_id++;
|
const auto result = utils::http::get_data(url);
|
||||||
::scheduler::once([url, id]()
|
::scheduler::once([result, id]
|
||||||
{
|
{
|
||||||
const auto result = utils::http::get_data(url);
|
event event;
|
||||||
::scheduler::once([result, id]
|
event.element = &ui_element;
|
||||||
|
event.name = "http_request_done";
|
||||||
|
if (result.has_value())
|
||||||
{
|
{
|
||||||
event event;
|
event.arguments = { id, true, result.value() };
|
||||||
event.element = &ui_element;
|
}
|
||||||
event.name = "http_request_done";
|
else
|
||||||
if (result.has_value())
|
{
|
||||||
{
|
event.arguments = { id, false };
|
||||||
event.arguments = {id, true, result.value()};
|
}
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
event.arguments = {id, false};
|
|
||||||
}
|
|
||||||
|
|
||||||
notify(event);
|
notify(event);
|
||||||
}, ::scheduler::pipeline::renderer);
|
}, ::scheduler::pipeline::renderer);
|
||||||
}, ::scheduler::pipeline::async);
|
}, ::scheduler::pipeline::async);
|
||||||
return id;
|
return id;
|
||||||
};
|
};
|
||||||
}
|
|
||||||
|
game_type["sha"] = [](const game&, const std::string& data)
|
||||||
|
{
|
||||||
|
return utils::cryptography::sha1::compute(data, true);
|
||||||
|
};
|
||||||
|
|
||||||
struct player
|
struct player
|
||||||
{
|
{
|
||||||
@ -1288,10 +1291,9 @@ namespace ui_scripting::lua
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
context::context(std::string data, script_type type, bool safe_mode)
|
context::context(std::string data, script_type type)
|
||||||
: scheduler_(state_)
|
: scheduler_(state_)
|
||||||
, event_handler_(state_)
|
, event_handler_(state_)
|
||||||
, safe_mode_(safe_mode)
|
|
||||||
|
|
||||||
{
|
{
|
||||||
this->state_.open_libraries(sol::lib::base,
|
this->state_.open_libraries(sol::lib::base,
|
||||||
@ -1307,8 +1309,7 @@ namespace ui_scripting::lua
|
|||||||
setup_vector_type(this->state_);
|
setup_vector_type(this->state_);
|
||||||
setup_element_type(this->state_, this->event_handler_, this->scheduler_);
|
setup_element_type(this->state_, this->event_handler_, this->scheduler_);
|
||||||
setup_menu_type(this->state_, this->event_handler_, this->scheduler_);
|
setup_menu_type(this->state_, this->event_handler_, this->scheduler_);
|
||||||
setup_game_type(this->state_, this->event_handler_,
|
setup_game_type(this->state_, this->event_handler_, this->scheduler_);
|
||||||
this->scheduler_, this->safe_mode_);
|
|
||||||
setup_lui_types(this->state_, this->event_handler_, this->scheduler_);
|
setup_lui_types(this->state_, this->event_handler_, this->scheduler_);
|
||||||
|
|
||||||
if (type == script_type::file)
|
if (type == script_type::file)
|
||||||
|
@ -29,7 +29,7 @@ namespace ui_scripting::lua
|
|||||||
class context
|
class context
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
context(std::string data, script_type type, bool safe_mode);
|
context(std::string data, script_type type);
|
||||||
~context();
|
~context();
|
||||||
|
|
||||||
context(context&&) noexcept = delete;
|
context(context&&) noexcept = delete;
|
||||||
@ -45,7 +45,6 @@ namespace ui_scripting::lua
|
|||||||
sol::state state_{};
|
sol::state state_{};
|
||||||
std::string folder_;
|
std::string folder_;
|
||||||
std::unordered_set<std::string> loaded_scripts_;
|
std::unordered_set<std::string> loaded_scripts_;
|
||||||
bool safe_mode_;
|
|
||||||
|
|
||||||
scheduler scheduler_;
|
scheduler scheduler_;
|
||||||
event_handler event_handler_;
|
event_handler event_handler_;
|
||||||
|
@ -318,14 +318,14 @@ namespace ui_scripting::lua::engine
|
|||||||
{
|
{
|
||||||
if (std::filesystem::is_directory(script) && utils::io::file_exists(script + "/__init__.lua"))
|
if (std::filesystem::is_directory(script) && utils::io::file_exists(script + "/__init__.lua"))
|
||||||
{
|
{
|
||||||
get_scripts().push_back(std::make_unique<context>(script, script_type::file, true));
|
get_scripts().push_back(std::make_unique<context>(script, script_type::file));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void load_code(const std::string& code, bool safe_mode)
|
void load_code(const std::string& code)
|
||||||
{
|
{
|
||||||
get_scripts().push_back(std::make_unique<context>(code, script_type::code, safe_mode));
|
get_scripts().push_back(std::make_unique<context>(code, script_type::code));
|
||||||
}
|
}
|
||||||
|
|
||||||
void render_menus()
|
void render_menus()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user