Closed towerofnix closed 1 year ago
I'll try to take a look at this later today. Would you mind rebasing it on top of the main branch since #89 is merged?
EDIT: I can also rebase it and push onto your branch if that's easier
Rebase done!
All PR's approved so this is good to go! π
This pull request does... a whole lot!!! Sorry, not sorry, I usually don't do monolithic PRs but sometimes you gotta take what you can get. π»
This PR builds off of #89. To isolate this PR's changes before that PR is merged: https://github.com/towerofnix/sb-edit/compare/var-ids...towerofnix:sb-edit:compat
Major changes summarized:
desiredInputShape
feature exists so that inputs are casted as needed (improves Scratch compatibility) and can be mutated from withinblockToJs
, providing custom equivalent-behavior forms to improve code legibility.any
,index
,number
,string
,boolean
,stack
(all strings)blockSource
variable instead of returning right away."number"
, conditionals always satisfy"boolean"
.index
desired input shape (which is for use in list and string indexing):satisfiesInputShape
toindex
(instead ofnumber
) if it was specially handledoperator_add
: If one of the values is a number and not a block (right-hand preferred), it is decremented by one, e.g.this.vars.list[this.vars.i + 1]
instead ofthis.vars.list[this.vars.i + 2 - 1]
; if the decremented value is just zero, returns the other side as-is, e.g.this.vars.list[this.vars.i]
instead ofthis.vars.i + 1 - 1]
data_itemnumoflist
: Does not do+ 1
if the desired input shape is index, e.g.this.vars.list[this.vars.indexOf(this.vars.foo)] = 42
instead ofthis.vars.list[this.vars.indexOf(this.vars.foo) + 1 - 1] = 42
this.vars.list[0]
instead ofthis.vars.list[1 - 1]
this.goto
andthis.glide
will work even if the input hasn't been casted to number, and so on. This could use some more investigation.this.compare()
Leopard-provided function for comparisons when neededCast.compare
function, implementation based on @apple502j's optimized code: https://github.com/LLK/scratch-vm/pull/2580>
or<
for numbers awkward.===
). I'm not sure this is exactly correct 100.00% of the time (particularly if Infinity is involved), but it should cover the vast majority of use cases.x === y
could be converted tox !== y
instead of!(x === y)
increase()
anddecrease()
"macros" for common operations, so that++
,--
,+=
, and-=
are all used as appropriate, instead of always using+=
++
and--
are disabled in most instances (only used fordata_setvariableto
and next costume/backdrop blocks), since they don't really fit the "feel" of changing tangible values β this matches existing Leopard behavior while allowing forthis.vars.i++
, which should feel more appropriate when treating variables as abstract datauniqueNameGenerator
and just spawn totally new generators when it makes sensethis.vars.i
,this.vars.i2
...this.vars.i12
,this.vars.i13
if you had 13 sprites with variables namedi
!sensing_of
) still works fine. There's no possibility for names to be duplicated within the same namespace!data_itemoflist
andoperator_letter_of
use the new helper functions to return an empty string when the index is out of rangeoperator_contains
,data_itemnumoflist
, anddata_listcontainsitem
use new helper functions for compatibility (parity with scratch-vmCast.compare
, most notably these are all case-insensitive)operator_mathop
uses new helper function for "tan" operation, Scratch has a custom implementationCostume
,Sprite
) β sprite names can't conflict with these!this
orthis.vars
), we also include a list of reserved JavaScript words β this avoids issues with custom block arguments with JS-reserved names such asfunction
orclass
.Target.blocks
was dubiously "flat" before, but only one level deep (e.g. "repeat 10" under a "forever" loop, but not "turn 15 degrees" under that "repeat 10"). This has been fixed, which is a sb-edit format change, but since this property seemed to be intended to flatten scripts in the first place, it seems more like a bug fix than a breaking interface change.step
are now passed through the watcher constructor.step
is 1 if "discrete", 0.01 otherwise. Scratch's default is discrete, only non-discrete if at least one of the bounds is written as a decimal e.g.1.00
β this is conveniently serialized info scratch-vm makes directly available instead of having to parse sliderMin/sliderMax ourselves (which is a number, not a string, anyway).This is a pretty big PR, but by covering a lot of ground, it should go a long way to make the output of Leopard more legible and usable as an actual basis for starting new projects from. This is what you get when I'm recovering from a cold and don't have anything better to do ^_^ (Except... sleep? It's almost 1AM? Oh, I'll hear none of that! π€)
Same as in the other PR: @adroitwhiz I've added you as a reviewer if you'd like to! If you're not interested or don't currently have the time, feel free to pass. πΎβ¨