lance-gg / lance

Multiplayer game server based on Node.JS
https://lance-gg.github.io/
Apache License 2.0
1.57k stars 165 forks source link

playerId vs id: update docs #121

Closed momander closed 5 years ago

momander commented 5 years ago

The doc for GameEngine.playerId says:

client's player ID, as a string. If running on the client, this is set at runtime by the clientEngine

This is confusing. I thought at first that this meant the id property of the GameObject. It seems it refers to the playerId property of the GameObject. But that property is not listed in the doc for GameObject, so there is no way of finding out about it, short of reading the code.

How to fix:

  1. Document GameObject.playerId and point to it from the doc for GameEngine.playerId.

  2. In other bug reports I have seen talk of an ownerId property. That is perhaps a better name, as it seems one player can own many GameObjects? If the switch is made to ownerId, update the docs for GameEngine and GameObject.

namel commented 5 years ago

The playerId is a unique id which is assigned to each player. GameObject.playerId is a reference to the current player. So GameObject.playerId should reference GameEngine.playerId (rather than the other way around).

I considered renaming GameObject.playerId to GameObject.ownerId but that proposal has its own disadvantage: then the attributes have different names and their relation is not as obvious. GameObject.owningPlayerID is clearer, but it's a bit long.

In any case, the code did not implement playerId in the base object GameObject, rather it was added separately to each subclass (DynamicObject, PhysicalObject2D, and PhysicalObject3D). That should be fixed.