using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using JetBrains.Annotations;
using Robust.Shared.GameObjects;
using Robust.Shared.Serialization;
#nullable disable
namespace Robust.Shared.ViewVariables
{
///
/// Data blob that gets sent from server to client to display a VV window for a remote object.
/// These blobs should be requested with a specific .
///
[Serializable, NetSerializable]
public abstract class ViewVariablesBlob
{
}
///
/// Contains the fundamental metadata for an object, such as type, output, and the list of "traits".
///
[Serializable, NetSerializable]
public sealed class ViewVariablesBlobMetadata : ViewVariablesBlob
{
///
/// A list of traits for this remote object.
/// A trait is basically saying "this object can be viewed in a specific way".
/// There's a trait for "this object has members that are directly accessible to VV (the usual),
/// A trait for objects that are , etc...
/// For flexibility, these traits can be any object that the server/client need to understand each other.
/// At the moment though the only thing they're used with is .
///
///
public List Traits { get; set; }
///
/// The pretty type name of the remote object.
///
public string ObjectTypePretty { get; set; }
///
/// The assembly qualified type name of the remote object.
///
public string ObjectType { get; set; }
///
/// The output of the remote object.
///
public string Stringified { get; set; }
}
///
/// Contains the VV-accessible members (fields or properties) of a remote object.
/// Requested by .
///
[Serializable, NetSerializable]
public sealed class ViewVariablesBlobMembers : ViewVariablesBlob
{
///
/// A list of VV-accessible the remote object has.
///
public List<(string groupName, List groupMembers)> MemberGroups { get; set; }
= new();
///
/// Token used to indicate "this is a reference, but I can't send the actual reference over".
///
[Serializable, NetSerializable]
[Virtual]
public class ReferenceToken
{
///
/// The output of the referenced object.
///
public string Stringified { get; set; }
// ToString override so EditorDummy displays it correctly.
public override string ToString()
{
return Stringified;
}
}
///
/// Token used to indicate "this is a prototype reference, but I can't send the actual reference over".
///
[Serializable, NetSerializable]
public sealed class PrototypeReferenceToken : ReferenceToken
{
///
/// The ID of the prototype.
///
[CanBeNull]
public string ID { get; set; }
///
/// The Prototype Variant identifier.
///
public string Variant { get; set; }
// ToString override so EditorDummy displays it correctly.
public override string ToString()
{
return $"{Stringified} Prototype: {Variant} ID: {ID}";
}
}
///
/// Sent if the value is a server-side only value type.
///
[Serializable, NetSerializable]
public sealed class ServerValueTypeToken
{
///
/// The output of the remote object.
///
public string Stringified { get; set; }
// ToString override so EditorDummy displays it correctly.
public override string ToString()
{
return Stringified;
}
}
[Serializable, NetSerializable]
public sealed class ServerKeyValuePairToken
{
public object Key { get; set; }
public object Value { get; set; }
}
///
/// Wrapper for a non-serializable value-type tuple.
///
[Serializable, NetSerializable]
public sealed class ServerTupleToken : ITuple
{
public object[] Items { get; set; }
public object this[int index] => Items[index];
public int Length => Items.Length;
}
///
/// Data for a specific property.
///
[Serializable, NetSerializable]
public sealed class MemberData
{
///
/// Whether the property can be edited by this client.
///
public bool Editable { get; set; }
///
/// Assembly qualified type name of the property.
///
public string Type { get; set; }
///
/// Pretty type name of the property.
///
public string TypePretty { get; set; }
///
/// Name of the property.
///
public string Name { get; set; }
///
/// Index of the property to be referenced when modifying it.
///
public int PropertyIndex { get; set; }
///
/// Value of the property.
/// If it's a value type that can be serialized it's literally sent over,
/// otherwise it's a meta token like or .
///
public object Value { get; set; }
}
}
///
/// Contains the type names of the components of a remote .
/// Requested by .
///
[Serializable, NetSerializable]
public sealed class ViewVariablesBlobEntityComponents : ViewVariablesBlob
{
public List ComponentTypes { get; set; } = new();
// This might as well be a ValueTuple but I couldn't get that to work.
[Serializable, NetSerializable]
public sealed class Entry : IComparable
{
public int CompareTo(Entry other)
{
if (ReferenceEquals(this, other)) return 0;
if (ReferenceEquals(null, other)) return 1;
return string.Compare(Stringified, other.Stringified, StringComparison.Ordinal);
}
public string FullName { get; set; }
public string Stringified { get; set; }
public string ComponentName { get; set; }
}
}
///
/// Contains a list of server-side component that can be added to a remote .
/// Requested by .
///
[Serializable, NetSerializable]
public sealed class ViewVariablesBlobAllValidComponents : ViewVariablesBlob
{
public List ComponentTypes { get; set; } = new();
}
///
/// Contains a list of all server-side prototypes of a variant.
/// Requested by .
///
[Serializable, NetSerializable]
public sealed class ViewVariablesBlobAllPrototypes : ViewVariablesBlob
{
public List Prototypes { get; set; } = new();
public string Variant { get; set; } = string.Empty;
}
///
/// Contains a range of a remote 's results.
/// Requested by
///
[Serializable, NetSerializable]
public sealed class ViewVariablesBlobEnumerable : ViewVariablesBlob
{
///
/// The list of objects inside the range specified by the
/// used to request this blob.
///
public List Objects { get; set; }
}
///
/// Base class for a "request" that can be sent to get information about the remote object of a session.
/// You should pass these requests to IViewVariablesManagerInternal.RequestData , which will return the corresponding blob over the wire.
///
[Serializable, NetSerializable]
public abstract class ViewVariablesRequest
{
}
///
/// Requests the server to send us a .
///
[Serializable, NetSerializable]
public sealed class ViewVariablesRequestMetadata : ViewVariablesRequest
{
}
///
/// Requests the server to send us a .
///
[Serializable, NetSerializable]
public sealed class ViewVariablesRequestMembers : ViewVariablesRequest
{
}
///
/// Requests the server to send us a .
///
[Serializable, NetSerializable]
public sealed class ViewVariablesRequestEntityComponents : ViewVariablesRequest
{
}
///
/// Requests the server to send us a .
///
[Serializable, NetSerializable]
public sealed class ViewVariablesRequestAllValidComponents : ViewVariablesRequest
{
}
///
/// Requests the server to send us a .
///
[Serializable, NetSerializable]
public sealed class ViewVariablesRequestAllPrototypes : ViewVariablesRequest
{
public string Variant { get; }
public ViewVariablesRequestAllPrototypes(string variant)
{
Variant = variant;
}
}
///
/// Requests the server to send us a containing data in the specified range.
///
[Serializable, NetSerializable]
public sealed class ViewVariablesRequestEnumerable : ViewVariablesRequest
{
public ViewVariablesRequestEnumerable(int fromIndex, int toIndex, bool refresh)
{
FromIndex = fromIndex;
ToIndex = toIndex;
Refresh = refresh;
}
///
/// The first index to be included.
///
public int FromIndex { get; }
///
/// The last index to be included.
///
public int ToIndex { get; }
///
/// If true, wipe the enumerator used and clear the cached values.
/// This is used for the refresh button in the VV window.
/// We need to wipe the server side cache or else it wouldn't be a refresh.
///
public bool Refresh { get; }
}
}