diff options
author | Aaron Franke <arnfranke@yahoo.com> | 2021-02-25 09:54:50 -0500 |
---|---|---|
committer | Aaron Franke <arnfranke@yahoo.com> | 2021-06-11 10:53:20 -0400 |
commit | 554c776e08c9ee35fa9e2677e02f4005c11ddbc0 (patch) | |
tree | 1ea2b367e5cd59a8c9b049ceaeb0d6f4253f9aed /core/variant/variant.cpp | |
parent | 6b0183ec893ddea3f8ae71005b5fce1ae988e8a0 (diff) | |
download | redot-engine-554c776e08c9ee35fa9e2677e02f4005c11ddbc0.tar.gz |
Reformat structure string operators
The order of numbers is not changed except for Transform2D. All logic is done inside of their structures (and not in Variant).
For the number of decimals printed, they now use String::num_real which works best with real_t, except for Color which is fixed at 4 decimals (this is a reliable number of float digits when converting from 16-bpc so it seems like a good choice)
Diffstat (limited to 'core/variant/variant.cpp')
-rw-r--r-- | core/variant/variant.cpp | 48 |
1 files changed, 12 insertions, 36 deletions
diff --git a/core/variant/variant.cpp b/core/variant/variant.cpp index 2bde08742c..1b14ea7c85 100644 --- a/core/variant/variant.cpp +++ b/core/variant/variant.cpp @@ -1636,51 +1636,27 @@ String Variant::stringify(List<const void *> &stack) const { case STRING: return *reinterpret_cast<const String *>(_data._mem); case VECTOR2: - return "(" + operator Vector2() + ")"; + return operator Vector2(); case VECTOR2I: - return "(" + operator Vector2i() + ")"; + return operator Vector2i(); case RECT2: - return "(" + operator Rect2() + ")"; + return operator Rect2(); case RECT2I: - return "(" + operator Rect2i() + ")"; - case TRANSFORM2D: { - Transform2D mat32 = operator Transform2D(); - return "(" + Variant(mat32.elements[0]).operator String() + ", " + Variant(mat32.elements[1]).operator String() + ", " + Variant(mat32.elements[2]).operator String() + ")"; - } break; + return operator Rect2i(); + case TRANSFORM2D: + return operator Transform2D(); case VECTOR3: - return "(" + operator Vector3() + ")"; + return operator Vector3(); case VECTOR3I: - return "(" + operator Vector3i() + ")"; + return operator Vector3i(); case PLANE: return operator Plane(); case AABB: return operator ::AABB(); case QUATERNION: - return "(" + operator Quaternion() + ")"; - case BASIS: { - Basis mat3 = operator Basis(); - - String mtx("("); - for (int i = 0; i < 3; i++) { - if (i != 0) { - mtx += ", "; - } - - mtx += "("; - - for (int j = 0; j < 3; j++) { - if (j != 0) { - mtx += ", "; - } - - mtx += Variant(mat3.elements[i][j]).operator String(); - } - - mtx += ")"; - } - - return mtx + ")"; - } break; + return operator Quaternion(); + case BASIS: + return operator Basis(); case TRANSFORM3D: return operator Transform3D(); case STRING_NAME: @@ -1688,7 +1664,7 @@ String Variant::stringify(List<const void *> &stack) const { case NODE_PATH: return operator NodePath(); case COLOR: - return String::num(operator Color().r) + "," + String::num(operator Color().g) + "," + String::num(operator Color().b) + "," + String::num(operator Color().a); + return operator Color(); case DICTIONARY: { const Dictionary &d = *reinterpret_cast<const Dictionary *>(_data._mem); if (stack.find(d.id())) { |