mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-09-15 06:42:25 +02:00
Fix more errors, client and server now build
This commit is contained in:
@@ -492,8 +492,7 @@ namespace Robust.Client.Placement
|
||||
{
|
||||
// Try to get current map.
|
||||
var map = MapId.Nullspace;
|
||||
var ent = PlayerManager.LocalPlayer!.ControlledEntity;
|
||||
if (ent != default)
|
||||
if (PlayerManager.LocalPlayer!.ControlledEntity is {Valid: true} ent)
|
||||
{
|
||||
map = EntityManager.GetComponent<TransformComponent>(ent).MapID;
|
||||
}
|
||||
@@ -633,11 +632,12 @@ namespace Robust.Client.Placement
|
||||
|
||||
CurrentMode.Render(handle);
|
||||
|
||||
if (CurrentPermission == null || CurrentPermission.Range <= 0 || !CurrentMode.RangeRequired
|
||||
|| PlayerManager.LocalPlayer?.ControlledEntity == null)
|
||||
if (CurrentPermission is not {Range: > 0} ||
|
||||
!CurrentMode.RangeRequired ||
|
||||
PlayerManager.LocalPlayer?.ControlledEntity is not {Valid: true} controlled)
|
||||
return;
|
||||
|
||||
var worldPos = EntityManager.GetComponent<TransformComponent>(PlayerManager.LocalPlayer.ControlledEntity).WorldPosition;
|
||||
var worldPos = EntityManager.GetComponent<TransformComponent>(controlled).WorldPosition;
|
||||
|
||||
handle.DrawCircle(worldPos, CurrentPermission.Range, new Color(1, 1, 1, 0.25f));
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace Robust.Client.Player
|
||||
/// Game entity that the local player is controlling. If this is default, the player is not attached to any
|
||||
/// entity at all.
|
||||
/// </summary>
|
||||
[ViewVariables] public EntityUid ControlledEntity { get; private set; }
|
||||
[ViewVariables] public EntityUid? ControlledEntity { get; private set; }
|
||||
|
||||
[ViewVariables] public NetUserId UserId { get; set; }
|
||||
|
||||
@@ -86,20 +86,22 @@ namespace Robust.Client.Player
|
||||
{
|
||||
var entMan = IoCManager.Resolve<IEntityManager>();
|
||||
var previous = ControlledEntity;
|
||||
if (previous != default && entMan.EntityExists(previous))
|
||||
if (entMan.TryGetComponent(previous, out MetaDataComponent? metaData) &&
|
||||
metaData.EntityInitialized &&
|
||||
!metaData.EntityDeleted)
|
||||
{
|
||||
entMan.GetComponent<EyeComponent>(previous).Current = false;
|
||||
entMan.GetComponent<EyeComponent>(previous.Value).Current = false;
|
||||
|
||||
// notify ECS Systems
|
||||
entMan.EventBus.RaiseEvent(EventSource.Local, new PlayerAttachSysMessage(default));
|
||||
entMan.EventBus.RaiseLocalEvent(previous, new PlayerDetachedEvent(previous));
|
||||
entMan.EventBus.RaiseLocalEvent(previous.Value, new PlayerDetachedEvent(previous.Value));
|
||||
}
|
||||
|
||||
ControlledEntity = default;
|
||||
|
||||
if (previous != default)
|
||||
if (previous != null)
|
||||
{
|
||||
EntityDetached?.Invoke(new EntityDetachedEventArgs(previous));
|
||||
EntityDetached?.Invoke(new EntityDetachedEventArgs(previous.Value));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -427,6 +427,13 @@ namespace Robust.Shared.GameObjects
|
||||
return HasComponent(uid, typeof(T));
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public bool HasComponent<T>(EntityUid? uid)
|
||||
{
|
||||
return uid.HasValue && HasComponent(uid.Value, typeof(T));
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public bool HasComponent(EntityUid uid, Type type)
|
||||
@@ -435,6 +442,19 @@ namespace Robust.Shared.GameObjects
|
||||
return dict.TryGetValue(uid, out var comp) && !comp.Deleted;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public bool HasComponent(EntityUid? uid, Type type)
|
||||
{
|
||||
if (!uid.HasValue)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var dict = _entTraitDict[type];
|
||||
return dict.TryGetValue(uid.Value, out var comp) && !comp.Deleted;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public bool HasComponent(EntityUid uid, ushort netId)
|
||||
@@ -443,6 +463,19 @@ namespace Robust.Shared.GameObjects
|
||||
&& netSet.ContainsKey(netId);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public bool HasComponent(EntityUid? uid, ushort netId)
|
||||
{
|
||||
if (!uid.HasValue)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return _netComponents.TryGetValue(uid.Value, out var netSet)
|
||||
&& netSet.ContainsKey(netId);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public T EnsureComponent<T>(EntityUid uid) where T : Component, new()
|
||||
{
|
||||
@@ -497,6 +530,28 @@ namespace Robust.Shared.GameObjects
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool TryGetComponent<T>([NotNullWhen(true)] EntityUid? uid, [NotNullWhen(true)] out T component)
|
||||
{
|
||||
if (!uid.HasValue)
|
||||
{
|
||||
component = default!;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (TryGetComponent(uid.Value, typeof(T), out var comp))
|
||||
{
|
||||
if (!comp.Deleted)
|
||||
{
|
||||
component = (T)comp;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
component = default!;
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool TryGetComponent(EntityUid uid, Type type, [NotNullWhen(true)] out IComponent? component)
|
||||
{
|
||||
@@ -514,6 +569,29 @@ namespace Robust.Shared.GameObjects
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool TryGetComponent([NotNullWhen(true)] EntityUid? uid, Type type, [NotNullWhen(true)] out IComponent? component)
|
||||
{
|
||||
if (!uid.HasValue)
|
||||
{
|
||||
component = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
var dict = _entTraitDict[type];
|
||||
if (dict.TryGetValue(uid.Value, out var comp))
|
||||
{
|
||||
if (!comp.Deleted)
|
||||
{
|
||||
component = comp;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
component = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool TryGetComponent(EntityUid uid, ushort netId, [MaybeNullWhen(false)] out IComponent component)
|
||||
{
|
||||
@@ -528,6 +606,26 @@ namespace Robust.Shared.GameObjects
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool TryGetComponent([NotNullWhen(true)] EntityUid? uid, ushort netId, [MaybeNullWhen(false)] out IComponent component)
|
||||
{
|
||||
if (!uid.HasValue)
|
||||
{
|
||||
component = default;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (_netComponents.TryGetValue(uid.Value, out var netSet)
|
||||
&& netSet.TryGetValue(netId, out var comp))
|
||||
{
|
||||
component = comp;
|
||||
return true;
|
||||
}
|
||||
|
||||
component = default;
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public IEnumerable<IComponent> GetComponents(EntityUid uid)
|
||||
{
|
||||
|
||||
@@ -305,6 +305,11 @@ namespace Robust.Shared.GameObjects
|
||||
return _entTraitDict[typeof(MetaDataComponent)].ContainsKey(uid);
|
||||
}
|
||||
|
||||
public bool EntityExists(EntityUid? uid)
|
||||
{
|
||||
return uid.HasValue && EntityExists(uid.Value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Disposes all entities and clears all lists.
|
||||
/// </summary>
|
||||
|
||||
@@ -521,14 +521,14 @@ public partial class EntitySystem
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
public EntityUid Spawn(string? prototype, EntityCoordinates coordinates)
|
||||
{
|
||||
return EntityManager.SpawnEntity(prototype, coordinates).Uid;
|
||||
return EntityManager.SpawnEntity(prototype, coordinates);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="IEntityManager.SpawnEntity(string?, MapCoordinates)" />
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
public EntityUid Spawn(string? prototype, MapCoordinates coordinates)
|
||||
{
|
||||
return EntityManager.SpawnEntity(prototype, coordinates).Uid;
|
||||
return EntityManager.SpawnEntity(prototype, coordinates);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.Players;
|
||||
|
||||
namespace Robust.Shared.GameObjects
|
||||
@@ -102,6 +101,14 @@ namespace Robust.Shared.GameObjects
|
||||
/// <returns>True if the entity has the component type, otherwise false.</returns>
|
||||
bool HasComponent<T>(EntityUid uid);
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the entity has a component type.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Component reference type to check for.</typeparam>
|
||||
/// <param name="uid">Entity UID to check.</param>
|
||||
/// <returns>True if the entity has the component type, otherwise false.</returns>
|
||||
bool HasComponent<T>(EntityUid? uid);
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the entity has a component type.
|
||||
/// </summary>
|
||||
@@ -110,6 +117,14 @@ namespace Robust.Shared.GameObjects
|
||||
/// <returns>True if the entity has the component type, otherwise false.</returns>
|
||||
bool HasComponent(EntityUid uid, Type type);
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the entity has a component type.
|
||||
/// </summary>
|
||||
/// <param name="uid">Entity UID to check.</param>
|
||||
/// <param name="type">A trait or component type to check for.</param>
|
||||
/// <returns>True if the entity has the component type, otherwise false.</returns>
|
||||
bool HasComponent(EntityUid ?uid, Type type);
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the entity has a component with a given network ID. This does not check
|
||||
/// if the component is deleted.
|
||||
@@ -119,6 +134,15 @@ namespace Robust.Shared.GameObjects
|
||||
/// <returns>True if the entity has a component with the given network ID, otherwise false.</returns>
|
||||
bool HasComponent(EntityUid uid, ushort netId);
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the entity has a component with a given network ID. This does not check
|
||||
/// if the component is deleted.
|
||||
/// </summary>
|
||||
/// <param name="uid">Entity UID to check.</param>
|
||||
/// <param name="netId">Network ID to check for.</param>
|
||||
/// <returns>True if the entity has a component with the given network ID, otherwise false.</returns>
|
||||
bool HasComponent(EntityUid? uid, ushort netId);
|
||||
|
||||
/// <summary>
|
||||
/// This method will always return a component for a certain entity, adding it if it's not there already.
|
||||
/// </summary>
|
||||
@@ -161,6 +185,15 @@ namespace Robust.Shared.GameObjects
|
||||
/// <returns>If the component existed in the entity.</returns>
|
||||
bool TryGetComponent<T>(EntityUid uid, [NotNullWhen(true)] out T component);
|
||||
|
||||
/// <summary>
|
||||
/// Returns the component of a specific type.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">A trait or type of a component to retrieve.</typeparam>
|
||||
/// <param name="uid">Entity UID to check.</param>
|
||||
/// <param name="component">Component of the specified type (if exists).</param>
|
||||
/// <returns>If the component existed in the entity.</returns>
|
||||
bool TryGetComponent<T>([NotNullWhen(true)] EntityUid? uid, [NotNullWhen(true)] out T component);
|
||||
|
||||
/// <summary>
|
||||
/// Returns the component of a specific type.
|
||||
/// </summary>
|
||||
@@ -170,6 +203,15 @@ namespace Robust.Shared.GameObjects
|
||||
/// <returns>If the component existed in the entity.</returns>
|
||||
bool TryGetComponent(EntityUid uid, Type type, [NotNullWhen(true)] out IComponent? component);
|
||||
|
||||
/// <summary>
|
||||
/// Returns the component of a specific type.
|
||||
/// </summary>
|
||||
/// <param name="uid">Entity UID to check.</param>
|
||||
/// <param name="type">A trait or component type to check for.</param>
|
||||
/// <param name="component">Component of the specified type (if exists).</param>
|
||||
/// <returns>If the component existed in the entity.</returns>
|
||||
bool TryGetComponent([NotNullWhen(true)] EntityUid? uid, Type type, [NotNullWhen(true)] out IComponent? component);
|
||||
|
||||
/// <summary>
|
||||
/// Returns the component with a specified network ID. This does not check
|
||||
/// if the component is deleted.
|
||||
@@ -180,6 +222,16 @@ namespace Robust.Shared.GameObjects
|
||||
/// <returns>If the component existed in the entity.</returns>
|
||||
bool TryGetComponent(EntityUid uid, ushort netId, [NotNullWhen(true)] out IComponent? component);
|
||||
|
||||
/// <summary>
|
||||
/// Returns the component with a specified network ID. This does not check
|
||||
/// if the component is deleted.
|
||||
/// </summary>
|
||||
/// <param name="uid">Entity UID to check.</param>
|
||||
/// <param name="netId">Component Network ID to check for.</param>
|
||||
/// <param name="component">Component with the specified network id.</param>
|
||||
/// <returns>If the component existed in the entity.</returns>
|
||||
bool TryGetComponent([NotNullWhen(true)] EntityUid? uid, ushort netId, [NotNullWhen(true)] out IComponent? component);
|
||||
|
||||
/// <summary>
|
||||
/// Returns ALL component type instances on an entity. A single component instance
|
||||
/// can have multiple component types.
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using JetBrains.Annotations;
|
||||
using Prometheus;
|
||||
using Robust.Shared.Map;
|
||||
@@ -95,6 +96,11 @@ namespace Robust.Shared.GameObjects
|
||||
/// </summary>
|
||||
bool EntityExists(EntityUid uid);
|
||||
|
||||
/// <summary>
|
||||
/// Checks whether an entity with the specified ID exists.
|
||||
/// </summary>
|
||||
bool EntityExists([NotNullWhen(true)] EntityUid? uid);
|
||||
|
||||
/// <summary>
|
||||
/// Returns a string representation of an entity with various information regarding it.
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user