Skip to content

Commit

Permalink
chore(gui):docking filemanager's spritelist
Browse files Browse the repository at this point in the history
  • Loading branch information
luoliwoshang committed Feb 5, 2024
1 parent e8dc500 commit 5835719
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 15 deletions.
7 changes: 2 additions & 5 deletions spx-gui/src/components/spx-code-editor/SpxCodeEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @Author: Zhang Zhi Yang
* @Date: 2024-01-15 15:30:26
* @LastEditors: Zhang Zhi Yang
* @LastEditTime: 2024-02-04 13:10:42
* @LastEditTime: 2024-02-05 13:24:58
* @FilePath: /spx-gui/src/components/spx-code-editor/SpxCodeEditor.vue
* @Description:
-->
Expand All @@ -24,7 +24,6 @@ import { useEditorStore } from "@/store"
import { useSpriteStore } from '@/store/modules/sprite';
import { storeToRefs } from 'pinia'
import { NButton } from "naive-ui"
const { setCurrentByName } = useSpriteStore()
const spriteStore = useSpriteStore()
const store = useEditorStore();
const code_editor = ref();
Expand Down Expand Up @@ -70,9 +69,7 @@ store.$onAction(({
}
})
})
const toggleCodeById = (name: string) => {
setCurrentByName(name)
}
</script>

Expand Down
11 changes: 4 additions & 7 deletions spx-gui/src/components/top-menu/TopMenu.vue
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<!--
* @Author: Xu Ning
* @Date: 2024-01-12 16:52:20
* @LastEditors: Xu Ning
* @LastEditTime: 2024-02-01 16:18:12
* @FilePath: /builder/spx-gui/src/components/top-menu/TopMenu.vue
* @LastEditors: Zhang Zhi Yang
* @LastEditTime: 2024-02-05 13:23:09
* @FilePath: /spx-gui/src/components/top-menu/TopMenu.vue
* @Description:
-->
<template>
Expand Down Expand Up @@ -320,11 +320,8 @@ const handleSelectImport = (key: string | number) => {
input.click();
input.onchange = async (e: any) => {
const file = e.target.files[0];
const dir = await projectStore.getDirPathFromZip(file);
projectStore.loadProject(dir);
// must set window.project_path
projectStore.loadProject(e.target.files[0], e.target.files[0].name.split(".")[0]);
window.project_path = projectStore.project.title;
await projectStore.saveByProject();
};
}
};
Expand Down
7 changes: 4 additions & 3 deletions spx-gui/src/store/modules/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
* @Author: Zhang Zhi Yang
* @Date: 2024-01-15 09:16:18
* @LastEditors: Zhang Zhi Yang
* @LastEditTime: 2024-01-25 17:05:29
* @FilePath: /builder/spx-gui/src/store/modules/index.ts
* @LastEditTime: 2024-02-05 13:18:15
* @FilePath: /spx-gui/src/store/modules/index.ts
* @Description:
*/
export * from "./user"
export * from "./editor"
export * from "./stage"
export * from "./project"
export * from "./project"
export * from "./sprite"
41 changes: 41 additions & 0 deletions spx-gui/src/store/modules/sprite/index.ts
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
}
})

0 comments on commit 5835719

Please sign in to comment.