mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-14 19:29:36 +01:00
Make VV work with structs in components (#6377)
* Make VV work with structs in components * Fix missing imports
This commit is contained in:
@@ -56,7 +56,7 @@ internal sealed class ViewVariableControlFactory : IViewVariableControlFactory
|
||||
RegisterForType<TimeSpan>(_ => new VVPropEditorTimeSpan());
|
||||
|
||||
RegisterWithCondition(
|
||||
type => type != typeof(ViewVariablesBlobMembers.ServerValueTypeToken) && !type.IsValueType,
|
||||
type => type != typeof(ViewVariablesBlobMembers.ServerValueTypeToken),
|
||||
_ => new VVPropEditorReference()
|
||||
);
|
||||
RegisterWithCondition(
|
||||
|
||||
@@ -12,5 +12,6 @@ namespace Robust.Server.ViewVariables
|
||||
object Object { get; }
|
||||
uint SessionId { get; }
|
||||
Type ObjectType { get; }
|
||||
Action<object>? ObjectChangeDelegate { get; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Robust.Server.Console;
|
||||
using Robust.Server.Player;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.Enums;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
@@ -138,6 +137,7 @@ namespace Robust.Server.ViewVariables
|
||||
}
|
||||
|
||||
object theObject;
|
||||
Action<object>? objectChangeDelegate = null;
|
||||
|
||||
switch (message.Selector)
|
||||
{
|
||||
@@ -200,13 +200,14 @@ namespace Robust.Server.ViewVariables
|
||||
return;
|
||||
}
|
||||
|
||||
if (value == null || value.GetType().IsValueType)
|
||||
if (value == null)
|
||||
{
|
||||
Deny(ViewVariablesResponseCode.NoObject);
|
||||
return;
|
||||
}
|
||||
|
||||
theObject = value;
|
||||
objectChangeDelegate = obj => relSession.Modify(sessionRelativeSelector.PropertyIndex, obj);
|
||||
break;
|
||||
}
|
||||
case ViewVariablesIoCSelector ioCSelector:
|
||||
@@ -250,7 +251,7 @@ namespace Robust.Server.ViewVariables
|
||||
}
|
||||
|
||||
var sessionId = _nextSessionId++;
|
||||
var session = new ViewVariablesSession(message.MsgChannel.UserId, theObject, sessionId, this,
|
||||
var session = new ViewVariablesSession(message.MsgChannel.UserId, theObject, objectChangeDelegate, sessionId, this,
|
||||
_robustSerializer, _entityManager, Sawmill);
|
||||
|
||||
_sessions.Add(sessionId, session);
|
||||
|
||||
@@ -2,7 +2,6 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Log;
|
||||
using Robust.Shared.Prototypes;
|
||||
@@ -198,6 +197,8 @@ namespace Robust.Server.ViewVariables.Traits
|
||||
try
|
||||
{
|
||||
field.SetValue(Session.Object, value);
|
||||
Session.ObjectChangeDelegate?.Invoke(Session.Object);
|
||||
|
||||
return true;
|
||||
}
|
||||
catch (Exception e)
|
||||
|
||||
@@ -22,6 +22,7 @@ namespace Robust.Server.ViewVariables
|
||||
public object Object { get; }
|
||||
public uint SessionId { get; }
|
||||
public Type ObjectType { get; }
|
||||
public Action<object>? ObjectChangeDelegate { get; }
|
||||
|
||||
/// <param name="playerUser">The session ID of the player who opened this session.</param>
|
||||
/// <param name="o">The object we represent.</param>
|
||||
@@ -29,13 +30,14 @@ namespace Robust.Server.ViewVariables
|
||||
/// The session ID for this session. This is what the server and client use to talk about this session.
|
||||
/// </param>
|
||||
/// <param name="host">The view variables host owning this session.</param>
|
||||
public ViewVariablesSession(NetUserId playerUser, object o, uint sessionId, IServerViewVariablesInternal host,
|
||||
public ViewVariablesSession(NetUserId playerUser, object o, Action<object>? objectChangeDelegate, uint sessionId, IServerViewVariablesInternal host,
|
||||
IRobustSerializer robustSerializer, IEntityManager entMan, ISawmill logger)
|
||||
{
|
||||
PlayerUser = playerUser;
|
||||
Object = o;
|
||||
SessionId = sessionId;
|
||||
ObjectType = o.GetType();
|
||||
ObjectChangeDelegate = objectChangeDelegate;
|
||||
Host = host;
|
||||
RobustSerializer = robustSerializer;
|
||||
EntityManager = entMan;
|
||||
|
||||
Reference in New Issue
Block a user