Skip to content

Commit

Permalink
added actions constants
Browse files Browse the repository at this point in the history
  • Loading branch information
kleber-jg committed Sep 3, 2021
1 parent bc9449a commit ea49337
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 20 deletions.
2 changes: 1 addition & 1 deletion TODO.todo
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ BASIC:
[ ] show reference

Refactors:
[ ] create a centralized class for all the singletons
[x] create a centralized class for all the singletons

======================================================

Expand Down
13 changes: 13 additions & 0 deletions src/actions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export class Actions {
public static readonly UNDO = 'UNDO';
public static readonly MOVE_UP_1 = 'MOVE_UP_1';
public static readonly MOVE_DOWN_1 = 'MOVE_DOWN_1';
public static readonly MOVE_LEFT_1 = 'MOVE_LEFT_1';
public static readonly MOVE_RIGHT_1 = 'MOVE_RIGHT_1';
public static readonly MOVE_UP_10 = 'MOVE_UP_10';
public static readonly MOVE_DOWN_10 = 'MOVE_DOWN_10';
public static readonly MOVE_LEFT_10 = 'MOVE_LEFT_10';
public static readonly MOVE_RIGHT_10 = 'MOVE_RIGHT_10';
public static readonly TOGGLE_SNAP = 'TOGGLE_SNAP';
public static readonly TOGGLE_GIZMOS = 'TOGGLE_GIZMOS';
}
2 changes: 1 addition & 1 deletion src/core/actions.ts → src/core/action-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export interface Action {
state?: () => any;
}

export class Actions {
export class ActionHandler {
private readonly actions: Record<string, Action> = {};
private readonly actionMap: Record<string, Action> = {};

Expand Down
6 changes: 3 additions & 3 deletions src/core/editor.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { EditorData } from 'data/editor-data';
import { InspectorData } from 'data/inspector-data';
import { PhaserMeta } from 'data/phaser-meta';
import { Actions } from './actions';
import { ActionHandler } from './action-handler';
import { History } from './history';
import { Preferences } from './preferences';

Expand All @@ -10,7 +10,7 @@ class EditorClass {
public inspectorData: InspectorData;
public meta: PhaserMeta;

public actions: Actions;
public actions: ActionHandler;
public history: History;
public prefs: Preferences;

Expand All @@ -19,7 +19,7 @@ class EditorClass {
this.inspectorData = new InspectorData();
this.meta = new PhaserMeta();

this.actions = new Actions();
this.actions = new ActionHandler();
this.history = new History(this.data);
this.prefs = new Preferences();
}
Expand Down
5 changes: 3 additions & 2 deletions src/editor-view/actions/actions-toolbar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ import { Widget } from 'editor-view/widget/widget';
import { Editor } from 'core/editor';
import './actions-toolbar.scss';
import { ActionButton } from './button/action-button';
import { Actions } from 'actions';

export class ActionsToolbar extends Widget {
public static readonly tagName: string = 'phred-actions-toolbar';

public connectedCallback() {
super.connectedCallback();
this.createButton('TOGGLE_SNAP');
this.createButton('UNDO');
this.createButton(Actions.TOGGLE_SNAP);
this.createButton(Actions.UNDO);
}

private createButton(actionId: string) {
Expand Down
32 changes: 19 additions & 13 deletions src/plugin.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Actions } from 'actions';
import { BooleanPropertyEditor } from 'editor-view/properties/editors/boolean/boolean-property-editor';
import { NumberPropertyEditor } from 'editor-view/properties/editors/number/number-property-editor';
import { PointPropertyEditor } from 'editor-view/properties/editors/point/point-property-editor';
Expand All @@ -9,15 +10,16 @@ import './plugin.scss';
import { SceneView } from './scene-view/scene-view';

export class Plugin extends Phaser.Plugin {
public constructor(game: Phaser.Game, group?: Phaser.Group | Phaser.Stage) {
public constructor(game: Phaser.Game, group?: Phaser.Group | Phaser.Stage, refImage?: Phaser.Image) {
super(game, game.plugins);
group = group ?? game.world;

Editor.init();
this.setupInspectorData();

const scene = new SceneView(game, group, game.stage);
this.setupActions(scene);
this.setupInspectorData();
if (refImage) this.setupRefImage(refImage);

const editorView = document.createElement(EditorView.tagName) as EditorView;
document.body.appendChild(editorView);
Expand Down Expand Up @@ -63,62 +65,62 @@ export class Plugin extends Phaser.Plugin {
const { history, prefs } = Editor;
Editor.actions.add(
{
id: 'UNDO',
id: Actions.UNDO,
label: 'undo',
icon: 'fa-undo-alt',
shortcut: 'ctrl+z',
command: history.undo.bind(history)
},
{
id: 'MOVE_UP_1',
id: Actions.MOVE_UP_1,
shortcut: 'ArrowUp',
command: () => scene.moveSelectedObject(0, -1)
},
{
id: 'MOVE_DOWN_1',
id: Actions.MOVE_DOWN_1,
shortcut: 'ArrowDown',
command: () => scene.moveSelectedObject(0, 1)
},
{
id: 'MOVE_LEFT_1',
id: Actions.MOVE_LEFT_1,
shortcut: 'ArrowLeft',
command: () => scene.moveSelectedObject(-1, 0)
},
{
id: 'MOVE_RIGHT_1',
id: Actions.MOVE_RIGHT_1,
shortcut: 'ArrowRight',
command: () => scene.moveSelectedObject(1, 0)
},
{
id: 'MOVE_UP_10',
id: Actions.MOVE_UP_10,
shortcut: 'shift+ArrowUp',
command: () => scene.moveSelectedObject(0, -10)
},
{
id: 'MOVE_DOWN_10',
id: Actions.MOVE_DOWN_10,
shortcut: 'shift+ArrowDown',
command: () => scene.moveSelectedObject(0, 10)
},
{
id: 'MOVE_LEFT_10',
id: Actions.MOVE_LEFT_10,
shortcut: 'shift+ArrowLeft',
command: () => scene.moveSelectedObject(-10, 0)
},
{
id: 'MOVE_RIGHT_10',
id: Actions.MOVE_RIGHT_10,
shortcut: 'shift+ArrowRight',
command: () => scene.moveSelectedObject(10, 0)
},
{
id: 'TOGGLE_SNAP',
id: Actions.TOGGLE_SNAP,
label: 'snap',
icon: 'fa-compress',
toggle: true,
command: () => prefs.snap = !prefs.snap,
state: () => prefs.snap,
},
{
id: 'TOGGLE_GIZMOS',
id: Actions.TOGGLE_GIZMOS,
toggle: true,
hold: true,
shortcut: 'shift+Shift',
Expand All @@ -128,6 +130,10 @@ export class Plugin extends Phaser.Plugin {
);
}

public setupRefImage(refImage: Phaser.Image) {

}

public postUpdate() {
Editor.data.dispatchScheduledEvents();
}
Expand Down

0 comments on commit ea49337

Please sign in to comment.