Browse Source

Resource vector inspector (WIP)

Josh Engebretson 9 years ago
parent
commit
3c87196d68

+ 0 - 5
Script/AtomicEditor/editor/EditorEvents.ts

@@ -161,11 +161,6 @@ export interface InspectorProjectReferenceEvent {
 
 
 }
 }
 
 
-export const RemoveCurrentAssetAssigned = "RemoveCurrentAssetAssigned";
-export interface RemoveCurrentAssetAssignedEvent {
-
-}
-
 export const UserPreferencesChangedNotification  = "UserPreferencesChangedNotification";
 export const UserPreferencesChangedNotification  = "UserPreferencesChangedNotification";
 export interface UserPreferencesChangedEvent {
 export interface UserPreferencesChangedEvent {
     /**
     /**

+ 5 - 5
Script/AtomicEditor/ui/frames/inspector/AttributeInfoEdit.ts

@@ -831,9 +831,9 @@ class ResourceRefAttributeEdit extends AttributeInfoEdit {
                 // for cached resources, use the asset name, otherwise use the resource path name
                 // for cached resources, use the asset name, otherwise use the resource path name
                 var resource: Atomic.Resource;
                 var resource: Atomic.Resource;
                 if (this.refListIndex != -1) {
                 if (this.refListIndex != -1) {
-                    resource = object.getAttribute(this.attrInfo.name).resources[this.refListIndex];
+                    resource = object.getAttribute(this.attrInfo.name).resources[this.refListIndex, this.arrayIndex];
                 } else {
                 } else {
-                    resource = <Atomic.Resource>object.getAttribute(this.attrInfo.name);
+                    resource = <Atomic.Resource>object.getAttribute(this.attrInfo.name, this.arrayIndex);
                 }
                 }
 
 
                 var text = "";
                 var text = "";
@@ -857,7 +857,7 @@ class ResourceRefAttributeEdit extends AttributeInfoEdit {
 
 
                     if (ev.type == Atomic.UI_EVENT_TYPE.UI_EVENT_TYPE_POINTER_DOWN) {
                     if (ev.type == Atomic.UI_EVENT_TYPE.UI_EVENT_TYPE_POINTER_DOWN) {
 
 
-                        resource = <Atomic.Resource>object.getAttribute(this.attrInfo.name);
+                        resource = <Atomic.Resource>object.getAttribute(this.attrInfo.name, this.arrayIndex);
 
 
                         if (resource instanceof Atomic.JSComponentFile) {
                         if (resource instanceof Atomic.JSComponentFile) {
 
 
@@ -930,7 +930,7 @@ class ResourceRefAttributeEdit extends AttributeInfoEdit {
 
 
                 }
                 }
 
 
-                this.editType.onAttributeInfoEdited(this.attrInfo, resource, this.refListIndex);
+                this.editType.onAttributeInfoEdited(this.attrInfo, resource, this.refListIndex, true, this.arrayIndex);
                 this.onResourceChanged(resource);
                 this.onResourceChanged(resource);
                 this.refresh();
                 this.refresh();
 
 
@@ -961,7 +961,7 @@ class ResourceRefAttributeEdit extends AttributeInfoEdit {
 
 
                     var resource = asset.getResource(resourceTypeName);
                     var resource = asset.getResource(resourceTypeName);
 
 
-                    this.editType.onAttributeInfoEdited(this.attrInfo, resource, this.refListIndex);
+                    this.editType.onAttributeInfoEdited(this.attrInfo, resource, this.refListIndex, true, this.arrayIndex);
                     this.onResourceChanged(resource);
                     this.onResourceChanged(resource);
                     this.refresh();
                     this.refresh();
 
 

+ 7 - 7
Script/AtomicEditor/ui/frames/inspector/ComponentAttributeUI.ts

@@ -146,21 +146,21 @@ class SubmeshAttributeEdit extends AttributeInfoEdit {
         this.name = name;
         this.name = name;
         this.hideName = true;
         this.hideName = true;
 
 
-        this.subscribeToEvent(EditorEvents.RemoveCurrentAssetAssigned, (ev: EditorEvents.RemoveCurrentAssetAssignedEvent) => {
-
-            this.editType.onAttributeInfoEdited(this.attrInfo, null, this.matIndex);
-            this.refresh();
-        });
-
 
 
     }
     }
 
 
     openResourceSelectionBox(materialIndex: number, resourceTypeName: string, importerName: string) {
     openResourceSelectionBox(materialIndex: number, resourceTypeName: string, importerName: string) {
 
 
         this.matIndex = materialIndex;
         this.matIndex = materialIndex;
-
+        
         EditorUI.getModelOps().showResourceSelection("Select " + resourceTypeName + " Resource", importerName, resourceTypeName, function (retObject: any) {
         EditorUI.getModelOps().showResourceSelection("Select " + resourceTypeName + " Resource", importerName, resourceTypeName, function (retObject: any) {
 
 
+            if (retObject == null) {
+                this.editType.onAttributeInfoEdited(this.attrInfo, null, this.matIndex);
+                this.refresh();
+                return;
+            }
+
             var resource: Atomic.Resource = null;
             var resource: Atomic.Resource = null;
 
 
             if (retObject instanceof ToolCore.Asset) {
             if (retObject instanceof ToolCore.Asset) {

+ 8 - 6
Script/AtomicEditor/ui/frames/inspector/MaterialInspector.ts

@@ -92,7 +92,6 @@ class MaterialInspector extends ScriptWidget {
         this.fd.id = "Vera";
         this.fd.id = "Vera";
         this.fd.size = 11;
         this.fd.size = 11;
 
 
-        this.subscribeToEvent(EditorEvents.RemoveCurrentAssetAssigned, (ev: EditorEvents.RemoveCurrentAssetAssignedEvent) => this.createTextureRemoveButtonCallback(this.tunit, this.textureWidget));
         this.subscribeToEvent("ResourceAdded", (ev: ToolCore.ResourceAddedEvent) => this.refreshTechniquesPopup());
         this.subscribeToEvent("ResourceAdded", (ev: ToolCore.ResourceAddedEvent) => this.refreshTechniquesPopup());
     }
     }
 
 
@@ -270,18 +269,21 @@ class MaterialInspector extends ScriptWidget {
 
 
     openTextureSelectionBox(textureUnit: number, textureWidget: Atomic.UITextureWidget) {
     openTextureSelectionBox(textureUnit: number, textureWidget: Atomic.UITextureWidget) {
 
 
-        var inspector = this;
-
         EditorUI.getModelOps().showResourceSelection("Select Texture", "TextureImporter", "Texture2D", function (asset: ToolCore.Asset, args: any) {
         EditorUI.getModelOps().showResourceSelection("Select Texture", "TextureImporter", "Texture2D", function (asset: ToolCore.Asset, args: any) {
 
 
+            if (asset == null) {
+                this.createTextureRemoveButtonCallback(this.tunit, this.textureWidget);
+                return;
+            }
+            
             var texture = <Atomic.Texture2D>Atomic.cache.getResource("Texture2D", asset.path);
             var texture = <Atomic.Texture2D>Atomic.cache.getResource("Texture2D", asset.path);
 
 
             if (texture) {
             if (texture) {
-                inspector.material.setTexture(textureUnit, texture);
-                textureWidget.texture = inspector.getTextureThumbnail(texture);
+                this.material.setTexture(textureUnit, texture);
+                textureWidget.texture = this.getTextureThumbnail(texture);
             }
             }
 
 
-        });
+        }.bind(this));
 
 
     }
     }
 
 

+ 4 - 0
Script/AtomicEditor/ui/frames/inspector/SelectionInspector.ts

@@ -165,6 +165,10 @@ class JSComponentSection extends ComponentSection {
         let jsc = this.editType.getFirstObject() as Atomic.JSComponent;
         let jsc = this.editType.getFirstObject() as Atomic.JSComponent;
         if (jsc && jsc.componentFile) {
         if (jsc && jsc.componentFile) {
             this.text = jsc.componentFile.name.split("/").pop();
             this.text = jsc.componentFile.name.split("/").pop();
+            let jscf = <Atomic.JSComponentFile> jsc.componentFile;
+            if (jscf.typeScriptClass) {
+                this.text = this.text.replace(".js", ".ts");
+            }            
         }
         }
     }
     }
 
 

+ 1 - 1
Script/AtomicEditor/ui/modal/ResourceSelection.ts

@@ -159,7 +159,7 @@ class ResourceSelection extends ModalWindow {
         var id = this.folderList.selectedItemID;
         var id = this.folderList.selectedItemID;
 
 
         if (id == "") {
         if (id == "") {
-            this.sendEvent(EditorEvents.RemoveCurrentAssetAssigned);
+            this.callback(null, this.args);
             this.hide();
             this.hide();
             return true;
             return true;
         }
         }

+ 24 - 2
Source/Atomic/Script/ScriptComponentFile.cpp

@@ -53,10 +53,10 @@ void ScriptComponentFile::AddEnum(const String& enumName, const EnumInfo& enumIn
     enumValues.Push(enumInfo);
     enumValues.Push(enumInfo);
 }
 }
 
 
-void ScriptComponentFile::AddField(const String& fieldName, VariantType variantType, bool isArray, const String &classname, const String& tooltip)
+void ScriptComponentFile::AddField(const String& fieldName, VariantType variantType, const String& resourceTypeName, bool isArray, const String &classname, const String& tooltip)
 {
 {
     FieldMap& fields = classFields_[classname];
     FieldMap& fields = classFields_[classname];
-    FieldInfo finfo(fieldName, variantType, isArray);
+    FieldInfo finfo(fieldName, variantType, resourceTypeName, isArray);
     fields[fieldName] = finfo;
     fields[fieldName] = finfo;
 
 
     if (tooltip.Length())
     if (tooltip.Length())
@@ -161,15 +161,37 @@ void ScriptComponentFile::GetDefaultFieldValue(const String& name, Variant& v,co
     case VAR_BOOL:
     case VAR_BOOL:
         v = false;
         v = false;
         break;
         break;
+    case VAR_INT:
+        v = 0;
+    case VAR_DOUBLE:
+        v = 0;
     case VAR_STRING:
     case VAR_STRING:
         v = "";
         v = "";
         break;
         break;
     case VAR_FLOAT:
     case VAR_FLOAT:
         v = 0.0f;
         v = 0.0f;
         break;
         break;
+    case VAR_VECTOR2:
+        v = Vector2::ZERO;
+        break;
     case VAR_VECTOR3:
     case VAR_VECTOR3:
         v = Vector3::ZERO;
         v = Vector3::ZERO;
         break;
         break;
+    case VAR_VECTOR4:
+        v = Vector4::ZERO;
+        break;
+    case VAR_INTVECTOR2:
+        v = IntVector2::ZERO;
+        break;
+    case VAR_COLOR:
+        v = Color::WHITE;
+        break;
+    case VAR_QUATERNION:
+        v = Quaternion::IDENTITY;
+        break;
+    case VAR_RESOURCEREF:
+        v = Quaternion::IDENTITY;
+        break;
     default:
     default:
         break;
         break;
     }
     }

+ 7 - 4
Source/Atomic/Script/ScriptComponentFile.h

@@ -39,15 +39,18 @@ struct FieldInfo
         isArray_ = false;
         isArray_ = false;
     }
     }
 
 
-    FieldInfo(const String& name, VariantType variantType, bool isArray = false)
+    FieldInfo(const String& name, VariantType variantType, const String& resourceTypeName = String::EMPTY, bool isArray = false)
     {
     {
-        name_ = name;
+        name_ = name;        
         variantType_ = variantType;
         variantType_ = variantType;
-        isArray_ = isArray;
+        resourceTypeName_ = resourceTypeName;
+        isArray_ = isArray;        
     }
     }
 
 
     String name_;
     String name_;
     VariantType variantType_;
     VariantType variantType_;
+    // for resource ref variants
+    String resourceTypeName_;
     bool isArray_;
     bool isArray_;
 };
 };
 
 
@@ -102,7 +105,7 @@ protected:
     void Clear();
     void Clear();
 
 
     void AddEnum(const String& enumName, const EnumInfo& enumInfo, const String& classname = String::EMPTY);
     void AddEnum(const String& enumName, const EnumInfo& enumInfo, const String& classname = String::EMPTY);
-    void AddField(const String& fieldName, VariantType variantType, bool isArray, const String& classname = String::EMPTY, const String& tooltip = String::EMPTY);
+    void AddField(const String& fieldName, VariantType variantType, const String& resourceTypeName = String::EMPTY, bool isArray = false, const String& classname = String::EMPTY, const String& tooltip = String::EMPTY);
     void AddDefaultValue(const String& fieldName, const Variant& value, const String& classname = String::EMPTY);
     void AddDefaultValue(const String& fieldName, const Variant& value, const String& classname = String::EMPTY);
 
 
     // only valid in editor
     // only valid in editor

+ 4 - 0
Source/AtomicJS/Javascript/JSAPI.cpp

@@ -363,6 +363,10 @@ namespace Atomic
             value = 0.0f;
             value = 0.0f;
             break;
             break;
 
 
+        case VAR_RESOURCEREF:            
+            value = ResourceRef();
+            break;
+
         default:
         default:
             break;
             break;
         }
         }

+ 9 - 2
Source/AtomicJS/Javascript/JSComponentFile.cpp

@@ -36,7 +36,8 @@ namespace Atomic
 
 
 JSComponentFile::JSComponentFile(Context* context) :
 JSComponentFile::JSComponentFile(Context* context) :
     ScriptComponentFile(context),
     ScriptComponentFile(context),
-    scriptClass_(false)
+    scriptClass_(false),
+    typescriptClass_(false)
 {
 {
 }
 }
 
 
@@ -181,6 +182,8 @@ bool JSComponentFile::InitModule()
 
 
 bool JSComponentFile::BeginLoad(Deserializer& source)
 bool JSComponentFile::BeginLoad(Deserializer& source)
 {
 {
+    typescriptClass_ = false;
+
     if (!InitModule())
     if (!InitModule())
         return false;
         return false;
 
 
@@ -211,6 +214,10 @@ bool JSComponentFile::BeginLoad(Deserializer& source)
     {
     {
         String line = lines[i];
         String line = lines[i];
 
 
+        // TODO: better TS detection
+        if (line.Contains("function __() { this.constructor = d; }"))
+            typescriptClass_ = true;
+
         bool added = false;
         bool added = false;
 
 
         if (!eval.Length())
         if (!eval.Length())
@@ -415,7 +422,7 @@ bool JSComponentFile::BeginLoad(Deserializer& source)
 
 
                     if (variantType != VAR_NONE)
                     if (variantType != VAR_NONE)
                     {
                     {
-                        AddField(name, variantType, false);
+                        AddField(name, variantType);
                     }
                     }
 
 
                     duk_pop_2(ctx);  // pop key value
                     duk_pop_2(ctx);  // pop key value

+ 4 - 0
Source/AtomicJS/Javascript/JSComponentFile.h

@@ -54,6 +54,9 @@ public:
 
 
     bool GetScriptClass() { return scriptClass_; }
     bool GetScriptClass() { return scriptClass_; }
 
 
+    /// Returns true is this component file containes a TypeScript class
+    bool GetTypeScriptClass() { return typescriptClass_; }
+
     SharedPtr<JSComponent> CreateJSComponent();
     SharedPtr<JSComponent> CreateJSComponent();
     bool PushModule();
     bool PushModule();
 
 
@@ -62,6 +65,7 @@ private:
     bool InitModule();
     bool InitModule();
 
 
     bool scriptClass_;
     bool scriptClass_;
+    bool typescriptClass_;
 
 
 };
 };
 
 

+ 73 - 29
Source/AtomicJS/Javascript/JSSceneSerializable.cpp

@@ -97,10 +97,9 @@ namespace Atomic
         }
         }
 
 
 
 
-        Variant v;
-        js_to_variant(ctx, 1, v, variantType);
-
-        ScriptComponent* jsc = NULL;
+        ScriptComponent* jsc = 0;
+        FieldInfo *fieldInfo = 0;
+        const HashMap<String, Vector<EnumInfo>>* enums = 0;
 
 
         // check dynamic
         // check dynamic
         if (!isAttr)
         if (!isAttr)
@@ -118,31 +117,37 @@ namespace Atomic
                     const FieldMap& fields = file->GetFields(className);
                     const FieldMap& fields = file->GetFields(className);
                     const HashMap<String, Vector<EnumInfo>>& enums = file->GetEnums(className);
                     const HashMap<String, Vector<EnumInfo>>& enums = file->GetEnums(className);
 
 
-                    if (FieldInfo *finfo = fields[name])
+                    if (fieldInfo = fields[name])
                     {
                     {
-                        variantType = finfo->variantType_;
+                        variantType = fieldInfo->variantType_;
 
 
-                        if (finfo->isArray_)
+                        if (fieldInfo->isArray_)
                         {
                         {
                             arrayVariantType = variantType;
                             arrayVariantType = variantType;
                             variantType = VAR_VARIANTVECTOR;
                             variantType = VAR_VARIANTVECTOR;
                         }
                         }
-                        else if (enums.Contains(name))
-                        {
-                            int idx = (int)v.GetFloat();
-
-                            if (idx > 0 && idx < enums[name]->Size())
-                            {
-                                VariantMap& values = jsc->GetFieldValues();
-                                values[name] = enums[name]->At(idx).value_;
-                                return 0;
-                            }
-                        }
                     }
                     }
                 }
                 }
             }
             }
         }
         }
 
 
+        Variant v;
+        js_to_variant(ctx, 1, v, variantType);
+
+        if (enums && enums->Contains(name))
+        {
+            int idx = (int)v.GetFloat();
+
+            if (idx > 0 && idx < (*enums)[name]->Size())
+            {
+                VariantMap& values = jsc->GetFieldValues();
+                values[name] = (*enums)[name]->At(idx).value_;
+                return 0;
+            }
+        }
+
+
+
         if (variantType == VAR_NONE)
         if (variantType == VAR_NONE)
             return 0;
             return 0;
 
 
@@ -178,12 +183,18 @@ namespace Atomic
                 v = ResourceRef(resource->GetType(), resource->GetName());
                 v = ResourceRef(resource->GetType(), resource->GetName());
 
 
             }
             }
+            else
+            {
+                v = ResourceRef();
+            }
 
 
         }
         }
         else if (variantType == VAR_VARIANTVECTOR)
         else if (variantType == VAR_VARIANTVECTOR)
         {
         {
             if (arrayIndex >= 0)
             if (arrayIndex >= 0)
             {
             {
+                assert(fieldInfo);
+
                 const VariantMap& values = jsc->GetFieldValues();
                 const VariantMap& values = jsc->GetFieldValues();
                 Variant *v2 = values[name];
                 Variant *v2 = values[name];
 
 
@@ -194,7 +205,29 @@ namespace Atomic
                     {
                     {
                         VariantVector* vector = v2->GetVariantVectorPtr();
                         VariantVector* vector = v2->GetVariantVectorPtr();
 
 
-                        if (v.GetType() == VAR_VECTOR4)
+                        if (arrayVariantType == VAR_RESOURCEREF)
+                        {
+                            RefCounted* ref = v.GetPtr();
+
+                            if (ref && ref->IsObject())
+                            {
+                                Object* o = (Object*)ref;
+
+                                // TODO: calling code must ensure we are a resource, can this be done here?
+                                Resource* resource = (Resource*)o;
+
+                                if (resource->GetType() == StringHash(fieldInfo->resourceTypeName_))
+                                    v = ResourceRef(resource->GetType(), resource->GetName());
+                                else
+                                    v = ResourceRef();
+                            }
+                            else
+                            {
+                                v = ResourceRef();
+                            }
+
+                        }
+                        else if (v.GetType() == VAR_VECTOR4)
                         {
                         {
                             if (arrayVariantType == VAR_COLOR)
                             if (arrayVariantType == VAR_COLOR)
                             {
                             {
@@ -207,8 +240,7 @@ namespace Atomic
                                 v = Quaternion(v4.w_, v4.x_, v4.y_, v4.z_);
                                 v = Quaternion(v4.w_, v4.x_, v4.y_, v4.z_);
                             }
                             }
                         }
                         }
-
-                        if (v.GetType() == VAR_FLOAT)
+                        else if (v.GetType() == VAR_FLOAT)
                         {
                         {
                             if (arrayVariantType == VAR_INT)
                             if (arrayVariantType == VAR_INT)
                                 v = (int)v.GetFloat();
                                 v = (int)v.GetFloat();
@@ -386,18 +418,30 @@ namespace Atomic
                 duk_push_number(ctx, (double)itr->second_.variantType_);
                 duk_push_number(ctx, (double)itr->second_.variantType_);
                 duk_put_prop_string(ctx, -2, "type");
                 duk_put_prop_string(ctx, -2, "type");
 
 
-                if (itr->second_.variantType_ == VAR_RESOURCEREF && defaultFieldValues.Contains(itr->first_))
+                const FieldInfo& fieldInfo = itr->second_;
+
+                if (fieldInfo.variantType_ == VAR_RESOURCEREF)
                 {
                 {
-                    if (defaultFieldValues[itr->first_]->GetType() == VAR_RESOURCEREF)
+                    if (fieldInfo.resourceTypeName_.Length())
                     {
                     {
-                        const ResourceRef& ref = defaultFieldValues[itr->first_]->GetResourceRef();
-                        const String& typeName = JSVM::GetJSVM(ctx)->GetContext()->GetTypeName(ref.type_);
-
-                        if (typeName.Length())
+                        duk_push_string(ctx, fieldInfo.resourceTypeName_.CString());
+                        duk_put_prop_string(ctx, -2, "resourceTypeName");
+                    }
+                    else if (defaultFieldValues.Contains(fieldInfo.name_) && defaultFieldValues[fieldInfo.name_]->GetType() == VAR_RESOURCEREF)
+                    {       
+                        if (const Variant* value = defaultFieldValues[fieldInfo.name_])
                         {
                         {
-                            duk_push_string(ctx, typeName.CString());
-                            duk_put_prop_string(ctx, -2, "resourceTypeName");
+                            if (value->GetType() == VAR_RESOURCEREF)
+                            {
+                                const ResourceRef& ref = value->GetResourceRef();
+                                const String& typeName = JSVM::GetJSVM(ctx)->GetContext()->GetTypeName(ref.type_);
 
 
+                                if (typeName.Length())
+                                {
+                                    duk_push_string(ctx, typeName.CString());
+                                    duk_put_prop_string(ctx, -2, "resourceTypeName");
+                                }
+                            }
                         }
                         }
                     }
                     }
                 }
                 }

+ 4 - 2
Source/AtomicNET/NETScript/CSComponentAssembly.cpp

@@ -93,7 +93,8 @@ namespace Atomic
 
 
                 bool isEnum = jfield.Get("isEnum").GetBool();
                 bool isEnum = jfield.Get("isEnum").GetBool();
                 bool isArray = jfield.Get("isArray").GetBool();
                 bool isArray = jfield.Get("isArray").GetBool();
-                String typeName = jfield.Get("typeName").GetString();               
+                String typeName = jfield.Get("typeName").GetString();
+                String resourceTypeName;
                 String fieldName = jfield.Get("name").GetString();
                 String fieldName = jfield.Get("name").GetString();
                 String defaultValue = jfield.Get("defaultValue").GetString();
                 String defaultValue = jfield.Get("defaultValue").GetString();
                 String tooltip;
                 String tooltip;
@@ -142,6 +143,7 @@ namespace Atomic
                         if (itr->second_->GetFactoryTypeName() == typeName)
                         if (itr->second_->GetFactoryTypeName() == typeName)
                         {
                         {
                             varType = VAR_RESOURCEREF;
                             varType = VAR_RESOURCEREF;
+                            resourceTypeName = typeName;
                             break;
                             break;
                         }
                         }
 
 
@@ -184,7 +186,7 @@ namespace Atomic
                     }
                     }
                 }
                 }
 
 
-                AddField(fieldName, varType, isArray, className, tooltip);
+                AddField(fieldName, varType, resourceTypeName, isArray, className, tooltip);
 
 
             }
             }