Allow a Drone to be created from the location and direction of another Drone#323
Conversation
|
I don't know how much time @walterhiggins has for evaluation of PRs but please don't lose faith. There's a lot going on and we simply have too much to do and not enough time. But your contribution won't be ignored or lost. Thanks. |
|
It took a while to get through this to ensure that the new drone is still correctly created. The Drone constructor function isn't very elegant in how it checks args, or for self, and now for Drone. At some point it would be nice to clean it up a little, perhaps to get a new Drone from other object types. There's some elegance to being able to clone a drone so I don't see anything wrong with this enhancement. However, the first parameter of the constructor can already be a Location object. The drone doesn't have a "location", it has properties that would otherwise be included in a location object. For this mod we're adding support for a concrete type Drone, where it would probably be better to give the Drone type a Location. Then we could use: ... and other code that wants the Drone's location could also be more standardized. It would allow for code like: With the current change, I'm also updating the inline doc to show that a Drone can be passed as a constructor parameter, but that wouldn't be necessary if Drone had a Location. The support for a Drone object in the constructor, and related documentation, has been incorporated into working code set 3.2.2 Bad Zombie. But I'll leave this PR open for comments from @walterhiggins and anyone else who may wish to contribute. |
|
Thanks for adding this.
The constructor currently does need refactoring because the amount of effort it took me to debug and find out which path the code was taking was mental. The issue seemed to be that location itself had 2 different forms, one with a dir attribute and one with a direction attribute where the values I believe are dependent on the type of server you are running.
As such if the code is to be refactored then may I suggest a utility method to be able to create a drone from various types of locations or indeed from another drone. By doing this any plugin could simply call say Drone.fromLocation (a static utility method in java speak) and generate a drone. That way plugins don't need to understand the underlying implementation of the various location related objects managed by Scriptcraft.
…On 20 August 2017 21:13:55 BST, Tony Gravagno ***@***.***> wrote:
It took a while to get through this to ensure that the new drone is
still correctly created. The Drone constructor function isn't very
elegant in how it checks args, or for self, and now for Drone. At some
point it would be nice to clean it up a little, perhaps to get a new
Drone from other object types.
There's some elegance to being able to clone a drone so I don't see
anything wrong with this enhancement. However, the first parameter of
the constructor can already be a Location object. The drone doesn't
have a "location", it has properties that would otherwise be included
in a location object. For this mod we're adding support for a concrete
type Drone, where it would probably be better to give the Drone type a
Location. Then we could use:
var clone = new Drone(original.location);
... and other code that wants the Drone's location could also be more
standardized. It would allow for code like:
var angleRadians =
drone.location.getVector().angle(townCenter.location.getVector());
With the current change, I'm also updating the inline doc to show that
a Drone can be passed as a constructor parameter, but that wouldn't be
necessary if Drone had a Location.
The support for a Drone object in the constructor, and related
documentation, has been incorporated into working code set [3.2.2 Bad
Zombie](https://github.com/TonyGravagno/ScriptCraft/tree/bad-zombie).
But I'll leave this PR open for comments from @walterhiggins and anyone
else who may wish to contribute.
--
You are receiving this because you authored the thread.
Reply to this email directly or view it on GitHub:
#323 (comment)
--
Sent from my Android device with K-9 Mail. Please excuse my brevity.
|
|
Actually looking at the code again I cannot see the location.dir / location.direction thing I mentioned earlier but it could still make sense to be able to create a new Drone using a utility method which takes as a parameter any of the location related objects. |
In my pursuit for creating more comprehensive worlds I need to be able to spin Drones off from the current position of another Drone without affecting the first one in any way.