@@ -2,8 +2,11 @@ import {
22 AllPlayers ,
33 Cell ,
44 Game ,
5+ NukeType ,
6+ nukeTypes ,
57 Player ,
68 PlayerType ,
9+ UnitType ,
710} from "../../../core/game/Game" ;
811import { PseudoRandom } from "../../../core/PseudoRandom" ;
912import { Theme } from "../../../core/configuration/Config" ;
@@ -15,6 +18,8 @@ import allianceRequestIcon from "../../../../resources/images/AllianceRequestIco
1518import crownIcon from "../../../../resources/images/CrownIcon.svg" ;
1619import targetIcon from "../../../../resources/images/TargetIcon.svg" ;
1720import embargoIcon from "../../../../resources/images/EmbargoIcon.svg" ;
21+ import nukeWhiteIcon from "../../../../resources/images/NukeIconWhite.svg" ;
22+ import nukeRedIcon from "../../../../resources/images/NukeIconRed.svg" ;
1823import { ClientID } from "../../../core/Schemas" ;
1924import { GameView , PlayerView } from "../../../core/game/GameView" ;
2025import { createCanvas , renderTroops } from "../../Utils" ;
@@ -47,6 +52,8 @@ export class NameLayer implements Layer {
4752 private targetIconImage : HTMLImageElement ;
4853 private crownIconImage : HTMLImageElement ;
4954 private embargoIconImage : HTMLImageElement ;
55+ private nukeWhiteIconImage : HTMLImageElement ;
56+ private nukeRedIconImage : HTMLImageElement ;
5057 private container : HTMLDivElement ;
5158 private myPlayer : PlayerView | null = null ;
5259 private firstPlace : PlayerView | null = null ;
@@ -69,6 +76,10 @@ export class NameLayer implements Layer {
6976 this . targetIconImage . src = targetIcon ;
7077 this . embargoIconImage = new Image ( ) ;
7178 this . embargoIconImage . src = embargoIcon ;
79+ this . nukeWhiteIconImage = new Image ( ) ;
80+ this . nukeWhiteIconImage . src = nukeWhiteIcon ;
81+ this . nukeRedIconImage = new Image ( ) ;
82+ this . nukeRedIconImage . src = nukeRedIcon ;
7283 }
7384
7485 resizeCanvas ( ) {
@@ -405,6 +416,47 @@ export class NameLayer implements Layer {
405416 existingEmbargo . remove ( ) ;
406417 }
407418
419+ const nukesSentByOtherPlayer = this . game . units ( ) . filter ( ( unit ) => {
420+ const isSendingNuke = render . player . id ( ) == unit . owner ( ) . id ( ) ;
421+ const notMyPlayer = unit . owner ( ) . id ( ) != myPlayer . id ( ) ;
422+ return (
423+ nukeTypes . includes ( unit . type ( ) ) &&
424+ isSendingNuke &&
425+ notMyPlayer &&
426+ unit . isActive ( )
427+ ) ;
428+ } ) ;
429+ const isMyPlayerTarget = nukesSentByOtherPlayer . find ( ( unit ) => {
430+ const detonationDst = unit . detonationDst ( ) ;
431+ const targetId = this . game . owner ( detonationDst ) . id ( ) ;
432+ return targetId == this . myPlayer . id ( ) ;
433+ } ) ;
434+ const existingNuke = iconsDiv . querySelector (
435+ '[data-icon="nuke"]' ,
436+ ) as HTMLImageElement ;
437+
438+ if ( existingNuke ) {
439+ if ( nukesSentByOtherPlayer . length == 0 ) {
440+ existingNuke . remove ( ) ;
441+ } else if (
442+ isMyPlayerTarget &&
443+ existingNuke . src != this . nukeRedIconImage . src
444+ ) {
445+ existingNuke . src = this . nukeRedIconImage . src ;
446+ } else if (
447+ ! isMyPlayerTarget &&
448+ existingNuke . src != this . nukeWhiteIconImage . src
449+ ) {
450+ existingNuke . src = this . nukeWhiteIconImage . src ;
451+ }
452+ } else if ( myPlayer && nukesSentByOtherPlayer . length > 0 ) {
453+ if ( ! existingNuke ) {
454+ const icon = isMyPlayerTarget
455+ ? this . nukeRedIconImage . src
456+ : this . nukeWhiteIconImage . src ;
457+ iconsDiv . appendChild ( this . createIconElement ( icon , iconSize , "nuke" ) ) ;
458+ }
459+ }
408460 // Update all icon sizes
409461 const icons = iconsDiv . getElementsByTagName ( "img" ) ;
410462 for ( const icon of icons ) {
0 commit comments