@@ -23,21 +23,20 @@ import type { GameTranscript, BoardSnapshot, CardSnapshot } from '../GameTranscr
2323import { TranscriptStore } from '../../../src/core-engine/TranscriptStore' ;
2424import { GameEventEmitter } from '../../../src/core-engine/GameEventEmitter' ;
2525import { PhaserEventBridge } from '../../../src/core-engine/PhaserEventBridge' ;
26- import { HelpPanel , HelpButton } from '../../../src/ui' ;
26+ import {
27+ HelpPanel , HelpButton ,
28+ CARD_W , CARD_H , GAME_W , GAME_H , FONT_FAMILY ,
29+ cardTextureKey , getCardTexture , preloadCardAssets ,
30+ } from '../../../src/ui' ;
2731import type { HelpSection } from '../../../src/ui' ;
2832import helpContent from '../help-content.json' ;
2933
3034// ── Constants ───────────────────────────────────────────────
3135
32- const CARD_W = 48 ;
33- const CARD_H = 65 ;
3436const CARD_GAP = 5 ;
3537const GRID_COLS = 3 ;
3638const GRID_ROWS = 3 ;
3739
38- const GAME_W = 800 ;
39- const GAME_H = 600 ;
40-
4140const AI_DELAY = 600 ; // ms before AI chooses
4241const AI_SHOW_DRAW_DELAY = 1000 ; // ms to show drawn card before moving
4342const ANIM_DURATION = 300 ; // ms for animations
@@ -50,8 +49,6 @@ const PILE_Y = 295; // center Y of stock/discard
5049const STOCK_X = GAME_W / 2 - 50 ;
5150const DISCARD_X = GAME_W / 2 + 50 ;
5251
53- const FONT_FAMILY = 'Arial, sans-serif' ;
54-
5552// ── Turn state machine ──────────────────────────────────────
5653
5754type TurnPhase =
@@ -112,26 +109,7 @@ export class GolfScene extends Phaser.Scene {
112109 // ── Preload ─────────────────────────────────────────────
113110
114111 preload ( ) : void {
115- // Load card back
116- this . load . svg ( 'card_back' , 'assets/cards/card_back.svg' , {
117- width : CARD_W ,
118- height : CARD_H ,
119- } ) ;
120-
121- // Load all 52 card faces
122- const suits : Suit [ ] = [ 'clubs' , 'diamonds' , 'hearts' , 'spades' ] ;
123- const ranks : Rank [ ] = [ 'A' , '2' , '3' , '4' , '5' , '6' , '7' , '8' , '9' , '10' , 'J' , 'Q' , 'K' ] ;
124-
125- for ( const suit of suits ) {
126- for ( const rank of ranks ) {
127- const key = this . cardTextureKey ( rank , suit ) ;
128- const fileName = this . cardFileName ( rank , suit ) ;
129- this . load . svg ( key , `assets/cards/${ fileName } ` , {
130- width : CARD_W ,
131- height : CARD_H ,
132- } ) ;
133- }
134- }
112+ preloadCardAssets ( this ) ;
135113 }
136114
137115 // ── Create ──────────────────────────────────────────────
@@ -424,32 +402,6 @@ export class GolfScene extends Phaser.Scene {
424402 } ;
425403 }
426404
427- // ── Texture helpers ─────────────────────────────────────
428-
429- private cardTextureKey ( rank : Rank , suit : Suit ) : string {
430- const rankName = this . rankFileName ( rank ) ;
431- return `${ rankName } _of_${ suit } ` ;
432- }
433-
434- private cardFileName ( rank : Rank , suit : Suit ) : string {
435- return `${ this . rankFileName ( rank ) } _of_${ suit } .svg` ;
436- }
437-
438- private rankFileName ( rank : Rank ) : string {
439- switch ( rank ) {
440- case 'A' : return 'ace' ;
441- case 'J' : return 'jack' ;
442- case 'Q' : return 'queen' ;
443- case 'K' : return 'king' ;
444- default : return rank ; // 2-10
445- }
446- }
447-
448- private getCardTexture ( card : Card ) : string {
449- if ( ! card . faceUp ) return 'card_back' ;
450- return this . cardTextureKey ( card . rank , card . suit ) ;
451- }
452-
453405 // ── Refresh display ─────────────────────────────────────
454406
455407 private refreshAll ( ) : void {
@@ -466,7 +418,7 @@ export class GolfScene extends Phaser.Scene {
466418 const sprites = player === 'human' ? this . humanCardSprites : this . aiCardSprites ;
467419
468420 for ( let i = 0 ; i < 9 ; i ++ ) {
469- sprites [ i ] . setTexture ( this . getCardTexture ( grid [ i ] ) ) ;
421+ sprites [ i ] . setTexture ( getCardTexture ( grid [ i ] ) ) ;
470422 }
471423 }
472424
@@ -483,7 +435,7 @@ export class GolfScene extends Phaser.Scene {
483435 const top = this . session . shared . discardPile . peek ( ) ;
484436 if ( top ) {
485437 this . discardSprite . setVisible ( true ) ;
486- this . discardSprite . setTexture ( this . getCardTexture ( top ) ) ;
438+ this . discardSprite . setTexture ( getCardTexture ( top ) ) ;
487439 } else {
488440 this . discardSprite . setVisible ( false ) ;
489441 }
@@ -755,7 +707,7 @@ export class GolfScene extends Phaser.Scene {
755707 ease : 'Power2' ,
756708 onComplete : ( ) => {
757709 // Reveal the card's actual face at the midpoint of the flip
758- sprite . setTexture ( this . getCardTexture ( grid [ idx ] ) ) ;
710+ sprite . setTexture ( getCardTexture ( grid [ idx ] ) ) ;
759711 // Second half: scaleX → 1 while completing movement to discard
760712 this . tweens . add ( {
761713 targets : sprite ,
@@ -803,7 +755,7 @@ export class GolfScene extends Phaser.Scene {
803755 duration : SWAP_ANIM_DURATION / 4 ,
804756 ease : 'Power2' ,
805757 onComplete : ( ) => {
806- sprite . setTexture ( this . getCardTexture ( grid [ idx ] ) ) ;
758+ sprite . setTexture ( getCardTexture ( grid [ idx ] ) ) ;
807759 this . tweens . add ( {
808760 targets : sprite ,
809761 scaleX : 1 ,
@@ -838,7 +790,7 @@ export class GolfScene extends Phaser.Scene {
838790 // Show drawn card to the right of the discard pile
839791 const x = DISCARD_X + CARD_W + 20 ;
840792 const y = PILE_Y ;
841- const texture = this . cardTextureKey ( card . rank , card . suit ) ;
793+ const texture = cardTextureKey ( card . rank , card . suit ) ;
842794
843795 this . drawnCardSprite = this . add . image ( x , y , texture ) ;
844796 this . drawnCardSprite . setAlpha ( 0 ) ;
0 commit comments