diff --git a/src/config/i18n/zh/index.ts b/src/config/i18n/zh/index.ts index 6eb0b29..2f900c2 100644 --- a/src/config/i18n/zh/index.ts +++ b/src/config/i18n/zh/index.ts @@ -156,7 +156,8 @@ export default class Zh { copyArchive = ['复制存档', '已经复制存档了,建议保存到备忘录', '复制存档失败']; pasteArchive = ['粘贴存档', '粘贴存档内容到输入框成功', '粘贴失败']; cleanArchive = ['删除存档']; - importArchive = ['导入', '导入存档成功,继续游戏吧!', '导入存档失败']; + importArchive = ['导入', '导入存档成功,继续游戏吧!', '导入存档失败', '存档版本已过期,无法导入!']; + experiential = ['导入体验存档成功,体验时间${0}分钟。', '体验存档无法保存!', '体验时间已过,自动读取本地存档。']; music = ['播放或禁音背景音乐(M)']; diff --git a/src/store/action.ts b/src/store/action.ts index 9c2fd2a..5e9ab42 100644 --- a/src/store/action.ts +++ b/src/store/action.ts @@ -1,5 +1,5 @@ import { initialWeapon, initialArmor, initialNeck, initialRing, i18n, audio_mp3 } from '@/config'; -import { conisOfsell, saveArchive, getArchive, getFromStore } from '@/tool'; +import { conisOfsell, saveArchive, getArchive } from '@/tool'; const backgound = new Audio(audio_mp3.background); backgound.loop = true; @@ -67,8 +67,12 @@ export const useEquip = ({ state, commit }, index) => { }; export const saveGame = ({ state, commit }) => { - saveArchive(state); - commit('set_sys_info', { msg: t('saveGame.2'), type: 'win' }); + if (state.experiential) { + commit('set_sys_info', { msg: t('experiential.1'), type: 'warning' }); + } else { + saveArchive(state); + commit('set_sys_info', { msg: t('saveGame.2'), type: 'win' }); + } }; export const loadGame = ({ commit }, data?) => { @@ -86,6 +90,7 @@ const loadArchive = (commit, data) => { } else if (data == 'undfind') { commit('set_sys_info', { msg: t('loadError'), type: 'warning' }); } else { + commit('set_experiential', data.experiential); commit('set_player_equips', data.equips); commit('set_player_layer', data.layer || 1); commit('set_player_coins', data.coins || 0); diff --git a/src/store/mutation.ts b/src/store/mutation.ts index 954cd64..4973308 100644 --- a/src/store/mutation.ts +++ b/src/store/mutation.ts @@ -123,3 +123,6 @@ export const add_player_curhp = (state, hp) => { curHp < 0 && (curHp = 0); state.playerAttribute.attribute.curHp = curHp; }; +export const set_experiential = (state, data) => { + state.experiential = data || false; +}; diff --git a/src/store/state.ts b/src/store/state.ts index 00dcbe5..92f8ec5 100644 --- a/src/store/state.ts +++ b/src/store/state.ts @@ -31,12 +31,9 @@ export default { left: '0', imgLeft: '0px', clip: 'rect(96px, 32px, 144px, 0px)', - // playerStyle: { - // left: '0%', - // backgroundPosition: '0px 96px', - // }, battleShow: false, repeat: true, upward: true, }, + experiential: false, }; diff --git a/src/tool/archive.ts b/src/tool/archive.ts index 18db076..dacda1a 100644 --- a/src/tool/archive.ts +++ b/src/tool/archive.ts @@ -1,7 +1,7 @@ import { Equip, Player, Points } from '@/config'; import { getFromStore, insertToStore, store_name_archive } from './IndexedDB'; import { uuid } from './random'; -const archive_version = '1.0'; +export const archive_version = '1.0'; const archive_version_strengthen = '1.0_flag'; export class GameArchive { diff --git a/src/views/archive.vue b/src/views/archive.vue index f9a0612..bf5cd77 100644 --- a/src/views/archive.vue +++ b/src/views/archive.vue @@ -23,7 +23,7 @@ import { computed, onMounted, ref, onBeforeUnmount } from "vue"; import { useI18n } from "vue3-i18n"; import { Tooltip, Dialog } from "@/components" import { menu_icons } from "@/config"; -import { getArchive, AES_CBC_ENCRYPT, AES_CBC_DECRYPT, checkImportArchive, saveArchive } from "@/tool"; +import { getArchive, AES_CBC_ENCRYPT, AES_CBC_DECRYPT, checkImportArchive, saveArchive, replace, archive_version } from "@/tool"; const { t } = useI18n(); @@ -33,6 +33,7 @@ const showArchive = computed(() => { }); const archive = ref(''); const key = 'KUf4hM5rThssysJhcRFCfxLR8Imihjl0eMsyhh1M7Wk'; +let timeOut = 0; const showMenu = () => { if (showArchive.value) { @@ -69,9 +70,23 @@ const importArchive = async () => { if (!data || data == 'undfind') { commit('set_sys_info', { msg: t('loadEmpty'), type: 'warning' }); } + if (data.version != archive_version) { + commit('set_sys_info', { msg: t('importArchive.3'), type: 'warning' }); + return; + } await checkImportArchive(data); await dispatch('loadGame', data); - saveArchive(state); + if (state.experiential) { + commit('set_sys_info', { msg: replace(t('experiential.0'), [data.experientialTime]), type: 'win' }); + const time = data.experientialTime || 10; + clearTimeout(timeOut); + timeOut = setTimeout(() => { + commit('set_sys_info', { msg: replace(t('experiential.2'), [data.experientialTime]), type: 'warning' }); + dispatch('loadGame'); + }, time * 60 * 100); + } else { + saveArchive(state); + } showMenu(); } catch (error) { console.log(error); @@ -85,10 +100,11 @@ const keydown = (e) => { } } onMounted(() => { - document.addEventListener('keydown', keydown) + document.addEventListener('keydown', keydown); }); onBeforeUnmount(() => { - document.removeEventListener('keydown', keydown) + document.removeEventListener('keydown', keydown); + clearTimeout(timeOut); }) onMounted(() => { });