add assets.parse_animation

This commit is contained in:
MihailRis 2026-09-08 19:38:25 +03:00
parent 41713e89a4
commit 86d2e6a614
5 changed files with 28 additions and 6 deletions

View file

@ -97,14 +97,13 @@ local function parse_track(root)
return raw_track return raw_track
end end
local function load_vca(filepath) local function load_vca(source, filepath)
local source = file.read(filepath)
local raw_track = parse_track(xml.parse_vcd(source, "track")) local raw_track = parse_track(xml.parse_vcd(source, "track"))
debug.print(raw_track) debug.print(raw_track)
return animation.compile_track(raw_track, filepath) return animation.compile_track(raw_track, filepath)
end end
function internals.load_vca_animation(filepath, identifier) function internals.load_vca_animation(filepath, source, identifier)
local track = load_vca(filepath) local track = load_vca(source or file.read(filepath), filepath)
internals.store_animation(identifier, track) internals.store_animation(identifier, track)
end end

View file

@ -55,7 +55,7 @@ assetload::postfunc assetload::animation(
loader.attachToFile(path, {name, AssetType::ANIMATION}); loader.attachToFile(path, {name, AssetType::ANIMATION});
if (io::is_regular_file(path)) { if (io::is_regular_file(path)) {
scripting::load_vca_animation(path, name); scripting::load_vca_animation(path, nullptr, name);
} }
return [](auto&) {}; return [](auto&) {};
} }

View file

@ -11,6 +11,7 @@
#include "graphics/commons/Model.hpp" #include "graphics/commons/Model.hpp"
#include "graphics/core/Atlas.hpp" #include "graphics/core/Atlas.hpp"
#include "graphics/core/Texture.hpp" #include "graphics/core/Texture.hpp"
#include "io/io.hpp"
#include "util/Buffer.hpp" #include "util/Buffer.hpp"
using namespace scripting; using namespace scripting;
@ -66,6 +67,20 @@ static int l_load_texture(lua::State* L) {
return 0; return 0;
} }
static int l_parse_animation(lua::State* L) {
auto format = lua::require_lstring(L, 1);
auto string = lua::require_lstring(L, 2);
std::string name = lua::require_string(L, 3);
if (format != "vca") {
throw std::runtime_error(
"unknown format " + util::quote(std::string(format))
);
}
scripting::load_vca_animation(name, &string, name);
return 0;
}
static int l_parse_model(lua::State* L) { static int l_parse_model(lua::State* L) {
auto& assets = engine->requireAssets(); auto& assets = engine->requireAssets();
@ -161,6 +176,7 @@ static int l_to_canvas(lua::State* L) {
const luaL_Reg assetslib[] = { const luaL_Reg assetslib[] = {
{"request_texture", lua::wrap<l_request_texture>}, {"request_texture", lua::wrap<l_request_texture>},
{"load_texture", lua::wrap<l_load_texture>}, {"load_texture", lua::wrap<l_load_texture>},
{"parse_animation", lua::wrap<l_parse_animation>},
{"parse_model", lua::wrap<l_parse_model>}, {"parse_model", lua::wrap<l_parse_model>},
{"to_canvas", lua::wrap<l_to_canvas>}, {"to_canvas", lua::wrap<l_to_canvas>},
{nullptr, nullptr} {nullptr, nullptr}

View file

@ -844,13 +844,19 @@ void scripting::load_layout_script(
void scripting::load_vca_animation( void scripting::load_vca_animation(
const io::path& file, const io::path& file,
const std::string_view* content,
const std::string& identifier const std::string& identifier
) { ) {
auto L = lua::get_main_state(); auto L = lua::get_main_state();
if (lua::get_from_registry(L, lua::INTERNALS_TABLE, "load_vca_animation", true)) { if (lua::get_from_registry(L, lua::INTERNALS_TABLE, "load_vca_animation", true)) {
lua::pushlstring(L, file.string()); lua::pushlstring(L, file.string());
if (content) {
lua::pushlstring(L, *content);
} else {
lua::pushnil(L);
}
lua::pushlstring(L, identifier); lua::pushlstring(L, identifier);
if (lua::call(L, 2, 0)) { if (lua::call(L, 3, 0)) {
lua::pop(L); lua::pop(L);
} }
lua::pop(L); lua::pop(L);

View file

@ -257,6 +257,7 @@ namespace scripting {
void load_vca_animation( void load_vca_animation(
const io::path& file, const io::path& file,
const std::string_view* content,
const std::string& identifier const std::string& identifier
); );