tangible.animate uses the new keyword parser.

This commit is contained in:
2022-07-22 16:22:04 -04:00
parent e6414e113d
commit 28ec61e47c
3 changed files with 52 additions and 52 deletions

View File

@@ -146,7 +146,7 @@ void AnimStep::read_from(StreamBuffer *sb) {
}
void AnimStep::from_lua_store_string(lua_State *L, int idx, eng::string *target, int16_t bits, const char *name) {
void AnimStep::config_store_string(lua_State *L, int idx, eng::string *target, int16_t bits, const char *name) {
if ((bits_ & bits)||(*target != "")) {
luaL_error(L, "specified %s twice", name);
}
@@ -157,7 +157,7 @@ void AnimStep::from_lua_store_string(lua_State *L, int idx, eng::string *target,
bits_ |= bits;
}
void AnimStep::from_lua_store_number(lua_State *L, int idx, float *target, float offset, int16_t bits, const char *name) {
void AnimStep::config_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);
}
@@ -168,44 +168,40 @@ void AnimStep::from_lua_store_number(lua_State *L, int idx, float *target, float
bits_ |= bits;
}
void AnimStep::from_lua(lua_State *L, int idx, bool ignex, const AnimStep &qback) {
LuaSpecial tab(idx);
LuaVar key, value;
LuaStack LS(L, key, value);
if (!LS.istable(tab)) {
luaL_error(L, "animation spec must be a table");
void AnimStep::configure(LuaKeywordParser &kp, const AnimStep &aqback) {
lua_State *L = kp.state();
LuaVar value;
LuaStack LS(L, value);
if (kp.parse(value, "action")) {
config_store_string(L, value.index(), &action_, 0, "action");
}
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");
}
eng::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 {
if (!ignex) {
luaL_error(L, "Unrecognized animation spec: %s", skey.c_str());
}
}
if (kp.parse(value, "graphic")) {
config_store_string(L, value.index(), &graphic_, HAS_GRAPHIC, "graphic");
}
if (kp.parse(value, "plane")) {
config_store_string(L, value.index(), &plane_, HAS_PLANE, "plane");
}
if (kp.parse(value, "x")) {
config_store_number(L, value.index(), &xyz_.x, 0.0, HAS_X, "X coordinate");
}
if (kp.parse(value, "y")) {
config_store_number(L, value.index(), &xyz_.y, 0.0, HAS_Y, "Z coordinate");
}
if (kp.parse(value, "z")) {
config_store_number(L, value.index(), &xyz_.z, 0.0, HAS_Z, "Z coordinate");
}
if (kp.parse(value, "dx")) {
config_store_number(L, value.index(), &xyz_.x, aqback.xyz().x, HAS_X, "X coordinate");
}
if (kp.parse(value, "dy")) {
config_store_number(L, value.index(), &xyz_.y, aqback.xyz().y, HAS_Y, "Y coordinate");
}
if (kp.parse(value, "dz")) {
config_store_number(L, value.index(), &xyz_.z, aqback.xyz().z, HAS_Z, "Z coordinate");
}
if (kp.parse(value, "facing")) {
config_store_number(L, value.index(), &facing_, 0.0, HAS_FACING, "facing");
}
}