This commit is contained in:
MihailRis 2025-08-07 22:37:40 +03:00
parent 0a02d3fbec
commit 9fcff65cca
5 changed files with 31 additions and 18 deletions

View File

@ -1,13 +1,13 @@
local menubg local menubg
function on_screen_changed(screen) local function clear_menu()
if screen ~= "menu" then if menubg then
if menubg then menubg:destruct()
menubg:destruct() menubg = nil
menubg = nil
end
return
end end
end
local function configure_menu()
local controller = {} local controller = {}
function controller.resize_menu_bg() function controller.resize_menu_bg()
local w, h = unpack(gui.get_viewport()) local w, h = unpack(gui.get_viewport())
@ -19,8 +19,16 @@ function on_screen_changed(screen)
end end
_GUI_ROOT.root:add( _GUI_ROOT.root:add(
"<image id='menubg' src='gui/menubg' size-func='DATA.resize_menu_bg' ".. "<image id='menubg' src='gui/menubg' size-func='DATA.resize_menu_bg' "..
"z-index='-1000' interactive='true'/>", controller) "z-index='-1' interactive='true'/>", controller)
menubg = _GUI_ROOT.menubg menubg = _GUI_ROOT.menubg
controller.resize_menu_bg() controller.resize_menu_bg()
menu.page = "main" menu.page = "main"
end end
function on_screen_changed(screen)
if screen ~= "menu" then
clear_menu()
else
configure_menu()
end
end

View File

@ -1,6 +1,9 @@
#include "Project.hpp" #include "Project.hpp"
#include "data/dv_util.hpp" #include "data/dv_util.hpp"
#include "logic/scripting/scripting.hpp"
Project::~Project() = default;
dv::value Project::serialize() const { dv::value Project::serialize() const {
return dv::object({ return dv::object({

View File

@ -2,13 +2,21 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include <memory>
#include "interfaces/Serializable.hpp" #include "interfaces/Serializable.hpp"
namespace scripting {
class IProjectScript;
}
struct Project : Serializable { struct Project : Serializable {
std::string name; std::string name;
std::string title; std::string title;
std::vector<std::string> basePacks; std::vector<std::string> basePacks;
std::unique_ptr<scripting::IProjectScript> script;
~Project();
dv::value serialize() const override; dv::value serialize() const override;
void deserialize(const dv::value& src) override; void deserialize(const dv::value& src) override;

View File

@ -185,7 +185,7 @@ void Engine::initialize(CoreParameters coreParameters) {
langs::setup(lang, paths.resPaths.collectRoots()); langs::setup(lang, paths.resPaths.collectRoots());
}, true)); }, true));
projectScript = load_project_script(); project->script = load_project_script();
} }
void Engine::loadSettings() { void Engine::loadSettings() {
@ -242,7 +242,6 @@ void Engine::run() {
} }
} }
#include "graphics/ui/elements/Container.hpp"
void Engine::postUpdate() { void Engine::postUpdate() {
network->update(); network->update();
postRunnables.run(); postRunnables.run();
@ -285,7 +284,6 @@ void Engine::saveSettings() {
} }
void Engine::close() { void Engine::close() {
projectScript.reset();
saveSettings(); saveSettings();
logger.info() << "shutting down"; logger.info() << "shutting down";
if (screen) { if (screen) {
@ -302,6 +300,7 @@ void Engine::close() {
audio::close(); audio::close();
network.reset(); network.reset();
clearKeepedObjects(); clearKeepedObjects();
project.reset();
scripting::close(); scripting::close();
logger.info() << "scripting finished"; logger.info() << "scripting finished";
if (!params.headless) { if (!params.headless) {
@ -368,8 +367,8 @@ void Engine::setScreen(std::shared_ptr<Screen> screen) {
if (this->screen) { if (this->screen) {
this->screen->onOpen(); this->screen->onOpen();
} }
if (projectScript && this->screen) { if (project->script && this->screen) {
projectScript->onScreenChange(this->screen->getName()); project->script->onScreenChange(this->screen->getName());
} }
} }

View File

@ -75,7 +75,6 @@ class Engine : public util::ObjectsKeeper {
std::unique_ptr<Input> input; std::unique_ptr<Input> input;
std::unique_ptr<gui::GUI> gui; std::unique_ptr<gui::GUI> gui;
std::unique_ptr<devtools::Editor> editor; std::unique_ptr<devtools::Editor> editor;
std::unique_ptr<scripting::IProjectScript> projectScript;
PostRunnables postRunnables; PostRunnables postRunnables;
Time time; Time time;
OnWorldOpen levelConsumer; OnWorldOpen levelConsumer;
@ -183,8 +182,4 @@ public:
const Project& getProject() { const Project& getProject() {
return *project; return *project;
} }
scripting::IProjectScript* getProjectScript() {
return projectScript.get();
}
}; };