saviola777 / hhm-plugins

Plugins for the Haxball Headless Manager (HHM).
MIT License
3 stars 5 forks source link

Make `sav/players` not add the id to player name by default #4

Closed morko closed 5 years ago

morko commented 5 years ago

Adding id to the player name is great idea but modifying the player objects name property by default is not.

When developing it is expected that the name property does not contain any extra markup and unexpected errors can happen when e.g. when comparing names with the names in room.getPlayerList (where names do not contain id).

In my opinion addPlayerIdToNickname should be false by default and if true, then id should be added to the players in room.getPlayerList() aswell.

saviola777 commented 5 years ago

Okay, I will change the default to false, but I'm not sure what you mean with room.getPlayerList, the player objects returned by that function are the same as the ones from getPlayer, so they also contain the ID.

morko commented 5 years ago

Sorry. You are right about room.getPlayerList returning the post fixed names. What I was supposed to write about is the situation when you want to match the names in the chat against the playerlist to find the player. Because the name might be post fixed or not post fixed it would make the following function more complex and confused me for a while because by default it added the id there.

 function getPlayerWithName(pName) {
    pName = pName.startsWith('@') ? pName.slice(1) : pName;
    let player = room.getPlayerList().find((p) => p.name === pName);
    return player;
  }
saviola777 commented 5 years ago

Ah yeah, I see. Maybe the whole idea is bad, I think I will remove this feature and make it an option for the chat display only. I could of course add a pre-event handler hook which automatically fixes names in incoming messages, but… nah, let's not go there. :D