feat: animation track as asset (WIP)

This commit is contained in:
MihailRis 2026-08-25 23:09:14 +03:00
parent df5bc1f9fe
commit 104c74e653
10 changed files with 86 additions and 24 deletions

View file

@ -18,6 +18,7 @@
class Assets;
enum class AssetType {
ANIMATION,
TEXTURE,
SHADER,
FONT,

View file

@ -26,17 +26,20 @@ namespace fs = std::filesystem;
static debug::Logger logger("assets-loader");
AssetsLoader::AssetsLoader(Engine& engine, Assets& assets, const ResPaths& paths)
AssetsLoader::AssetsLoader(
Engine& engine, Assets& assets, const ResPaths& paths
)
: engine(engine), assets(assets), paths(paths) {
addLoader(AssetType::SHADER, assetload::shader);
addLoader(AssetType::TEXTURE, assetload::texture);
addLoader(AssetType::FONT, assetload::font);
addLoader(AssetType::ANIMATION, assetload::animation);
addLoader(AssetType::ATLAS, assetload::atlas);
addLoader(AssetType::FONT, assetload::font);
addLoader(AssetType::LAYOUT, assetload::layout);
addLoader(AssetType::SOUND, assetload::sound);
addLoader(AssetType::MODEL, assetload::model);
addLoader(AssetType::POST_EFFECT, assetload::posteffect);
addLoader(AssetType::SHADER, assetload::shader);
addLoader(AssetType::SKELETON, assetload::skeleton);
addLoader(AssetType::SOUND, assetload::sound);
addLoader(AssetType::TEXTURE, assetload::texture);
}
void AssetsLoader::addLoader(AssetType tag, aloader_func func) {
@ -127,24 +130,26 @@ void AssetsLoader::tryAddSound(const std::string& name) {
static std::string assets_def_folder(AssetType tag) {
switch (tag) {
case AssetType::FONT:
return FONTS_FOLDER;
case AssetType::SHADER:
return SHADERS_FOLDER;
case AssetType::TEXTURE:
return TEXTURES_FOLDER;
case AssetType::ANIMATION:
return ANIMATION_FOLDER;
case AssetType::ATLAS:
return TEXTURES_FOLDER;
case AssetType::FONT:
return FONTS_FOLDER;
case AssetType::LAYOUT:
return LAYOUTS_FOLDER;
case AssetType::SOUND:
return SOUNDS_FOLDER;
case AssetType::MODEL:
return MODELS_FOLDER;
case AssetType::POST_EFFECT:
return POST_EFFECTS_FOLDER;
case AssetType::SHADER:
return SHADERS_FOLDER;
case AssetType::SKELETON:
return SKELETONS_FOLDER;
case AssetType::SOUND:
return SOUNDS_FOLDER;
case AssetType::TEXTURE:
return TEXTURES_FOLDER;
}
return "<error>";
}
@ -221,14 +226,15 @@ void AssetsLoader::processPreloadList(AssetType tag, const dv::value& list) {
void AssetsLoader::processPreloadConfig(const io::path& file) {
auto root = io::read_json(file);
processPreloadList(AssetType::ANIMATION, root["animation"]);
processPreloadList(AssetType::ATLAS, root["atlases"]);
processPreloadList(AssetType::FONT, root["fonts"]);
processPreloadList(AssetType::SHADER, root["shaders"]);
processPreloadList(AssetType::TEXTURE, root["textures"]);
processPreloadList(AssetType::SOUND, root["sounds"]);
processPreloadList(AssetType::MODEL, root["models"]);
processPreloadList(AssetType::POST_EFFECT, root["post-effects"]);
processPreloadList(AssetType::SHADER, root["shaders"]);
processPreloadList(AssetType::SKELETON, root["skeletons"]);
processPreloadList(AssetType::SOUND, root["sounds"]);
processPreloadList(AssetType::TEXTURE, root["textures"]);
// layouts are loaded automatically
}

View file

@ -23,6 +23,7 @@
#include "graphics/core/Shader.hpp"
#include "graphics/core/Texture.hpp"
#include "graphics/core/TextureAnimation.hpp"
#include "logic/scripting/scripting.hpp"
#include "io/io.hpp"
#include "util/stringutil.hpp"
@ -44,6 +45,20 @@ static bool load_animated_texture(
Atlas* dstAtlas
);
assetload::postfunc assetload::animation(
AssetsLoader&,
const ResPaths& paths,
const std::string& filename,
const std::string& name,
const std::shared_ptr<AssetCfg>&
) {
auto path = paths.find(filename + ".vca");
if (io::is_regular_file(path)) {
scripting::load_vca_animation(path, name);
}
return [](auto&) {};
}
assetload::postfunc assetload::texture(
AssetsLoader&,
const ResPaths& paths,

View file

@ -13,6 +13,13 @@ struct AssetCfg;
/// @brief see AssetsLoader.h: aloader_func
namespace assetload {
postfunc animation(
AssetsLoader&,
const ResPaths& paths,
const std::string& filename,
const std::string& name,
const std::shared_ptr<AssetCfg>& settings
);
postfunc texture(
AssetsLoader&,
const ResPaths& paths,