Browse Source

存档功能更新

1.保存和导入存档时添加体验功能校验
2.导入存档时添加版本校验
v1.0
许孟阳 1 week ago
parent
commit
8cd786b1e8
  1. 3
      src/config/i18n/zh/index.ts
  2. 7
      src/store/action.ts
  3. 3
      src/store/mutation.ts
  4. 5
      src/store/state.ts
  5. 2
      src/tool/archive.ts
  6. 22
      src/views/archive.vue

3
src/config/i18n/zh/index.ts

@ -156,7 +156,8 @@ export default class Zh {
copyArchive = ['复制存档', '已经复制存档了,建议保存到备忘录', '复制存档失败']; copyArchive = ['复制存档', '已经复制存档了,建议保存到备忘录', '复制存档失败'];
pasteArchive = ['粘贴存档', '粘贴存档内容到输入框成功', '粘贴失败']; pasteArchive = ['粘贴存档', '粘贴存档内容到输入框成功', '粘贴失败'];
cleanArchive = ['删除存档']; cleanArchive = ['删除存档'];
importArchive = ['导入', '导入存档成功,继续游戏吧!', '导入存档失败']; importArchive = ['导入', '导入存档成功,继续游戏吧!', '导入存档失败', '存档版本已过期,无法导入!'];
experiential = ['导入体验存档成功,体验时间${0}分钟。', '体验存档无法保存!', '体验时间已过,自动读取本地存档。'];
music = ['播放或禁音背景音乐(M)']; music = ['播放或禁音背景音乐(M)'];

7
src/store/action.ts

@ -1,5 +1,5 @@
import { initialWeapon, initialArmor, initialNeck, initialRing, i18n, audio_mp3 } from '@/config'; 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); const backgound = new Audio(audio_mp3.background);
backgound.loop = true; backgound.loop = true;
@ -67,8 +67,12 @@ export const useEquip = ({ state, commit }, index) => {
}; };
export const saveGame = ({ state, commit }) => { export const saveGame = ({ state, commit }) => {
if (state.experiential) {
commit('set_sys_info', { msg: t('experiential.1'), type: 'warning' });
} else {
saveArchive(state); saveArchive(state);
commit('set_sys_info', { msg: t('saveGame.2'), type: 'win' }); commit('set_sys_info', { msg: t('saveGame.2'), type: 'win' });
}
}; };
export const loadGame = ({ commit }, data?) => { export const loadGame = ({ commit }, data?) => {
@ -86,6 +90,7 @@ const loadArchive = (commit, data) => {
} else if (data == 'undfind') { } else if (data == 'undfind') {
commit('set_sys_info', { msg: t('loadError'), type: 'warning' }); commit('set_sys_info', { msg: t('loadError'), type: 'warning' });
} else { } else {
commit('set_experiential', data.experiential);
commit('set_player_equips', data.equips); commit('set_player_equips', data.equips);
commit('set_player_layer', data.layer || 1); commit('set_player_layer', data.layer || 1);
commit('set_player_coins', data.coins || 0); commit('set_player_coins', data.coins || 0);

3
src/store/mutation.ts

@ -123,3 +123,6 @@ export const add_player_curhp = (state, hp) => {
curHp < 0 && (curHp = 0); curHp < 0 && (curHp = 0);
state.playerAttribute.attribute.curHp = curHp; state.playerAttribute.attribute.curHp = curHp;
}; };
export const set_experiential = (state, data) => {
state.experiential = data || false;
};

5
src/store/state.ts

@ -31,12 +31,9 @@ export default {
left: '0', left: '0',
imgLeft: '0px', imgLeft: '0px',
clip: 'rect(96px, 32px, 144px, 0px)', clip: 'rect(96px, 32px, 144px, 0px)',
// playerStyle: {
// left: '0%',
// backgroundPosition: '0px 96px',
// },
battleShow: false, battleShow: false,
repeat: true, repeat: true,
upward: true, upward: true,
}, },
experiential: false,
}; };

2
src/tool/archive.ts

@ -1,7 +1,7 @@
import { Equip, Player, Points } from '@/config'; import { Equip, Player, Points } from '@/config';
import { getFromStore, insertToStore, store_name_archive } from './IndexedDB'; import { getFromStore, insertToStore, store_name_archive } from './IndexedDB';
import { uuid } from './random'; import { uuid } from './random';
const archive_version = '1.0'; export const archive_version = '1.0';
const archive_version_strengthen = '1.0_flag'; const archive_version_strengthen = '1.0_flag';
export class GameArchive { export class GameArchive {

22
src/views/archive.vue

@ -23,7 +23,7 @@ import { computed, onMounted, ref, onBeforeUnmount } from "vue";
import { useI18n } from "vue3-i18n"; import { useI18n } from "vue3-i18n";
import { Tooltip, Dialog } from "@/components" import { Tooltip, Dialog } from "@/components"
import { menu_icons } from "@/config"; 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(); const { t } = useI18n();
@ -33,6 +33,7 @@ const showArchive = computed(() => {
}); });
const archive = ref(''); const archive = ref('');
const key = 'KUf4hM5rThssysJhcRFCfxLR8Imihjl0eMsyhh1M7Wk'; const key = 'KUf4hM5rThssysJhcRFCfxLR8Imihjl0eMsyhh1M7Wk';
let timeOut = 0;
const showMenu = () => { const showMenu = () => {
if (showArchive.value) { if (showArchive.value) {
@ -69,9 +70,23 @@ const importArchive = async () => {
if (!data || data == 'undfind') { if (!data || data == 'undfind') {
commit('set_sys_info', { msg: t('loadEmpty'), type: 'warning' }); 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 checkImportArchive(data);
await dispatch('loadGame', data); await dispatch('loadGame', data);
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); saveArchive(state);
}
showMenu(); showMenu();
} catch (error) { } catch (error) {
console.log(error); console.log(error);
@ -85,10 +100,11 @@ const keydown = (e) => {
} }
} }
onMounted(() => { onMounted(() => {
document.addEventListener('keydown', keydown) document.addEventListener('keydown', keydown);
}); });
onBeforeUnmount(() => { onBeforeUnmount(() => {
document.removeEventListener('keydown', keydown) document.removeEventListener('keydown', keydown);
clearTimeout(timeOut);
}) })
onMounted(() => { }); onMounted(() => { });

Loading…
Cancel
Save