瀏覽代碼

Add to_vector2() and to_vector4()

Daniele Bartolini 11 年之前
父節點
當前提交
3fa511710f
共有 2 個文件被更改,包括 35 次插入2 次删除
  1. 26 1
      engine/core/json/JSONParser.cpp
  2. 9 1
      engine/core/json/JSONParser.h

+ 26 - 1
engine/core/json/JSONParser.cpp

@@ -30,7 +30,9 @@ OTHER DEALINGS IN THE SOFTWARE.
 #include "StringUtils.h"
 #include "Vector.h"
 #include "Map.h"
+#include "Vector2.h"
 #include "Vector3.h"
+#include "Vector4.h"
 #include "Quaternion.h"
 #include "File.h"
 
@@ -163,6 +165,17 @@ void JSONElement::to_string(DynamicString& str) const
 	json::parse_string(m_at, str);
 }
 
+//--------------------------------------------------------------------------
+Vector2 JSONElement::to_vector2() const
+{
+	TempAllocator64 alloc;
+	Array<const char*> array(alloc);
+	json::parse_array(m_at, array);
+
+	return Vector2(json::parse_float(array[0]),
+					json::parse_float(array[1]));
+}
+
 //--------------------------------------------------------------------------
 Vector3 JSONElement::to_vector3() const
 {
@@ -175,6 +188,19 @@ Vector3 JSONElement::to_vector3() const
 					json::parse_float(array[2]));
 }
 
+//--------------------------------------------------------------------------
+Vector4 JSONElement::to_vector4() const
+{
+	TempAllocator64 alloc;
+	Array<const char*> array(alloc);
+	json::parse_array(m_at, array);
+
+	return Vector4(json::parse_float(array[0]),
+					json::parse_float(array[1]),
+					json::parse_float(array[2]),
+					json::parse_float(array[3]));
+}
+
 //--------------------------------------------------------------------------
 Quaternion JSONElement::to_quaternion() const
 {
@@ -407,7 +433,6 @@ uint32_t JSONElement::size() const
 		{
 			Array<const char*> array(default_allocator());
 			json::parse_array(m_at, array);
-
 			return array::size(array);
 		}
 		case JSONType::STRING:

+ 9 - 1
engine/core/json/JSONParser.h

@@ -119,10 +119,18 @@ public:
 	/// Returns the string value of the element.
 	void to_string(DynamicString& str) const;
 
-	/// Rerutns the Vector3 value of the element.
+	/// Returns the Vector2 value of the element.
+	/// @note Vector2 = [x, y]
+	Vector2 to_vector2() const;
+
+	/// Returns the Vector3 value of the element.
 	/// @note Vector3 = [x, y, z]
 	Vector3 to_vector3() const;
 
+	/// Returns the Vector4 value of the element.
+	/// @note Vector4 = [x, y, z, w]
+	Vector4 to_vector4() const;
+
 	/// Returns the Quaternion value of the element.
 	/// @note Quaternion = [x, y, z, w]
 	Quaternion to_quaternion() const;