Skip to content

Commit

Permalink
added clearPrefs to PluginConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
kleber-jg committed Sep 17, 2021
1 parent 55dd5fd commit d9bfbe4
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion TODO.todo
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ BASIC:
[ ] config
[ ] getter for root container and ref image
[x] onShow/onHide callbacks
[ ] save editor state / preferences
[x] save editor state / preferences

Refactors:
[x] create a centralized class for all the singletons
Expand Down
4 changes: 2 additions & 2 deletions src/core/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ class EditorClass {

public referenceImage?: ReferenceImage;

public init() {
public init(clearPrefs: boolean) {
this.data = new EditorData();
this.inspectorData = new InspectorData();
this.meta = new PhaserMeta();

this.actions = new ActionHandler();
this.history = new History(this.data);
this.prefs = new Preferences();
this.prefs = new Preferences(clearPrefs);
}

public enable() {
Expand Down
3 changes: 2 additions & 1 deletion src/core/preferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ export class Preferences {
public readonly onPreferenceChanged = new Phaser.Signal();


public constructor() {
public constructor(clean: boolean) {
if (clean) localStorage.clear();
this._snap = this.load('snap', true);
this._gizmos = this.load('gizmos', true);
this._guides = this.load('guides', false);
Expand Down
6 changes: 4 additions & 2 deletions src/editor.window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,16 @@ export class EditorWindow {
private readonly game: Phaser.Game;
private readonly root: Container;
private readonly refImage?: PIXI.Sprite;
private readonly clearPrefs?: boolean;

public onshow: () => void;
public onhide: () => void;

constructor(game: Phaser.Game, root: Container, refImage?: PIXI.Sprite) {
constructor(game: Phaser.Game, root: Container, refImage?: PIXI.Sprite, clearPrefs?: boolean) {
this.game = game;
this.root = root ?? game.world;
this.refImage = refImage;
this.clearPrefs = clearPrefs;

this.disabledUI = new DisabledUI();
this.disabledUI.onclick = this.show.bind(this);
Expand All @@ -41,7 +43,7 @@ export class EditorWindow {
private init() {
this._initialized = true;

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

const scene = this.sceneView = new SceneView(this.game);
Expand Down
3 changes: 2 additions & 1 deletion src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export interface PluginConfig {
root?: Container;
refImage?: PIXI.Sprite;
pauseGame?: boolean;
clearPrefs?: boolean;
onShow?: () => void;
onHide?: () => void;
}
Expand All @@ -21,7 +22,7 @@ export class Plugin extends Phaser.Plugin {
this.insertHead();
if (!config) config = {};
this.config = config;
this.editorWindow = new EditorWindow(game, config.root, config.refImage);
this.editorWindow = new EditorWindow(game, config.root, config.refImage, config.clearPrefs);
this.editorWindow.onshow = this.onEditorShow.bind(this);
this.editorWindow.onhide = this.onEditorHide.bind(this);
this.editorWindow.start();
Expand Down

0 comments on commit d9bfbe4

Please sign in to comment.