tangible.animate uses the new keyword parser.
This commit is contained in:
@@ -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 != "")) {
|
if ((bits_ & bits)||(*target != "")) {
|
||||||
luaL_error(L, "specified %s twice", name);
|
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;
|
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) {
|
if (bits_ & bits) {
|
||||||
luaL_error(L, "specified %s twice", name);
|
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;
|
bits_ |= bits;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AnimStep::from_lua(lua_State *L, int idx, bool ignex, const AnimStep &qback) {
|
void AnimStep::configure(LuaKeywordParser &kp, const AnimStep &aqback) {
|
||||||
LuaSpecial tab(idx);
|
lua_State *L = kp.state();
|
||||||
LuaVar key, value;
|
LuaVar value;
|
||||||
LuaStack LS(L, key, value);
|
LuaStack LS(L, value);
|
||||||
if (!LS.istable(tab)) {
|
|
||||||
luaL_error(L, "animation spec must be a table");
|
if (kp.parse(value, "action")) {
|
||||||
|
config_store_string(L, value.index(), &action_, 0, "action");
|
||||||
}
|
}
|
||||||
LS.set(key, LuaNil);
|
if (kp.parse(value, "graphic")) {
|
||||||
while (LS.next(tab, key, value)) {
|
config_store_string(L, value.index(), &graphic_, HAS_GRAPHIC, "graphic");
|
||||||
if (!LS.isstring(key)) {
|
}
|
||||||
luaL_error(L, "animation specs must be key/value where key is a string");
|
if (kp.parse(value, "plane")) {
|
||||||
}
|
config_store_string(L, value.index(), &plane_, HAS_PLANE, "plane");
|
||||||
eng::string skey = LS.ckstring(key);
|
}
|
||||||
if (skey == "action") {
|
if (kp.parse(value, "x")) {
|
||||||
from_lua_store_string(L, value.index(), &action_, 0, "action");
|
config_store_number(L, value.index(), &xyz_.x, 0.0, HAS_X, "X coordinate");
|
||||||
} else if (skey == "graphic") {
|
}
|
||||||
from_lua_store_string(L, value.index(), &graphic_, HAS_GRAPHIC, "graphic");
|
if (kp.parse(value, "y")) {
|
||||||
} else if (skey == "plane") {
|
config_store_number(L, value.index(), &xyz_.y, 0.0, HAS_Y, "Z coordinate");
|
||||||
from_lua_store_string(L, value.index(), &plane_, HAS_PLANE, "plane");
|
}
|
||||||
} else if (skey == "x") {
|
if (kp.parse(value, "z")) {
|
||||||
from_lua_store_number(L, value.index(), &xyz_.x, 0.0, HAS_X, "X coordinate");
|
config_store_number(L, value.index(), &xyz_.z, 0.0, HAS_Z, "Z coordinate");
|
||||||
} else if (skey == "y") {
|
}
|
||||||
from_lua_store_number(L, value.index(), &xyz_.y, 0.0, HAS_Y, "Z coordinate");
|
if (kp.parse(value, "dx")) {
|
||||||
} else if (skey == "z") {
|
config_store_number(L, value.index(), &xyz_.x, aqback.xyz().x, HAS_X, "X coordinate");
|
||||||
from_lua_store_number(L, value.index(), &xyz_.z, 0.0, HAS_Z, "Z coordinate");
|
}
|
||||||
} else if (skey == "dx") {
|
if (kp.parse(value, "dy")) {
|
||||||
from_lua_store_number(L, value.index(), &xyz_.x, qback.xyz().x, HAS_X, "X coordinate");
|
config_store_number(L, value.index(), &xyz_.y, aqback.xyz().y, HAS_Y, "Y coordinate");
|
||||||
} else if (skey == "dy") {
|
}
|
||||||
from_lua_store_number(L, value.index(), &xyz_.y, qback.xyz().y, HAS_Y, "Y coordinate");
|
if (kp.parse(value, "dz")) {
|
||||||
} else if (skey == "dz") {
|
config_store_number(L, value.index(), &xyz_.z, aqback.xyz().z, HAS_Z, "Z coordinate");
|
||||||
from_lua_store_number(L, value.index(), &xyz_.z, qback.xyz().z, HAS_Z, "Z coordinate");
|
}
|
||||||
} else if (skey == "facing") {
|
if (kp.parse(value, "facing")) {
|
||||||
from_lua_store_number(L, value.index(), &facing_, 0.0, HAS_FACING, "facing");
|
config_store_number(L, value.index(), &facing_, 0.0, HAS_FACING, "facing");
|
||||||
} else {
|
|
||||||
if (!ignex) {
|
|
||||||
luaL_error(L, "Unrecognized animation spec: %s", skey.c_str());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -130,10 +130,10 @@ public:
|
|||||||
// graphic: "graphic"
|
// graphic: "graphic"
|
||||||
// plane: "plane"
|
// plane: "plane"
|
||||||
//
|
//
|
||||||
// qback: the animation queue back, from which relative
|
// aqback: the animation queue back, from which relative
|
||||||
// moves are computed.
|
// moves are computed.
|
||||||
//
|
//
|
||||||
void from_lua(lua_State *L, int idx, bool ignex, const AnimStep &qback);
|
void configure(LuaKeywordParser &kp, const AnimStep &aqback);
|
||||||
|
|
||||||
// Make this step into a first-step of an anim queue.
|
// Make this step into a first-step of an anim queue.
|
||||||
void keep_state_only();
|
void keep_state_only();
|
||||||
@@ -161,8 +161,8 @@ private:
|
|||||||
eng::string graphic_;
|
eng::string graphic_;
|
||||||
eng::string plane_;
|
eng::string plane_;
|
||||||
|
|
||||||
void from_lua_store_string(lua_State *L, int idx, eng::string *target, int16_t bits, const char *name);
|
void config_store_string(lua_State *L, int idx, eng::string *target, int16_t bits, const char *name);
|
||||||
void from_lua_store_number(lua_State *L, int idx, float *target, float offset, int16_t bits, const char *name);
|
void config_store_number(lua_State *L, int idx, float *target, float offset, int16_t bits, const char *name);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -58,12 +58,13 @@ LuaDefine(tangible_animate, "tan,configtable",
|
|||||||
"|action,graphic,plane,x,y,z,facing") {
|
"|action,graphic,plane,x,y,z,facing") {
|
||||||
LuaArg tanobj, config;
|
LuaArg tanobj, config;
|
||||||
LuaStack LS(L, tanobj, config);
|
LuaStack LS(L, tanobj, config);
|
||||||
|
LuaKeywordParser kp(LS, config);
|
||||||
World *w = World::fetch_global_pointer(L);
|
World *w = World::fetch_global_pointer(L);
|
||||||
Tangible *tan = w->tangible_get(LS, tanobj);
|
Tangible *tan = w->tangible_get(LS, tanobj);
|
||||||
int64_t id = w->alloc_id_predictable();
|
int64_t id = w->alloc_id_predictable();
|
||||||
const AnimStep &prev = tan->anim_queue_.back();
|
|
||||||
AnimStep step;
|
AnimStep step;
|
||||||
step.from_lua(L, config.index(), false, prev);
|
step.configure(kp, tan->anim_queue_.back());
|
||||||
|
kp.check_unparsed_keywords();
|
||||||
if (step.action() == "") {
|
if (step.action() == "") {
|
||||||
luaL_error(L, "animation action must be specified");
|
luaL_error(L, "animation action must be specified");
|
||||||
}
|
}
|
||||||
@@ -129,18 +130,20 @@ LuaDefine(tangible_delete, "tan",
|
|||||||
return LS.result();
|
return LS.result();
|
||||||
}
|
}
|
||||||
|
|
||||||
LuaDefine(tangible_build, "configtable",
|
LuaDefine(tangible_build, "config",
|
||||||
"|Build a new tangible object."
|
"|Build a new tangible object."
|
||||||
"|The configtable must contain: class,x,y,z,plane,graphic."
|
"|The config table must contain: class,x,y,z,plane,graphic."
|
||||||
"|The configtable can optionally contain: facing.") {
|
"|The config table can optionally contain: facing.") {
|
||||||
LuaArg config;
|
LuaArg config;
|
||||||
LuaVar classname, classtab, mt;
|
LuaVar classname, classtab, mt;
|
||||||
LuaRet database;
|
LuaRet database;
|
||||||
LuaStack LS(L, config, classname, classtab, database, mt);
|
LuaStack LS(L, config, classname, classtab, database, mt);
|
||||||
|
LuaKeywordParser kp(LS, config);
|
||||||
LS.checktable(config, "config");
|
|
||||||
// Get the class of the new tangible.
|
// Get the class of the new tangible.
|
||||||
LS.rawget(classname, config, "class");
|
if (!kp.parse(classname, "class")) {
|
||||||
|
luaL_error(L, "You must specify a class for the tangible");
|
||||||
|
}
|
||||||
eng::string err = LS.getclass(classtab, classname);
|
eng::string err = LS.getclass(classtab, classname);
|
||||||
if (err != "") {
|
if (err != "") {
|
||||||
luaL_error(L, "%s", err.c_str());
|
luaL_error(L, "%s", err.c_str());
|
||||||
@@ -148,7 +151,8 @@ LuaDefine(tangible_build, "configtable",
|
|||||||
|
|
||||||
// Parse the initial animation step.
|
// Parse the initial animation step.
|
||||||
AnimStep initstep, blank;
|
AnimStep initstep, blank;
|
||||||
initstep.from_lua(L, config.index(), true, blank);
|
initstep.configure(kp, blank);
|
||||||
|
kp.check_unparsed_keywords();
|
||||||
if (!initstep.has_xyz()) {
|
if (!initstep.has_xyz()) {
|
||||||
luaL_error(L, "You must specify (X,Y,Z) for new tangible");
|
luaL_error(L, "You must specify (X,Y,Z) for new tangible");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user