Skip to content

Commit

Permalink
undoing things made in the inspector
Browse files Browse the repository at this point in the history
  • Loading branch information
kleber-swf committed Sep 2, 2021
1 parent 7c50534 commit 10b947c
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 13 deletions.
6 changes: 5 additions & 1 deletion src/data/history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ class HistoryClass {
// TODO change this name please
public readonly onHistoryWalk = new Phaser.Signal();

public holdEntry(entry: HistoryEntry) { this.holdingEntry = entry; }
public holdEntry(entry: HistoryEntry) {
this.holdingEntry = entry;
return this;
}

public cancel() { this.holdingEntry = null; }

public commit() {
Expand Down
1 change: 0 additions & 1 deletion src/editor/object-tree/tree-node/tree-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ export class TreeNode extends HTMLElement {
public clearSelection() { this.classList.remove(SELECTED_CLASS); }

public onCollapseIconClick(e: MouseEvent) {
console.log('collapse icon click')
if (this.model.collapsed) this.expand();
else this.collapse();
e.stopImmediatePropagation();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ export class BooleanPropertyEditor extends PropertyEditor<boolean> {
return input;
}

public getInternalValue() { return this.input.checked; }

public setInternalValue(value: boolean) {
this.input.checked = value;
this._internalValue = value;
Expand Down
13 changes: 11 additions & 2 deletions src/editor/properties/editors/point/point-property-editor.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Data } from 'data/data';
import { History } from 'data/history';
import { PropertyInspectionData } from 'editor/properties-editors';
import { NumberPropertyEditor } from '../number/number-property-editor';
import { PropertyEditor } from '../property-editor';
Expand All @@ -21,17 +23,24 @@ export class PointPropertyEditor extends PropertyEditor<PIXI.Point> {

const xinput = this.xinput = document.createElement(NumberPropertyEditor.tagName) as NumberPropertyEditor;
xinput.setContent({ name: 'x', typeHint: 'number', data: prop.data }, value.x, fieldId);
xinput.onchange = this.onValueChanged.bind(this);
xinput.onchange = this.onInputChanged.bind(this);
parent.appendChild(xinput);

const yinput = this.yinput = document.createElement(NumberPropertyEditor.tagName) as NumberPropertyEditor;
yinput.setContent({ name: 'y', typeHint: 'number', data: prop.data }, value.y);
yinput.onchange = this.onValueChanged.bind(this);
yinput.onchange = this.onInputChanged.bind(this);
parent.appendChild(yinput);

return parent;
}

protected onInputChanged(e: Event) { this.onValueChanged(e, true); }

protected onValueChanged(e: Event, save?: boolean) {
if (save) this.savePreviousValue();
super.onValueChanged(e, false);
}

public getInternalValue() { return this.internalValue.clone(); }

public setInternalValue(value: PIXI.Point) {
Expand Down
22 changes: 17 additions & 5 deletions src/editor/properties/editors/property-editor.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Data, DataOrigin } from 'data/data';
import { History } from 'data/history';
import { PropertyInspectionData } from 'editor/properties-editors';
import { IdUtil } from 'util/id.util';
import './property-editor.scss';
Expand Down Expand Up @@ -51,15 +52,26 @@ export abstract class PropertyEditor<T> extends HTMLElement {
this.setInternalValue(value);
}

protected onValueChanged(e: Event) {
if (this.changedOutsideInspector) this.changedOutsideInspector = false;
else {
this.updateInternalValue(e);
Data.propertyChanged(this.prop.name, this.getInternalValue(), DataOrigin.INSPECTOR);
protected onValueChanged(e: Event, save = true) {
if (this.changedOutsideInspector) {
this.changedOutsideInspector = false;
return;
}
if (save) this.savePreviousValue();
this.updateInternalValue(e);
Data.propertyChanged(this.prop.name, this.getInternalValue(), DataOrigin.INSPECTOR);
}

public getInternalValue(): T { return this._internalValue; }
public abstract setInternalValue(value: T): void;
public abstract updateInternalValue(e: Event): void;

public savePreviousValue() {
History.holdEntry({
obj: Data.selectedObject,
properties: {
[this.prop.name]: this.getInternalValue()
}
}).commit();
}
}
7 changes: 5 additions & 2 deletions src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,12 @@ export class Plugin extends Phaser.Plugin {
editor.setup(game, group);
}

document.onkeypress = (e: KeyboardEvent) => {
if (e.ctrlKey && e.key === 'z')
document.onkeydown = (e: KeyboardEvent) => {
if (e.ctrlKey && e.key === 'z') {
History.undo();
e.stopImmediatePropagation();
return;
}
}
}

Expand Down

0 comments on commit 10b947c

Please sign in to comment.