Skip to content

Commit

Permalink
preferences refactory: added preferences model
Browse files Browse the repository at this point in the history
  • Loading branch information
kleber-swf committed Dec 10, 2021
1 parent b7fded3 commit fd35bff
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 35 deletions.
2 changes: 1 addition & 1 deletion src/core/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { PluginConfig, Size } from 'plugin.model';
import { PropertyElementTag } from 'property-element-tag';
import { ActionHandler } from './action-handler';
import { History } from './history';
import { Preferences } from './preferences';
import { Preferences } from './preferences/preferences';
import { ReferenceImageController } from './reference-image.controller';

class EditorClass {
Expand Down
27 changes: 27 additions & 0 deletions src/core/preferences/preferences.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { Size } from 'plugin.model';

export interface PreferencesData {
snap: boolean;
gizmos: boolean;
guides: boolean;
hitArea: boolean;
allHitAreasSnapshot: boolean; // do not save it

// TODO join these properties
leftPanelVisible: boolean;
leftPanelSize: string;

// TODO join these properties
rightPanelVisible: boolean;
rightPanelSize: string;

// TODO join these properties
responsive: boolean;
responsiveSize: Size;
responsiveSizeTemplateIndex: number;

referenceImageVisible: boolean;

}

export type PreferenceKey = keyof PreferencesData;
31 changes: 4 additions & 27 deletions src/core/preferences.ts → src/core/preferences/preferences.ts
Original file line number Diff line number Diff line change
@@ -1,40 +1,15 @@
import { Size } from 'plugin.model';

export interface PreferencesData {
snap: boolean;
gizmos: boolean;
guides: boolean;
hitArea: boolean;
allHitAreasSnapshot: boolean; // do not save it

// TODO join these properties
leftPanelVisible: boolean;
leftPanelSize: string;

// TODO join these properties
rightPanelVisible: boolean;
rightPanelSize: string;

// TODO join these properties
responsive: boolean;
responsiveSize: Size;
responsiveSizeTemplateIndex: number;

referenceImageVisible: boolean;

}

export type PreferenceKey = keyof PreferencesData;
import { PreferenceKey, PreferencesData } from './preferences.model';

const LS_KEY = '_phred_preferences_';

export class Preferences {
public static readonly DefaultResponsiveSize: Readonly<Size> = { width: 450, height: 800 };

private data: PreferencesData = {
snap: true,
gizmos: true,
guides: false,
referenceImageVisible: false,
hitArea: false,
allHitAreasSnapshot: false,
responsive: false,
Expand All @@ -46,6 +21,8 @@ export class Preferences {

rightPanelVisible: true,
rightPanelSize: undefined,

referenceImageVisible: false,
};

public readonly onPreferenceChanged = new Phaser.Signal();
Expand Down
2 changes: 1 addition & 1 deletion src/editor-view/actions/actions-toolbar.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Action, ActionHandler } from 'core/action-handler';
import { Actions } from 'core/actions';
import { Editor } from 'core/editor';
import { PreferenceKey } from 'core/preferences';
import { PreferenceKey } from 'core/preferences/preferences.model';
import { Widget } from 'editor-view/widget/widget';
import './actions-toolbar.scss';
import { ActionButton } from './button/action-button';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Editor } from 'core/editor';
import { Preferences } from 'core/preferences';
import { Preferences } from 'core/preferences/preferences';
import { Size } from 'plugin.model';
import './size-templates-panel.scss';

Expand Down
2 changes: 1 addition & 1 deletion src/editor-view/panel/panel.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Editor } from 'core/editor';
import { PreferenceKey } from 'core/preferences';
import { PreferenceKey } from 'core/preferences/preferences.model';
import { DataOrigin } from 'data/editor-data';
import { Inspector } from 'editor-view/inspector/inspector';
import { Widget } from 'editor-view/widget/widget';
Expand Down
2 changes: 1 addition & 1 deletion src/editor-view/panel/resize-handle/panel-resize-handle.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Editor } from 'core/editor';
import { PreferenceKey } from 'core/preferences';
import { PreferenceKey } from 'core/preferences/preferences.model';
import { PanelSide } from 'types';
import './panel-resize-handle.scss';

Expand Down
2 changes: 1 addition & 1 deletion src/old-ref-image/reference-image/reference-image-panel.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ActionHandler } from 'core/action-handler';
import { Actions } from 'core/actions';
import { Editor } from 'core/editor';
import { PreferenceKey } from 'core/preferences';
import { PreferenceKey } from 'core/preferences/preferences.model';
import { OldReferenceImage } from 'old-ref-image/reference-image';
import { ActionButton } from '../../editor-view/actions/button/action-button';
import './reference-image-panel.scss';
Expand Down
2 changes: 1 addition & 1 deletion src/scene-view/game-container/game-container.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ActionHandler } from 'core/action-handler';
import { Editor } from 'core/editor';
import { PreferenceKey } from 'core/preferences';
import { PreferenceKey } from 'core/preferences/preferences.model';
import { PluginConfig, Size } from 'plugin.model';
import { GameParent } from 'scene-view/game-parent/game-parent';
import { SelectionArea } from 'scene-view/selection-area/selection-area';
Expand Down
2 changes: 1 addition & 1 deletion src/scene-view/selection-area/selection-area.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Editor } from 'core/editor';
import { PreferenceKey } from 'core/preferences';
import { PreferenceKey } from 'core/preferences/preferences.model';
import { PluginConfig } from 'plugin.model';
import { Gizmo, GIZMO_MOVE, GIZMO_SCALE } from './gizmos/gizmo';
import { SelectionGizmo } from './gizmos/selection-gizmo';
Expand Down

0 comments on commit fd35bff

Please sign in to comment.