diff --git a/js/sim/Simulations.js b/js/sim/Simulations.js index fb0e95b..4eef2ba 100644 --- a/js/sim/Simulations.js +++ b/js/sim/Simulations.js @@ -433,9 +433,11 @@ function Sim(config){ //////////////////////// self.STEP = 0; + self.STEP_AT_LAST_CALL = -1; self.save = function(){ self.STEP = 0; + self.STEP_AT_LAST_CALL = -1; self.networkConfig = self.getCurrentNetwork(); }; @@ -444,6 +446,7 @@ function Sim(config){ self.reload = function(){ var contagionLevel = self.contagion; // hack for sandbox: keep contagion the same self.STEP = 0; + self.STEP_AT_LAST_CALL = -1; self._canPlayBonkSound = true; self.init(); self.contagion = contagionLevel; @@ -451,6 +454,11 @@ function Sim(config){ self.nextStep = function(){ + // STEP++ is time-based; nextStep() is frame-based. This check ensures + // one nextStep() per STEP to avoid duplicate animations and infections. + if(self.STEP == self.STEP_AT_LAST_CALL) return; + self.STEP_AT_LAST_CALL = self.STEP; + // SOUND! If anyone can be infected, play Contagion sound. // Otherwise play Bonk sound ONCE var canBeInfected = self.peeps.filter(function(peep){