Skip to content

Commit

Permalink
scheduled changes on editor
Browse files Browse the repository at this point in the history
  • Loading branch information
kleber-swf committed Aug 31, 2021
1 parent 533e5fc commit 92b9b01
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 19 deletions.
5 changes: 0 additions & 5 deletions src/editor/selection/scale/scale.handler.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { Data, EDITOR } from 'data';
import { ScaleGizmo } from './scale.gizmo';
import { Scaler } from './scaler';

Expand Down Expand Up @@ -67,10 +66,6 @@ export class ScaleHandler extends Phaser.Group {
if (!this._scaling) return false;
const pointer = this.game.input.mousePointer;
this.scaler.scaleToPoint(pointer.x, pointer.y);

// TODO schedule all changes to the next update
Data.propertyChanged('scale', this.selectedObject.scale, EDITOR);
Data.propertyChanged('position', this.selectedObject.position, EDITOR);
return true;
}
}
35 changes: 21 additions & 14 deletions src/editor/selection/selection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ import { ANCHOR_COLOR, ANCHOR_STROKE, BORDER_COLOR, BORDER_STROKE, PIVOT_COLOR,
import { ScaleHandler } from './scale/scale.handler';

export class Selection extends Phaser.Group {
private _obj: PIXI.DisplayObject = null;
public get hasObject() { return !!this._obj; }
private _selectedObject: PIXI.DisplayObject = null;
public get hasObject() { return !!this._selectedObject; }

private readonly view: Phaser.Graphics;
private readonly scaleHandler: ScaleHandler;
private _hasScheduledChanges = false;

constructor(game: Phaser.Game) {
super(game);
Expand All @@ -24,24 +25,24 @@ export class Selection extends Phaser.Group {
}

public select(obj: PIXI.DisplayObject) {
this._obj = obj;
this._selectedObject = obj;
this.view.clear();
this.scaleHandler.selectedObject = obj;
if (this.visible = !!obj) this.redraw();
}

private redraw() {
this.view.clear();
if (!this._obj) return;
const bounds = this._obj.getBounds();
if (!this._selectedObject) return;
const bounds = this._selectedObject.getBounds();
this.drawBorder(bounds);
this.drawPivot(this.scaleHandler.scaling
? this.scaleHandler.scaler.originalPivot
: this._obj.pivot);
this.drawAnchor(this._obj.anchor, bounds);
: this._selectedObject.pivot);
this.drawAnchor(this._selectedObject.anchor, bounds);
this.scaleHandler.redraw(bounds);
this.position.set(bounds.x, bounds.y);
this.rotation = this._obj.rotation;
this.rotation = this._selectedObject.rotation;
}

private drawBorder(bounds: PIXI.Rectangle) {
Expand Down Expand Up @@ -81,15 +82,21 @@ export class Selection extends Phaser.Group {
public move(deltaX: number, deltaY: number) {
let pos: PIXI.Point = this.position;
this.position.set(pos.x + deltaX, pos.y + deltaY);
pos = this._obj.position;
this._obj.position.set(pos.x + deltaX, pos.y + deltaY);

// TODO schedule all changes to the next update
Data.propertyChanged('position', pos, EDITOR);
pos = this._selectedObject.position;
this._selectedObject.position.set(pos.x + deltaX, pos.y + deltaY);
this._hasScheduledChanges = true;
}


public update() {
super.update();
if (this.scaleHandler.handle()) this.redraw();
if (this.scaleHandler.handle()) {
this.redraw();
this._hasScheduledChanges = true;
}
if (!this._hasScheduledChanges) return;
Data.propertyChanged('position', this._selectedObject.position, EDITOR);
Data.propertyChanged('scale', this._selectedObject.scale, EDITOR);
this._hasScheduledChanges = false;
}
}

0 comments on commit 92b9b01

Please sign in to comment.