New animation step constructor

This commit is contained in:
2021-02-25 16:32:48 -05:00
parent 1814f39e1a
commit 9076666b2b
4 changed files with 145 additions and 23 deletions

View File

@@ -22,14 +22,114 @@ void AnimQueue::set_size_limit(int n) {
size_limit_ = n;
}
void AnimQueue::add(int64_t id, const std::string &action) {
steps_.emplace_back();
AnimStep &last = steps_.back();
last = steps_[steps_.size() - 2];
last.id_ = id;
last.action_ = action;
last.bits_ = 0;
void AnimQueue::add(int64_t id, lua_State *L, int idx) {
LuaSpecial tab(idx);
LuaVar value;
LuaStack LS(L, value);
if (!LS.istable(tab)) {
luaL_error(L, "animation spec must be a table");
}
AnimStep step = steps_.back();
step.id_ = id;
step.bits_ = 0;
step.action_ = "";
LS.rawget(value, tab, "action");
if (!LS.isstring(value)) {
luaL_error(L, "animation action is not optional and must be a string");
}
step.action_ = LS.ckstring(value);
LS.rawget(value, tab, "facing");
if (LS.isnumber(value)) {
step.facing_ = LS.cknumber(value);
step.bits_ |= AnimStep::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)) {
step.xyz_.x = LS.cknumber(value);
step.bits_ |= AnimStep::HAS_XYZ;
} else if (!LS.isnil(value)) {
luaL_error(L, "animation X coordinate must be a number");
}
LS.rawget(value, tab, "y");
if (LS.isnumber(value)) {
step.xyz_.y = LS.cknumber(value);
step.bits_ |= AnimStep::HAS_XYZ;
} else if (!LS.isnil(value)) {
luaL_error(L, "animation Y coordinate must be a number");
}
LS.rawget(value, tab, "z");
if (LS.isnumber(value)) {
step.xyz_.z = LS.cknumber(value);
step.bits_ |= AnimStep::HAS_XYZ;
} else if (!LS.isnil(value)) {
luaL_error(L, "animation Z coordinate must be a number");
}
LS.rawget(value, tab, "dx");
if (LS.isnumber(value)) {
step.xyz_.x += LS.cknumber(value);
step.bits_ |= AnimStep::HAS_XYZ;
} else if (!LS.isnil(value)) {
luaL_error(L, "animation DX offset must be a number");
}
LS.rawget(value, tab, "dy");
if (LS.isnumber(value)) {
step.xyz_.y += LS.cknumber(value);
step.bits_ |= AnimStep::HAS_XYZ;
} else if (!LS.isnil(value)) {
luaL_error(L, "animation DY offset must be a number");
}
LS.rawget(value, tab, "dz");
if (LS.isnumber(value)) {
step.xyz_.z += LS.cknumber(value);
step.bits_ |= AnimStep::HAS_XYZ;
} else if (!LS.isnil(value)) {
luaL_error(L, "animation DZ offset must be a number");
}
LS.rawget(value, tab, "graphic");
if (LS.isstring(value)) {
step.graphic_ = LS.ckstring(value);
step.bits_ |= AnimStep::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)) {
step.plane_ = LS.ckstring(value);
step.bits_ |= AnimStep::HAS_PLANE;
} else if (!LS.isnil(value)) {
luaL_error(L, "animation plane must be a string");
}
steps_.push_back(step);
while (int(steps_.size()) > size_limit_) {
steps_.pop_front();
}
AnimStep &init = steps_.front();
init.id_ = 0;
init.action_ = "";
init.bits_ = AnimStep::HAS_EVERYTHING;
}
void AnimQueue::add(int64_t id, const std::string &action) {
AnimStep step = steps_.back();
step.id_ = id;
step.action_ = action;
step.bits_ = 0;
steps_.push_back(step);
while (int(steps_.size()) > size_limit_) {
steps_.pop_front();
}