Skip to content

Commit

Permalink
Merge pull request #3 from tsanth/grass-disappearing-on-switch-fix
Browse files Browse the repository at this point in the history
Code now fixes/guards against negative saved grass (i.e. fix disappearing grass)
  • Loading branch information
Icecreamdudes authored Oct 11, 2024
2 parents fdb1a8a + f02c6c8 commit 01881b4
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions js/grass.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,13 @@
},
loadGrass()
{
// savedGrass should never be negative!
if (player.g.savedGrass < 0) {
player.g.savedGrass = player.g.grassCount > 0
? player.g.grassCount
: 0
}

removeAllGrass();
createGrass(player.g.savedGrass);
player.g.grassCount = player.g.savedGrass
Expand Down Expand Up @@ -770,6 +777,16 @@
})

function createGrass(quantity) {
// This _shouldn't_ happen, but there existed cases where e.g.
// player.g.savedGrass somehow got a massively-negative number and
// as a result, the loop down below never finished.
// We now dump some info to console if this happens.
if (quantity < 0) {
console.log('%cCalled .../js/grass.js:createGrass with negative quantity!', 'color:red; font-size: 150%; font-weight: bold')
console.log(`%cInfo for the devs: fx: .../js/grass.js:createGrass; quantity: ${quantity}; player.g.grassCount ${player.g.grassCount}; player.g.savedGrass: ${player.g.savedGrass}`, 'color: yellow; font-size: 125%')
return
}

const spawnArea = document.getElementById('spawn-area');
const spawnAreaRect = spawnArea?.getBoundingClientRect();

Expand Down

0 comments on commit 01881b4

Please sign in to comment.