Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Angle and Vector types #24

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

Conversation

Halithor
Copy link
Contributor

@Halithor Halithor commented Nov 23, 2020

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 😄

export const radians = Angle.fromRadians;
export const randomAngle = Angle.random;

export class Vec2 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are all classes in one file? Should be split.

Copy link
Contributor Author

@Halithor Halithor Nov 23, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wrote these classes originally in separate files, but for some reason when I added the angleTo method on the vec2, games were crashing before getting to the load screen (I think this means invalid Lua in the map's Lua). I spent some time trying to figure it out, but nothing solved the issue except moving them into the same file.

If you have some ideas on why this was happening, I'm all ears to try again.

@cipherxof
Copy link
Owner

cipherxof commented Nov 23, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants