Skip to content

Commit

Permalink
info-all
Browse files Browse the repository at this point in the history
  • Loading branch information
Pseudonian committed Feb 2, 2025
1 parent 261cd0b commit 1b538cd
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 5 deletions.
42 changes: 39 additions & 3 deletions src/Login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,13 @@ export const activeConsumables: Record<PseudoCoinConsumableNames, number> = {
HAPPY_HOUR_BELL: 0
}

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

export const allConsumableTimes: Record<PseudoCoinConsumableNames, Array<number>> = {
HAPPY_HOUR_BELL: []
}

const messageSchema = z.preprocess(
(data, ctx) => {
Expand Down Expand Up @@ -75,6 +81,14 @@ const messageSchema = z.preprocess(
}).array(),
tips: z.number().int().nonnegative()
}),
z.object({
type: z.literal('info-all'),
active: z.object({
name: z.string(),
internalName: z.string(),
endsAt: z.number().int()
}).array(),
}),
/** Received after the *user* successfully redeems a consumable. */
z.object({ type: z.literal('thanks') }),
/** Received when a user is tipped */
Expand Down Expand Up @@ -330,6 +344,14 @@ const queue: string[] = []
const exponentialBackoff = [5000, 15000, 30000, 60000]
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
}
}

function handleWebSocket () {
assert(!ws || ws.readyState === WebSocket.CLOSED, 'WebSocket has been set and is not closed')

Expand All @@ -344,6 +366,7 @@ function handleWebSocket () {
Notification(
'Could not re-establish your connection. Consumables and events related to Consumables will not work.'
)
resetConsumables()
}
})

Expand All @@ -363,6 +386,7 @@ function handleWebSocket () {

if (data.type === 'error') {
Notification(data.message, 5_000)
resetConsumables()
} else if (data.type === 'consumed') {
activeConsumables[data.consumable as PseudoCoinConsumableNames]++
Notification(`Someone redeemed a(n) ${data.consumable}!`)
Expand All @@ -378,17 +402,29 @@ 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)
}

happyHourEndTime = ends

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`
}

Notification(message)
// i don't think the current ui uses updateEvents page

} else if (data.type === 'thanks') {
Alert(i18next.t('pseudoCoins.consumables.thanks'))
} else if (data.type === 'tip-backlog' || data.type === 'tips') {
Expand Down
12 changes: 10 additions & 2 deletions src/UpdateVisuals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import type { IMultiBuy } from './Cubes'
import { BuffType, consumableEventBuff, eventBuffType, getEvent, getEventBuff } from './Event'
import type { hepteractTypes } from './Hepteracts'
import { hepteractTypeList } from './Hepteracts'
import { activeConsumables, happyHourEndTime } from './Login'
import { activeConsumables, allConsumableTimes, type PseudoCoinConsumableNames } from './Login'
import { PCoinUpgradeEffects } from './PseudoCoinUpgrades'
import { getQuarkBonus, quarkHandler } from './Quark'
import { displayRuneInformation } from './Runes'
Expand Down Expand Up @@ -1809,6 +1809,14 @@ export const visualUpdateShop = () => {
} Quarks Each`
}

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

export const visualUpdateEvent = () => {
const event = getEvent()
if (event !== null) {
Expand All @@ -1835,7 +1843,7 @@ export const visualUpdateEvent = () => {
}
const { HAPPY_HOUR_BELL } = activeConsumables
if (HAPPY_HOUR_BELL > 0) {
DOMCacheGetOrSet('consumableEventTimer').textContent = timeReminingHours(new Date(happyHourEndTime))
DOMCacheGetOrSet('consumableEventTimer').textContent = constructConsumableTimes('HAPPY_HOUR_BELL')
DOMCacheGetOrSet('consumableEventBonus').textContent = `${HAPPY_HOUR_BELL}`

for (let i = 0; i < eventBuffType.length; i++) {
Expand Down

0 comments on commit 1b538cd

Please sign in to comment.