leopard-js / leopard

Library for making Scratch-like projects with JavaScript.
https://leopardjs.com
MIT License
136 stars 26 forks source link

Don't error when setting costume number to zero #160

Closed towerofnix closed 1 year ago

towerofnix commented 1 year ago

This fixes errors to do with setting a sprite's costume number to zero or below, using two approaches:

The latter part improves compatibility: in Scratch, a sprite's costume number wraps on both ends of its bounding range, > this.costumes.length and <= 0. In Leopard, we were only properly wrapping on the positive end — this PR fixes that with the same wrap algorithm used in scratch-vm.

Thanks, @tmickel :P LLK/scratch-vm#87

towerofnix commented 1 year ago

I've reverted the commit which affects the renderer because I'm not well familiar with the code paths and it's not necessary to change the renderer to avoid the circumstance which brought about errors there.