From 67d39774c27717b06befb66fb0e666bb76866f7a Mon Sep 17 00:00:00 2001 From: Christian Montoya Date: Sun, 16 Jun 2024 17:22:15 -0400 Subject: [PATCH] Stats --- packages/snap/snap.manifest.json | 2 +- packages/snap/src/index.tsx | 54 ++++++++++++++++++++------------ 2 files changed, 35 insertions(+), 21 deletions(-) diff --git a/packages/snap/snap.manifest.json b/packages/snap/snap.manifest.json index 681378c..a87930f 100644 --- a/packages/snap/snap.manifest.json +++ b/packages/snap/snap.manifest.json @@ -7,7 +7,7 @@ "url": "https://github.com/Montoya/slots-snap.git" }, "source": { - "shasum": "9LteXMaIR1qJf3ZoSRix3X3uxNgZn3dYNr6Ho8t/pqk=", + "shasum": "DC4TOAGG3PD/f7nlb+oaIBNDKyr8ZZfgsyoJE710Bvg=", "location": { "npm": { "filePath": "dist/bundle.js", diff --git a/packages/snap/src/index.tsx b/packages/snap/src/index.tsx index 1e06414..e85d929 100644 --- a/packages/snap/src/index.tsx +++ b/packages/snap/src/index.tsx @@ -41,7 +41,9 @@ export const onHomePage: OnHomePageHandler = async () => { const playerState = await snap.request({ method: "snap_manageState", params: { operation: "get" }, - }) || { balance: 1000, new: true, lastBet: 0, lastResult: [reel[0],reel[0],reel[0]], reel: "fox" }; + }) || { balance: 1000, new: true, lastBet: 0, lastResult: [reel[0],reel[0],reel[0]], reel: "fox", stats: { + spins: 0, restarts:0, high: 1000, triples: 0 + } }; const interfaceId = await snap.request({ method: "snap_createInterface", params: { @@ -60,18 +62,21 @@ export const onHomePage: OnHomePageHandler = async () => { export const onUserInput: OnUserInputHandler = async ({id, event}) => { - if(event.name=="clear") { - await snap.request({ - method: "snap_manageState", - params: { operation: "clear" }, - }); - event.name = "startFresh"; - } - const playerState = await snap.request({ method: "snap_manageState", params: { operation: "get" }, - }) || { balance: 1000, new: true, lastBet: 0, lastResult: [reel[0],reel[0],reel[0]], reel: "fox" }; + }) || { balance: 1000, new: true, lastBet: 0, lastResult: [reel[0],reel[0],reel[0]], reel: "fox", stats: { + spins: 0, restarts:0, high: 1000, triples: 0, bet5s: 0, bet10s: 0, bet25s: 0 + } }; + + if(event.name=="startOver") { + playerState.balance = 1000; + playerState.new = true; + playerState.lastBet = 0; + playerState.lastResult = [reel[0],reel[0],reel[0]]; + playerState.stats.restarts += 1; + event.name = "startFresh"; + } if(event.name=="settingsForm" && event.type==UserInputEventType.FormSubmitEvent) { playerState.reel = ''+event.value.reel; @@ -121,10 +126,6 @@ export const onUserInput: OnUserInputHandler = async ({id, event}) => { } }); break; - case "startOver": - playerState.balance = 1000; - playerState.lastBet = 0; - playerState.lastResult = [reel[0],reel[0],reel[0]]; case "startFresh": playerState.new = false; await snap.request({ @@ -165,6 +166,8 @@ export const onUserInput: OnUserInputHandler = async ({id, event}) => { case "bet5": case "bet10": case "bet25": + playerState.stats.spins += 1; + playerState.stats[event.name+'s'] += 1; playerState.lastBet = parseInt(event.name.substring(3)); playerState.balance -= playerState.lastBet; const valuesArray = new Uint32Array(3); @@ -191,6 +194,7 @@ export const onUserInput: OnUserInputHandler = async ({id, event}) => { win = playerState.lastBet * 2; break; } + playerState.stats.triples += 1; } else if(one==reel[0] && one==two || two==reel[0] && two==three || three==reel[0] && one==three) { win = playerState.lastBet * 8; } @@ -213,6 +217,9 @@ export const onUserInput: OnUserInputHandler = async ({id, event}) => { }, }); playerState.balance += win; + if(playerState.stats.high < playerState.balance) { + playerState.stats.high = playerState.balance; + } await snap.request({ method: "snap_manageState", params: { @@ -275,10 +282,17 @@ export const onUserInput: OnUserInputHandler = async ({id, event}) => { - - - - + + Stats + {"$"+playerState.stats.high} + {''+playerState.stats.spins} + {''+playerState.stats.bet5s} + {''+playerState.stats.bet10s} + {''+playerState.stats.bet25s} + {''+playerState.stats.triples} + {''+playerState.stats.restarts} + + ), @@ -293,10 +307,10 @@ export const onUserInput: OnUserInputHandler = async ({id, event}) => { ui: ( Are you sure? - This will erase your game data. This cannot be undone. + This will set your balance back to $1000. You will not lose your stats. - + ),