@@ -111,8 +111,13 @@ export class DemoApp {
111111 startCustomBtn . addEventListener ( 'click' , ( e ) => {
112112 e . preventDefault ( ) ;
113113 e . stopPropagation ( ) ;
114- console . log ( 'Start Custom Battle clicked' ) ;
115- if ( ! this . isRunning ) {
114+ if ( this . isRunning ) {
115+ // Stop battle
116+ console . log ( 'Stop Battle clicked' ) ;
117+ this . stopBattle ( ) ;
118+ } else {
119+ // Start battle
120+ console . log ( 'Start Custom Battle clicked' ) ;
116121 this . runCustomBattle ( ) ;
117122 }
118123 } ) ;
@@ -435,11 +440,11 @@ export class DemoApp {
435440 this . setStatus ( 'loading' , i18n . t ( 'status.running' , { scenario : 'Custom' } ) ) ;
436441 this . clearOutput ( ) ;
437442
438- // Update button state to show running
443+ // Update button state to show stop option
439444 const startBtn = document . getElementById ( 'startCustomBattle' ) ;
440445 if ( startBtn ) {
441446 startBtn . classList . add ( 'running' ) ;
442- startBtn . querySelector ( '.label' ) ! . textContent = '⚔ ️ ' + i18n . t ( 'custom.running ' ) ;
447+ startBtn . querySelector ( '.label' ) ! . textContent = '⏹ ️ ' + i18n . t ( 'custom.stop ' ) ;
443448 }
444449
445450 // Show and update character view
@@ -486,6 +491,7 @@ export class DemoApp {
486491 // Check if should stop
487492 if ( this . shouldStop ) {
488493 console . log ( 'Simulation stopped by user' ) ;
494+ this . setStatus ( 'success' , i18n . t ( 'status.stopped' ) ) ;
489495 return ;
490496 }
491497
@@ -515,6 +521,7 @@ export class DemoApp {
515521 // Check if stopped during animation
516522 if ( this . shouldStop ) {
517523 console . log ( 'Simulation stopped during battle animation' ) ;
524+ this . setStatus ( 'success' , i18n . t ( 'status.stopped' ) ) ;
518525 return ;
519526 }
520527 } else {
@@ -619,12 +626,16 @@ ${i18n.t('status.battleDetails.hp', { hp: Math.round(lastResult.battleData[lastR
619626 if ( progressContainer ) progressContainer . style . display = 'none' ;
620627 } finally {
621628 this . isRunning = false ;
629+ this . shouldStop = false ;
622630 // Reset button state
623631 const startBtn = document . getElementById ( 'startCustomBattle' ) ;
624632 if ( startBtn ) {
625633 startBtn . classList . remove ( 'running' ) ;
626634 startBtn . querySelector ( '.label' ) ! . textContent = '⚔️ ' + i18n . t ( 'custom.start' ) ;
627635 }
636+ // Hide progress bar
637+ const progressContainer = document . getElementById ( 'customProgress' ) ;
638+ if ( progressContainer ) progressContainer . style . display = 'none' ;
628639 }
629640 }
630641
@@ -903,6 +914,15 @@ ${i18n.t('status.battleDetails.footer')}
903914 }
904915 }
905916
917+ private stopBattle ( ) {
918+ if ( ! this . isRunning ) return ;
919+
920+ this . shouldStop = true ;
921+ this . setStatus ( 'loading' , i18n . t ( 'status.stopping' ) ) ;
922+
923+ // Button will be reset when the battle loop detects shouldStop
924+ }
925+
906926 private levelWarningToast : HTMLElement | null = null ;
907927 private levelWarningTimer : number | null = null ;
908928
0 commit comments