Fixed dynamic asset loading.
This commit is contained in:
		@@ -15,6 +15,10 @@ void AssetManager::init() {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void AssetManager::update() {
 | 
				
			||||||
 | 
					  this->syncTick();
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void AssetManager::queueLoad(std::vector<Asset*> assets) {
 | 
					void AssetManager::queueLoad(std::vector<Asset*> assets) {
 | 
				
			||||||
  vectorAppend(&this->assetsToLoad, &assets);
 | 
					  vectorAppend(&this->assetsToLoad, &assets);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -26,6 +26,11 @@ namespace Dawn {
 | 
				
			|||||||
       */
 | 
					       */
 | 
				
			||||||
      void init();
 | 
					      void init();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      /**
 | 
				
			||||||
 | 
					       * Updates the asset manager.
 | 
				
			||||||
 | 
					       */
 | 
				
			||||||
 | 
					      void update();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      /**
 | 
					      /**
 | 
				
			||||||
       * Queue a loading of a list of assets. Does not actually begin loading.
 | 
					       * Queue a loading of a list of assets. Does not actually begin loading.
 | 
				
			||||||
       * 
 | 
					       * 
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -18,7 +18,11 @@ void LocaleManager::init() {
 | 
				
			|||||||
  // Begin loading
 | 
					  // Begin loading
 | 
				
			||||||
  if(this->currentlyLoadedAsset == nullptr && this->loadingAsset == nullptr) {
 | 
					  if(this->currentlyLoadedAsset == nullptr && this->loadingAsset == nullptr) {
 | 
				
			||||||
    this->loadingAsset = this->game->assetManager.getAndLoad<LanguageAsset>("language_" + this->locale.language);
 | 
					    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();
 | 
					  auto oldLocale = this->getLocale();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  this->locale = locale;
 | 
					  this->locale = locale;
 | 
				
			||||||
 | 
					  this->eventLocaleChanged.invoke();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // Did the language change?
 | 
					  // Did the language change?
 | 
				
			||||||
  if(this->locale.language != oldLocale.language) {
 | 
					  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 = 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() {
 | 
					struct Locale LocaleManager::getLocale() {
 | 
				
			||||||
@@ -58,6 +65,7 @@ std::string LocaleManager::getString(std::string key) {
 | 
				
			|||||||
void LocaleManager::onLanguageLoaded() {
 | 
					void LocaleManager::onLanguageLoaded() {
 | 
				
			||||||
  // Unload the previously loaded language
 | 
					  // Unload the previously loaded language
 | 
				
			||||||
  if(this->currentlyLoadedAsset != nullptr) {
 | 
					  if(this->currentlyLoadedAsset != nullptr) {
 | 
				
			||||||
 | 
					    this->currentlyLoadedAsset->eventLoaded.removeListener(this, &LocaleManager::onLanguageLoaded);
 | 
				
			||||||
    this->game->assetManager.queueUnload(this->currentlyLoadedAsset);
 | 
					    this->game->assetManager.queueUnload(this->currentlyLoadedAsset);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -89,6 +89,7 @@ void UILabel::setTransform(
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void UILabel::onLanguageUpdated() {
 | 
					void UILabel::onLanguageUpdated() {
 | 
				
			||||||
 | 
					  std::cout << "LANG UPDATED" << std::endl;
 | 
				
			||||||
  this->needsRebuffering = true;
 | 
					  this->needsRebuffering = true;
 | 
				
			||||||
  if(key.size() > 0 && this->getGame()->localeManager.getString(key).size()>0){
 | 
					  if(key.size() > 0 && this->getGame()->localeManager.getString(key).size()>0){
 | 
				
			||||||
    this->hasText = true;
 | 
					    this->hasText = true;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -24,6 +24,7 @@ add_subdirectory(scenes)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
# Assets
 | 
					# Assets
 | 
				
			||||||
tool_language(language_en locale/en.csv)
 | 
					tool_language(language_en locale/en.csv)
 | 
				
			||||||
 | 
					tool_language(language_fr locale/fr.csv)
 | 
				
			||||||
tool_texture(texture_test texture_test.png)
 | 
					tool_texture(texture_test texture_test.png)
 | 
				
			||||||
tool_texture(texture_city_day borrowed/city_day.png)
 | 
					tool_texture(texture_city_day borrowed/city_day.png)
 | 
				
			||||||
tool_texture(texture_city_night borrowed/city_night.png)
 | 
					tool_texture(texture_city_night borrowed/city_night.png)
 | 
				
			||||||
@@ -42,6 +43,7 @@ tool_truetype(truetype_ark
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
add_dependencies(${DAWN_TARGET_NAME}
 | 
					add_dependencies(${DAWN_TARGET_NAME}
 | 
				
			||||||
  language_en
 | 
					  language_en
 | 
				
			||||||
 | 
					  language_fr
 | 
				
			||||||
  texture_test
 | 
					  texture_test
 | 
				
			||||||
  tileset_penny
 | 
					  tileset_penny
 | 
				
			||||||
  truetype_ark
 | 
					  truetype_ark
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -30,6 +30,7 @@ int32_t DawnGame::init() {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int32_t DawnGame::update(float_t delta) {
 | 
					int32_t DawnGame::update(float_t delta) {
 | 
				
			||||||
 | 
					  this->assetManager.update();
 | 
				
			||||||
  this->inputManager.update();
 | 
					  this->inputManager.update();
 | 
				
			||||||
  this->timeManager.update(delta);
 | 
					  this->timeManager.update(delta);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -39,6 +39,10 @@ namespace Dawn {
 | 
				
			|||||||
        auto start = new VisualNovelChangeSimpleBackgroundEvent(
 | 
					        auto start = new VisualNovelChangeSimpleBackgroundEvent(
 | 
				
			||||||
          vnManager, &texture->texture
 | 
					          vnManager, &texture->texture
 | 
				
			||||||
        );
 | 
					        );
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        struct Locale loc;
 | 
				
			||||||
 | 
					        loc.language = "fr";
 | 
				
			||||||
 | 
					        this->game->localeManager.setLocale(loc);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        start
 | 
					        start
 | 
				
			||||||
          ->then(new VisualNovelTextboxEvent(vnManager, "test"))
 | 
					          ->then(new VisualNovelTextboxEvent(vnManager, "test"))
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user