Skip to content

Commit

Permalink
feat
Browse files Browse the repository at this point in the history
  • Loading branch information
Mees committed Oct 21, 2024
1 parent a07687e commit b6a2dc7
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/components/OfflineSummary.vue
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ import { computed } from 'vue'
const gameStore = useGameStore()
const offlineTime = computed(() => {
return Date.now() - gameStore.lastSavedTime
return Date.now() - gameStore.previousSaveTime
})
function closeOfflineSummary() {
Expand Down
16 changes: 10 additions & 6 deletions src/stores/gameStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export const useGameStore = defineStore('gameStore', {
loaded: false,
loggedIn: false,
lastSavedTime: Date.now(),
previousSaveTime: Date.now(), // Add this new property

deltaMultiplier: 1,

Expand Down Expand Up @@ -216,7 +217,7 @@ export const useGameStore = defineStore('gameStore', {
const resourceStore = useResourcesStore()
const trainingStore = useTrainingStore()
const currentTime = Date.now()
let timeElapsed = (currentTime - this.lastSavedTime) / 1000 // Total offline time in seconds
let timeElapsed = (currentTime - this.previousSaveTime) / 1000 // Use previousSaveTime here

// Define the offline cap (24 hours = 86400 seconds)
const OFFLINE_CAP = 86400
Expand Down Expand Up @@ -260,6 +261,7 @@ export const useGameStore = defineStore('gameStore', {
this.offlineGains.xp[skill] = trainingStore.training[skill].xp - initialTraining[skill].xp
})

this.previousSaveTime = this.lastSavedTime // Update previousSaveTime
this.lastSavedTime = currentTime
this.progress = 100
console.log('Offline progress simulation complete.')
Expand Down Expand Up @@ -612,6 +614,7 @@ export const useGameStore = defineStore('gameStore', {
this.showSaveToast()
}

this.previousSaveTime = this.lastSavedTime // Store the previous save time
this.lastSavedTime = Date.now()
} catch (error: FirestoreError | any) {
toast.error('Failed to save game state', {
Expand Down Expand Up @@ -717,13 +720,13 @@ export const useGameStore = defineStore('gameStore', {
position: 'top-left',
})
}

this.saveGameState({
force: true,
})
} catch (error) {
console.error('Error loading game state from Firestore:', error)
}

this.saveGameState({
force: true,
})
},

async loadStateFromFirebase(savedState) {
Expand All @@ -734,7 +737,8 @@ export const useGameStore = defineStore('gameStore', {
const evolveStore = useEvolveStore()
evolveStore.loadEvolveState(savedState)

this.lastSavedTime = savedState.lastSavedTime ?? this.lastSavedTime
this.previousSaveTime = savedState.lastSavedTime ?? this.previousSaveTime
this.lastSavedTime = Date.now() // Set lastSavedTime to current time on load

const adventureStore = useAdventureStore()
await adventureStore.loadAdventureState(savedState)
Expand Down
2 changes: 2 additions & 0 deletions src/views/HomePage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
'dark': settingsStore.darkMode,
}"
>
<OfflineSummary />
<AntSimulation
v-if="gameStore.loaded && settingsStore.showBackground"
:show-animation="settingsStore.showAnimation"
Expand Down Expand Up @@ -342,6 +343,7 @@ import {toast} from 'vue3-toastify'
import BossPage from '@/views/BossPage.vue'
import AntTraining from '@/views/AntTraining.vue'
import {storeToRefs} from 'pinia'
import OfflineSummary from '@/components/OfflineSummary.vue'
const deferredPrompt = ref(null)
const gameStore = useGameStore()
Expand Down
2 changes: 2 additions & 0 deletions src/views/InventoryPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,12 @@ const useItem = (itemId: string, amount = 1) => {
if (useInventoryStore().useItem(itemId, amount)) {
toast.success('Item used successfully', {
position: 'top-left',
toastId: 'use-item-toast',
})
} else {
toast.error('Failed to use item', {
position: 'top-left',
toastId: 'use-item-toast',
})
}
Expand Down

0 comments on commit b6a2dc7

Please sign in to comment.