DoubleDeez / MDFramework

A multiplayer C# game framework for Godot 3.4 Mono.
https://discord.gg/UH49eHK
MIT License
76 stars 13 forks source link

GetOrCreatePlayerObject has useless assignment #5

Closed Beider closed 4 years ago

Beider commented 4 years ago

In MDGameSession.GetOrCreatePlayerObject(int PeerId) we have this line,

string PlayerName = String.Format(PlayerNameFormat, PeerId);

This variable is never used, simply assigned. This of course is not a big deal, however I would suggest that this should be added to the MDPlayerInfo by default as most multiplayer games require a name, this could also serve as a good example on how to replicate values.

Personally I added the following to my MDPlayerInfo:

private String _playerName = "UnkownPlayer";
[MDReplicated]
public string PlayerName
{
    get { return _playerName; }
    set {
        _playerName = value;
        this.GetGameSession().NotifyPlayerNameChanged(PeerId);
    }
}

In addition I added a new event to the MDGameSession,

public event PlayerEventHandler OnPlayerNameChanged = delegate {};
public void NotifyPlayerNameChanged(int peerId)
{
    OnPlayerNameChanged(peerId);
}

I think this is something that almost every multiplayer game needs and it also serves as a simple example on how you can replicate values and send out a notification.

DoubleDeez commented 4 years ago

Thanks @Beider !

Would you be able to create a PR for this?

Beider commented 4 years ago

Done.