diff --git a/Blueprint-Values.txt b/Blueprint-Values.txt index f63eec49..9e0ce9ff 100644 --- a/Blueprint-Values.txt +++ b/Blueprint-Values.txt @@ -8,7 +8,7 @@ doubleWithUnit :66.6px list of any single value: vector :["Hello","How are you?","fine"] -vector :[true, false, 0, 1] +vector :[true, false, 0, 1] vector :[100,200,400,800] vector :[50px,100px,200px] vector :[33.3,66.6,100.5] diff --git a/kgEngine-2.0/TileMapGame/ChunkSystem.cpp b/kgEngine-2.0/TileMapGame/ChunkSystem.cpp index 603bcaed..b9aa70c1 100644 --- a/kgEngine-2.0/TileMapGame/ChunkSystem.cpp +++ b/kgEngine-2.0/TileMapGame/ChunkSystem.cpp @@ -170,6 +170,12 @@ namespace kg // its a bug -.- } + void ChunkSystem::saveOpenSavegame( Engine& engine, World& world, SaveManager& saveManager ) + { + saveAllLoadedChunks( engine, world, saveManager ); + saveManager.saveSystems( world ); + } + bool ChunkSystem::ensureChunkLoaded( Engine& engine, World& world, SaveManager& saveManager, const sf::Vector2i& chunkPosition ) { if( !m_loadedChunks[chunkPosition.x][chunkPosition.y] ) diff --git a/kgEngine-2.0/TileMapGame/ChunkSystem.h b/kgEngine-2.0/TileMapGame/ChunkSystem.h index c8570209..b0f7118e 100644 --- a/kgEngine-2.0/TileMapGame/ChunkSystem.h +++ b/kgEngine-2.0/TileMapGame/ChunkSystem.h @@ -82,6 +82,7 @@ namespace kg /*std::list> getEntitiesInChunk( const sf::Vector2i& from, const sf::Vector2i& to )const;*/ + void saveOpenSavegame( Engine& engine, World& world, SaveManager& saveManager ); void saveAllLoadedChunks( Engine& engine, World& world, SaveManager& saveManager ); // returns the position in chunks for the position of an entity diff --git a/kgEngine-2.0/TileMapGame/DefaultGameState.cpp b/kgEngine-2.0/TileMapGame/DefaultGameState.cpp new file mode 100644 index 00000000..d5494eee --- /dev/null +++ b/kgEngine-2.0/TileMapGame/DefaultGameState.cpp @@ -0,0 +1,72 @@ +#include "DefaultGameState.h" +using namespace std; +using namespace sf; + +namespace kg +{ + + void DefaultGameState::onInit() + { + return; + } + + void DefaultGameState::registerGui( tgui::Gui& gui ) + { + return; + } + + void DefaultGameState::registerInputCallbacks( InputManager& inputManager ) + { + Action escapePress( Keyboard::Escape, Action::PressOnce ); + + Action eventClose( Event::Closed ); + + inputManager.setAction( id::Input::SHUT_DOWN, + escapePress || eventClose, + bind( &DefaultGameState::shutDown, this ) ); + } + + void DefaultGameState::onUpdate( GameStateManager& gameStateManager ) + { + if( !m_singleplayerGameStateLaunched ) + { + gameStateManager.push( std::make_shared() ); + m_singleplayerGameStateLaunched = true; + } + } + + void DefaultGameState::removeInputCallbacks( InputManager& inputManager ) + { + inputManager.removeAction( id::Input::SHUT_DOWN ); + } + + void DefaultGameState::removeGui( tgui::Gui& gui ) + { + return; + } + + void DefaultGameState::onDestroy() + { + throw exception( "DefaultGameState should never be destroyed" ); + } + + + const Plugin::Name& DefaultGameState::getPluginName() const + { + return PLUGIN_NAME; + } + + Plugin::Id DefaultGameState::getPluginId() const + { + return id::DEFAULT_GAMESTATE_ID; + } + + const std::string DefaultGameState::PLUGIN_NAME = "Default GameState"; + + void DefaultGameState::shutDown() + { + r_world->getSystem()->saveOpenSavegame( *r_engine, *r_world, *r_saveManager ); + r_engine->shouldTerminate = true; + } + +} diff --git a/kgEngine-2.0/TileMapGame/DefaultGameState.h b/kgEngine-2.0/TileMapGame/DefaultGameState.h new file mode 100644 index 00000000..8d071c41 --- /dev/null +++ b/kgEngine-2.0/TileMapGame/DefaultGameState.h @@ -0,0 +1,39 @@ +#pragma once +#include "stdafx.h" +#include "ChunkSystem.h" +#include "SingleplayerGameState.h" + +namespace kg +{ + class DefaultGameState : public GameState + { + bool m_singleplayerGameStateLaunched = false; + + public: + virtual void onInit() override; + + virtual void registerGui( tgui::Gui& gui ) override; + + virtual void registerInputCallbacks( InputManager& inputManager ) override; + + virtual void onUpdate( GameStateManager& gameStateManager ) override; + + virtual void removeInputCallbacks( InputManager& inputManager ) override; + + virtual void removeGui( tgui::Gui& gui ) override; + + virtual void onDestroy() override; + + + virtual const Plugin::Name& getPluginName() const override; + + virtual Plugin::Id getPluginId() const override; + + + static const std::string PLUGIN_NAME; + + //Input Callbacks + private: + void shutDown(); + }; +} diff --git a/kgEngine-2.0/TileMapGame/GameController.cpp b/kgEngine-2.0/TileMapGame/GameController.cpp deleted file mode 100644 index c325a91d..00000000 --- a/kgEngine-2.0/TileMapGame/GameController.cpp +++ /dev/null @@ -1,271 +0,0 @@ -#include "GameController.h" -using namespace std; -using namespace sf; -using namespace tgui; -using Action = thor::Action; - -namespace kg -{ - void GameController::m_onSavegameOpened( Engine& engine ) - { - m_cameraZoomFactor = 1; - } - - void GameController::init( Engine& engine, World& world, SaveManager& saveManager, std::shared_ptr& configFile ) - { - r_engine = &engine; - r_world = &world; - r_saveManager = &saveManager; - r_graphicsSystem = world.getSystem(); - - m_connectToSignal( saveManager.s_savegameOpened, &GameController::m_onSavegameOpened ); - registerInputCallbacks( engine.inputManager ); - - saveManager.openSavegame( engine, world, "MyFirstSavegameEver" ); - - auto button = make_shared