2021-12-01 09:48:11 +00:00
|
|
|
|
using System;
|
2021-11-26 17:36:14 +00:00
|
|
|
|
|
|
|
|
|
namespace QSB.Utility.VariableSync
|
|
|
|
|
{
|
2021-11-26 19:33:56 +00:00
|
|
|
|
public class VariableReference<T>
|
2021-11-26 17:36:14 +00:00
|
|
|
|
{
|
2021-12-01 09:48:11 +00:00
|
|
|
|
private BaseVariableSyncer _owner;
|
|
|
|
|
|
2021-11-26 22:31:52 +00:00
|
|
|
|
public Func<T> Getter;
|
|
|
|
|
public Action<T> Setter;
|
2021-11-26 17:36:14 +00:00
|
|
|
|
|
2021-12-01 09:48:11 +00:00
|
|
|
|
public VariableReference(BaseVariableSyncer owner)
|
|
|
|
|
=> _owner = owner;
|
|
|
|
|
|
2021-11-26 17:36:14 +00:00
|
|
|
|
public T Value
|
|
|
|
|
{
|
2021-11-26 22:31:52 +00:00
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (Getter != null)
|
|
|
|
|
{
|
|
|
|
|
return Getter();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2021-12-01 09:48:11 +00:00
|
|
|
|
if (_owner.Ready)
|
2021-11-26 22:31:52 +00:00
|
|
|
|
{
|
|
|
|
|
DebugLog.ToConsole($"Warning - Getter is null!", OWML.Common.MessageType.Warning);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return default;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (Setter != null)
|
|
|
|
|
{
|
|
|
|
|
Setter(value);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2021-12-01 09:48:11 +00:00
|
|
|
|
if (_owner.Ready)
|
2021-11-26 22:31:52 +00:00
|
|
|
|
{
|
|
|
|
|
DebugLog.ToConsole($"Warning - Setter is null!", OWML.Common.MessageType.Warning);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-11-26 17:36:14 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|