Browse Source

Working on editable component fields

Josh Engebretson 10 years ago
parent
commit
647d97a5b7

+ 2 - 2
Build/AtomicNETTest/MyClass.cs

@@ -7,7 +7,7 @@ namespace AtomicNETTest
     public enum BehaviorState
     public enum BehaviorState
     {
     {
       Friendly,
       Friendly,
-      Aggressive = 10,
+      Aggressive,
       Neutral
       Neutral
     }
     }
 
 
@@ -23,7 +23,7 @@ namespace AtomicNETTest
         public Vector3 MyVector3Value = new Vector3(1, 1, 1);
         public Vector3 MyVector3Value = new Vector3(1, 1, 1);
 
 
         [Inspector]
         [Inspector]
-        public Quaternion MyQuaternionValue = new Quaternion(1, 1, 1, 1);
+        public Quaternion MyQuaternionValue = new Quaternion(1, 0, 0, 0);
 
 
         [Inspector(Value1 = "This is a", Value2 = "test")]
         [Inspector(Value1 = "This is a", Value2 = "test")]
         public float MyFloatValue = 42.0f;
         public float MyFloatValue = 42.0f;

+ 1 - 1
Source/AtomicJS/Javascript/JSSceneSerializable.cpp

@@ -148,7 +148,7 @@ static int Serializable_SetAttribute(duk_context* ctx)
 
 
                             if (idx > 0 && idx < enums[name]->Size())
                             if (idx > 0 && idx < enums[name]->Size())
                             {
                             {
-                                VariantMap& values = jsc->GetFieldValues();
+                                VariantMap& values = csc->GetFieldValues();
                                 values[name] = enums[name]->At(idx).value_;
                                 values[name] = enums[name]->At(idx).value_;
                                 return 0;
                                 return 0;
                             }
                             }

+ 42 - 1
Source/AtomicNET/NETCore/NETAssemblyFile.cpp

