Browse Source

Filter AnimatedSprite2D root node, save existing prefabs instead of serializing node

Josh Engebretson 10 years ago
parent
commit
bfaa08af3b

+ 15 - 5
Script/AtomicEditor/ui/frames/ProjectFrame.ts

@@ -254,12 +254,22 @@ class ProjectFrame extends ScriptWidget {
         if (dragObject.object && dragObject.object.typeName == "Node") {
         if (dragObject.object && dragObject.object.typeName == "Node") {
 
 
             var node = <Atomic.Node> dragObject.object;
             var node = <Atomic.Node> dragObject.object;
-            var destFilename = Atomic.addTrailingSlash(asset.path);
-            destFilename += node.name + ".prefab";
 
 
-            var file = new Atomic.File(destFilename, Atomic.FILE_WRITE);
-            node.saveXML(file);
-            file.close();
+            var prefabComponent = <Atomic.PrefabComponent> node.getComponent("PrefabComponent");
+
+            if (prefabComponent) {
+
+              prefabComponent.savePrefab();
+
+            }
+            else {
+                var destFilename = Atomic.addTrailingSlash(asset.path);
+                destFilename += node.name + ".prefab";
+
+                var file = new Atomic.File(destFilename, Atomic.FILE_WRITE);
+                node.saveXML(file);
+                file.close();
+            }
 
 
             this.rescan(asset);
             this.rescan(asset);
 
 

+ 15 - 1
Source/Atomic/Scene/PrefabComponent.cpp

@@ -6,6 +6,7 @@
 #include <Atomic/Resource/ResourceEvents.h>
 #include <Atomic/Resource/ResourceEvents.h>
 
 
 #include <Atomic/Physics/RigidBody.h>
 #include <Atomic/Physics/RigidBody.h>
+#include <Atomic/Atomic2D/AnimatedSprite2D.h>
 
 
 #include "PrefabEvents.h"
 #include "PrefabEvents.h"
 #include "PrefabComponent.h"
 #include "PrefabComponent.h"
@@ -114,18 +115,31 @@ void PrefabComponent::BreakPrefab()
     // flip temporary root children and components to break prefab
     // flip temporary root children and components to break prefab
     const Vector<SharedPtr<Component>>& rootComponents = node_->GetComponents();
     const Vector<SharedPtr<Component>>& rootComponents = node_->GetComponents();
     const Vector<SharedPtr<Node> >& children = node_->GetChildren();
     const Vector<SharedPtr<Node> >& children = node_->GetChildren();
+    PODVector<Node*> filterNodes;
 
 
     for (unsigned i = 0; i < rootComponents.Size(); i++)
     for (unsigned i = 0; i < rootComponents.Size(); i++)
     {
     {
         if (rootComponents[i]->IsTemporary())
         if (rootComponents[i]->IsTemporary())
         {
         {
             rootComponents[i]->SetTemporary(false);
             rootComponents[i]->SetTemporary(false);
+
+            // Animated sprites contain a temporary node we don't want to save in the prefab
+            // it would be nice if this was general purpose because have to test this when
+            // saving a prefab as well
+
+            if (rootComponents[i]->GetType() == AnimatedSprite2D::GetTypeStatic())
+            {
+                AnimatedSprite2D* asprite = (AnimatedSprite2D*) rootComponents[i].Get();
+                if (asprite->GetRootNode())
+                    filterNodes.Push(asprite->GetRootNode());
+            }
+
         }
         }
     }
     }
 
 
     for (unsigned i = 0; i < children.Size(); i++)
     for (unsigned i = 0; i < children.Size(); i++)
     {
     {
-        if (children[i]->IsTemporary())
+        if (children[i]->IsTemporary() && !filterNodes.Contains(children[i].Get()))
         {
         {
             children[i]->SetTemporary(false);
             children[i]->SetTemporary(false);
         }
         }

+ 9 - 7
Source/ToolCore/Assets/PrefabImporter.cpp

@@ -59,9 +59,9 @@ void PrefabImporter::HandlePrefabSave(StringHash eventType, VariantMap& eventDat
     const Vector<SharedPtr<Component>>& rootComponents = node->GetComponents();
     const Vector<SharedPtr<Component>>& rootComponents = node->GetComponents();
     const Vector<SharedPtr<Node> >& children = node->GetChildren();
     const Vector<SharedPtr<Node> >& children = node->GetChildren();
 
 
-    Vector<SharedPtr<Component>> tempComponents;
-    Vector<SharedPtr<Node>> tempChildren;
-    Vector<SharedPtr<Node>> filterNodes;
+    PODVector<Component*> tempComponents;
+    PODVector<Node*> tempChildren;
+    PODVector<Node*> filterNodes;
 
 
     for (unsigned i = 0; i < rootComponents.Size(); i++)
     for (unsigned i = 0; i < rootComponents.Size(); i++)
     {
     {
@@ -71,11 +71,13 @@ void PrefabImporter::HandlePrefabSave(StringHash eventType, VariantMap& eventDat
             tempComponents.Push(rootComponents[i]);
             tempComponents.Push(rootComponents[i]);
 
 
             // Animated sprites contain a temporary node we don't want to save in the prefab
             // Animated sprites contain a temporary node we don't want to save in the prefab
+            // it would be nice if this was general purpose because have to test this when
+            // breaking node as well
             if (rootComponents[i]->GetType() == AnimatedSprite2D::GetTypeStatic())
             if (rootComponents[i]->GetType() == AnimatedSprite2D::GetTypeStatic())
             {
             {
                 AnimatedSprite2D* asprite = (AnimatedSprite2D*) rootComponents[i].Get();
                 AnimatedSprite2D* asprite = (AnimatedSprite2D*) rootComponents[i].Get();
-                if (asprite->GetNode())
-                    filterNodes.Push(SharedPtr<Node>(asprite->GetNode()));
+                if (asprite->GetRootNode())
+                    filterNodes.Push(asprite->GetRootNode());
             }
             }
 
 
         }
         }
@@ -83,13 +85,13 @@ void PrefabImporter::HandlePrefabSave(StringHash eventType, VariantMap& eventDat
 
 
     for (unsigned i = 0; i < children.Size(); i++)
     for (unsigned i = 0; i < children.Size(); i++)
     {
     {
-        if (filterNodes.Contains(children[i]))
+        if (filterNodes.Contains(children[i].Get()))
             continue;
             continue;
 
 
         if (children[i]->IsTemporary())
         if (children[i]->IsTemporary())
         {
         {
             children[i]->SetTemporary(false);
             children[i]->SetTemporary(false);
-            tempChildren.Push(children);
+            tempChildren.Push(children[i]);
         }
         }
     }
     }