mirror of
https://github.com/kihashi/stardew_community_checklist.git
synced 2025-10-19 08:03:17 +00:00
Migrate state from V1 and V2 if they exist
This commit is contained in:
parent
7843372ad6
commit
0a7047b6e9
@ -1,7 +1,16 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
|
import { onMounted } from 'vue'
|
||||||
import AppFooter from './components/AppFooter.vue'
|
import AppFooter from './components/AppFooter.vue'
|
||||||
import HeaderBar from './components/HeaderBar.vue'
|
import HeaderBar from './components/HeaderBar.vue'
|
||||||
import { RouterView } from 'vue-router'
|
import { RouterView } from 'vue-router'
|
||||||
|
import { useGeneralStore } from './store'
|
||||||
|
|
||||||
|
const store = useGeneralStore()
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
store.migrateV1StateIfExists()
|
||||||
|
store.migrateV2StateIfExists()
|
||||||
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
|||||||
@ -165,32 +165,56 @@ export const useGeneralStore = defineStore('general', {
|
|||||||
},
|
},
|
||||||
resetData() {
|
resetData() {
|
||||||
this.StoredBundleItemIds = {}
|
this.StoredBundleItemIds = {}
|
||||||
|
},
|
||||||
|
migrateV1StateIfExists() {
|
||||||
|
const v1data = localStorage.getItem('user_data')
|
||||||
|
|
||||||
|
if (v1data === null || v1data === '') return
|
||||||
|
|
||||||
|
const v1state = JSON.parse(atob(v1data)) as { item: number }[][]
|
||||||
|
|
||||||
|
for (let bundleId = 0; bundleId < v1state.length; bundleId++) {
|
||||||
|
for (let j = 0; j < v1state[bundleId].length; j++) {
|
||||||
|
let itemId = v1state[bundleId][j].item
|
||||||
|
// Patch for duplicate oak
|
||||||
|
if (itemId === 116) {
|
||||||
|
itemId = 24
|
||||||
|
}
|
||||||
|
// Patch for parsnip
|
||||||
|
if (itemId === 26 && bundleId === 6) {
|
||||||
|
itemId = 27
|
||||||
}
|
}
|
||||||
// loadV1State(v1state: { item: number }[][]) {
|
|
||||||
// for (let i = 0; i < v1state.length; i++) {
|
|
||||||
// for (let j = 0; j < v1state[i].length; j++) {
|
|
||||||
// let itemId = v1state[i][j].item
|
|
||||||
// // Patch for duplicate oak
|
|
||||||
// if (itemId === 116) {
|
|
||||||
// itemId = 24
|
|
||||||
// }
|
|
||||||
// // Patch for parsnip
|
|
||||||
// if (itemId === 26 && i === 6) {
|
|
||||||
// itemId = 27
|
|
||||||
// }
|
|
||||||
|
|
||||||
// const bundleItems = this.getOpenBundleItems(i, itemId)
|
const bundleItemsToStore = this.getBundleItemsForItem(itemId)
|
||||||
|
.filter((bundleItem) => bundleItem.bundle_id === bundleId)
|
||||||
|
.filter((bundleItem) => !this.isBundleItemStored(bundleItem.id))
|
||||||
|
|
||||||
// if (bundleItems.length > 0) {
|
if (bundleItemsToStore.length > 0) {
|
||||||
// this.storeItem(bundleItems[0])
|
this.storeItem(bundleItemsToStore[0].id)
|
||||||
// } else {
|
} else {
|
||||||
// console.log(
|
console.log(
|
||||||
// `Tried to redeem bundle ${i} item ${itemId}, but no open bundle items were found`
|
`Tried to redeem bundle ${bundleId} item ${itemId}, but no open bundle items were found`
|
||||||
// )
|
)
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
// }
|
|
||||||
|
localStorage.removeItem('user_data')
|
||||||
|
localStorage.setItem('v1data', v1data)
|
||||||
|
},
|
||||||
|
migrateV2StateIfExists() {
|
||||||
|
const v2data = localStorage.getItem('vuex')
|
||||||
|
|
||||||
|
console.log(v2data)
|
||||||
|
if (v2data === null || v2data === '') return
|
||||||
|
|
||||||
|
const v2state = JSON.parse(v2data)
|
||||||
|
|
||||||
|
this.StoredBundleItemIds = v2state.StoredItems
|
||||||
|
|
||||||
|
localStorage.removeItem('vuex')
|
||||||
|
localStorage.setItem('v2data', v2data)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user