Browse Source

Merge pull request #1499 from JimMarlowe/JM-USER-VARS

Add access to Node vars from scripting languages
JoshEngebretson 8 years ago
parent
commit
93f3727731
1 changed files with 32 additions and 0 deletions
  1. 32 0
      Source/Atomic/Scene/Node.h

+ 32 - 0
Source/Atomic/Scene/Node.h

@@ -602,6 +602,38 @@ public:
     /// Return child scene nodes by name hash, optionally recursive
     void GetChildrenWithName(PODVector<Node*>& dest, StringHash nameHash, bool recursive = false) const;
 
+    /// Scripting interface to set user data, the data type can be 
+    ///   Int, Bool, Float, Vector2, Vector3, Vector4, Quaternion
+    ///   String, Buffer, ResourceRef, ResourceRefList, IntRect,
+    ///   IntVector2, Matrix3,Matrix3x4, Matrix4, Double, Color
+    /// The data value must be formatted in the Variant type string format.
+    void SetVarFromString (const String& name, const String& vartype, const String& value) 
+    { 
+        vars_[name].FromString(vartype, value); 
+    }
+
+    /// Scripting interface to get user data as a string.
+    /// an empty string is returned if the entry name is not present.
+    String GetVarAsString (const String& name) const {
+        if ( IsVar(name) )
+            return vars_[name]->ToString();
+        return String::EMPTY;
+    }
+
+    /// Scripting interface to check if the user data entry exists
+    /// returns true if present, returns false if it is not present.
+    bool IsVar (const String& name) const {
+        return vars_.Contains(name);
+    }
+
+    /// Scripting interface to get user data type as a string
+    /// an empty string is returned if the entry name is not present.
+    String GetVarType (const String& name) const {
+         if ( IsVar(name) )
+            return vars_[name]->GetTypeName();
+         return String::EMPTY;
+   }
+
     // ATOMIC END
 
 protected: