|
@@ -1,9 +1,30 @@
|
|
|
import { createStore } from 'vuex'
|
|
|
|
|
|
+function resetGameProgress() {
|
|
|
+ const ret = {
|
|
|
+ jagsawProgress: config.sceneTree.map((item) => {
|
|
|
+ return {
|
|
|
+ name: item.name,
|
|
|
+ isJagsawDone: false,
|
|
|
+ children: item.children.map((innerItem) => {
|
|
|
+ return {
|
|
|
+ name: innerItem.name,
|
|
|
+ hasGotJagsaw: false,
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }),
|
|
|
+ buildProgress: 0,
|
|
|
+ }
|
|
|
+ localStorage.setItem('HuiZhouGuJianZhuProgress', JSON.stringify(ret))
|
|
|
+ return ret
|
|
|
+}
|
|
|
+
|
|
|
export default createStore({
|
|
|
state: {
|
|
|
hasPlayedStartupVideo: process.env.VUE_APP_CLI_MODE === 'dev' ? true : false,
|
|
|
hasPlayedGameRule: false,
|
|
|
+ gameProgress: localStorage.getItem('HuiZhouGuJianZhuProgress') ? JSON.parse(localStorage.getItem('HuiZhouGuJianZhuProgress')) : resetGameProgress()
|
|
|
},
|
|
|
getters: {
|
|
|
},
|
|
@@ -13,6 +34,34 @@ export default createStore({
|
|
|
},
|
|
|
recordGameRulePlayed(state) {
|
|
|
state.hasPlayedGameRule = true
|
|
|
+ },
|
|
|
+ // 获得拼图碎片
|
|
|
+ recordJagsawGot(state, sceneL2Id, sceneL3Id) {
|
|
|
+ try {
|
|
|
+ state.gameProgress.jagsawProgress[sceneL2Id].children[sceneL3Id].hasGotJagsaw = true
|
|
|
+ localStorage.setItem('HuiZhouGuJianZhuProgress', JSON.stringify(state.gameProgress))
|
|
|
+ } catch (error) {
|
|
|
+ console.error(error)
|
|
|
+ state.gameProgress = resetGameProgress()
|
|
|
+ }
|
|
|
+ },
|
|
|
+ recordJagsawDone(state, sceneL2Id) {
|
|
|
+ try {
|
|
|
+ state.gameProgress.jagsawProgress[sceneL2Id].isJagsawDone = true
|
|
|
+ localStorage.setItem('HuiZhouGuJianZhuProgress', JSON.stringify(state.gameProgress))
|
|
|
+ } catch (error) {
|
|
|
+ console.error(error)
|
|
|
+ state.gameProgress = resetGameProgress()
|
|
|
+ }
|
|
|
+ },
|
|
|
+ recordBuildProgress(state, progress) {
|
|
|
+ try {
|
|
|
+ state.jagsawProgress.gameProgress.buildProgress = progress
|
|
|
+ localStorage.setItem('HuiZhouGuJianZhuProgress', JSON.stringify(state.gameProgress))
|
|
|
+ } catch (error) {
|
|
|
+ console.error(error)
|
|
|
+ state.gameProgress = resetGameProgress()
|
|
|
+ }
|
|
|
}
|
|
|
},
|
|
|
actions: {
|