Skip to content

Commit

Permalink
history moved to editor
Browse files Browse the repository at this point in the history
  • Loading branch information
kleber-jg committed Sep 3, 2021
1 parent 958eef5 commit 10aa89a
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 16 deletions.
3 changes: 3 additions & 0 deletions src/core/editor.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { History } from './history';
import { Actions } from './actions';

class EditorClass {
public actions: Actions;
public history: History;

public init() {
this.actions = new Actions();
this.history = new History();
}
}

Expand Down
6 changes: 2 additions & 4 deletions src/data/history.ts → src/core/history.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Data, DataOrigin } from './data';
import { Data, DataOrigin } from '../data/data';

export interface HistoryEntry {
obj: PIXI.DisplayObject;
Expand All @@ -7,7 +7,7 @@ export interface HistoryEntry {

const HISTORY_LIMIT = 100;

class HistoryClass {
export class History {
private readonly entries: HistoryEntry[] = [];
private holdingEntry: HistoryEntry;

Expand Down Expand Up @@ -59,5 +59,3 @@ class HistoryClass {
this.onHistoryWalk.dispatch(entry);
}
}

export const History = new HistoryClass();
4 changes: 2 additions & 2 deletions src/editor-view/properties/editors/property-editor.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Data, DataOrigin } from 'data/data';
import { History } from 'data/history';
import { Editor } from 'core/editor';
import { PropertyInspectionData } from 'editor-view/properties-editors';
import { IdUtil } from 'util/id.util';
import './property-editor.scss';
Expand Down Expand Up @@ -67,7 +67,7 @@ export abstract class PropertyEditor<T> extends HTMLElement {
public abstract updateInternalValue(e: Event): void;

public savePreviousValue() {
History.prepare(Data.selectedObject, {
Editor.history.prepare(Data.selectedObject, {
[this.prop.name]: this.getInternalValue()
}).commit();
}
Expand Down
3 changes: 1 addition & 2 deletions src/plugin.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Data } from 'data/data';
import { History } from 'data/history';
import { Preferences } from 'data/preferences';
import Phaser from 'phaser-ce';
import { Editor } from './core/editor';
Expand Down Expand Up @@ -37,7 +36,7 @@ export class Plugin extends Phaser.Plugin {
label: 'undo',
icon: 'fa-undo-alt',
shortcut: 'ctrl+z',
command: History.undo.bind(History)
command: Editor.history.undo.bind(Editor.history)
},
{
id: 'MOVE_UP_1',
Expand Down
10 changes: 5 additions & 5 deletions src/scene-view/scene-view.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Editor } from 'core/editor';
import { Data, DataOrigin } from 'data/data';
import { History } from 'data/history';
import { DragUtil } from '../util/drag.util';
import { SceneModel } from './scene-model';
import { Selection } from './selection/selection';
Expand Down Expand Up @@ -80,18 +80,18 @@ export class SceneView extends Phaser.Group {
const obj = Data.selectedObject
if (!obj) return;

History.prepare(Data.selectedObject, { position: obj.position.clone() });
Editor.history.prepare(Data.selectedObject, { position: obj.position.clone() });
}

private onInputUp(_: any, pointer: Phaser.Pointer) {
this._isInputDown = false;
const wasDragging = this._isDragging;
this._isDragging = false;
if (wasDragging) {
History.commit();
Editor.history.commit();
return;
}
History.cancel();
Editor.history.cancel();
if (this._hasSelected) return;
this.trySelectOver(pointer);
this._hasSelected = false;
Expand Down Expand Up @@ -124,7 +124,7 @@ export class SceneView extends Phaser.Group {
public moveSelectedObject(deltaX: number, deltaY: number) {
const obj = Data.selectedObject;
if (!obj) return;
History.prepare(obj, { position: obj.position.clone() }).commit();
Editor.history.prepare(obj, { position: obj.position.clone() }).commit();
obj.position.set(obj.position.x + deltaX, obj.position.y + deltaY);
obj.updateTransform();
this.selection.redraw();
Expand Down
6 changes: 3 additions & 3 deletions src/scene-view/selection/scale/scale.handler.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Editor } from 'core/editor';
import { Data, DataOrigin } from 'data/data';
import { History } from 'data/history';
import { ScaleGizmo } from './scale.gizmo';
import { Scaler } from './scaler';

Expand Down Expand Up @@ -56,7 +56,7 @@ export class ScaleHandler extends Phaser.Group {

private startScaling(gizmos: ScaleGizmo) {
const obj = Data.selectedObject;
History.prepare(obj, {
Editor.history.prepare(obj, {
scale: obj.scale.clone(),
position: obj.position.clone(),
});
Expand All @@ -68,7 +68,7 @@ export class ScaleHandler extends Phaser.Group {
private stopScaling() {
this._scaling = false;
this.scaler.stopScaling();
History.commit();
Editor.history.commit();
}

public handle() {
Expand Down

0 comments on commit 10aa89a

Please sign in to comment.