This commit is contained in:
2024-04-01 23:13:39 +02:00
parent 3c9065ee8c
commit 3cda9c3e96
14 changed files with 382 additions and 214 deletions

View File

@@ -1,33 +1,26 @@
import { inject, type InjectionKey, ref } from "vue";
import { inject, type InjectionKey, ref, provide, getCurrentInstance } from "vue";
import { Bound } from "./utils";
export type UITool =
| "track-unit-type"
| "eraser"
| "sticking";
export function createAppStateStore() {
const selectedTool = ref<UITool>("track-unit-type");
const activeTrackUnitType = ref(0);
const activeStickingType = ref(1);
const unitMouseStart = ref<string | null>(null);
const selectingUnits = ref(false);
const deselectingUnits = ref(false);
return {
selectingUnits,
deselectingUnits,
selectedTool,
activeTrackUnitType,
activeStickingType,
unitMouseStart,
};
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);
}
export type AppStateStore = ReturnType<typeof createAppStateStore>;
export const AppStateStoreKey = Symbol("AppStateStore") as InjectionKey<AppStateStore>;
const AppStateStoreKey = Symbol("AppStateStore") as InjectionKey<AppStateStore>;
export function useAppStateStore(): AppStateStore {
return inject(AppStateStoreKey, createAppStateStore, true);
return inject(AppStateStoreKey, () => {
const store = new AppStateStore();
getCurrentInstance()?.appContext?.app.provide(AppStateStoreKey, store);
return store;
}, true);
}