mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-15 03:30:53 +01:00
Remove casts to Component (#4495)
This commit is contained in:
@@ -26,7 +26,7 @@ namespace Robust.Client.Console.Commands
|
||||
var entity = _entityManager.GetEntity(netEntity);
|
||||
var componentName = args[1];
|
||||
|
||||
var component = (Component) _componentFactory.GetComponent(componentName);
|
||||
var component = _componentFactory.GetComponent(componentName);
|
||||
|
||||
component.Owner = entity;
|
||||
|
||||
|
||||
@@ -1187,7 +1187,7 @@ namespace Robust.Client.GameStates
|
||||
{
|
||||
if (!meta.NetComponents.TryGetValue(id, out var comp))
|
||||
{
|
||||
comp = (Component) _compFactory.GetComponent(id);
|
||||
comp = _compFactory.GetComponent(id);
|
||||
comp.Owner = uid;
|
||||
_entityManager.AddComponent(uid, comp, true, metadata: meta);
|
||||
}
|
||||
@@ -1201,7 +1201,7 @@ namespace Robust.Client.GameStates
|
||||
{
|
||||
if (!meta.NetComponents.TryGetValue(compChange.NetID, out var comp))
|
||||
{
|
||||
comp = (Component) _compFactory.GetComponent(compChange.NetID);
|
||||
comp = _compFactory.GetComponent(compChange.NetID);
|
||||
comp.Owner = uid;
|
||||
_entityManager.AddComponent(uid, comp, true, metadata:meta);
|
||||
}
|
||||
@@ -1428,7 +1428,7 @@ namespace Robust.Client.GameStates
|
||||
{
|
||||
if (!meta.NetComponents.TryGetValue(id, out var comp))
|
||||
{
|
||||
comp = (Component) _compFactory.GetComponent(id);
|
||||
comp = _compFactory.GetComponent(id);
|
||||
comp.Owner = uid;
|
||||
_entityManager.AddComponent(uid, comp, true, meta);
|
||||
}
|
||||
|
||||
@@ -431,7 +431,7 @@ namespace Robust.Client.ViewVariables.Instances
|
||||
|
||||
try
|
||||
{
|
||||
var comp = (Component) componentFactory.GetComponent(registration.Type);
|
||||
var comp = componentFactory.GetComponent(registration.Type);
|
||||
comp.Owner = _entity;
|
||||
_entityManager.AddComponent(_entity, comp);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using JetBrains.Annotations;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.Console;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
@@ -47,7 +46,7 @@ namespace Robust.Server.Console.Commands
|
||||
shell.WriteLine($"Entity {_entityManager.GetComponent<MetaDataComponent>(uid.Value).EntityName} already has a {componentName} component.");
|
||||
}
|
||||
|
||||
var component = (Component) _componentFactory.GetComponent(registration.Type);
|
||||
var component = _componentFactory.GetComponent(registration.Type);
|
||||
|
||||
#pragma warning disable CS0618
|
||||
component.Owner = uid.Value;
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace Robust.Shared.Analyzers;
|
||||
/// component state replication beyond just directly setting variables should not use this attribute.
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Class, Inherited = false)]
|
||||
[BaseTypeRequired(typeof(Component))]
|
||||
[BaseTypeRequired(typeof(IComponent))]
|
||||
public sealed class AutoGenerateComponentStateAttribute : Attribute
|
||||
{
|
||||
/// <summary>
|
||||
|
||||
@@ -172,9 +172,9 @@ namespace Robust.Shared.GameObjects
|
||||
}
|
||||
}
|
||||
|
||||
public Component AddComponent(EntityUid uid, ushort netId, MetaDataComponent? meta = null)
|
||||
public IComponent AddComponent(EntityUid uid, ushort netId, MetaDataComponent? meta = null)
|
||||
{
|
||||
var newComponent = (Component)_componentFactory.GetComponent(netId);
|
||||
var newComponent = _componentFactory.GetComponent(netId);
|
||||
#pragma warning disable CS0618 // Type or member is obsolete
|
||||
newComponent.Owner = uid;
|
||||
#pragma warning restore CS0618 // Type or member is obsolete
|
||||
@@ -365,7 +365,7 @@ namespace Robust.Shared.GameObjects
|
||||
if (!TryGetComponent(uid, type, out var comp))
|
||||
return false;
|
||||
|
||||
RemoveComponentImmediate((Component)comp, uid, false, meta);
|
||||
RemoveComponentImmediate(comp, uid, false, meta);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -379,20 +379,13 @@ namespace Robust.Shared.GameObjects
|
||||
if (!TryGetComponent(uid, netId, out var comp, meta))
|
||||
return false;
|
||||
|
||||
RemoveComponentImmediate((Component)comp, uid, false, meta);
|
||||
RemoveComponentImmediate(comp, uid, false, meta);
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void RemoveComponent(EntityUid uid, IComponent component, MetaDataComponent? meta = null)
|
||||
{
|
||||
RemoveComponent(uid, (Component)component, meta);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void RemoveComponent(EntityUid uid, Component component, MetaDataComponent? meta = null)
|
||||
{
|
||||
RemoveComponentImmediate(component, uid, false, meta);
|
||||
}
|
||||
@@ -410,7 +403,7 @@ namespace Robust.Shared.GameObjects
|
||||
if (!TryGetComponent(uid, type, out var comp))
|
||||
return false;
|
||||
|
||||
RemoveComponentDeferred((Component)comp, uid, false);
|
||||
RemoveComponentDeferred(comp, uid, false);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -424,14 +417,14 @@ namespace Robust.Shared.GameObjects
|
||||
if (!TryGetComponent(uid, netId, out var comp, meta))
|
||||
return false;
|
||||
|
||||
RemoveComponentDeferred((Component)comp, uid, false);
|
||||
RemoveComponentDeferred(comp, uid, false);
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void RemoveComponentDeferred(EntityUid owner, IComponent component)
|
||||
{
|
||||
RemoveComponentDeferred((Component)component, owner, false);
|
||||
RemoveComponentDeferred(component, owner, false);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -489,7 +482,7 @@ namespace Robust.Shared.GameObjects
|
||||
_entCompIndex.Remove(uid);
|
||||
}
|
||||
|
||||
private void RemoveComponentDeferred(Component component, EntityUid uid, bool terminating)
|
||||
private void RemoveComponentDeferred(IComponent component, EntityUid uid, bool terminating)
|
||||
{
|
||||
if (component == null) throw new ArgumentNullException(nameof(component));
|
||||
|
||||
|
||||
@@ -47,6 +47,7 @@ namespace Robust.Shared.GameObjects
|
||||
/// Entity that this component is attached to.
|
||||
/// </summary>
|
||||
/// <seealso cref="EntityQueryEnumerator{TComp1}"/>
|
||||
[Obsolete("Update your API to allow accessing Owner through other means")]
|
||||
EntityUid Owner { get; set; }
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -49,7 +49,7 @@ namespace Robust.Shared.GameObjects
|
||||
/// <summary>
|
||||
/// Adds a Component with a given network id to an entity.
|
||||
/// </summary>
|
||||
Component AddComponent(EntityUid uid, ushort netId, MetaDataComponent? meta = null);
|
||||
IComponent AddComponent(EntityUid uid, ushort netId, MetaDataComponent? meta = null);
|
||||
|
||||
/// <summary>
|
||||
/// Adds an uninitialized Component type to an entity.
|
||||
|
||||
@@ -77,7 +77,7 @@ internal sealed class PrototypeReloadSystem : EntitySystem
|
||||
.Except(oldPrototypeComponents))
|
||||
{
|
||||
var data = newPrototype.Components[name];
|
||||
var component = (Component)_componentFactory.GetComponent(name);
|
||||
var component = _componentFactory.GetComponent(name);
|
||||
component.Owner = entity;
|
||||
EntityManager.AddComponent(entity, component);
|
||||
}
|
||||
|
||||
@@ -11,7 +11,6 @@ using Robust.Shared.Serialization.Manager;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.Serialization.Markdown.Mapping;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Array;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Set;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Robust.Shared.Prototypes
|
||||
@@ -250,7 +249,7 @@ namespace Robust.Shared.Prototypes
|
||||
|
||||
if (!entityManager.TryGetComponent(entity, compReg.Idx, out var component))
|
||||
{
|
||||
var newComponent = (Component) factory.GetComponent(compName);
|
||||
var newComponent = factory.GetComponent(compName);
|
||||
newComponent.Owner = entity;
|
||||
entityManager.AddComponent(entity, newComponent);
|
||||
component = newComponent;
|
||||
|
||||
@@ -34,7 +34,7 @@ internal abstract partial class ViewVariablesManager
|
||||
|| !_entMan.TryGetComponent(uid, registration.Idx, out var component))
|
||||
return null;
|
||||
|
||||
return new ViewVariablesComponentPath((Component) component, uid);
|
||||
return new ViewVariablesComponentPath(component, uid);
|
||||
}
|
||||
|
||||
private IEnumerable<string> EntityComponentList(EntityUid uid)
|
||||
|
||||
@@ -263,11 +263,11 @@ public sealed class ViewVariablesInstancePath : ViewVariablesPath
|
||||
|
||||
public sealed class ViewVariablesComponentPath : ViewVariablesPath
|
||||
{
|
||||
public readonly Component Component;
|
||||
public readonly IComponent Component;
|
||||
public readonly EntityUid Owner;
|
||||
public override Type Type => Component?.GetType() ?? typeof(void);
|
||||
|
||||
public ViewVariablesComponentPath(Component component, EntityUid owner)
|
||||
public ViewVariablesComponentPath(IComponent component, EntityUid owner)
|
||||
{
|
||||
Component = component;
|
||||
Owner = owner;
|
||||
|
||||
Reference in New Issue
Block a user