Skip to content

Commit

Permalink
keeping reference image state
Browse files Browse the repository at this point in the history
  • Loading branch information
kleber-swf committed Nov 30, 2021
1 parent ae421f1 commit ab89165
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/editor-view/editor-view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ export class EditorView extends Widget {
if (!this._enabled) return;
this._enabled = false;
this.gameContainer.returnGameToItsParent();
this.panels.forEach(panel => panel.enable());
this.parentElement.removeChild(this);
this.panels.forEach(panel => panel.disable());
this.remove()
}

public selectObject(from: DataOrigin, obj: PIXI.DisplayObject) {
Expand Down
3 changes: 2 additions & 1 deletion src/editor.state-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export class EditorStateHandler {

this.sceneView.enable(this.config.root, this.game.stage);
this.editorView.enable();
this.referenceImageController.setImage(this.config.refImage);
this.referenceImageController.enable(this.config.refImage);

Editor.enable();
if (this.onshow) this.onshow();
Expand All @@ -80,6 +80,7 @@ export class EditorStateHandler {
Editor.disable();
this.sceneView.disable();
this.editorView.disable();
this.referenceImageController.disable();

this.disabledUI.enable();
if (this.onhide) this.onhide();
Expand Down
21 changes: 14 additions & 7 deletions src/reference-image/reference-image.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,25 @@ export class ReferenceImageController {
this.panel.setupActions(actions);
}

public setImage(image: PIXI.Sprite) {
public enable(image: PIXI.Sprite) {
if (!this.actionsToolbar) {
this.actionsToolbar = document.querySelector(ComponentTags.ActionsToolbar);
}

if (this.image === image) return;
this.referenceImage.image = image;
if (this.image !== image) {
this.referenceImage.image = image;

if (image) {
this.actionsToolbar.appendChild(this.panel);
} else {
this.actionsToolbar.removeChild(this.panel);
if (image) {
this.actionsToolbar.appendChild(this.panel);
} else {
this.actionsToolbar.removeChild(this.panel);
}
}

this.referenceImage.enable();
}

public disable() {
this.referenceImage.disable();
}
}
11 changes: 9 additions & 2 deletions src/scene-view/reference-image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,11 @@ export class ReferenceImage extends Phaser.Group {

this._parent = root;
Editor.prefs.onPreferenceChanged.add(this.onPreferenceChanged, this);
this.onPreferenceChanged('refImage', Editor.prefs.refImage);
this.visible = false;
}

private onPreferenceChanged(pref: PreferenceKey, value: any) {
if (pref !== 'refImage') return;
console.log(value);
if (value) this.show();
else this.hide();
}
Expand All @@ -41,4 +40,12 @@ export class ReferenceImage extends Phaser.Group {
public hide() {
if (this.parent) this.parent.removeChild(this);
}

public enable() {
this.onPreferenceChanged('refImage', Editor.prefs.refImage);
}

public disable() {
this.hide();
}
}

0 comments on commit ab89165

Please sign in to comment.