Code cleanup and refactoring.
This commit is contained in:
@@ -105,12 +105,12 @@ void AnimStepEditor::print_debug_string(eng::ostringstream &oss) {
|
||||
oss << ":";
|
||||
}
|
||||
switch (value.type) {
|
||||
case SimpleDynamicTag::UNINITIALIZED: oss << "UNINITIALIZED"; break;
|
||||
case SimpleDynamicTag::STRING: oss << value.s; break;
|
||||
case SimpleDynamicTag::TOKEN: oss << "[" << value.s << "]"; break;
|
||||
case SimpleDynamicTag::NUMBER: oss << value.x; break;
|
||||
case SimpleDynamicTag::BOOLEAN: oss << ((value.x == 1.0) ? "true":"false"); break;
|
||||
case SimpleDynamicTag::VECTOR: oss << value.x << "," << value.y << "," << value.z; break;
|
||||
case LuaValueType::UNINITIALIZED: oss << "UNINITIALIZED"; break;
|
||||
case LuaValueType::STRING: oss << value.s; break;
|
||||
case LuaValueType::TOKEN: oss << "[" << value.s << "]"; break;
|
||||
case LuaValueType::NUMBER: oss << value.x; break;
|
||||
case LuaValueType::BOOLEAN: oss << ((value.x == 1.0) ? "true":"false"); break;
|
||||
case LuaValueType::VECTOR: oss << value.x << "," << value.y << "," << value.z; break;
|
||||
default: assert(false);
|
||||
}
|
||||
first = false;
|
||||
@@ -166,7 +166,7 @@ void AnimStepEditor::decode_persistent(std::string_view s) {
|
||||
eng::string AnimStepEditor::add_default(const eng::string &name, const AnimValue &def, const AnimStepEditor *other) {
|
||||
AnimValue &value = map_[name];
|
||||
value.persistent = true;
|
||||
if (value.type == SimpleDynamicTag::UNINITIALIZED) {
|
||||
if (value.type == LuaValueType::UNINITIALIZED) {
|
||||
if (other != nullptr) {
|
||||
auto otheriter = other->map_.find(name);
|
||||
if (otheriter != other->map_.end()) {
|
||||
@@ -228,7 +228,7 @@ eng::string AnimStepEditor::from_lua(LuaCoreStack &LS0, LuaSlot tab, bool persis
|
||||
return "in animation key-value pairs, key must be a valid lua identifier.";
|
||||
}
|
||||
AnimValue parsedvalue = parse_anim_value(LS, val);
|
||||
if (parsedvalue.type == SimpleDynamicTag::UNINITIALIZED) {
|
||||
if (parsedvalue.type == LuaValueType::UNINITIALIZED) {
|
||||
return "in animation key-value pairs, value must be string, token, number, boolean, or xyz";
|
||||
}
|
||||
if (parsedvalue.is_token("auto") && !allowauto) {
|
||||
@@ -253,15 +253,15 @@ eng::string AnimStepEditor::merge(const AnimStepEditor &previous, const AnimStep
|
||||
// Handle autocalculation rules.
|
||||
if (src.is_token("auto")) {
|
||||
if (name == "facing") {
|
||||
if (!dst.persistent || dst.type != SimpleDynamicTag::NUMBER) {
|
||||
if (!dst.persistent || dst.type != LuaValueType::NUMBER) {
|
||||
return "Cannot auto-calculate facing because facing has not been specified as a persistent number";
|
||||
}
|
||||
const auto xyz_previous = previous.map_.find("xyz");
|
||||
const auto xyz_update = update.map_.find("xyz");
|
||||
if ((xyz_previous == previous.map_.end()) ||
|
||||
(xyz_update == update.map_.end()) ||
|
||||
(xyz_previous->second.type != SimpleDynamicTag::VECTOR) ||
|
||||
(xyz_update->second.type != SimpleDynamicTag::VECTOR)) {
|
||||
(xyz_previous->second.type != LuaValueType::VECTOR) ||
|
||||
(xyz_update->second.type != LuaValueType::VECTOR)) {
|
||||
return "Cannot auto-calculate facing because before/after xyz coordinates are not present";
|
||||
}
|
||||
double dx = xyz_update->second.x - xyz_previous->second.x;
|
||||
@@ -298,15 +298,15 @@ void AnimStepEditor::to_lua(LuaCoreStack &LS0, LuaSlot tab, bool transient, bool
|
||||
}
|
||||
LS.set(name, pair.first);
|
||||
const AnimValue &value = pair.second;
|
||||
if (value.type == SimpleDynamicTag::BOOLEAN) {
|
||||
if (value.type == LuaValueType::BOOLEAN) {
|
||||
LS.set(val, (value.x == 1.0));
|
||||
} else if (value.type == SimpleDynamicTag::NUMBER) {
|
||||
} else if (value.type == LuaValueType::NUMBER) {
|
||||
LS.set(val, value.x);
|
||||
} else if (value.type == SimpleDynamicTag::STRING) {
|
||||
} else if (value.type == LuaValueType::STRING) {
|
||||
LS.set(val, std::string_view(value.s));
|
||||
} else if (value.type == SimpleDynamicTag::TOKEN) {
|
||||
} else if (value.type == LuaValueType::TOKEN) {
|
||||
LS.set(val, LuaToken(value.s));
|
||||
} else if (value.type == SimpleDynamicTag::VECTOR) {
|
||||
} else if (value.type == LuaValueType::VECTOR) {
|
||||
LS.newtable(val);
|
||||
LS.rawset(val, 1, value.x);
|
||||
LS.rawset(val, 2, value.y);
|
||||
@@ -351,8 +351,8 @@ void AnimCoreState::decode(std::string_view s) {
|
||||
bool persistent = sb.read_bool();
|
||||
sb.read_simple_dynamic(&value);
|
||||
if (persistent) {
|
||||
if ((name == "xyz") && (value.type == SimpleDynamicTag::VECTOR)) xyz = util::DXYZ(value.x, value.y, value.z);
|
||||
if ((name == "plane") && (value.type == SimpleDynamicTag::STRING)) plane = value.s;
|
||||
if ((name == "xyz") && (value.type == LuaValueType::VECTOR)) xyz = util::DXYZ(value.x, value.y, value.z);
|
||||
if ((name == "plane") && (value.type == LuaValueType::STRING)) plane = value.s;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user