migrated to vue wtf
This commit is contained in:
@@ -1,37 +1,31 @@
|
||||
import { ISubscriber, Publisher } from "@djledda/ladder";
|
||||
import { TrackUnitStickingType, TrackUnitType } from "./TrackUnit";
|
||||
import { inject, type InjectionKey, ref } from 'vue';
|
||||
|
||||
export type UITool =
|
||||
| "track-unit-type"
|
||||
| "eraser"
|
||||
| "sticking";
|
||||
|
||||
export type AppStateEvent = "appstate-tool-select";
|
||||
|
||||
export default class AppState {
|
||||
private publisher = new Publisher<AppStateEvent, AppState>(this);
|
||||
selectedTool: UITool = "track-unit-type";
|
||||
activeTrackUnitType: TrackUnitType = "Normal";
|
||||
activeStickingType: TrackUnitStickingType = "lh";
|
||||
|
||||
constructor() {}
|
||||
|
||||
addSubscriber(subscriber: ISubscriber<AppStateEvent>, subscribeTo: Parameters<Publisher<AppStateEvent, AppState>["addSubscriber"]>[1]) {
|
||||
this.publisher.addSubscriber(subscriber, subscribeTo);
|
||||
}
|
||||
|
||||
selectStickingTypePaint(stickingType: TrackUnitStickingType) {
|
||||
this.activeStickingType = stickingType;
|
||||
this.publisher.notifySubs("appstate-tool-select");
|
||||
}
|
||||
|
||||
selectTrackUnitTypePaint(trackUnitType: TrackUnitType) {
|
||||
this.activeTrackUnitType = trackUnitType;
|
||||
this.publisher.notifySubs("appstate-tool-select");
|
||||
}
|
||||
|
||||
selectTool(tool: UITool) {
|
||||
this.selectedTool = tool;
|
||||
this.publisher.notifySubs("appstate-tool-select");
|
||||
}
|
||||
export function createAppStateStore() {
|
||||
const selectedTool = ref<UITool>('track-unit-type');
|
||||
const activeTrackUnitType = ref(0);
|
||||
const activeStickingType = ref(1);
|
||||
const selectingUnits = ref(false);
|
||||
const deselectingUnits = ref(false);
|
||||
|
||||
return {
|
||||
selectingUnits,
|
||||
deselectingUnits,
|
||||
selectedTool,
|
||||
activeTrackUnitType,
|
||||
activeStickingType,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
export type AppStateStore = ReturnType<typeof createAppStateStore>;
|
||||
|
||||
export const AppStateStoreKey = Symbol('AppStateStore') as InjectionKey<AppStateStore>;
|
||||
|
||||
export function useAppStateStore(): AppStateStore {
|
||||
return inject(AppStateStoreKey, createAppStateStore, true);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user