Skip to content

Commit

Permalink
added editor view
Browse files Browse the repository at this point in the history
  • Loading branch information
kleber-jg committed Aug 24, 2021
1 parent c1f5a4b commit 0b2b5b2
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 7 deletions.
36 changes: 36 additions & 0 deletions src/editor/editor.view.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
export class EditorView extends Phaser.Group {
private readonly touchArea: Phaser.Graphics;
private readonly container: Phaser.Group | Phaser.Stage;

constructor(game: Phaser.Game, container: Phaser.Group | Phaser.Stage, parent: Phaser.Group | Phaser.Stage) {
super(game, parent);
this.container = container;
this.touchArea = this.createTouchArea(game);
this.redrawTouchArea();
}

private createTouchArea(game: Phaser.Game) {
const graphics = new Phaser.Graphics(game);
graphics.inputEnabled = true;
graphics.events.onInputUp.add(this.onTouch, this);
game.scale.onSizeChange.add(this.redrawTouchArea, this);
this.add(graphics);
return graphics;
}

private redrawTouchArea() {
const sm = this.game.scale;
this.touchArea.clear()
.beginFill(0, 0)
.drawRect(0, 0, sm.width, sm.height)
.endFill();
}

private onTouch(_: any, pointer: Phaser.Pointer) {

}

private getObjectsUnderPoint(x: number, y: number) {

}
}
7 changes: 2 additions & 5 deletions src/plugin.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import Phaser from 'phaser-ce';
import { Stage } from './stage';
import { ToolBar } from './ui/toolbar';

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

const stage = new Stage(game, game.stage);
const stage = new Stage(game, group, game.stage);
// this.container = null;
// _defs();

Expand Down
4 changes: 3 additions & 1 deletion src/stage.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { EditorView } from './editor/editor.view';
import { ToolBar } from './ui/toolbar';

export class Stage extends Phaser.Group {
constructor(game: Phaser.Game, parent: Phaser.Group | Phaser.Stage) {
constructor(game: Phaser.Game, container: Phaser.Group | Phaser.Stage, parent: Phaser.Group | Phaser.Stage) {
super(game, parent);

const scale = game.scale.scaleFactor;
this.scale.copyFrom(scale);
game.scale.onSizeChange.add(() => this.scale.copyFrom(game.scale.scaleFactor));

const editor = new EditorView(game, container, this);
const toolbar = new ToolBar(game, this);
}
}
2 changes: 1 addition & 1 deletion src/ui/button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class Button extends Phaser.Group {
}

private createGraphics(game: Phaser.Game, config: ButtonConfig) {
const g = new Phaser.Graphics(game).beginFill(0, 1).drawRect(0, 0, config.width, config.height).endFill();
const g = new Phaser.Graphics(game);
this.add(g);

g.inputEnabled = true;
Expand Down

0 comments on commit 0b2b5b2

Please sign in to comment.