forked from goplus/builder
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(gui):docking filemanager's spritelist
- Loading branch information
1 parent
e8dc500
commit 5835719
Showing
4 changed files
with
51 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { defineStore, storeToRefs } from 'pinia' | ||
import Sprite from '@/class/sprite' | ||
import { computed, ref } from 'vue' | ||
import type { ComputedRef, Ref } from 'vue' | ||
import { useProjectStore } from '../index' | ||
export const useSpriteStore = defineStore("sprite", () => { | ||
const projectStore = useProjectStore(); | ||
const { project } = storeToRefs(projectStore); | ||
|
||
const current: Ref<Sprite | null> = ref(null) | ||
|
||
const list: ComputedRef<Sprite[]> = computed(() => { | ||
return project.value.sprite.list as Sprite[] | ||
}) | ||
|
||
const map = computed(() => new Map(list.value.map(item => [item.name, item]))) | ||
|
||
function setCurrentByName(name: string) { | ||
if (map.value.has(name)) { | ||
current.value = map.value.get(name) || null | ||
} | ||
} | ||
|
||
function removeItemByName(name: string) { | ||
const sprite = map.value.get(name) | ||
if (sprite) { | ||
if (current.value === sprite) { | ||
current.value = list.value[0] || null | ||
} | ||
project.value.sprite.remove(sprite) | ||
} | ||
} | ||
|
||
|
||
|
||
return { | ||
list, current, | ||
setCurrentByName, | ||
removeItemByName | ||
} | ||
}) |