change: skeletons are assets now, not content units

This commit is contained in:
MihailRis 2026-01-16 00:34:20 +03:00
parent 587c140a6b
commit 42c4716be2
17 changed files with 144 additions and 120 deletions

View file

@ -24,7 +24,8 @@ enum class AssetType {
LAYOUT,
SOUND,
MODEL,
POST_EFFECT
POST_EFFECT,
SKELETON
};
namespace assetload {

View file

@ -36,6 +36,7 @@ AssetsLoader::AssetsLoader(Engine& engine, Assets& assets, const ResPaths& paths
addLoader(AssetType::SOUND, assetload::sound);
addLoader(AssetType::MODEL, assetload::model);
addLoader(AssetType::POST_EFFECT, assetload::posteffect);
addLoader(AssetType::SKELETON, assetload::skeleton);
}
void AssetsLoader::addLoader(AssetType tag, aloader_func func) {
@ -141,6 +142,8 @@ static std::string assets_def_folder(AssetType tag) {
return MODELS_FOLDER;
case AssetType::POST_EFFECT:
return POST_EFFECTS_FOLDER;
case AssetType::SKELETON:
return SKELETONS_FOLDER;
}
return "<error>";
}
@ -263,21 +266,20 @@ void AssetsLoader::addDefaults(AssetsLoader& loader, const Content* content) {
add_layouts(pack->getEnvironment(), info.id, folder, loader);
}
for (auto& entry : content->getSkeletons()) {
auto& skeleton = *entry.second;
for (auto& bone : skeleton.getBones()) {
std::string model = bone->model.name;
size_t pos = model.rfind('.');
if (pos != std::string::npos) {
model = model.substr(0, pos);
}
if (!model.empty()) {
loader.add(
AssetType::MODEL, MODELS_FOLDER + "/" + model, model
);
}
for (const auto& entry : content->getPacks()) {
io::path skeletonsDir = entry.first + ":skeletons";
if (!io::is_directory(skeletonsDir)) {
continue;
}
for (const auto& file : io::directory_iterator(skeletonsDir)) {
loader.add(
AssetType::SKELETON,
file.string(),
entry.first + ":" + file.stem()
);
}
}
for (const auto& [_, def] : content->blocks.getDefs()) {
if (def->variants) {
for (const auto& variant : def->variants->variants) {

View file

@ -393,6 +393,32 @@ assetload::postfunc assetload::model(
}
}
assetload::postfunc assetload::skeleton(
AssetsLoader* loader,
const ResPaths& paths,
const std::string& file,
const std::string& name,
const std::shared_ptr<AssetCfg>& settings
) {
return [=](auto assets) {
std::string text = io::read_string(file);
auto skeleton = rigging::SkeletonConfig::parse(text, file, name);
for (auto& bone : skeleton->getBones()) {
std::string model = bone->model.name;
size_t pos = model.rfind('.');
if (pos != std::string::npos) {
model = model.substr(0, pos);
}
if (!model.empty()) {
loader->add(
AssetType::MODEL, MODELS_FOLDER + "/" + model, model
);
}
}
assets->store(std::move(skeleton), name);
};
}
static void read_anim_file(
const std::string& animFile,
std::vector<std::pair<std::string, int>>& frameList

View file

@ -69,4 +69,12 @@ namespace assetload {
const std::string& name,
const std::shared_ptr<AssetCfg>& settings
);
postfunc skeleton(
AssetsLoader*,
const ResPaths& paths,
const std::string& file,
const std::string& name,
const std::shared_ptr<AssetCfg>& settings
);
}