@@ -346,6 +346,11 @@ export class Game extends Lock {
346346 this . hasSpoilers = false ;
347347 }
348348
349+ private withCacheState < T > ( fn : ( ) => T ) : T {
350+ // Roll back only the keys mutated during `fn` (cheap), instead of copying the whole cache.
351+ return this . cache . withRollback ( fn ) ;
352+ }
353+
349354 private getNode ( id : string ) {
350355 let c = this . cache . getNode ( id ) ;
351356
@@ -653,6 +658,14 @@ export class Game extends Lock {
653658 return new JokerData ( joker , rarity , edition , stickers ) ;
654659 }
655660
661+ /**
662+ * Returns what `nextJoker(...)` would return, but does NOT advance RNG/cache state.
663+ * Intended for spoiler/peek UI.
664+ */
665+ peekJoker ( source : QueueNames , ante : number , hasStickers : boolean ) : JokerData {
666+ return this . withCacheState ( ( ) => this . nextJoker ( source , ante , hasStickers ) ) ;
667+ }
668+
656669 getShopInstance ( ) : ShopInstance {
657670 let tarotRate = 4 ;
658671 let planetRate = 4 ;
@@ -1031,7 +1044,7 @@ export class Game extends Lock {
10311044 const item = ( card as ItemImpl ) . getName ( ) ;
10321045 const spoilerSource = this . hasSpoilersMap [ item ] ;
10331046 if ( this . hasSpoilers ) {
1034- return this . nextJoker ( spoilerSource , ante , false )
1047+ return this . peekJoker ( spoilerSource , ante , false )
10351048 }
10361049 return card as Card ;
10371050 }
@@ -1132,18 +1145,18 @@ item wheel_of_fortune_edition(instance* inst) {
11321145 }
11331146 return ( value + this . hashedSeed ) / 2 ;
11341147 }
1135- static get CARDS_ABANDONED ( ) : Array < Card > {
1148+ static get CARDS_ABANDONED ( ) : Card [ ] {
11361149 // Abandoned Deck: 40 cards, no face cards (J, Q, K).
11371150 return this . CARDS . filter ( c => {
11381151 const name = c . getName ( ) ;
11391152 return ! name . includes ( "_J" ) && ! name . includes ( "_Q" ) && ! name . includes ( "_K" ) ;
11401153 } ) . map ( c => new Card ( c . getName ( ) as PlayingCard ) ) ;
11411154 }
11421155
1143- static get CARDS_CHECKERED ( ) : Array < Card > {
1156+ static get CARDS_CHECKERED ( ) : Card [ ] {
11441157 // Checkered Deck: 52 cards (Hearts/Spades only).
11451158 return this . CARDS . map ( c => {
1146- const name = c . getName ( ) ;
1159+ const name = c . getName ( ) as string ;
11471160 const rank = name . split ( "_" ) [ 1 ] ;
11481161 const suit = name . split ( "_" ) [ 0 ] ;
11491162 let newSuit = suit ;
@@ -1156,9 +1169,9 @@ item wheel_of_fortune_edition(instance* inst) {
11561169 /**
11571170 * Returns a fully shuffled deck for the given ante and round index (1, 2, or 3).
11581171 */
1159- private getShuffledDeck ( ante : number , round : number = 1 ) : Array < Card > {
1172+ private getShuffledDeck ( ante : number , round : number = 1 ) : Card [ ] {
11601173 const deckType = this . params . getDeck ( ) . name ;
1161- let cards : Array < Card > ;
1174+ let cards : Card [ ] ;
11621175
11631176 switch ( deckType ) {
11641177 case deckNames [ DeckType . ABANDONED_DECK ] :
@@ -1168,7 +1181,7 @@ item wheel_of_fortune_edition(instance* inst) {
11681181 cards = Game . CARDS_CHECKERED ;
11691182 break ;
11701183 case deckNames [ DeckType . ERRATIC_DECK ] : {
1171- const randomizedCards : Array < Card > = [ ] ;
1184+ const randomizedCards : Card [ ] = [ ] ;
11721185 for ( let i = 0 ; i < 52 ; i ++ ) {
11731186 const card = this . randchoice_simple ( RandomQueueNames . R_Erratic , Game . CARDS ) ;
11741187 randomizedCards . push ( new Card ( card . getName ( ) as PlayingCard ) ) ;
@@ -1185,7 +1198,7 @@ item wheel_of_fortune_edition(instance* inst) {
11851198
11861199 for ( let i = cards . length - 1 ; i >= 1 ; i -- ) {
11871200 const j = rng . randint ( 1 , i + 1 ) - 1 ;
1188- const temp = cards [ i ] ;
1201+ let temp = cards [ i ] ;
11891202 cards [ i ] = cards [ j ] ;
11901203 cards [ j ] = temp ;
11911204
@@ -1202,29 +1215,13 @@ item wheel_of_fortune_edition(instance* inst) {
12021215 * @param round The round index within the ante (1, 2, or 3) (default 1)
12031216 * @param count Number of cards to draw (default 8)
12041217 */
1205- getDeckDraw ( ante : number , round : number = 1 , count : number = 8 ) : Array < Card > {
1218+ getDeckDraw ( ante : number , round : number = 1 , count : number = 8 ) : Card [ ] {
12061219 const deck = this . getShuffledDeck ( ante , round ) ;
12071220 return deck . slice ( 0 , count ) ;
12081221 }
12091222
1210- getStartingDeckDraw ( count = 8 , sort : 'rank' | 'suit' = 'rank' ) : Array < Card > {
1223+ getStartingDeckDraw ( ) : Card [ ] {
12111224 // pifreak loves you!
1212- const hand = this . getDeckDraw ( 1 , 1 , count ) ;
1213- if ( sort === 'rank' ) {
1214- return hand . sort ( ( a , b ) => {
1215- const rankA = parseInt ( a . getName ( ) . split ( '_' ) [ 1 ] ) ;
1216- const rankB = parseInt ( b . getName ( ) . split ( '_' ) [ 1 ] ) ;
1217- return rankA - rankB ;
1218- } ) ;
1219- }
1220- else {
1221- const suitOrder : Record < string , number > = { 'C' : 1 , 'D' : 2 , 'H' : 3 , 'S' : 4 } ;
1222- return hand . sort ( ( a , b ) => {
1223- const suitA = a . getName ( ) . split ( '_' ) [ 0 ] ;
1224- const suitB = b . getName ( ) . split ( '_' ) [ 0 ] ;
1225- return suitOrder [ suitA ] - suitOrder [ suitB ] ;
1226- } ) ;
1227- }
1225+ return this . getDeckDraw ( 1 , 1 , 8 ) ;
12281226 }
12291227}
1230-
0 commit comments