Fixed traceback issue, improved animqueue primitives

This commit is contained in:
2021-06-03 13:29:19 -04:00
parent 427c82ea8b
commit 5b19d407fb
7 changed files with 79 additions and 91 deletions

View File

@@ -62,67 +62,64 @@ AnimQueue::AnimQueue() {
clear_steps();
}
void AnimStep::from_lua(lua_State *L, int idx) {
void AnimStep::from_lua_store_string(lua_State *L, int idx, std::string *target, int16_t bits, const char *name) {
if ((bits_ & bits)||(*target != "")) {
luaL_error(L, "specified %s twice", name);
}
if (lua_type(L, idx) != LUA_TSTRING) {
luaL_error(L, "Expected %s to be a string", name);
}
*target = lua_tostring(L, idx);
bits_ |= bits;
}
void AnimStep::from_lua_store_number(lua_State *L, int idx, float *target, float offset, int16_t bits, const char *name) {
if (bits_ & bits) {
luaL_error(L, "specified %s twice", name);
}
if (lua_type(L, idx) != LUA_TNUMBER) {
luaL_error(L, "Expected %s to be a number", name);
}
*target = lua_tonumber(L, idx) + offset;
bits_ |= bits;
}
void AnimStep::from_lua(lua_State *L, int idx, const AnimStep &qback) {
LuaSpecial tab(idx);
LuaVar value;
LuaStack LS(L, value);
LuaVar key, value;
LuaStack LS(L, key, value);
if (!LS.istable(tab)) {
luaL_error(L, "animation spec must be a table");
}
LS.rawget(value, tab, "action");
if (LS.isstring(value)) {
action_ = LS.ckstring(value);
} else if (!LS.isnil(value)) {
luaL_error(L, "animation action must be a string");
}
LS.rawget(value, tab, "facing");
if (LS.isnumber(value)) {
facing_ = LS.cknumber(value);
bits_ |= HAS_FACING;
} else if (!LS.isnil(value)) {
luaL_error(L, "animation facing must be a number");
}
LS.rawget(value, tab, "x");
if (LS.isnumber(value)) {
xyz_.x = LS.cknumber(value);
bits_ |= HAS_X;
} else if (!LS.isnil(value)) {
luaL_error(L, "animation X coordinate must be a number");
}
LS.rawget(value, tab, "y");
if (LS.isnumber(value)) {
xyz_.y = LS.cknumber(value);
bits_ |= HAS_Y;
} else if (!LS.isnil(value)) {
luaL_error(L, "animation Y coordinate must be a number");
}
LS.rawget(value, tab, "z");
if (LS.isnumber(value)) {
xyz_.z = LS.cknumber(value);
bits_ |= HAS_Z;
} else if (!LS.isnil(value)) {
luaL_error(L, "animation Z coordinate must be a number");
}
LS.rawget(value, tab, "graphic");
if (LS.isstring(value)) {
graphic_ = LS.ckstring(value);
bits_ |= HAS_GRAPHIC;
} else if (!LS.isnil(value)) {
luaL_error(L, "animation graphic must be a string");
}
LS.rawget(value, tab, "plane");
if (LS.isstring(value)) {
plane_ = LS.ckstring(value);
bits_ |= HAS_PLANE;
} else if (!LS.isnil(value)) {
luaL_error(L, "animation plane must be a string");
LS.set(key, LuaNil);
while (LS.next(tab, key, value)) {
if (!LS.isstring(key)) {
luaL_error(L, "animation specs must be key/value where key is a string");
}
std::string skey = LS.ckstring(key);
if (skey == "action") {
from_lua_store_string(L, value.index(), &action_, 0, "action");
} else if (skey == "graphic") {
from_lua_store_string(L, value.index(), &graphic_, HAS_GRAPHIC, "graphic");
} else if (skey == "plane") {
from_lua_store_string(L, value.index(), &plane_, HAS_PLANE, "plane");
} else if (skey == "x") {
from_lua_store_number(L, value.index(), &xyz_.x, 0.0, HAS_X, "X coordinate");
} else if (skey == "y") {
from_lua_store_number(L, value.index(), &xyz_.y, 0.0, HAS_Y, "Z coordinate");
} else if (skey == "z") {
from_lua_store_number(L, value.index(), &xyz_.z, 0.0, HAS_Z, "Z coordinate");
} else if (skey == "dx") {
from_lua_store_number(L, value.index(), &xyz_.x, qback.xyz().x, HAS_X, "X coordinate");
} else if (skey == "dy") {
from_lua_store_number(L, value.index(), &xyz_.y, qback.xyz().y, HAS_Y, "Y coordinate");
} else if (skey == "dz") {
from_lua_store_number(L, value.index(), &xyz_.z, qback.xyz().z, HAS_Z, "Z coordinate");
} else if (skey == "facing") {
from_lua_store_number(L, value.index(), &facing_, 0.0, HAS_FACING, "facing");
} else {
luaL_error(L, "Unrecognized animation spec: %s", skey.c_str());
}
}
}