Explorar o código

Add to_resource_id()

Daniele Bartolini %!s(int64=11) %!d(string=hai) anos
pai
achega
40bf7b5c3c
Modificáronse 2 ficheiros con 18 adicións e 0 borrados
  1. 13 0
      engine/core/json/JSONParser.cpp
  2. 5 0
      engine/core/json/JSONParser.h

+ 13 - 0
engine/core/json/JSONParser.cpp

@@ -197,6 +197,19 @@ StringId32 JSONElement::to_string_id() const
 	return str.to_string_id();
 }
 
+//--------------------------------------------------------------------------
+ResourceId JSONElement::to_resource_id(const char* type) const
+{
+	TempAllocator1024 alloc;
+	DynamicString str(alloc);
+	json::parse_string(m_at, str);
+
+	if (type == NULL)
+		return ResourceId(str.c_str());
+
+	return ResourceId(type, str.c_str());
+}
+
 //--------------------------------------------------------------------------
 void JSONElement::to_array(Array<bool>& array) const
 {

+ 5 - 0
engine/core/json/JSONParser.h

@@ -30,6 +30,7 @@ OTHER DEALINGS IN THE SOFTWARE.
 #include "ContainerTypes.h"
 #include "MathTypes.h"
 #include "Macros.h"
+#include "Resource.h"
 
 namespace crown
 {
@@ -129,6 +130,10 @@ public:
 	/// Returns the string id value hashed to string::murmur2_32() of the element.
 	StringId32 to_string_id() const;
 
+	/// Returns the resource id value of the element.
+	/// If @a type is NULL then the string element is assumed to already contain extension.
+	ResourceId to_resource_id(const char* type) const;
+
 	/// Returns the array value of the element.
 	/// @note
 	/// Calling this function is way faster than accessing individual