You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
project-kyoku/src/application/src/application.cpp

67 lines
1.9 KiB
C++

2 years ago
#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 "application/about.h"
2 years ago
#include "classicmode/classicfactory.h"
bool Application::init()
{
if (!_core_factory)
2 years ago
return false;
MainMenu::Callbacks callbacks =
{
[&](){ pushState(GUIState::Tag::GAME); },
[&](){ pushState(GUIState::Tag::EDITOR); },
[&](){ pushState(GUIState::Tag::ABOUT); },
2 years ago
};
EditorState::Callbacks editor_callbacks = {[&](){ popState(); }};
About::Callbacks about_callbacks = {[&](){ popState(); }};
2 years ago
const auto main_menu = std::make_shared<MainMenu>(_core_factory, std::move(callbacks));
const auto game_state = std::make_shared<GameState>(_core_factory, classic::getGame(_core_factory), GameState::Callbacks());
const auto editor = std::make_shared<EditorState>(_core_factory, classic::getEditor(_core_factory), std::move(editor_callbacks));
const auto about = std::make_shared<About>(_core_factory, std::move(about_callbacks));
2 years ago
_states[GUIState::Tag::MAIN_MENU] = main_menu;
_states[GUIState::Tag::GAME] = game_state;
_states[GUIState::Tag::EDITOR] = editor;
_states[GUIState::Tag::ABOUT] = about;
2 years ago
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();
}