From 462f0d5b7eb03edd1346d3bce85d196d2847c1b5 Mon Sep 17 00:00:00 2001 From: ShakeFlower Date: Mon, 23 Jun 2025 15:55:38 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E7=BB=98=E5=88=B6=E5=AD=98=E6=A1=A3?= =?UTF-8?q?=E7=95=8C=E9=9D=A2=E7=BC=A9=E7=95=A5=E5=9B=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../client-modules/src/render/ui/save.tsx | 84 ++++++++++++++++--- .../client-modules/src/render/ui/toolbar.tsx | 6 +- src/types/declaration/map.d.ts | 5 ++ 3 files changed, 83 insertions(+), 12 deletions(-) diff --git a/packages-user/client-modules/src/render/ui/save.tsx b/packages-user/client-modules/src/render/ui/save.tsx index add0a6f..a7dd183 100644 --- a/packages-user/client-modules/src/render/ui/save.tsx +++ b/packages-user/client-modules/src/render/ui/save.tsx @@ -7,10 +7,12 @@ import { SetupComponentOptions, UIComponentProps } from '@motajs/system-ui'; -import { defineComponent, ref, computed } from 'vue'; +import { defineComponent, ref, computed, watch } from 'vue'; import { Page, PageExpose } from '../components'; import { useKey } from '../use'; import { MAP_WIDTH, MAP_HEIGHT } from '../shared'; +import { getSave, SaveData } from '../utils'; +import { Thumbnail } from '../components/thumbnail'; export interface SaveProps extends UIComponentProps, DefaultProps { loc: ElementLocator; @@ -32,6 +34,11 @@ export type SaveEmits = { exit: () => void; }; +export type SaveBtnEmits = { + /** 读取数据 */ + updateData: (isValid: boolean) => void; +}; + const saveProps = { props: ['loc', 'controller', 'instance'], emits: ['delete', 'emit', 'exit'] @@ -41,10 +48,24 @@ const saveBtnProps = { props: ['loc', 'index', 'isSelected', 'isDelete'] } satisfies SetupComponentOptions; -export const SaveBtn = defineComponent(props => { +export const SaveBtn = defineComponent< + SaveBtnProps, + SaveBtnEmits, + keyof SaveBtnEmits +>((props, { emit }) => { const w = props.loc[2] ?? 200; const font = new Font('normal', 18); const statusFont = new Font('normal', 14); + const data = ref(null); + const mapBlocks = computed(() => { + if (data.value == null) return void 0; + else { + const currData = data.value?.data; + const map = core.maps.loadMap(currData.maps, currData.floorId); + core.extractBlocksForUI(map, currData.hero.flags); // 这一步会向map写入blocks + return map.blocks; + } + }); const text = computed(() => props.index === -1 ? '自动存档' : `存档${props.index + 1}` ); @@ -53,6 +74,18 @@ export const SaveBtn = defineComponent(props => { else return 'white'; }); const lineWidth = computed(() => (props.isSelected ? 2 : 1)); + + watch( + () => props.index, + newIndex => { + getSave(newIndex + 1).then(value => { + data.value = value; + emit('updateData', value != null); + }); + }, + { immediate: true } + ); + return () => ( (props => { lineWidth={lineWidth.value} lineJoin="miter" /> +