Open chromapid opened 2 years ago
Thank you for implementing this feature. Do you know what needs to be added to the frontend to complete this feature?
The frontend needs to be able to understand that operation trees that act on constants should be considered a single, valid operator (except for before DUP, but that could potentially change). I don't know how the checks are implemented front-end so I can't really give anything more specific than that.
Hello,
This implements compile time constant evaluation as specified in #139. Anywhere an integer is permitted, there can instead be an expression that acts on any combination of these. Operations include shifts, rotations, arithmetic, and bitwise operations. The issue was fairly open-ended, so I took a bit of creative liberty in some of the features it has and how it operates. The token-based parsing system is fairly flexible, so it would not be a large problem to modify it to fit a different syntax.
The DUP factor does not support expressions right now as the amount of space the directive takes up can be dependent on labels, which depend on positions. However, the value to be repeated does support it.
The in-game editor does not recognize it as valid syntax, but it compiles successfully and seems to run perfectly in game. On that note, I added some tests in src/test/java/net/simon987/mar/server/assembly/TokenTest.java. I commented out a couple existing test cases as they conflicted with constant expressions.
There were some minor fixes I made here and there to get it the typescript to compile successfully in src/main/typescript/World.ts and src/main/typescript/phaser.d.ts. These are independent changes and may be reverted with no effect if they cause problems with different typescript versions (I am using v4.5.4 from npm).