Open hakusaro opened 6 years ago
It would be a lot simpler if the naming within the game's code was akin to Minecraft's (or CraftBukkit's? I don't remember) - CraftPlayer
can then be wrapped by the generic Player
, and the entire conflict would be gone.
It would be nice if OTAPI/TSAPI could enforce this (name terraria player objects TPlayer or TerraPlayer) so that we can have the generic tshock player object named "Player" without conflicts.
If we cannot get this benefit, I think that renaming TSPlayer to something without a T (WrappedPlayer
perhaps? idk) and then making the 'native player' named TPlayer/Player could work?
Or we can take example from CBukkit and just make it a .Handle or .Native getter to get the "native" "handle" to the player.
I can't decide which would work better. I'd personally opt with version 1 if @DeathCradle can arrange that, then if that's impossible - version 3 [more familiar to devs from other backgrounds] and then as a last resort version2. This will be a breaking change for all plugins though. [let's break it this too right now, if the next release breaks a lot anyway]
I'm not sure that we ever discussed this when implementing it. Are
TSPlayer
andTPlayer
really the best names forTSPlayer
andPlayer
objects, respectively?I understand that there's some level of verbosity we avoid in spelling out what objects are. However, I think it's probably really counterintuitive to new developers who look at this codebase what's going on. You can get really great references too:
Player
object namedTPlayer
from aTSPlayer
object namedPlayer
.TSPlayer
and aTPlayer
in the same block of code, such that you can mis-read one as the other.Finally, though this isn't part of a discussion, we should really clarify how to canonically refer to players we're passing around. Right now, we have three really brilliant ways of doing nearly the same thing:
TSPlayer
objects (which containPlayer
objects namedTPlayer
).Player
objects (each of which obviously doesn't contain aTSPlayer
).int player
or equivalent, the index that the player is in the array inTerraria.Main
.In my opinion, I think we should:
T
. This makes it easy to distinguish between the two objects in code.TSPlayer
objects. If we're reading raw net code, we should never pass another method a TerrariaPlayer
or an index to a Terraria player.This all comes down to usability. We need to expose hooks consistently and pass data around consistently. A lot of the newer code already passes around the right object (
TSPlayer
) but a lot of legacy code swaps around player indexes like they're going out of style.