1- import { GameImage } from "../../Assets" ;
1+ import { GameImage , SpriteRegion } from "../../Assets" ;
22import { Game } from "../../Game" ;
33import { City } from "../../city/City" ;
44import { GameMap } from "../../map/GameMap" ;
@@ -20,6 +20,7 @@ export class InGameScene extends Scene {
2020 private players : AbstractPlayer [ ] ;
2121 private clientPlayer : ClientPlayer ;
2222 private tileInformationLabel : Label ;
23+ private tileYieldActors : Actor [ ] = [ ] ;
2324 private statusBar : StatusBar ;
2425 private cityDisplayInfo : CityDisplayInfo ;
2526 private nextTurnButton : Button ;
@@ -72,6 +73,8 @@ export class InGameScene extends Scene {
7273 text : "N/A" ,
7374 font : "16px serif" ,
7475 fontColor : "white" ,
76+ shadowColor : "black" ,
77+ lineWidth : 4 ,
7578 x : 0 ,
7679 y : 0 ,
7780 z : 5
@@ -131,9 +134,14 @@ export class InGameScene extends Scene {
131134 } ) ;
132135
133136 this . on ( "tileHovered" , ( options ) => {
134- if ( ! options . tile ) {
135- this . tileInformationLabel . setText ( "" ) ;
136- } else {
137+ // Remove previous yield icons
138+ for ( const actor of this . tileYieldActors ) {
139+ this . removeActor ( actor ) ;
140+ }
141+
142+ this . tileYieldActors = [ ] ;
143+
144+ if ( options . tile && ! this . cityDisplayInfo ) {
137145 let tileTypes : string = options . tile . getTileTypes ( ) . toString ( ) ;
138146 tileTypes = tileTypes . replaceAll ( "_" , " " ) ;
139147 tileTypes = tileTypes . replaceAll ( "," , ", " ) ;
@@ -148,15 +156,72 @@ export class InGameScene extends Scene {
148156
149157 tileTypes = strArray . join ( "" ) ;
150158
159+ // Get tile yields
160+ const yields = options . tile . getTileYield ( ) ;
161+
162+ // Map stat keys to SpriteRegion
163+ const statSpriteRegions : Record < string , SpriteRegion > = {
164+ food : SpriteRegion . FOOD_ICON ,
165+ production : SpriteRegion . PRODUCTION_ICON ,
166+ gold : SpriteRegion . GOLD_ICON ,
167+ faith : SpriteRegion . FAITH_ICON ,
168+ morale : SpriteRegion . MORALE_ICON ,
169+ science : SpriteRegion . SCIENCE_ICON ,
170+ culture : SpriteRegion . CULTURE_ICON ,
171+ } ;
172+
173+ // Set the label text (without yields)
151174 this . tileInformationLabel . setText (
152- "[" +
153- options . tile . getGridX ( ) +
154- "," +
155- options . tile . getGridY ( ) +
156- "] " +
175+ `[${ options . tile . getGridX ( ) } ,${ options . tile . getGridY ( ) } ] ` +
157176 tileTypes +
158177 ( options . tile . hasRiver ( ) ? ", River" : "" )
159178 ) ;
179+
180+
181+
182+ this . tileInformationLabel . conformSize ( ) . then ( ( ) => {
183+ // Positioning for icons (right after the label)
184+ let iconX = this . tileInformationLabel . getX ( ) + this . tileInformationLabel . getWidth ( ) ;
185+ const iconY = this . tileInformationLabel . getY ( ) - 10 ;
186+
187+ if ( yields ) {
188+ for ( const [ key , value ] of Object . entries ( yields ) ) {
189+ if ( typeof value === "number" && value > 0 && statSpriteRegions [ key ] ) {
190+ // Create icon actor
191+ const iconActor = new Actor ( {
192+ image : Game . getInstance ( ) . getImage ( GameImage . SPRITESHEET ) ,
193+ spriteRegion : statSpriteRegions [ key ] ,
194+ x : iconX ,
195+ y : iconY ,
196+ width : 32 ,
197+ height : 32 ,
198+ z : 10 ,
199+ cameraApplies : false
200+ } ) ;
201+ this . addActor ( iconActor ) ;
202+ this . tileYieldActors . push ( iconActor ) ;
203+
204+ // Create value label
205+ const valueLabel = new Label ( {
206+ text : value . toString ( ) ,
207+ font : "16px serif" ,
208+ fontColor : "white" ,
209+ shadowColor : "black" ,
210+ lineWidth : 4 ,
211+ x : iconX + iconActor . getWidth ( ) - 6 ,
212+ y : this . tileInformationLabel . getY ( ) ,
213+ z : 10
214+ } ) ;
215+ this . addActor ( valueLabel ) ;
216+ this . tileYieldActors . push ( valueLabel ) ;
217+
218+ // Move X for next icon
219+ iconX += 42 ;
220+ }
221+ }
222+ }
223+ } ) ;
224+
160225 }
161226 } ) ;
162227 //DEBUG top layer chunks -
@@ -237,6 +302,10 @@ export class InGameScene extends Scene {
237302
238303 this . removeActor ( this . nextTurnButton ) ;
239304 this . removeActor ( this . tileInformationLabel ) ;
305+ this . tileInformationLabel . setText ( "" ) ;
306+ this . tileYieldActors . forEach ( ( actor ) => {
307+ this . removeActor ( actor ) ;
308+ } ) ;
240309
241310 this . addActor ( this . closeCityDisplayButton ) ;
242311 }
0 commit comments