Closed Energyxxer closed 2 years ago
https://github.com/JannisX11/snowstorm/blob/master/src/export.js#L354
I wonder what the best way to fix this is as I don't think MolangJS exposes an AST we could operate on. Hacking together a different fix based on pure string manipulation would probably be far too vulnerable to break due to changes to Molang itself. We could remove this for now and then see whether we can either add AST generation to MolangJS or pull in a different lib that can do this.
I think it's fine if complex expressions are not automatically clamped on export.
Whenever a particle is saved with Expression mode for color, it wraps the expression with
Math.clamp(, 0, 1)
, even if that expression is made up of several expressions and a return statement, causing a syntax error. It should only wrap the return value, not the entire field.Example (in the Red field of the color expression):
v.index = Math.mod((v.index ?? -1) + 1, 10); return v.index / 10;
After saving:
Math.clamp(v.index = Math.mod((v.index ?? -1) + 1, 10); return v.index / 10;, 0, 1)
Expected:
v.index = Math.mod((v.index ?? -1) + 1, 10); return Math.clamp(v.index / 10, 0, 1);
(or no change at all)