forked from nikita/muzika-gromche
Port to modern [Rpc] attribute
Method ChooseTrackServerRpc should never have been an RPC. Server will invoke it when it's the right time. And only server was calling it anyway.
This commit is contained in:
parent
28f63eff3d
commit
702eb9fccd
|
|
@ -2044,7 +2044,7 @@ namespace MuzikaGromche
|
|||
const string LoopAudioGameObjectName = "MuzikaGromcheAudio (Loop)";
|
||||
|
||||
// Number of times a selected track has been played.
|
||||
// Increases by 1 with each ChooseTrackServerRpc call.
|
||||
// Increases by 1 with each ChooseTrackOnServer call.
|
||||
// Resets on SettingChanged.
|
||||
private int SelectedTrackIndex = 0;
|
||||
|
||||
|
|
@ -2108,6 +2108,7 @@ namespace MuzikaGromche
|
|||
|
||||
public override void OnNetworkSpawn()
|
||||
{
|
||||
HostIsModded = IsServer;
|
||||
ChooseTrackDeferred();
|
||||
foreach (var track in Plugin.Tracks)
|
||||
{
|
||||
|
|
@ -2159,7 +2160,8 @@ namespace MuzikaGromche
|
|||
}
|
||||
|
||||
// Once host has set a track via RPC, it is considered modded, and expected to always set tracks, so never reset this flag back to false.
|
||||
bool HostIsModded = false;
|
||||
// Initialized to `IsServer` on network spawn. If I am the host, then I am modded, otherwise we'll find out later.
|
||||
bool HostIsModded;
|
||||
|
||||
// Playing with modded host automatically disables vanilla compatability mode
|
||||
public bool VanillaCompatMode => IsServer ? Config.VanillaCompatMode : !HostIsModded;
|
||||
|
|
@ -2173,12 +2175,12 @@ namespace MuzikaGromche
|
|||
|
||||
if (Config.VanillaCompatMode)
|
||||
{
|
||||
// In vanilla compat mode no, matter whether you are a host or a client, you should skip networking anyway
|
||||
// In vanilla compat mode, no matter whether you are a host or a client, you should skip networking anyway
|
||||
ChooseTrackCompat();
|
||||
}
|
||||
else if (IsServer)
|
||||
{
|
||||
ChooseTrackServerRpc();
|
||||
ChooseTrackOnServer();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -2195,7 +2197,7 @@ namespace MuzikaGromche
|
|||
}
|
||||
}
|
||||
|
||||
[ClientRpc]
|
||||
[Rpc(SendTo.Everyone)]
|
||||
void SetTrackClientRpc(string name)
|
||||
{
|
||||
Plugin.Log.LogDebug($"SetTrackClientRpc {name}");
|
||||
|
|
@ -2218,12 +2220,11 @@ namespace MuzikaGromche
|
|||
}
|
||||
}
|
||||
|
||||
[ServerRpc]
|
||||
void ChooseTrackServerRpc()
|
||||
void ChooseTrackOnServer()
|
||||
{
|
||||
var selectableTrack = Plugin.ChooseTrack();
|
||||
var audioTrack = selectableTrack.SelectTrack(SelectedTrackIndex);
|
||||
Plugin.Log.LogInfo($"ChooseTrackServerRpc {selectableTrack.Name} #{SelectedTrackIndex} {audioTrack.Name}");
|
||||
Plugin.Log.LogInfo($"ChooseTrackOnServer {selectableTrack.Name} #{SelectedTrackIndex} {audioTrack.Name}");
|
||||
SetTrackClientRpc(audioTrack.Name);
|
||||
SelectedTrackIndex += 1;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue