From abccffa7134de975ff98680331dcc82a7eac0006 Mon Sep 17 00:00:00 2001 From: Bill Date: Tue, 15 Mar 2022 17:27:44 -0400 Subject: [PATCH] Fix purse --- src/api/utils/PlaySound.ts | 4 ++-- src/components/purse/PurseView.tsx | 8 ++++---- src/components/purse/common/Purse.ts | 23 +++++++++++++++++++++-- 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/src/api/utils/PlaySound.ts b/src/api/utils/PlaySound.ts index 392e4d01..94c50ee9 100644 --- a/src/api/utils/PlaySound.ts +++ b/src/api/utils/PlaySound.ts @@ -1,4 +1,4 @@ -import { MouseEventType, TouchEventType } from '@nitrots/nitro-renderer'; +import { MouseEventType } from '@nitrots/nitro-renderer'; import { NitroSoundEvent } from '@nitrots/nitro-renderer/src/nitro/events/NitroSoundEvent'; import { DispatchMainEvent } from '../../hooks'; @@ -11,7 +11,7 @@ export const PlaySound = (sampleCode: string) => DispatchMainEvent(new NitroSoundEvent(NitroSoundEvent.PLAY_SOUND, sampleCode)); } -const eventTypes = [ MouseEventType.MOUSE_CLICK, MouseEventType.MOUSE_MOVE, MouseEventType.MOUSE_MOVE, TouchEventType.TOUCH_MOVE, 'focus' ]; +const eventTypes = [ MouseEventType.MOUSE_CLICK ]; const startListening = () => { diff --git a/src/components/purse/PurseView.tsx b/src/components/purse/PurseView.tsx index a3fe611b..afe67380 100644 --- a/src/components/purse/PurseView.tsx +++ b/src/components/purse/PurseView.tsx @@ -72,7 +72,7 @@ export const PurseView: FC<{}> = props => setPurse(prevValue => { - const newValue = { ...prevValue }; + const newValue = Purse.from(prevValue as Purse); newValue.credits = parseFloat(parser.credits); @@ -90,7 +90,7 @@ export const PurseView: FC<{}> = props => setPurse(prevValue => { - const newValue = { ...prevValue }; + const newValue = Purse.from(prevValue as Purse); newValue.activityPoints = parser.currencies; @@ -106,7 +106,7 @@ export const PurseView: FC<{}> = props => setPurse(prevValue => { - const newValue = { ...prevValue }; + const newValue = Purse.from(prevValue as Purse); newValue.activityPoints = new Map(newValue.activityPoints); @@ -129,7 +129,7 @@ export const PurseView: FC<{}> = props => setPurse(prevValue => { - const newValue = { ...prevValue }; + const newValue = Purse.from(prevValue as Purse); newValue.clubDays = Math.max(0, parser.daysToPeriodEnd); newValue.clubPeriods = Math.max(0, parser.periodsSubscribedAhead); diff --git a/src/components/purse/common/Purse.ts b/src/components/purse/common/Purse.ts index 9f0e66a6..f9ea045a 100644 --- a/src/components/purse/common/Purse.ts +++ b/src/components/purse/common/Purse.ts @@ -13,8 +13,27 @@ export class Purse implements IPurse private _pastVipDays: number = 0; private _isExpiring: boolean = false; private _minutesUntilExpiration: number = 0; - private _minutesSinceLastModified: number; - private _lastUpdated: number; + private _minutesSinceLastModified: number = 0; + private _lastUpdated: number = 0; + + public static from(purse: Purse): Purse + { + const newPurse = new Purse(); + + newPurse._credits = purse._credits; + newPurse._activityPoints = purse._activityPoints; + newPurse._clubDays = purse._clubDays; + newPurse._clubPeriods = purse._clubPeriods; + newPurse._isVIP = purse._isVIP; + newPurse._pastClubDays = purse._pastClubDays; + newPurse._pastVipDays = purse._pastVipDays; + newPurse._isExpiring = purse._isExpiring; + newPurse._minutesUntilExpiration = purse._minutesUntilExpiration; + newPurse._minutesSinceLastModified = purse._minutesSinceLastModified; + newPurse._lastUpdated = purse._lastUpdated; + + return newPurse; + } public get credits(): number {