Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
KhafraDev committed Feb 2, 2025
1 parent ddaa3b8 commit 91366c6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 29 deletions.
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<meta property="og:description" content="The greatest idle game of all time. This is the best idle game ever.">

<link rel="icon" href="favicon.ico" type="image/x-icon" sizes="16x16">
<link rel="canonical" href="https://synergism.cc/" />
<link rel="canonical" href="https://synergism.cc/">

<link rel="stylesheet" href="Synergism.css">
<title>Synergism</title>
Expand Down
36 changes: 11 additions & 25 deletions src/Login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,6 @@ export const activeConsumables: Record<PseudoCoinConsumableNames, number> = {
HAPPY_HOUR_BELL: 0
}

export const consumableTimes: Record<PseudoCoinConsumableNames, number> = {
HAPPY_HOUR_BELL: 0
}

export const allConsumableTimes: Record<PseudoCoinConsumableNames, Array<number>> = {
HAPPY_HOUR_BELL: []
}
Expand Down Expand Up @@ -87,7 +83,7 @@ const messageSchema = z.preprocess(
name: z.string(),
internalName: z.string(),
endsAt: z.number().int()
}).array(),
}).array()
}),
/** Received after the *user* successfully redeems a consumable. */
z.object({ type: z.literal('thanks') }),
Expand Down Expand Up @@ -347,7 +343,6 @@ let tries = 0
function resetConsumables () {
for (const key in activeConsumables) {
activeConsumables[key as PseudoCoinConsumableNames] = 0
consumableTimes[key as PseudoCoinConsumableNames] = 0
allConsumableTimes[key as PseudoCoinConsumableNames].length = 0 // Specifically for info-all
}
}
Expand Down Expand Up @@ -378,6 +373,7 @@ function handleWebSocket () {
}

queue.length = 0
sendToWebsocket(JSON.stringify({ type: 'info-all' }))
})

ws.addEventListener('message', (ev) => {
Expand All @@ -402,29 +398,27 @@ function handleWebSocket () {

for (const { amount, internalName, name, endsAt } of data.active) {
activeConsumables[internalName as PseudoCoinConsumableNames] = amount
consumableTimes[internalName as PseudoCoinConsumableNames] = endsAt
message += `${name} (x${amount})`
ends = Math.max(ends, endsAt)
}

Notification(message)
updateEventsPage(ends)
}

tips = data.tips
} else if (data.type === 'info-all') { // new, needs to be checked
resetConsumables() // So that we can get an accurate count each time
let message = 'The following consumables are active:\n'

for (const { internalName, name, endsAt } of data.active) {
activeConsumables[internalName as PseudoCoinConsumableNames]++
allConsumableTimes[internalName as PseudoCoinConsumableNames].push(endsAt)
message += `${name}, until ${endsAt}\n`
}
if (data.active.length !== 0) {
let message = 'The following consumables are active:\n'

Notification(message)
// i don't think the current ui uses updateEvents page
for (const { internalName, name, endsAt } of data.active) {
activeConsumables[internalName as PseudoCoinConsumableNames]++
allConsumableTimes[internalName as PseudoCoinConsumableNames].push(endsAt)
message += `${name}, until ${endsAt}\n`
}

Notification(message)
}
} else if (data.type === 'thanks') {
Alert(i18next.t('pseudoCoins.consumables.thanks'))
} else if (data.type === 'tip-backlog' || data.type === 'tips') {
Expand All @@ -441,14 +435,6 @@ function handleWebSocket () {
})
}

function updateEventsPage (endsAt: number) {
const amount = document.getElementById('consumableEventBonus')!
const timer = document.getElementById('consumableEventTimer')!

timer.textContent = new Date(endsAt).toLocaleString()
amount.textContent = `${Object.values(activeConsumables).reduce((a, b) => a + b, 0)}`
}

export function sendToWebsocket (message: string) {
if (ws?.readyState !== WebSocket.OPEN) {
queue.push(message)
Expand Down
6 changes: 3 additions & 3 deletions src/UpdateVisuals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1810,11 +1810,11 @@ export const visualUpdateShop = () => {
}

export const constructConsumableTimes = (p: PseudoCoinConsumableNames) => {
let msg = ''
const msg: string[] = []
for (const time of allConsumableTimes[p]) {
msg += timeReminingHours(new Date(time)) + ', '
msg.push(timeReminingHours(new Date(time)))
}
return msg
return msg.join(', ')
}

export const visualUpdateEvent = () => {
Expand Down

0 comments on commit 91366c6

Please sign in to comment.