This commit is contained in:
2023-03-09 22:52:22 -08:00
parent 12b6f4091d
commit f69312e9f9
16 changed files with 448 additions and 423 deletions

View File

@ -1,68 +1,68 @@
// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "state/State.hpp"
#include "asset/AssetManager.hpp"
namespace Dawn {
class DawnGame;
struct Locale {
std::string language;
};
class LocaleManager : public StateOwner {
private:
DawnGame *game;
LanguageAsset *asset;
struct Locale locale;
LanguageAsset *currentlyLoadedAsset = nullptr;
LanguageAsset *loadingAsset = nullptr;
/** Listens for when the pending language loads. */
void onLanguageLoaded();
public:
StateEvent<> eventLocaleChanged;
StateEvent<> eventLanguageUpdated;
/**
* Initializes the Locale Manager Instance. Locale Manager is responsible
* for handling anything that will change depending on which region the
* player is in.
*
* @param game Game instance this manager belongs to.
*/
LocaleManager(DawnGame *game);
/**
* Initializes the LocaleManager and loads the default language.
*/
void init();
/**
* Change the locale and begin loading the new language.
*
* @param locale Locale to switch to.
*/
void setLocale(struct Locale locale);
/**
* Gets the current locale.
*
* @return Current locale.
*/
struct Locale getLocale();
/**
* Returns a language string from the language CSV file.
*
* @param key Key of the string to get.
* @return The translated string.
*/
std::string getString(std::string key);
};
// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "state/StateEvent.hpp"
#include "asset/AssetManager.hpp"
namespace Dawn {
class DawnGame;
struct Locale {
std::string language;
};
class LocaleManager {
private:
DawnGame *game;
LanguageAsset *asset;
struct Locale locale;
LanguageAsset *currentlyLoadedAsset = nullptr;
LanguageAsset *loadingAsset = nullptr;
/** Listens for when the pending language loads. */
void onLanguageLoaded();
public:
StateEvent<> eventLocaleChanged;
StateEvent<> eventLanguageUpdated;
/**
* Initializes the Locale Manager Instance. Locale Manager is responsible
* for handling anything that will change depending on which region the
* player is in.
*
* @param game Game instance this manager belongs to.
*/
LocaleManager(DawnGame *game);
/**
* Initializes the LocaleManager and loads the default language.
*/
void init();
/**
* Change the locale and begin loading the new language.
*
* @param locale Locale to switch to.
*/
void setLocale(struct Locale locale);
/**
* Gets the current locale.
*
* @return Current locale.
*/
struct Locale getLocale();
/**
* Returns a language string from the language CSV file.
*
* @param key Key of the string to get.
* @return The translated string.
*/
std::string getString(std::string key);
};
}