w3ts icon indicating copy to clipboard operation
w3ts copied to clipboard

Add Angle and Vector types

Open Halithor opened this issue 5 years ago • 1 comments

Add a math folder with types file to contain useful types for basic spatial mathematics.

The Angle type can be used to abstract the problem of degrees versus radians in the Warcraft III API, since it inconsistently uses angular units. Changing the type of Unit.setFacing(value: number) to Unit.setFacing(value: Angle) would allow the library to know that the SetUnitFacing() takes an angle in degrees.

The Vectors are useful as they can store a location, but not require explicit cleanup. Instead the Lua memory management will cleanup vectors, lowering the usage burden. They also have useful functionality and can have more WC3 specific functionality added.

I'd like to follow this PR up with another that replaces all usages of the Point class, plain x&y number arguments, and raw number angles with these strongly typed alternatives, but this would be a big breaking change. What are your thoughts @cipherxof ?

Having the well typed angles and vectors is something I've missed from Wurst, so I wanted to add them to this library 😄

Halithor avatar Nov 23 '20 07:11 Halithor

I'd like to follow this PR up with another that replaces all usages of the Point class, plain x&y number arguments, and raw number angles with these strongly typed alternatives, but this would be a big breaking change.

I want to try and hold off on breaking changes at least until I publish the next version of w3ts, but you can start the PR in the meantime. Although I think using coordinates and Point should still be an option, so it shouldn't be a breaking change.

games were crashing before getting to the load screen

Check your log file in Documents\Warcraft III\Logs\War3Log.txt. It should notify you of any script errors towards the bottom of the log. I would also prefer having classes in separate files.

cipherxof avatar Nov 23 '20 23:11 cipherxof