Fixed dynamic asset loading.

This commit is contained in:
2022-12-16 09:04:12 -08:00
parent 71dbf6e646
commit 4090e61406
7 changed files with 29 additions and 4 deletions

View File

@ -15,6 +15,10 @@ void AssetManager::init() {
}
void AssetManager::update() {
this->syncTick();
}
void AssetManager::queueLoad(std::vector<Asset*> assets) {
vectorAppend(&this->assetsToLoad, &assets);
}

View File

@ -26,6 +26,11 @@ namespace Dawn {
*/
void init();
/**
* Updates the asset manager.
*/
void update();
/**
* Queue a loading of a list of assets. Does not actually begin loading.
*

View File

@ -18,7 +18,11 @@ void LocaleManager::init() {
// Begin loading
if(this->currentlyLoadedAsset == nullptr && this->loadingAsset == nullptr) {
this->loadingAsset = this->game->assetManager.getAndLoad<LanguageAsset>("language_" + this->locale.language);
this->loadingAsset->eventLoaded.addListener(this, &LocaleManager::onLanguageLoaded);
if(this->loadingAsset->loaded) {
this->onLanguageLoaded();
} else {
this->loadingAsset->eventLoaded.addListener(this, &LocaleManager::onLanguageLoaded);
}
}
}
@ -26,6 +30,7 @@ void LocaleManager::setLocale(struct Locale locale) {
auto oldLocale = this->getLocale();
this->locale = locale;
this->eventLocaleChanged.invoke();
// Did the language change?
if(this->locale.language != oldLocale.language) {
@ -39,10 +44,12 @@ void LocaleManager::setLocale(struct Locale locale) {
}
this->loadingAsset = this->game->assetManager.getAndLoad<LanguageAsset>("language_" + this->locale.language);
this->loadingAsset->eventLoaded.addListener(this, &LocaleManager::onLanguageLoaded);
if(this->loadingAsset->loaded) {
this->onLanguageLoaded();
} else {
this->loadingAsset->eventLoaded.addListener(this, &LocaleManager::onLanguageLoaded);
}
}
this->eventLocaleChanged.invoke();
}
struct Locale LocaleManager::getLocale() {
@ -58,6 +65,7 @@ std::string LocaleManager::getString(std::string key) {
void LocaleManager::onLanguageLoaded() {
// Unload the previously loaded language
if(this->currentlyLoadedAsset != nullptr) {
this->currentlyLoadedAsset->eventLoaded.removeListener(this, &LocaleManager::onLanguageLoaded);
this->game->assetManager.queueUnload(this->currentlyLoadedAsset);
}

View File

@ -89,6 +89,7 @@ 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;

View File

@ -24,6 +24,7 @@ add_subdirectory(scenes)
# Assets
tool_language(language_en locale/en.csv)
tool_language(language_fr locale/fr.csv)
tool_texture(texture_test texture_test.png)
tool_texture(texture_city_day borrowed/city_day.png)
tool_texture(texture_city_night borrowed/city_night.png)
@ -42,6 +43,7 @@ tool_truetype(truetype_ark
add_dependencies(${DAWN_TARGET_NAME}
language_en
language_fr
texture_test
tileset_penny
truetype_ark

View File

@ -30,6 +30,7 @@ int32_t DawnGame::init() {
}
int32_t DawnGame::update(float_t delta) {
this->assetManager.update();
this->inputManager.update();
this->timeManager.update(delta);

View File

@ -39,6 +39,10 @@ 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"))