Skip to content
This repository has been archived by the owner on Feb 23, 2023. It is now read-only.

Interacting with EitherType #111

Closed
IkonOne opened this issue Mar 3, 2017 · 5 comments
Closed

Interacting with EitherType #111

IkonOne opened this issue Mar 3, 2017 · 5 comments

Comments

@IkonOne
Copy link
Contributor

IkonOne commented Mar 3, 2017

There are multiple instances of EitherType being used. What would be the ideal method of retrieving the value of a variable that is of EitherType? I am specifically looking at the hitArea of an Interactive Target:

var hitArea: EitherType< Rectangle,

As far as I can tell at the moment, it is impossible? When using haxe.ds.Either, you can at least use a switch with Left and Right, but that doesn't work in this case.

Thank you for your guidance and work on this project.

@IkonOne
Copy link
Contributor Author

IkonOne commented Mar 4, 2017

Hi, I figured it out: http://try.haxe.org/#e07B7

If there is a better method, I'm all ears, but this doesn't seem too bad.

@IkonOne IkonOne closed this as completed Mar 4, 2017
@IkonOne
Copy link
Contributor Author

IkonOne commented Mar 4, 2017

Actually, that doesn't work.

In the proposed solution, I was using Type.getClass to get the class of the hitArea of an InteractiveTarget at runtime. Unfortunately, there is no type information for pixi classes at runtime so this will never work.

@IkonOne IkonOne reopened this Mar 4, 2017
@IkonOne
Copy link
Contributor Author

IkonOne commented Mar 4, 2017

OK. Here is a hacky working solution. Since I am trying to specifically access the InteractiveTarget.hitArea member, this works.

Solution: http://try.haxe.org/#4f078

This shouldn't actually work but since pixi has a 'type' member in all of the Shape classes, I can take advantage of that. If there are any instances of using EitherType that don't have something like this, this method will likely fail. Because of this, I am going to leave the issue open as a better solution should be found.

EitherType seems to be ok for function parameters, but when using it for variables, it renders the variables almost unusable without hacks.

@IkonOne
Copy link
Contributor Author

IkonOne commented Mar 4, 2017

I'm closing this again. The above solution is not really as hacky as I originally thought. The pixi Shapes all have the 'type' member variable so that instanceof (Std.is in haxe) doesn't have to be used. While Std.is still works, casting the hitArea to a typedef with a 'type' member variable is an effective solution.

For anyone curious, here is a try.haxe that illustrates what does and doesn't work with EitherType: http://try.haxe.org/#B0783

@modjke
Copy link
Contributor

modjke commented Mar 6, 2017

Here ya go, mate :) #113

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

No branches or pull requests

2 participants