Skip to content

Commit

Permalink
Do not repeat children objects in copy/paste.
Browse files Browse the repository at this point in the history
  • Loading branch information
PhaserEditor2D committed Dec 23, 2023
1 parent 8868954 commit a075645
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,15 @@ namespace phasereditor2d.scene.ui {
const selection = alternativeSelection
|| this._editorScene.getEditor().getSelectedGameObjects();

const areDropingScriptNodes = dropObjects.filter(obj => obj instanceof sceneobjects.ScriptNode).length === dropObjects.length;
const areDroppingScriptNodes = dropObjects.filter(obj => obj instanceof sceneobjects.ScriptNode).length === dropObjects.length;

for (const sprite of selection) {

const dropTarget = areDropingScriptNodes ? this.findDropScriptTargetParent(sprite) : this.findDropTargetParent(sprite);
const dropTarget = areDroppingScriptNodes ? this.findDropScriptTargetParent(sprite) : this.findDropTargetParent(sprite);

if (dropTarget) {

if (areDropingScriptNodes) {
if (areDroppingScriptNodes) {

dropInObj = dropTarget;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,38 @@ namespace phasereditor2d.scene.ui.editor {

const p = new Phaser.Math.Vector2();

const gameObjects = this._editor.getSelectedGameObjects();
const selection = new Set(this._editor.getSelectedGameObjects());

for (const obj of gameObjects) {
const copyObjects: sceneobjects.ISceneGameObject[] = [];

// filter off the children of selected parents

for(const obj of selection) {

let include = true;

const objES = obj.getEditorSupport();

const parents = objES.getAllParents();

for(const parent of parents) {

if (selection.has(parent)) {

include = false;
break;
}
}

if (include) {

copyObjects.push(obj);
}
}

// record game objects positions

for (const obj of copyObjects) {

const sprite = obj as unknown as Phaser.GameObjects.Sprite;

Expand All @@ -111,7 +140,9 @@ namespace phasereditor2d.scene.ui.editor {
minY = Math.min(minY, p.y);
}

for (const obj of gameObjects) {
// serialize objects

for (const obj of copyObjects) {

const objData = {} as any;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,6 @@ namespace phasereditor2d.scene.ui.editor.undo {

private async pasteGameObjects(clipboardItems: IClipboardItem[], sel: any[]) {

console.log("pasteGamesObjects", clipboardItems.map(i => i.data));

const scene = this._editor.getScene();

const maker = this._editor.getSceneMaker();
Expand Down

0 comments on commit a075645

Please sign in to comment.