From 1e7dcb815e00e41e3e8771d16d94fb3eb4ca3b08 Mon Sep 17 00:00:00 2001 From: Dominic Masters Date: Sat, 17 Dec 2022 23:18:06 -0800 Subject: [PATCH] Save Manager --- src/dawn/CMakeLists.txt | 1 + src/dawn/game/_DawnGame.hpp | 1 + src/dawn/save/CMakeLists.txt | 11 + src/dawn/save/SaveFile.cpp | 32 +++ src/dawn/save/SaveFile.hpp | 63 +++++ src/dawn/save/SaveManager.cpp | 217 ++++++++++++++++++ src/dawn/save/SaveManager.hpp | 91 ++++++++ src/dawn/time/CMakeLists.txt | 2 +- .../{TimeManager.cpp => ITimeManager.cpp} | 10 +- .../{TimeManager.hpp => ITimeManager.hpp} | 11 +- src/dawn/ui/UILabel.cpp | 1 - src/dawn/util/string.hpp | 35 +++ src/dawnpokergame/CMakeLists.txt | 1 + src/dawnpokergame/game/DawnGame.cpp | 3 +- src/dawnpokergame/game/DawnGame.hpp | 2 + src/dawnpokergame/save/CMakeLists.txt | 10 + src/dawnpokergame/save/PokerSaveManager.cpp | 28 +++ src/dawnpokergame/save/PokerSaveManager.hpp | 22 ++ src/dawnpokergame/scenes/TestScene.hpp | 4 - src/dawnwin32/CMakeLists.txt | 3 +- src/dawnwin32/time/CMakeLists.txt | 10 + src/dawnwin32/time/TimeManager.cpp | 16 ++ src/dawnwin32/time/TimeManager.hpp | 15 ++ 23 files changed, 574 insertions(+), 15 deletions(-) create mode 100644 src/dawn/save/CMakeLists.txt create mode 100644 src/dawn/save/SaveFile.cpp create mode 100644 src/dawn/save/SaveFile.hpp create mode 100644 src/dawn/save/SaveManager.cpp create mode 100644 src/dawn/save/SaveManager.hpp rename src/dawn/time/{TimeManager.cpp => ITimeManager.cpp} (73%) rename src/dawn/time/{TimeManager.hpp => ITimeManager.hpp} (79%) create mode 100644 src/dawn/util/string.hpp create mode 100644 src/dawnpokergame/save/CMakeLists.txt create mode 100644 src/dawnpokergame/save/PokerSaveManager.cpp create mode 100644 src/dawnpokergame/save/PokerSaveManager.hpp create mode 100644 src/dawnwin32/time/CMakeLists.txt create mode 100644 src/dawnwin32/time/TimeManager.cpp create mode 100644 src/dawnwin32/time/TimeManager.hpp diff --git a/src/dawn/CMakeLists.txt b/src/dawn/CMakeLists.txt index e4cada52..3446c2a2 100644 --- a/src/dawn/CMakeLists.txt +++ b/src/dawn/CMakeLists.txt @@ -23,6 +23,7 @@ add_subdirectory(display) add_subdirectory(input) add_subdirectory(locale) add_subdirectory(poker) +add_subdirectory(save) add_subdirectory(scene) add_subdirectory(time) add_subdirectory(ui) diff --git a/src/dawn/game/_DawnGame.hpp b/src/dawn/game/_DawnGame.hpp index 2a0fca30..ae4ff3c2 100644 --- a/src/dawn/game/_DawnGame.hpp +++ b/src/dawn/game/_DawnGame.hpp @@ -12,6 +12,7 @@ #include "time/TimeManager.hpp" #include "input/InputBinds.hpp" #include "locale/LocaleManager.hpp" +#include "save/SaveManager.hpp" #define DAWN_GAME_INIT_RESULT_SUCCESS 0 #define DAWN_GAME_UPDATE_RESULT_SUCCESS 0 diff --git a/src/dawn/save/CMakeLists.txt b/src/dawn/save/CMakeLists.txt new file mode 100644 index 00000000..8bb54958 --- /dev/null +++ b/src/dawn/save/CMakeLists.txt @@ -0,0 +1,11 @@ +# Copyright (c) 2022 Dominic Masters +# +# This software is released under the MIT License. +# https://opensource.org/licenses/MIT + +# Sources +target_sources(${DAWN_TARGET_NAME} + PRIVATE + SaveFile.cpp + SaveManager.cpp +) \ No newline at end of file diff --git a/src/dawn/save/SaveFile.cpp b/src/dawn/save/SaveFile.cpp new file mode 100644 index 00000000..db457acf --- /dev/null +++ b/src/dawn/save/SaveFile.cpp @@ -0,0 +1,32 @@ +// Copyright (c) 2022 Dominic Masters +// +// This software is released under the MIT License. +// https://opensource.org/licenses/MIT + +#include "SaveFile.hpp" + +using namespace Dawn; + +bool_t SaveFile::has(std::string key) { + auto exist = this->values.find(key); + return exist != this->values.end(); +} + +savedata_t SaveFile::get(std::string key) { + auto exist = this->values.find(key); + assertTrue(exist != this->values.end()); + return exist->second; +} + +void SaveFile::set(std::string key, savedata_t value) { + this->hasChanges = true; + this->values[key] = value; +} + +void SaveFile::copy(struct SaveFile raw, std::string key) { + this->set(key, raw.get(key)); +} + +void SaveFile::reset() { + this->values.clear(); +} \ No newline at end of file diff --git a/src/dawn/save/SaveFile.hpp b/src/dawn/save/SaveFile.hpp new file mode 100644 index 00000000..09e398c9 --- /dev/null +++ b/src/dawn/save/SaveFile.hpp @@ -0,0 +1,63 @@ +// Copyright (c) 2022 Dominic Masters +// +// This software is released under the MIT License. +// https://opensource.org/licenses/MIT + +#pragma once +#include "dawnlibs.hpp" +#include "assert/assert.hpp" +#include "util/array.hpp" + +namespace Dawn { + typedef union { + float_t f; + int64_t i64; + int32_t i32; + uint32_t u32; + int16_t i16; + uint16_t u16; + uint8_t u8; + int8_t i8; + } savedata_t; + + struct SaveFile { + bool_t hasChanges; + std::map values; + // std::map stringValues; + // std::map> arrayValues; + + /** + * Returns true if the given key exists in the save file. + * + * @param key Key to check if exists. + * @return True if exists. + */ + bool_t has(std::string key); + + /** + * Returns the value of a given key. + * + * @param key Key to get the value of. + * @return The value. + */ + savedata_t get(std::string key); + + // std::string getString(std::string key); + // std::vector getArray(std::string key); + + /** + * Sets the given value to the save file. + * + * @param key Key to set. + * @param data Data to set. + */ + void set(std::string key, savedata_t data); + + void copy(struct SaveFile raw, std::string key); + + /** + * Completely resets the save file (empties all the values). + */ + void reset(); + }; +} \ No newline at end of file diff --git a/src/dawn/save/SaveManager.cpp b/src/dawn/save/SaveManager.cpp new file mode 100644 index 00000000..ad33df71 --- /dev/null +++ b/src/dawn/save/SaveManager.cpp @@ -0,0 +1,217 @@ +// Copyright (c) 2022 Dominic Masters +// +// This software is released under the MIT License. +// https://opensource.org/licenses/MIT + +#include "SaveManager.hpp" +#include "game/DawnGame.hpp" + +using namespace Dawn; + +SaveManager::SaveManager(DawnGame *game) { + this->game = game; +} + +void SaveManager::saveFile() { + savedata_t value; + + assertTrue(this->currentSaveSlot >= 0); + + // Update metadata + auto timestamp = this->game->timeManager.getTimestamp(); + value.i64 = timestamp; + this->currentSave.set(SAVE_KEY_TIMESTAMP, value); + value.i16 = this->currentSaveSlot; + this->currentSave.set(SAVE_KEY_SLOT, value); + + // Now open output buffer. + char filename[SAVE_MANAGER_FILENAME_LENGTH]; + sprintf(filename, "savefile_%u.save", this->currentSaveSlot); + FILE *fptr = fopen(filename, "wb"); + if(fptr == NULL) { + printf("Error opening %s\n", filename); + assertUnreachable(); + return; + } + + // Now begin buffering data. First we start with the common phrase, the engine + // version, the timestamp. In future we will store the MD5 here too. + char buffer[SAVE_MANAGER_BUFFER_LENGTH]; + auto len = sprintf(buffer, "DE_SAVE|%s|%lld|", "1.00", timestamp); + fwrite(buffer, sizeof(char), len, fptr); + + // Now buffer out the data, this is almost certain to change over time. + auto it = this->currentSave.values.begin(); + while(it != this->currentSave.values.end()) { + uint8_t *buffer = (uint8_t *)&it->second; + char delim = '|'; + fwrite(it->first.c_str(), sizeof(char), strlen(it->first.c_str()), fptr); + fwrite(&delim, sizeof(char), 1, fptr); + fwrite(buffer, sizeof(uint8_t), sizeof(savedata_t) / sizeof(uint8_t), fptr); + fwrite(&delim, sizeof(char), 1, fptr); + ++it; + } + + // Buffering done, close the file buffer. + fclose(fptr); + this->currentSave.hasChanges = false; +} + +enum SaveLoadResult SaveManager::loadFile() { + this->currentSave.reset(); + + assertTrue(this->currentSaveSlot >= 0); + + // Load file + struct SaveFile temporaryFile; + + char filename[SAVE_MANAGER_FILENAME_LENGTH]; + sprintf(filename, "savefile_%u.save", this->currentSaveSlot); + FILE *fptr = fopen(filename, "rb"); + if(fptr == NULL) { + return SAVE_LOAD_RESULT_FILE_NOT_PRESENT; + } + + // Let's read how long the file is first. + fseek(fptr, 0, SEEK_END); + auto len = ftell(fptr); + + // Now let's just ensure the file isn't too small, this starts by us making + // sure we have at least "DE_SAVE|%s|%lld|", the string is unknown length, + // but we can be 100% sure of the rest of the file size. So we take + // 7+1+1+1+19+1=30 + if(len < 30) { + fclose(fptr); + return SAVE_LOAD_RESULT_TOO_SMALL; + } + + // Rewind. + fseek(fptr, 0, SEEK_SET); + + // Ok let's buffer the first 8 characters to validate "DE_SAVE|" + char buffer[SAVE_MANAGER_BUFFER_LENGTH]; + auto read = fread(buffer, sizeof(char), SAVE_MANAGER_BUFFER_LENGTH, fptr); + if( + read < 8 || + buffer[0] != 'D' || + buffer[1] != 'E' || + buffer[2] != '_' || + buffer[3] != 'S' || + buffer[4] != 'A' || + buffer[5] != 'V' || + buffer[6] != 'E' || + buffer[7] != '|' + ) { + fclose(fptr); + return SAVE_LOAD_RESULT_CORRUPTED_DE_SAVE; + } + + // Now read ahead to the next vertical bar, that will give us the engine + // version + char *bufferCurrent = buffer + 8; + char *p = stringFindNext(bufferCurrent, '|', 10); + if(p == NULL) { + fclose(fptr); + return SAVE_LOAD_RESULT_CORRUPTED_VERSION; + } + *p = '\0'; + char *version = bufferCurrent; + bufferCurrent = p + 1; + + // Now read the timestamp string. + p = stringFindNext(bufferCurrent, '|', 64); + if(p == NULL) { + fclose(fptr); + return SAVE_LOAD_RESULT_CORRUPTED_TIMESTAMP; + } + *p = '\0'; + char *strTimestamp = bufferCurrent; + + // Parse timestamp + int64_t timestamp = strtoll(strTimestamp, NULL, 10); + if(timestamp == 0) { + fclose(fptr); + return SAVE_LOAD_RESULT_CORRUPTED_TIMESTAMP; + } + + // Now begin parsing the data in the save file. We start here, at the end of + // the previous string, so it will INCLUDE "|" at the first char. + read = p - buffer; + while(read < (len-1)) { + // Rewind and then buffer the next set of bytes + fseek(fptr, (long)read, SEEK_SET); + if(fread(buffer, sizeof(char), SAVE_MANAGER_BUFFER_LENGTH, fptr) <= 1) { + break; + } + + // Because we finish the last string INCLUDING "|", then we skip it here. + bufferCurrent = buffer + 1; + + // Now, read the key + p = stringFindNext(bufferCurrent, '|', SAVE_MANAGER_BUFFER_LENGTH); + if(p == NULL) { + fclose(fptr); + return SAVE_LOAD_RESULT_CORRUPTED_DATA_KEY; + } + + *p = '\0'; + char *key = bufferCurrent; + + // Validate the string lengths + if(strlen(key) <= 0) { + fclose(fptr); + return SAVE_LOAD_RESULT_CORRUPTED_DATA_KEY; + } + + // Now read the value + bufferCurrent = p + 1; + savedata_t destination; + uint8_t *ptrValue = (uint8_t*)bufferCurrent; + memoryCopy(ptrValue, &destination, sizeof(savedata_t)); + + // Now advance the pointer... + p = bufferCurrent + sizeof(savedata_t); + if(*p != '|') { + fclose(fptr); + return SAVE_LOAD_RESULT_CORRUPTED_DATA_VALUE; + } + + // Set the value. + temporaryFile.set(std::string(key), destination); + read += (p - buffer); + } + + // Close file + fclose(fptr); + + // OK Let's validate that everything was read OK + if(temporaryFile.get(SAVE_KEY_TIMESTAMP).i64 != timestamp) { + return SAVE_LOAD_RESULT_MISMATCH_TIMESTAMP; + } + + // Now pass off to the loader + if(this->validateSave(temporaryFile) != false) { + return SAVE_LOAD_RESULT_ERROR; + } + + // Unmark changes. In future I may need to do more complex testing, e.g. if + // the game has a newer version that updates save files some how. + this->currentSave.hasChanges = false; + return SAVE_LOAD_SUCCESS; +} + +void SaveManager::deleteFile(int16_t slot) { + assertTrue(slot >= 0); +} + +void SaveManager::useSlot(int16_t slot) { + assertTrue(slot >= 0); + this->currentSaveSlot = slot; + this->currentSave.reset(); +} + +std::vector SaveManager::getUsedSlots() { + std::vector slots; + + return slots; +} \ No newline at end of file diff --git a/src/dawn/save/SaveManager.hpp b/src/dawn/save/SaveManager.hpp new file mode 100644 index 00000000..120f3ed6 --- /dev/null +++ b/src/dawn/save/SaveManager.hpp @@ -0,0 +1,91 @@ +// Copyright (c) 2022 Dominic Masters +// +// This software is released under the MIT License. +// https://opensource.org/licenses/MIT + +#pragma once +#include "SaveFile.hpp" +#include "util/string.hpp" + +#define SAVE_KEY_TIMESTAMP "meta.timestamp" +#define SAVE_KEY_SLOT "meta.slot" +#define SAVE_MANAGER_BUFFER_LENGTH 128 +#define SAVE_MANAGER_FILENAME_LENGTH 512 + +namespace Dawn { + class DawnGame; + + enum SaveLoadResult { + SAVE_LOAD_SUCCESS, + SAVE_LOAD_RESULT_FILE_NOT_PRESENT, + SAVE_LOAD_RESULT_TOO_SMALL, + SAVE_LOAD_RESULT_CORRUPTED_DE_SAVE, + SAVE_LOAD_RESULT_CORRUPTED_VERSION, + SAVE_LOAD_RESULT_CORRUPTED_TIMESTAMP, + SAVE_LOAD_RESULT_CORRUPTED_DATA_KEY, + SAVE_LOAD_RESULT_CORRUPTED_DATA_VALUE, + SAVE_LOAD_RESULT_MISMATCH_TIMESTAMP, + SAVE_LOAD_RESULT_ERROR + }; + + class SaveManager { + protected: + int16_t currentSaveSlot = -1; + struct SaveFile currentSave; + + /** + * Reads a save file and then validates all of the values. If a value is + * not validated then it will NOT be retained. + * + * @param file Save file to read from. + * @return Whether or not the save file is corrupt, false for not corrupt. + */ + virtual bool_t validateSave(struct SaveFile raw) = 0; + + public: + DawnGame *game; + + /** + * Create a new Save Manager. Used by the game instance to decide when/how + * to perform saving. + * + * @param game Game that this save manager belongs to. + */ + SaveManager(DawnGame *game); + + /** + * Immediately save the game to the given file. This will invoke the + * game's custom writer to write the output data to the save file. + */ + void saveFile(); + + /** + * Loads the current slotted save file. Invokes the internal managers read + * function. + */ + enum SaveLoadResult loadFile(); + + /** + * Deletes the given save file slot. We use slots here because we need to + * be able to delete a file without reading it (in case of corruption). + * + * @param slot Slot to delete. + */ + void deleteFile(int16_t slot); + + /** + * Determines which save slot to use. + * + * @param slot Save slot to use. + */ + void useSlot(int16_t slot); + + /** + * Returns a list of used save slots, does not confirm if they are corrupt + * or not, just whether they are in existance or not. + * + * @return List of used save slots. + */ + std::vector getUsedSlots(); + }; +} \ No newline at end of file diff --git a/src/dawn/time/CMakeLists.txt b/src/dawn/time/CMakeLists.txt index c335bf6d..7255bb8c 100644 --- a/src/dawn/time/CMakeLists.txt +++ b/src/dawn/time/CMakeLists.txt @@ -6,5 +6,5 @@ # Sources target_sources(${DAWN_TARGET_NAME} PRIVATE - TimeManager.cpp + ITimeManager.cpp ) \ No newline at end of file diff --git a/src/dawn/time/TimeManager.cpp b/src/dawn/time/ITimeManager.cpp similarity index 73% rename from src/dawn/time/TimeManager.cpp rename to src/dawn/time/ITimeManager.cpp index 6307da86..0181f193 100644 --- a/src/dawn/time/TimeManager.cpp +++ b/src/dawn/time/ITimeManager.cpp @@ -3,15 +3,15 @@ // This software is released under the MIT License. // https://opensource.org/licenses/MIT -#include "TimeManager.hpp" +#include "ITimeManager.hpp" using namespace Dawn; -TimeManager::TimeManager() { +ITimeManager::ITimeManager() { } -void TimeManager::update(float_t delta) { +void ITimeManager::update(float_t delta) { this->delta = delta; this->time += delta; if(!this->isPaused) { @@ -19,13 +19,13 @@ void TimeManager::update(float_t delta) { } } -void TimeManager::pause() { +void ITimeManager::pause() { if(this->isPaused) return; this->isPaused = true; this->eventTimePaused.invoke(); } -void TimeManager::resume() { +void ITimeManager::resume() { if(!this->isPaused) return; this->isPaused = false; this->eventTimeResumed.invoke(); diff --git a/src/dawn/time/TimeManager.hpp b/src/dawn/time/ITimeManager.hpp similarity index 79% rename from src/dawn/time/TimeManager.hpp rename to src/dawn/time/ITimeManager.hpp index b9c3f606..752cc4e5 100644 --- a/src/dawn/time/TimeManager.hpp +++ b/src/dawn/time/ITimeManager.hpp @@ -8,7 +8,7 @@ #include "event/Event.hpp" namespace Dawn { - class TimeManager { + class ITimeManager { public: float_t time = 0.0f; float_t unpausedTime = 0.0f; @@ -21,7 +21,7 @@ namespace Dawn { /** * Constructor for the Time Manager. */ - TimeManager(); + ITimeManager(); /** * Updates / Ticks the time manager instance. @@ -39,5 +39,12 @@ namespace Dawn { * Resumes the game. */ void resume(); + + /** + * Returns the current system timestamp. + * + * @return Current timestamp. + */ + virtual int64_t getTimestamp() = 0; }; } \ No newline at end of file diff --git a/src/dawn/ui/UILabel.cpp b/src/dawn/ui/UILabel.cpp index bbb73e64..10ddf9c5 100644 --- a/src/dawn/ui/UILabel.cpp +++ b/src/dawn/ui/UILabel.cpp @@ -89,7 +89,6 @@ void UILabel::setTransform( } void UILabel::onLanguageUpdated() { - std::cout << "LANG UPDATED" << std::endl; this->needsRebuffering = true; if(key.size() > 0 && this->getGame()->localeManager.getString(key).size()>0){ this->hasText = true; diff --git a/src/dawn/util/string.hpp b/src/dawn/util/string.hpp new file mode 100644 index 00000000..0ef9b954 --- /dev/null +++ b/src/dawn/util/string.hpp @@ -0,0 +1,35 @@ +// Copyright (c) 2022 Dominic Masters +// +// This software is released under the MIT License. +// https://opensource.org/licenses/MIT + +#pragma once +#include "assert/assert.hpp" + +/** + * Finds the next instance of a character within a string, safely (with a + * limit). The returned pointer will be NULL if not found, or a pointer to a + * point within the string where the instance is. + * + * @param haystack String to search. + * @param needle Character to search for. + * @param limit Max length you want to search for to limit yourself to. + * @return Pointer to the character found, or NULL if not found. + */ +static inline char * stringFindNext( + char *haystack, + char needle, + size_t limit +) { + char *p; + + assertNotNull(haystack); + assertTrue(limit > 0); + + for(p = haystack; (size_t)(p - haystack) < limit; p++) { + if(*p == needle) return p; + assertFalse(*p == '\0');// We don't allow you to have a limit > strlen + } + + return NULL; +} \ No newline at end of file diff --git a/src/dawnpokergame/CMakeLists.txt b/src/dawnpokergame/CMakeLists.txt index 6a3ccbe4..00f3b4cf 100644 --- a/src/dawnpokergame/CMakeLists.txt +++ b/src/dawnpokergame/CMakeLists.txt @@ -20,6 +20,7 @@ add_subdirectory(game) add_subdirectory(prefabs) add_subdirectory(ui) add_subdirectory(visualnovel) +add_subdirectory(save) add_subdirectory(scenes) # Assets diff --git a/src/dawnpokergame/game/DawnGame.cpp b/src/dawnpokergame/game/DawnGame.cpp index 650c0737..5f0f6aaf 100644 --- a/src/dawnpokergame/game/DawnGame.cpp +++ b/src/dawnpokergame/game/DawnGame.cpp @@ -15,7 +15,8 @@ DawnGame::DawnGame(DawnHost *host) : host(host), renderManager(this), inputManager(this), - localeManager(this) + localeManager(this), + saveManager(this) { } diff --git a/src/dawnpokergame/game/DawnGame.hpp b/src/dawnpokergame/game/DawnGame.hpp index 9f628a1f..83c3f34d 100644 --- a/src/dawnpokergame/game/DawnGame.hpp +++ b/src/dawnpokergame/game/DawnGame.hpp @@ -6,6 +6,7 @@ #pragma once #include "game/_DawnGame.hpp" #include "scene/components/Components.hpp" +#include "save/PokerSaveManager.hpp" namespace Dawn { class DawnGame : public IDawnGame { @@ -16,6 +17,7 @@ namespace Dawn { InputManager inputManager; TimeManager timeManager; LocaleManager localeManager; + PokerSaveManager saveManager; DawnGame(DawnHost *host); int32_t init() override; diff --git a/src/dawnpokergame/save/CMakeLists.txt b/src/dawnpokergame/save/CMakeLists.txt new file mode 100644 index 00000000..15aca32e --- /dev/null +++ b/src/dawnpokergame/save/CMakeLists.txt @@ -0,0 +1,10 @@ +# Copyright (c) 2022 Dominic Masters +# +# This software is released under the MIT License. +# https://opensource.org/licenses/MIT + +# Sources +target_sources(${DAWN_TARGET_NAME} + PRIVATE + PokerSaveManager.cpp +) \ No newline at end of file diff --git a/src/dawnpokergame/save/PokerSaveManager.cpp b/src/dawnpokergame/save/PokerSaveManager.cpp new file mode 100644 index 00000000..8015c4bd --- /dev/null +++ b/src/dawnpokergame/save/PokerSaveManager.cpp @@ -0,0 +1,28 @@ +// Copyright (c) 2022 Dominic Masters +// +// This software is released under the MIT License. +// https://opensource.org/licenses/MIT + +#include "PokerSaveManager.hpp" + +using namespace Dawn; + +PokerSaveManager::PokerSaveManager(DawnGame *game) : SaveManager(game) { +} + +bool_t PokerSaveManager::validateSave(struct SaveFile raw) { + if(!raw.has(POKER_SAVE_KEY_EXAMPLE)) return true; + this->currentSave.copy(raw, POKER_SAVE_KEY_EXAMPLE); + + return false; +} + +void PokerSaveManager::setExample(int32_t val) { + savedata_t value; + value.i32 = val; + this->currentSave.set(POKER_SAVE_KEY_EXAMPLE, value); +} + +int32_t PokerSaveManager::getExample() { + return this->currentSave.get(POKER_SAVE_KEY_EXAMPLE).i32; +} \ No newline at end of file diff --git a/src/dawnpokergame/save/PokerSaveManager.hpp b/src/dawnpokergame/save/PokerSaveManager.hpp new file mode 100644 index 00000000..38ae3332 --- /dev/null +++ b/src/dawnpokergame/save/PokerSaveManager.hpp @@ -0,0 +1,22 @@ +// Copyright (c) 2022 Dominic Masters +// +// This software is released under the MIT License. +// https://opensource.org/licenses/MIT + +#pragma once +#include "save/SaveManager.hpp" + +#define POKER_SAVE_KEY_EXAMPLE "poker.example" + +namespace Dawn { + class PokerSaveManager : public SaveManager { + protected: + virtual bool_t validateSave(struct SaveFile raw) override; + + public: + PokerSaveManager(DawnGame *game); + + void setExample(int32_t value); + int32_t getExample(); + }; +} \ No newline at end of file diff --git a/src/dawnpokergame/scenes/TestScene.hpp b/src/dawnpokergame/scenes/TestScene.hpp index b7401386..e2bfdf53 100644 --- a/src/dawnpokergame/scenes/TestScene.hpp +++ b/src/dawnpokergame/scenes/TestScene.hpp @@ -39,10 +39,6 @@ namespace Dawn { auto start = new VisualNovelChangeSimpleBackgroundEvent( vnManager, &texture->texture ); - - struct Locale loc; - loc.language = "fr"; - this->game->localeManager.setLocale(loc); start ->then(new VisualNovelTextboxEvent(vnManager, "test")) diff --git a/src/dawnwin32/CMakeLists.txt b/src/dawnwin32/CMakeLists.txt index 99252d61..2b22ec3d 100644 --- a/src/dawnwin32/CMakeLists.txt +++ b/src/dawnwin32/CMakeLists.txt @@ -16,4 +16,5 @@ target_compile_definitions(${DAWN_TARGET_NAME} ) # Subdirs -add_subdirectory(host) \ No newline at end of file +add_subdirectory(host) +add_subdirectory(time) \ No newline at end of file diff --git a/src/dawnwin32/time/CMakeLists.txt b/src/dawnwin32/time/CMakeLists.txt new file mode 100644 index 00000000..c335bf6d --- /dev/null +++ b/src/dawnwin32/time/CMakeLists.txt @@ -0,0 +1,10 @@ +# Copyright (c) 2022 Dominic Masters +# +# This software is released under the MIT License. +# https://opensource.org/licenses/MIT + +# Sources +target_sources(${DAWN_TARGET_NAME} + PRIVATE + TimeManager.cpp +) \ No newline at end of file diff --git a/src/dawnwin32/time/TimeManager.cpp b/src/dawnwin32/time/TimeManager.cpp new file mode 100644 index 00000000..6dc19858 --- /dev/null +++ b/src/dawnwin32/time/TimeManager.cpp @@ -0,0 +1,16 @@ +// Copyright (c) 2022 Dominic Masters +// +// This software is released under the MIT License. +// https://opensource.org/licenses/MIT + +#include "TimeManager.hpp" + +using namespace Dawn; + +TimeManager::TimeManager() : ITimeManager() { + +} + +int64_t TimeManager::getTimestamp() { + return (int64_t)std::time(nullptr); +} \ No newline at end of file diff --git a/src/dawnwin32/time/TimeManager.hpp b/src/dawnwin32/time/TimeManager.hpp new file mode 100644 index 00000000..c803ee0d --- /dev/null +++ b/src/dawnwin32/time/TimeManager.hpp @@ -0,0 +1,15 @@ +// Copyright (c) 2022 Dominic Masters +// +// This software is released under the MIT License. +// https://opensource.org/licenses/MIT + +#pragma once +#include "time/ITimeManager.hpp" + +namespace Dawn { + class TimeManager : public ITimeManager { + public: + TimeManager(); + int64_t getTimestamp() override; + }; +} \ No newline at end of file