27 lines
817 B
TypeScript
27 lines
817 B
TypeScript
import { inject, type InjectionKey, ref, provide, getCurrentInstance } from "vue";
|
|
import { Bound } from "./utils";
|
|
|
|
export type UITool =
|
|
| "track-unit-type"
|
|
| "eraser"
|
|
| "sticking";
|
|
|
|
export class AppStateStore extends Bound {
|
|
selectedTool = ref<UITool>("track-unit-type");
|
|
activeTrackUnitType = ref(0);
|
|
activeStickingType = ref(1);
|
|
unitMouseStart = ref<string | null>(null);
|
|
selectingUnits = ref(false);
|
|
deselectingUnits = ref(false);
|
|
}
|
|
|
|
const AppStateStoreKey = Symbol("AppStateStore") as InjectionKey<AppStateStore>;
|
|
|
|
export function useAppStateStore(): AppStateStore {
|
|
return inject(AppStateStoreKey, () => {
|
|
const store = new AppStateStore();
|
|
getCurrentInstance()?.appContext?.app.provide(AppStateStoreKey, store);
|
|
return store;
|
|
}, true);
|
|
}
|