public override ViewVariablesBlob?DataRequest(ViewVariablesRequest viewVariablesRequest) { var entMan = IoCManager.Resolve <IEntityManager>(); if (viewVariablesRequest is ViewVariablesRequestMembers) { var blob = new ViewVariablesBlobMembers(); // TODO VV: Fill blob with info about this entity. return(blob); } if (viewVariablesRequest is ViewVariablesRequestEntityComponents) { var list = new List <ViewVariablesBlobEntityComponents.Entry>(); // See engine#636 for why the Distinct() call. foreach (var component in entMan.GetComponents(_entity)) { var type = component.GetType(); list.Add(new ViewVariablesBlobEntityComponents.Entry { Stringified = TypeAbbreviation.Abbreviate(type), FullName = type.FullName, ComponentName = component.Name }); } return(new ViewVariablesBlobEntityComponents { ComponentTypes = list }); } if (viewVariablesRequest is ViewVariablesRequestAllValidComponents) { var list = new List <string>(); var componentFactory = IoCManager.Resolve <IComponentFactory>(); foreach (var type in componentFactory.AllRegisteredTypes) { if (entMan.HasComponent(_entity, type)) { continue; } list.Add(componentFactory.GetRegistration(type).Name); } return(new ViewVariablesBlobAllValidComponents() { ComponentTypes = list }); } return(base.DataRequest(viewVariablesRequest)); }
public override void ReadFromBuffer(NetIncomingMessage buffer) { RequestId = buffer.ReadUInt32(); SessionId = buffer.ReadUInt32(); var serializer = IoCManager.Resolve <IRobustSerializer>(); var length = buffer.ReadInt32(); using var stream = buffer.ReadAlignedMemory(length); RequestMeta = serializer.Deserialize <ViewVariablesRequest>(stream); }
public override void ReadFromBuffer(NetIncomingMessage buffer) { RequestId = buffer.ReadUInt32(); SessionId = buffer.ReadUInt32(); var serializer = IoCManager.Resolve <ISS14Serializer>(); var length = buffer.ReadInt32(); var bytes = buffer.ReadBytes(length); using (var stream = new MemoryStream(bytes)) { RequestMeta = serializer.Deserialize <ViewVariablesRequest>(stream); } }
public override ViewVariablesBlob?DataRequest(ViewVariablesRequest viewVariablesRequest) { if (viewVariablesRequest is ViewVariablesRequestEnumerable requestEnumerable) { if (requestEnumerable.Refresh) { _refresh(); } _cacheTo(requestEnumerable.ToIndex); var list = new List <object?>(); for (var i = requestEnumerable.FromIndex; i < _cache.Count && i <= requestEnumerable.ToIndex; i++) { list.Add(MakeValueNetSafe(_cache[i])); } return(new ViewVariablesBlobEnumerable { Objects = list }); } return(base.DataRequest(viewVariablesRequest)); }
public override ViewVariablesBlob DataRequest(ViewVariablesRequest viewVariablesRequest) { if (viewVariablesRequest is ViewVariablesRequestEntityComponents) { var list = new List <ViewVariablesBlobEntityComponents.Entry>(); // See engine#636 for why the Distinct() call. foreach (var component in _entity.GetAllComponents().Distinct()) { var type = component.GetType(); list.Add(new ViewVariablesBlobEntityComponents.Entry { Stringified = type.ToString(), Qualified = type.AssemblyQualifiedName }); } return(new ViewVariablesBlobEntityComponents { ComponentTypes = list }); } return(base.DataRequest(viewVariablesRequest)); }
public override ViewVariablesBlob?DataRequest(ViewVariablesRequest viewVariablesRequest) { if (viewVariablesRequest is ViewVariablesRequestEntityComponents) { var list = new List <ViewVariablesBlobEntityComponents.Entry>(); // See engine#636 for why the Distinct() call. foreach (var component in _entity.GetAllComponents()) { var type = component.GetType(); list.Add(new ViewVariablesBlobEntityComponents.Entry { Stringified = TypeAbbreviation.Abbreviate(type), FullName = type.FullName }); } return(new ViewVariablesBlobEntityComponents { ComponentTypes = list }); } return(base.DataRequest(viewVariablesRequest)); }
public ViewVariablesBlob DataRequest(ViewVariablesRequest messageRequestMeta) { if (messageRequestMeta is ViewVariablesRequestMetadata) { return(new ViewVariablesBlobMetadata { ObjectType = ObjectType.AssemblyQualifiedName, ObjectTypePretty = ObjectType.ToString(), Stringified = Object.ToString(), Traits = new List <object>(Host.TraitIdsFor(ObjectType)) }); } foreach (var trait in _traits) { var blob = trait.DataRequest(messageRequestMeta); if (blob != null) { return(blob); } } return(null); }
/// <summary> /// Invoked when the client requests a data blob from the session this trait is bound to, /// Using <see cref="MsgViewVariablesReqData"/>. /// </summary> /// <param name="viewVariablesRequest"> /// The request meta object, equivalent to the <see cref="MsgViewVariablesReqData.RequestMeta"/> object. /// </param> /// <returns> /// <see langword="null"/>If this trait doesn't care about this request, a meaningful blob otherwise. /// No, not the game mode, the other kind of blob. /// </returns> public virtual ViewVariablesBlob DataRequest(ViewVariablesRequest viewVariablesRequest) { return(null); }
public override ViewVariablesBlob?DataRequest(ViewVariablesRequest messageRequestMeta) { if (!(messageRequestMeta is ViewVariablesRequestMembers)) { return(null); } var dataList = new List <ViewVariablesBlobMembers.MemberData>(); var blob = new ViewVariablesBlobMembers { Members = dataList }; foreach (var property in Session.ObjectType.GetAllProperties()) { var attr = property.GetCustomAttribute <ViewVariablesAttribute>(); if (attr == null) { continue; } if (!property.IsBasePropertyDefinition()) { continue; } dataList.Add(new ViewVariablesBlobMembers.MemberData { Editable = attr.Access == VVAccess.ReadWrite, Name = property.Name, Type = property.PropertyType.AssemblyQualifiedName, TypePretty = TypeAbbreviation.Abbreviate(property.PropertyType), Value = property.GetValue(Session.Object), PropertyIndex = _members.Count }); _members.Add(property); } foreach (var field in Session.ObjectType.GetAllFields()) { var attr = field.GetCustomAttribute <ViewVariablesAttribute>(); if (attr == null) { continue; } dataList.Add(new ViewVariablesBlobMembers.MemberData { Editable = attr.Access == VVAccess.ReadWrite, Name = field.Name, Type = field.FieldType.AssemblyQualifiedName, TypePretty = TypeAbbreviation.Abbreviate(field.FieldType), Value = field.GetValue(Session.Object), PropertyIndex = _members.Count }); _members.Add(field); } dataList.Sort((a, b) => string.Compare(a.Name, b.Name, StringComparison.Ordinal)); foreach (var data in dataList) { data.Value = MakeValueNetSafe(data.Value); } return(blob); }
public override ViewVariablesBlob?DataRequest(ViewVariablesRequest messageRequestMeta) { if (!(messageRequestMeta is ViewVariablesRequestMembers)) { return(null); } var members = new List <(MemberData mData, MemberInfo mInfo)>(); foreach (var property in Session.ObjectType.GetAllProperties()) { var attr = property.GetCustomAttribute <ViewVariablesAttribute>(); if (attr == null) { continue; } if (!property.IsBasePropertyDefinition()) { continue; } members.Add((new MemberData { Editable = attr.Access == VVAccess.ReadWrite, Name = property.Name, Type = property.PropertyType.AssemblyQualifiedName, TypePretty = TypeAbbreviation.Abbreviate(property.PropertyType), Value = property.GetValue(Session.Object), PropertyIndex = _members.Count }, property)); _members.Add(property); } foreach (var field in Session.ObjectType.GetAllFields()) { var attr = field.GetCustomAttribute <ViewVariablesAttribute>(); if (attr == null) { continue; } members.Add((new MemberData { Editable = attr.Access == VVAccess.ReadWrite, Name = field.Name, Type = field.FieldType.AssemblyQualifiedName, TypePretty = TypeAbbreviation.Abbreviate(field.FieldType), Value = field.GetValue(Session.Object), PropertyIndex = _members.Count }, field)); _members.Add(field); } foreach (var(mData, _) in members) { mData.Value = MakeValueNetSafe(mData.Value); } var dataList = members .OrderBy(p => p.mData.Name) .GroupBy(p => p.mInfo.DeclaringType !) .OrderByDescending(g => g.Key, TypeHelpers.TypeInheritanceComparer) .Select(g => ( TypeAbbreviation.Abbreviate(g.Key), g.Select(d => d.mData).ToList() )) .ToList(); return(new ViewVariablesBlobMembers { MemberGroups = dataList }); }