#include "application/application.h" #include "core/gameevent.h" #include "core/editor.h" #include "application/mainmenu.h" #include "application/gamestate.h" #include "application/editorstate.h" #include "classicmode/classicfactory.h" bool Application::init() { if (!_game_factory || !_core_factory) return false; MainMenu::Callbacks callbacks = { [&](){ pushState(GUIState::Tag::GAME); }, [&](){ pushState(GUIState::Tag::EDITOR); } }; EditorState::Callbacks editor_callbacks = {[&](){ popState(); }}; const auto main_menu = std::make_shared(_core_factory, std::move(callbacks)); const auto game_state = std::make_shared(_game_factory->getGame(), GameState::Callbacks()); const auto editor = std::make_shared(_core_factory, _game_factory->getEditor(), std::move(editor_callbacks)); _states[GUIState::Tag::MAIN_MENU] = main_menu; _states[GUIState::Tag::GAME] = game_state; _states[GUIState::Tag::EDITOR] = editor; pushState(GUIState::Tag::MAIN_MENU); return true; } void Application::input(const kku::SystemEvent& event) { _state_stack.back()->input(event); } void Application::update(const kku::microsec& dt) { _state_stack.back()->update(dt); } void Application::pushState(GUIState::Tag new_state) { if (!_state_stack.empty()) _state_stack.back()->leave(); _state_stack.emplace_back(_states.at(new_state)); _state_stack.back()->enter(); } void Application::popState() { _state_stack.back()->leave(); _state_stack.pop_back(); _state_stack.back()->enter(); }