You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
75 lines
2.4 KiB
75 lines
2.4 KiB
import { Equip, Player, RebornPoints } from '@/config'; |
|
import { getFromStore, insertToStore, store_name_archive } from './IndexedDB'; |
|
import { uuid } from './random'; |
|
import { version } from 'vue'; |
|
const archive_version = '1.0'; |
|
const archive_version_strengthen = '1.0_flag'; |
|
|
|
export class GameArchive { |
|
version: String; |
|
equips: Equip[]; |
|
lv: number; |
|
coins: number; |
|
grid: any[]; |
|
autoSell: string[]; |
|
shop: any[]; |
|
reborn: RebornPoints; |
|
|
|
constructor(player: Player, grid: any[], autoSell: any[], shop: any[], reboren: RebornPoints) { |
|
this.version = archive_version; |
|
this.equips = [player.weapon, player.armor, player.ring, player.neck, player.jewelry, player.pants, player.shoes, player.bracers]; |
|
this.lv = player.lv; |
|
this.coins = player.coins; |
|
this.grid = grid; |
|
this.autoSell = autoSell; |
|
this.shop = shop; |
|
this.reborn = reboren; |
|
} |
|
} |
|
|
|
export const saveArchive = (state) => { |
|
const archive = new GameArchive(state.playerAttribute, state.grid, state.autoSell, state.shop, state.rebornPoints); |
|
getFromStore(store_name_archive, archive_version_strengthen).then((flag: any) => { |
|
const time = new Date().getTime(); |
|
if (!flag || !flag.time || flag.time + 10 * 60 * 1000 < time) { |
|
flag = { version: archive_version_strengthen, time: time }; |
|
} |
|
const equips = new Array(); |
|
Array.prototype.push.apply(equips, archive.equips); |
|
Array.prototype.push.apply(equips, archive.grid); |
|
equips.forEach((equip) => { |
|
if (!equip) return; |
|
|
|
if (equip.strengthenLv > 0 && !equip.id) { |
|
equip.id = uuid(); |
|
} |
|
if (equip.id) { |
|
flag[equip.id] = equip.strengthenLv; |
|
} |
|
}); |
|
insertToStore(store_name_archive, archive); |
|
insertToStore(store_name_archive, flag); |
|
}); |
|
}; |
|
|
|
export const checkImportArchive = async (data): Promise<void> => { |
|
getFromStore(store_name_archive, archive_version_strengthen).then((rsp: any) => { |
|
if (!rsp) return; |
|
const equips = new Array(); |
|
Array.prototype.push.apply(equips, data.equips); |
|
Array.prototype.push.apply(equips, data.grid); |
|
equips.forEach((equip) => { |
|
if (!equip || !equip.id) return; |
|
const slv = rsp[equip.id]; |
|
slv && (equip.strengthenLv = slv); |
|
}); |
|
}); |
|
}; |
|
|
|
export const getArchive = () => { |
|
return new Promise((resolve, reject) => { |
|
getFromStore(store_name_archive, archive_version).then((rsp: any) => { |
|
resolve(rsp); |
|
}); |
|
}); |
|
};
|
|
|