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

@ -4,7 +4,7 @@
// https://opensource.org/licenses/MIT
#pragma once
#include "state/State.hpp"
#include "state/StateEvent.hpp"
namespace Dawn {
class AssetManager;

View File

@ -4,7 +4,7 @@
// https://opensource.org/licenses/MIT
#pragma once
#include "state/State.hpp"
#include "state/StateEvent.hpp"
#include "Easing.hpp"
#include "util/mathutils.hpp"

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);
};
}

View File

@ -8,7 +8,7 @@
#include "asset/Asset.hpp"
#include "scene/debug/SceneDebugLine.hpp"
#include "physics/ScenePhysicsManager.hpp"
#include "state/State.hpp"
#include "state/StateEvent.hpp"
namespace Dawn {
class DawnGame;

View File

@ -0,0 +1,53 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "state/State.hpp"
namespace Dawn {
class SceneItemComponent;
template<typename D, typename...A>
struct StateListener {
std::function<void(A...)> callback;
D data;
};
template<typename D, typename...A>
struct StateProviderSet {
private:
std::vector<StateListener<D,A...>> listeners;
public:
std::function<void()> addEffect(
std::function<void(A...)> callback,
D data
) {
struct StateListener<D, A...> l;
l.callback = callback;
l.data = data;
this->listeners.push_back(l);
l.callback();
return std::bind([&](struct StateListener<D, A...> listener) {
assertUnreachable();
}, l);
}
};
class TimeProvider {
public:
StateProviderSet<float_t> effect;
};
std::function<void()> useTimeout(
std::function<void()> someCallback,
float_t timeout,
SceneItemComponent *context
) {
return (TimeProvider()).effect.addEffect(someCallback, timeout);
}
}