mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-04 10:31:50 +00:00
add assets.parse_animation
This commit is contained in:
parent
41713e89a4
commit
86d2e6a614
5 changed files with 28 additions and 6 deletions
|
|
@ -97,14 +97,13 @@ local function parse_track(root)
|
|||
return raw_track
|
||||
end
|
||||
|
||||
local function load_vca(filepath)
|
||||
local source = file.read(filepath)
|
||||
local function load_vca(source, filepath)
|
||||
local raw_track = parse_track(xml.parse_vcd(source, "track"))
|
||||
debug.print(raw_track)
|
||||
return animation.compile_track(raw_track, filepath)
|
||||
end
|
||||
|
||||
function internals.load_vca_animation(filepath, identifier)
|
||||
local track = load_vca(filepath)
|
||||
function internals.load_vca_animation(filepath, source, identifier)
|
||||
local track = load_vca(source or file.read(filepath), filepath)
|
||||
internals.store_animation(identifier, track)
|
||||
end
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ assetload::postfunc assetload::animation(
|
|||
loader.attachToFile(path, {name, AssetType::ANIMATION});
|
||||
|
||||
if (io::is_regular_file(path)) {
|
||||
scripting::load_vca_animation(path, name);
|
||||
scripting::load_vca_animation(path, nullptr, name);
|
||||
}
|
||||
return [](auto&) {};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@
|
|||
#include "graphics/commons/Model.hpp"
|
||||
#include "graphics/core/Atlas.hpp"
|
||||
#include "graphics/core/Texture.hpp"
|
||||
#include "io/io.hpp"
|
||||
#include "util/Buffer.hpp"
|
||||
|
||||
using namespace scripting;
|
||||
|
|
@ -66,6 +67,20 @@ static int l_load_texture(lua::State* L) {
|
|||
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) {
|
||||
auto& assets = engine->requireAssets();
|
||||
|
||||
|
|
@ -161,6 +176,7 @@ static int l_to_canvas(lua::State* L) {
|
|||
const luaL_Reg assetslib[] = {
|
||||
{"request_texture", lua::wrap<l_request_texture>},
|
||||
{"load_texture", lua::wrap<l_load_texture>},
|
||||
{"parse_animation", lua::wrap<l_parse_animation>},
|
||||
{"parse_model", lua::wrap<l_parse_model>},
|
||||
{"to_canvas", lua::wrap<l_to_canvas>},
|
||||
{nullptr, nullptr}
|
||||
|
|
|
|||
|
|
@ -844,13 +844,19 @@ void scripting::load_layout_script(
|
|||
|
||||
void scripting::load_vca_animation(
|
||||
const io::path& file,
|
||||
const std::string_view* content,
|
||||
const std::string& identifier
|
||||
) {
|
||||
auto L = lua::get_main_state();
|
||||
if (lua::get_from_registry(L, lua::INTERNALS_TABLE, "load_vca_animation", true)) {
|
||||
lua::pushlstring(L, file.string());
|
||||
if (content) {
|
||||
lua::pushlstring(L, *content);
|
||||
} else {
|
||||
lua::pushnil(L);
|
||||
}
|
||||
lua::pushlstring(L, identifier);
|
||||
if (lua::call(L, 2, 0)) {
|
||||
if (lua::call(L, 3, 0)) {
|
||||
lua::pop(L);
|
||||
}
|
||||
lua::pop(L);
|
||||
|
|
|
|||
|
|
@ -257,6 +257,7 @@ namespace scripting {
|
|||
|
||||
void load_vca_animation(
|
||||
const io::path& file,
|
||||
const std::string_view* content,
|
||||
const std::string& identifier
|
||||
);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue