mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-14 19:29:36 +01:00
Change state manager methods to return the new state
This commit is contained in:
@@ -8,8 +8,8 @@ namespace Robust.Client.State
|
||||
event Action<StateChangedEventArgs> OnStateChanged;
|
||||
|
||||
State CurrentState { get; }
|
||||
void RequestStateChange<T>() where T : State, new();
|
||||
T RequestStateChange<T>() where T : State, new();
|
||||
void FrameUpdate(FrameEventArgs e);
|
||||
void RequestStateChange(Type type);
|
||||
State RequestStateChange(Type type);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using Robust.Shared.Log;
|
||||
using System;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Log;
|
||||
using Robust.Shared.Timing;
|
||||
|
||||
namespace Robust.Client.State
|
||||
@@ -22,23 +22,20 @@ namespace Robust.Client.State
|
||||
CurrentState?.FrameUpdate(e);
|
||||
}
|
||||
|
||||
public void RequestStateChange<T>() where T : State, new()
|
||||
public T RequestStateChange<T>() where T : State, new()
|
||||
{
|
||||
RequestStateChange(typeof(T));
|
||||
return (T) RequestStateChange(typeof(T));
|
||||
}
|
||||
|
||||
public void RequestStateChange(Type type)
|
||||
public State RequestStateChange(Type type)
|
||||
{
|
||||
if(!typeof(State).IsAssignableFrom(type))
|
||||
throw new ArgumentException($"Needs to be derived from {typeof(State).FullName}", nameof(type));
|
||||
|
||||
if (CurrentState?.GetType() != type)
|
||||
{
|
||||
SwitchToState(type);
|
||||
}
|
||||
return CurrentState?.GetType() == type ? CurrentState : SwitchToState(type);
|
||||
}
|
||||
|
||||
private void SwitchToState(Type type)
|
||||
private State SwitchToState(Type type)
|
||||
{
|
||||
Logger.Debug($"Switching to state {type}");
|
||||
|
||||
@@ -51,6 +48,8 @@ namespace Robust.Client.State
|
||||
CurrentState.Startup();
|
||||
|
||||
OnStateChanged?.Invoke(new StateChangedEventArgs(old, CurrentState));
|
||||
|
||||
return CurrentState;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user