@@ -33,6 +33,20 @@
 namespace Atomic
 namespace Atomic
 {
 {
 
 
+/*
+
+"enums":[
+      {
+         "name":"BehaviorState",
+         "values":{
+            "Friendly":0,
+            "Aggressive":10,
+            "Neutral":11
+         }
+      }
+   ],
+
+*/
 NETAssemblyFile::NETAssemblyFile(Context* context) :
 NETAssemblyFile::NETAssemblyFile(Context* context) :
     Resource(context)
     Resource(context)
 {
 {
@@ -56,6 +70,33 @@ NETComponentClass* NETAssemblyFile::GetComponentClass(const String& name)
 bool NETAssemblyFile::ParseAssemblyJSON(const JSONValue& json)
 bool NETAssemblyFile::ParseAssemblyJSON(const JSONValue& json)
 {
 {
     componentClasses_.Clear();
     componentClasses_.Clear();
+    enums_.Clear();
+
+    const JSONArray& enums = json.Get("enums").GetArray();
+
+    for (unsigned i = 0; i < enums.Size(); i++)
+    {
+        const JSONValue& ejson = enums.At(i);
+
+        String enumName = ejson.Get("name").GetString();
+
+        const JSONObject& evalues = ejson.Get("values").GetObject();
+
+        JSONObject::ConstIterator itr = evalues.Begin();
+
+        Vector<EnumInfo> values;
+
+        while(itr != evalues.End())
+        {
+            EnumInfo info;
+            info.name_ = itr->first_;
+            info.value_ = itr->second_.GetInt();
+            values.Push(info);
+            itr++;
+        }
+
+        enums_[enumName] = values;
+    }
 
 
     const JSONArray& components = json.Get("components").GetArray();
     const JSONArray& components = json.Get("components").GetArray();
 
 
@@ -63,7 +104,7 @@ bool NETAssemblyFile::ParseAssemblyJSON(const JSONValue& json)
     {
     {
         const JSONValue& cjson = components.At(i);
         const JSONValue& cjson = components.At(i);
 
 
-        SharedPtr<NETComponentClass> c(new NETComponentClass(context_));
+        SharedPtr<NETComponentClass> c(new NETComponentClass(context_, this));
 
 
         if (c->ParseJSON(cjson))
         if (c->ParseJSON(cjson))
             componentClasses_[c->GetName()] = c;
             componentClasses_[c->GetName()] = c;

+ 4 - 0
Source/AtomicNET/NETCore/NETAssemblyFile.h

@@ -27,6 +27,8 @@
 #include <Atomic/Container/ArrayPtr.h>
 #include <Atomic/Container/ArrayPtr.h>
 #include <Atomic/Container/List.h>
 #include <Atomic/Container/List.h>
 
 
+#include <Atomic/Script/Script.h>
+
 namespace Atomic
 namespace Atomic
 {
 {
 
 
@@ -47,6 +49,7 @@ public:
 
 
     bool ParseAssemblyJSON(const JSONValue& json);
     bool ParseAssemblyJSON(const JSONValue& json);
 
 
+    const HashMap<String, Vector<EnumInfo>>& GetEnums() const { return enums_; }
     NETComponentClass* GetComponentClass(const String& name);
     NETComponentClass* GetComponentClass(const String& name);
 
 
     /// Load resource from stream. May be called from a worker thread. Return true if successful.
     /// Load resource from stream. May be called from a worker thread. Return true if successful.
@@ -59,6 +62,7 @@ public:
 
 
 private:
 private:
 
 
+    HashMap<String, Vector<EnumInfo>> enums_;
     HashMap<StringHash, SharedPtr<NETComponentClass>> componentClasses_;
     HashMap<StringHash, SharedPtr<NETComponentClass>> componentClasses_;
 
 
 };
 };

+ 28 - 3
Source/AtomicNET/NETCore/NETComponentClass.cpp

@@ -21,6 +21,7 @@
 //
 //
 
 
 #include <Atomic/IO/Log.h>
 #include <Atomic/IO/Log.h>
+#include "NETAssemblyFile.h"
 #include "NETComponentClass.h"
 #include "NETComponentClass.h"
 
 
 /*
 /*
@@ -46,8 +47,9 @@ namespace Atomic
 
 
 HashMap<String, VariantType> NETComponentClass::typeMap_;
 HashMap<String, VariantType> NETComponentClass::typeMap_;
 
 
-NETComponentClass::NETComponentClass(Context* context) :
-    Object(context)
+NETComponentClass::NETComponentClass(Context* context, NETAssemblyFile* assemblyFile) :
+    Object(context),
+    assemblyFile_(assemblyFile)
 {
 {
 
 
 }
 }
@@ -118,6 +120,10 @@ bool NETComponentClass::ParseJSON(const JSONValue& json)
     if (!typeMap_.Size())
     if (!typeMap_.Size())
         InitTypeMap();
         InitTypeMap();
 
 
+    const HashMap<String, Vector<EnumInfo>>& fileEnums = assemblyFile_->GetEnums();
+
+    enums_.Clear();
+
     name_ = json.Get("name").GetString();
     name_ = json.Get("name").GetString();
 
 
     const JSONValue& jfields = json.Get("fields");
     const JSONValue& jfields = json.Get("fields");
@@ -137,7 +143,26 @@ bool NETComponentClass::ParseJSON(const JSONValue& json)
 
 
             if (isEnum)
             if (isEnum)
             {
             {
-                varType = typeMap_["Enum"];
+                if (fileEnums.Contains(typeName))
+                {
+                    Vector<EnumInfo> values;
+
+                    for (unsigned i = 0; i < fileEnums[typeName]->Size(); i++)
+                    {
+                        values.Push(fileEnums[typeName]->At(i));
+                    }
+
+                    enums_[fieldName] = values;
+
+                    varType = typeMap_["Enum"];
+
+                    fields_[fieldName] = varType;
+
+                    Variant value;
+                    value.FromString(varType, defaultValue);
+                    defaultFieldValues_[fieldName] = value;
+                }
+
             }
             }
             else
             else
             {
             {

+ 5 - 1
Source/AtomicNET/NETCore/NETComponentClass.h

@@ -31,6 +31,8 @@
 namespace Atomic
 namespace Atomic
 {
 {
 
 
+class NETAssemblyFile;
+
 /// NET Assembly resource.
 /// NET Assembly resource.
 class ATOMIC_API NETComponentClass : public Object
 class ATOMIC_API NETComponentClass : public Object
 {
 {
@@ -39,7 +41,7 @@ class ATOMIC_API NETComponentClass : public Object
 public:
 public:
 
 
     /// Construct.
     /// Construct.
-    NETComponentClass(Context* context);
+    NETComponentClass(Context* context, NETAssemblyFile* assemblyFile);
     /// Destruct.
     /// Destruct.
     virtual ~NETComponentClass();
     virtual ~NETComponentClass();
 
 
@@ -54,6 +56,8 @@ public:
 
 
 private:
 private:
 
 
+    WeakPtr<NETAssemblyFile> assemblyFile_;
+
     static void InitTypeMap();
     static void InitTypeMap();
 
 
     String name_;
     String name_;