feat: added saving of orientation, fixed experimental css style

This commit is contained in:
Daniel Ledda
2022-04-17 14:23:58 +02:00
parent 1861403f24
commit b4e3ecfac6
3 changed files with 22 additions and 8 deletions

View File

@@ -18,6 +18,7 @@ export default class BeatStore implements ISubscriber<EventTypeSubscriptions> {
private activeBeat: Ref<Beat>; private activeBeat: Ref<Beat>;
private onBeatChangeCbs: (() => void)[] = []; private onBeatChangeCbs: (() => void)[] = [];
private autoSave: boolean; private autoSave: boolean;
private orientation: "horizontal" | "vertical" | null = null;
constructor(options: { loadFromLocalStorage: boolean, autoSave: boolean }) { constructor(options: { loadFromLocalStorage: boolean, autoSave: boolean }) {
this.autoSave = options.autoSave; this.autoSave = options.autoSave;
@@ -103,6 +104,7 @@ export default class BeatStore implements ISubscriber<EventTypeSubscriptions> {
localStorage.setItem("drum-slayer-save", JSON.stringify({ localStorage.setItem("drum-slayer-save", JSON.stringify({
beats: serials, beats: serials,
activeBeatIndex: this.beats.indexOf(this.activeBeat.val), activeBeatIndex: this.beats.indexOf(this.activeBeat.val),
orientation: this.orientation,
})); }));
} }
} }
@@ -110,15 +112,26 @@ export default class BeatStore implements ISubscriber<EventTypeSubscriptions> {
loadFromSave(source: any): void { loadFromSave(source: any): void {
this.beats.length = 0; this.beats.length = 0;
if (Array.isArray(source.beats) if (Array.isArray(source.beats)
&& (typeof source.activeBeatIndex === "number" || typeof source.activeBeatIndex === "undefined")) { && (typeof source.activeBeatIndex === "number" || typeof source.activeBeatIndex === "undefined")
&& typeof source.orientation === "string") {
try { try {
source.beats.forEach((beat: any) => this.beats.push(Beat.deserialise(beat))); source.beats.forEach((beat: any) => this.beats.push(Beat.deserialise(beat)));
if (typeof source.activeBeatIndex === "number") { if (typeof source.activeBeatIndex === "number") {
this.activeBeat.val = this.beats[source.activeBeatIndex]; this.activeBeat.val = this.beats[source.activeBeatIndex];
} }
this.orientation = source.orientation;
} catch (err) { } catch (err) {
console.error(err); console.error(err);
} }
} }
} }
setOrientation(orientation: "horizontal" | "vertical"): void {
this.orientation = orientation;
this.save("localStorage");
}
getSavedOrientation(): "horizontal" | "vertical" | null {
return this.orientation;
}
} }

View File

@@ -107,8 +107,7 @@
} }
.root-sidebar-left-strip { .root-sidebar-left-strip {
text-align: right; writing-mode: vertical-rl;
writing-mode: sideways-lr;
background-color: var(--color-bg-light); background-color: var(--color-bg-light);
} }
@@ -117,6 +116,7 @@
} }
.root-sidebar-left-tab { .root-sidebar-left-tab {
transform: rotate(-180deg);
display: inline-block; display: inline-block;
width: 100%; width: 100%;
padding: 8px 3px 8px 3px; padding: 8px 3px 8px 3px;

View File

@@ -30,12 +30,12 @@ export default class RootView extends UINode {
loadFromLocalStorage: true, loadFromLocalStorage: true,
autoSave: true, autoSave: true,
}); });
this.currentOrientation = options.orientation ?? "horizontal";
this.activeBeat = this.beatStore.getActiveBeat(); this.activeBeat = this.beatStore.getActiveBeat();
this.activeBeat.watch((newVal) => { this.activeBeat.watch((newVal) => {
this.beatSettingsView.setBeat(newVal); this.beatSettingsView.setBeat(newVal);
this.beatView.setBeat(newVal); this.beatView.setBeat(newVal);
}); });
this.currentOrientation = this.beatStore.getSavedOrientation() ?? options.orientation ?? "horizontal";
this.beatView = new BeatView({ this.beatView = new BeatView({
beat: this.activeBeat.val, beat: this.activeBeat.val,
orientation: this.currentOrientation, orientation: this.currentOrientation,
@@ -77,6 +77,7 @@ export default class RootView extends UINode {
} else { } else {
this.getNode().classList.remove("vertical-mode"); this.getNode().classList.remove("vertical-mode");
} }
this.beatStore.setOrientation(orientation);
this.beatView.setOrientation(orientation); this.beatView.setOrientation(orientation);
} }
@@ -88,14 +89,14 @@ export default class RootView extends UINode {
return h("div", { return h("div", {
className: "root-sidebar-left-strip", className: "root-sidebar-left-strip",
}, [ }, [
h("div", {
saveTo: this.sidebarLeftTabs
}, this.buildTabs()),
h("div", { h("div", {
className: "root-sidebar-add-beat", className: "root-sidebar-add-beat",
onclick: () => this.beatStore.addNewBeat(), onclick: () => this.beatStore.addNewBeat(),
innerText: "+", innerText: "+",
}), }),
h("div", {
saveTo: this.sidebarLeftTabs
}, this.buildTabs()),
]); ]);
} }
@@ -114,7 +115,7 @@ export default class RootView extends UINode {
} }
}); });
return node; return node;
}).reverse(); });
} }
private buildSidebarQuickButtons(): HTMLElement { private buildSidebarQuickButtons(): HTMLElement {