diff --git a/packages-user/client-modules/src/render/components/thumbnail.tsx b/packages-user/client-modules/src/render/components/thumbnail.tsx index 0c30a30..e1bd37f 100644 --- a/packages-user/client-modules/src/render/components/thumbnail.tsx +++ b/packages-user/client-modules/src/render/components/thumbnail.tsx @@ -43,6 +43,7 @@ export const Thumbnail = defineComponent(props => { }; const drawThumbnail = (canvas: MotaOffscreenCanvas2D) => { + if (props.hidden) return; const ctx = canvas.ctx; const hero = props.hero; const options: Partial = { diff --git a/packages-user/client-modules/src/render/ui/save.tsx b/packages-user/client-modules/src/render/ui/save.tsx index 1ffa6cc..72c9cb6 100644 --- a/packages-user/client-modules/src/render/ui/save.tsx +++ b/packages-user/client-modules/src/render/ui/save.tsx @@ -7,7 +7,7 @@ import { SetupComponentOptions, UIComponentProps } from '@motajs/system-ui'; -import { defineComponent, ref, computed, watch, nextTick } from 'vue'; +import { defineComponent, ref, computed, onMounted } from 'vue'; import { Page, PageExpose } from '../components'; import { useKey } from '../use'; import { MAP_WIDTH, MAP_HEIGHT } from '../shared'; @@ -23,6 +23,7 @@ export interface SaveBtnProps extends DefaultProps { index: number; isSelected: boolean; isDelete: boolean; + data: SaveData | null; } export type SaveEmits = { @@ -45,22 +46,17 @@ const saveProps = { } satisfies SetupComponentOptions; const saveBtnProps = { - props: ['loc', 'index', 'isSelected', 'isDelete'] + props: ['loc', 'index', 'isSelected', 'isDelete', 'data'] } satisfies SetupComponentOptions; -export const SaveBtn = defineComponent< - SaveBtnProps, - SaveBtnEmits, - keyof SaveBtnEmits ->((props, { emit }) => { +export const SaveBtn = defineComponent(props => { 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; + if (props.data === null || props.data === undefined) return void 0; else { - const currData = data.value?.data; + const currData = props.data?.data; const map = core.maps.loadMap(currData.maps, currData.floorId); core.extractBlocksForUI(map, currData.hero.flags); // 这一步会向map写入blocks return map.blocks; @@ -75,17 +71,6 @@ export const SaveBtn = defineComponent< }); 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 () => ( )} @@ -385,6 +399,14 @@ export function selectSave( validate?: SaveValidationFunction, props?: SaveProps ) { + const validateDelete = (index: number, exist: boolean): SaveValidation => { + if (index === -1) { + return { message: '不能删除自动存档!', valid: false }; + } else { + return { message: '无法删除该存档!', valid: exist }; + } + }; + return new Promise(res => { const instance = controller.open(SaveUI, { loc, @@ -403,6 +425,15 @@ export function selectSave( core.drawTip(validation.message); } }, + onDelete: (index: number, exist: boolean) => { + if (!validate) return; + const validation = validateDelete(index, exist); + if (validation.valid) { + core.removeSave(index); + } else { + core.drawTip(validation.message); + } + }, onExit: () => { res(-2); } @@ -424,6 +455,7 @@ export async function saveSave( }; const index = await selectSave(controller, loc, validate, props); if (index === -2) return false; + // 由于样板存档编号从1开始,这里需要+1 core.doSL(index + 1, 'save'); return true; }