Extra2D/include/animation/ani_parser.h

51 lines
1.4 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#pragma once
#include <animation/animation_cache.h>
#include <animation/animation_clip.h>
#include <core/types.h>
#include <functional>
#include <string>
namespace extra2d {
// ============================================================================
// ANI 文件解析结果
// ============================================================================
struct AniParseResult {
bool success = false;
std::string errorMessage;
Ptr<AnimationClip> clip;
};
// ============================================================================
// AniParser - ANI 脚本文件解析器
// 将原始 ANI 文件格式解析为 AnimationClip 数据
// ============================================================================
class AniParser {
public:
AniParser() = default;
/// 从文件解析
AniParseResult parse(const std::string &filePath);
/// 从内存内容解析
AniParseResult parseFromMemory(const std::string &content,
const std::string &basePath = "");
/// 设置路径替换回调(对应原始 AdditionalOptions
void setPathResolver(PathResolveCallback callback) {
pathResolver_ = std::move(callback);
}
/// 设置基础路径(用于解析相对路径)
void setBasePath(const std::string &basePath) { basePath_ = basePath; }
private:
PathResolveCallback pathResolver_;
std::string basePath_;
std::string resolvePath(const std::string &relativePath) const;
};
} // namespace extra2d