Skip to content

Commit

Permalink
Merge pull request AtomicGameEngine#527 from AtomicGameEngine/JME-ATO…
Browse files Browse the repository at this point in the history
…MIC-526

Handle node deletion with context menu properly, guard against deleti…
  • Loading branch information
JoshEngebretson committed Dec 17, 2015
2 parents 421d347 + 178aee6 commit b599070
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
19 changes: 14 additions & 5 deletions Script/AtomicEditor/ui/frames/menus/HierarchyFrameMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class HierarchyFrameMenus extends Atomic.ScriptObject {
}

if (child) {
child.scene.sendEvent("SceneEditNodeCreated", { node : child});
child.scene.sendEvent("SceneEditNodeCreated", { node: child });
}

return true;
Expand All @@ -69,21 +69,30 @@ class HierarchyFrameMenus extends Atomic.ScriptObject {

if (target.id == "node context menu") {

var node = <Atomic.Node> target['node'];
var node = <Atomic.Node>target['node'];

if (!node) {
return false;
}

if (refid == "delete_node") {

node.removeAllComponents();
node.remove();
if (node instanceof Atomic.Scene)
return;

var scene = node.scene;
scene.sendEvent("SceneEditAddRemoveNodes", { end: false });
scene.sendEvent("SceneEditNodeRemoved", { node: node, parent: node.parent, scene: scene });
node.remove();
scene.sendEvent("SceneEditAddRemoveNodes", { end: true });

} else if (refid == "duplicate_node") {

if (node instanceof Atomic.Scene)
return;

var newnode = node.clone();
node.scene.sendEvent("SceneEditNodeCreated", { node : newnode});
node.scene.sendEvent("SceneEditNodeCreated", { node: newnode });
}

return true;
Expand Down
7 changes: 5 additions & 2 deletions Source/AtomicJS/Javascript/JSScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,13 @@ static int Node_GetComponents(duk_context* ctx)

duk_push_array(ctx);

int count = 0;
for (unsigned i = 0; i < dest.Size(); i++)
{
if (js_push_class_object_instance(ctx, dest[i], "Component"))
duk_put_prop_index(ctx, -2, i);
if (js_push_class_object_instance(ctx, dest[i], dest[i]->GetTypeName().CString()))
{
duk_put_prop_index(ctx, -2, count++);
}
}

return 1;
Expand Down

0 comments on commit b599070

Please sign in to comment.