SnapGridComponent Removal (#3884)
* Removed SnapGridOffset, there is only center now. * SnapGridComponent methods are now static. * Removed SnapGridComponent.OnPositionChanged. * Refactored static functions off SnapGridComponent to MapGrid. Refactored away usages of SnapGridComponent.Position. * Added Transform.Anchored for checking if an entity is a tile entity. More refactoring for static MapGrid functions. * Static snapgrid methods on MapGrid are no longer static. * Add setter to ITransformComponent.Anchored. Removed direct references to SnapGridComponent from content. * Grid functions now deal with EntityUids instead of SnapGridComponents. Began renaming public API functions from SnapGrid to Anchor. * Remove the SnapGridComponent 'Offset' field from all yaml files. This was removed in code previously, so the yaml linter was upset. * Update engine submodule to v0.4.46.
This commit is contained in:
@@ -1,12 +1,14 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Content.Client.GameObjects.EntitySystems;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.Utility;
|
||||
using static Robust.Client.GameObjects.SpriteComponent;
|
||||
|
||||
namespace Content.Client.GameObjects.Components.IconSmoothing
|
||||
@@ -25,6 +27,8 @@ namespace Content.Client.GameObjects.Components.IconSmoothing
|
||||
[RegisterComponent]
|
||||
public class IconSmoothComponent : Component
|
||||
{
|
||||
[Dependency] private readonly IMapManager _mapManager = default!;
|
||||
|
||||
[DataField("mode")]
|
||||
private IconSmoothingMode _mode = IconSmoothingMode.Corners;
|
||||
|
||||
@@ -32,8 +36,6 @@ namespace Content.Client.GameObjects.Components.IconSmoothing
|
||||
|
||||
internal ISpriteComponent? Sprite { get; private set; }
|
||||
|
||||
internal SnapGridComponent? SnapGrid { get; private set; }
|
||||
|
||||
private (GridId, Vector2i) _lastPosition;
|
||||
|
||||
/// <summary>
|
||||
@@ -62,7 +64,6 @@ namespace Content.Client.GameObjects.Components.IconSmoothing
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SnapGrid = Owner.GetComponent<SnapGridComponent>();
|
||||
Sprite = Owner.GetComponent<ISpriteComponent>();
|
||||
}
|
||||
|
||||
@@ -71,15 +72,14 @@ namespace Content.Client.GameObjects.Components.IconSmoothing
|
||||
{
|
||||
base.Startup();
|
||||
|
||||
if (SnapGrid != null)
|
||||
if (Owner.Transform.Anchored)
|
||||
{
|
||||
SnapGrid.OnPositionChanged += SnapGridOnPositionChanged;
|
||||
|
||||
// ensures lastposition initial value is populated on spawn. Just calling
|
||||
// the hook here would cause a dirty event to fire needlessly
|
||||
_lastPosition = (Owner.Transform.GridID, SnapGrid.Position);
|
||||
var grid = _mapManager.GetGrid(Owner.Transform.GridID);
|
||||
_lastPosition = (Owner.Transform.GridID, grid.TileIndicesFor(Owner.Transform.Coordinates));
|
||||
|
||||
Owner.EntityManager.EventBus.RaiseEvent(EventSource.Local, new IconSmoothDirtyEvent(Owner,null, SnapGrid.Offset, Mode));
|
||||
Owner.EntityManager.EventBus.RaiseEvent(EventSource.Local, new IconSmoothDirtyEvent(Owner, null, Mode));
|
||||
}
|
||||
|
||||
if (Sprite != null && Mode == IconSmoothingMode.Corners)
|
||||
@@ -115,20 +115,22 @@ namespace Content.Client.GameObjects.Components.IconSmoothing
|
||||
|
||||
private void CalculateNewSpriteCardinal()
|
||||
{
|
||||
if (SnapGrid == null || Sprite == null)
|
||||
if (!Owner.Transform.Anchored || Sprite == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var dirs = CardinalConnectDirs.None;
|
||||
|
||||
if (MatchingEntity(SnapGrid.GetInDir(Direction.North)))
|
||||
var grid = _mapManager.GetGrid(Owner.Transform.GridID);
|
||||
var position = Owner.Transform.Coordinates;
|
||||
if (MatchingEntity(grid.GetInDir(position, Direction.North)))
|
||||
dirs |= CardinalConnectDirs.North;
|
||||
if (MatchingEntity(SnapGrid.GetInDir(Direction.South)))
|
||||
if (MatchingEntity(grid.GetInDir(position, Direction.South)))
|
||||
dirs |= CardinalConnectDirs.South;
|
||||
if (MatchingEntity(SnapGrid.GetInDir(Direction.East)))
|
||||
if (MatchingEntity(grid.GetInDir(position, Direction.East)))
|
||||
dirs |= CardinalConnectDirs.East;
|
||||
if (MatchingEntity(SnapGrid.GetInDir(Direction.West)))
|
||||
if (MatchingEntity(grid.GetInDir(position, Direction.West)))
|
||||
dirs |= CardinalConnectDirs.West;
|
||||
|
||||
Sprite.LayerSetState(0, $"{StateBase}{(int) dirs}");
|
||||
@@ -151,19 +153,21 @@ namespace Content.Client.GameObjects.Components.IconSmoothing
|
||||
|
||||
protected (CornerFill ne, CornerFill nw, CornerFill sw, CornerFill se) CalculateCornerFill()
|
||||
{
|
||||
if (SnapGrid == null)
|
||||
if (!Owner.Transform.Anchored)
|
||||
{
|
||||
return (CornerFill.None, CornerFill.None, CornerFill.None, CornerFill.None);
|
||||
}
|
||||
|
||||
var n = MatchingEntity(SnapGrid.GetInDir(Direction.North));
|
||||
var ne = MatchingEntity(SnapGrid.GetInDir(Direction.NorthEast));
|
||||
var e = MatchingEntity(SnapGrid.GetInDir(Direction.East));
|
||||
var se = MatchingEntity(SnapGrid.GetInDir(Direction.SouthEast));
|
||||
var s = MatchingEntity(SnapGrid.GetInDir(Direction.South));
|
||||
var sw = MatchingEntity(SnapGrid.GetInDir(Direction.SouthWest));
|
||||
var w = MatchingEntity(SnapGrid.GetInDir(Direction.West));
|
||||
var nw = MatchingEntity(SnapGrid.GetInDir(Direction.NorthWest));
|
||||
var grid = _mapManager.GetGrid(Owner.Transform.GridID);
|
||||
var position = Owner.Transform.Coordinates;
|
||||
var n = MatchingEntity(grid.GetInDir(position, Direction.North));
|
||||
var ne = MatchingEntity(grid.GetInDir(position, Direction.NorthEast));
|
||||
var e = MatchingEntity(grid.GetInDir(position, Direction.East));
|
||||
var se = MatchingEntity(grid.GetInDir(position, Direction.SouthEast));
|
||||
var s = MatchingEntity(grid.GetInDir(position, Direction.South));
|
||||
var sw = MatchingEntity(grid.GetInDir(position, Direction.SouthWest));
|
||||
var w = MatchingEntity(grid.GetInDir(position, Direction.West));
|
||||
var nw = MatchingEntity(grid.GetInDir(position, Direction.NorthWest));
|
||||
|
||||
// ReSharper disable InconsistentNaming
|
||||
var cornerNE = CornerFill.None;
|
||||
@@ -234,28 +238,28 @@ namespace Content.Client.GameObjects.Components.IconSmoothing
|
||||
{
|
||||
base.Shutdown();
|
||||
|
||||
if (SnapGrid != null)
|
||||
if (Owner.Transform.Anchored)
|
||||
{
|
||||
SnapGrid.OnPositionChanged -= SnapGridOnPositionChanged;
|
||||
Owner.EntityManager.EventBus.RaiseEvent(EventSource.Local, new IconSmoothDirtyEvent(Owner, _lastPosition, SnapGrid.Offset, Mode));
|
||||
Owner.EntityManager.EventBus.RaiseEvent(EventSource.Local, new IconSmoothDirtyEvent(Owner, _lastPosition, Mode));
|
||||
}
|
||||
}
|
||||
|
||||
private void SnapGridOnPositionChanged()
|
||||
public void SnapGridOnPositionChanged()
|
||||
{
|
||||
if (SnapGrid != null)
|
||||
if (Owner.Transform.Anchored)
|
||||
{
|
||||
Owner.EntityManager.EventBus.RaiseEvent(EventSource.Local, new IconSmoothDirtyEvent(Owner, _lastPosition, SnapGrid.Offset, Mode));
|
||||
_lastPosition = (Owner.Transform.GridID, SnapGrid.Position);
|
||||
Owner.EntityManager.EventBus.RaiseEvent(EventSource.Local, new IconSmoothDirtyEvent(Owner, _lastPosition, Mode));
|
||||
var grid = _mapManager.GetGrid(Owner.Transform.GridID);
|
||||
_lastPosition = (Owner.Transform.GridID, grid.TileIndicesFor(Owner.Transform.Coordinates));
|
||||
}
|
||||
}
|
||||
|
||||
[System.Diagnostics.Contracts.Pure]
|
||||
protected bool MatchingEntity(IEnumerable<IEntity> candidates)
|
||||
protected bool MatchingEntity(IEnumerable<EntityUid> candidates)
|
||||
{
|
||||
foreach (var entity in candidates)
|
||||
{
|
||||
if (!entity.TryGetComponent(out IconSmoothComponent? other))
|
||||
if (!Owner.EntityManager.ComponentManager.TryGetComponent(entity, out IconSmoothComponent? other))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Diagnostics.Contracts;
|
||||
using Content.Client.GameObjects.Components.IconSmoothing;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Utility;
|
||||
using Robust.Shared.ViewVariables;
|
||||
using static Robust.Client.GameObjects.SpriteComponent;
|
||||
|
||||
@@ -23,6 +26,8 @@ namespace Content.Client.GameObjects.Components
|
||||
{
|
||||
public override string Name => "LowWall";
|
||||
|
||||
[Dependency] private readonly IMapManager _mapManager = default!;
|
||||
|
||||
public CornerFill LastCornerNE { get; private set; }
|
||||
public CornerFill LastCornerSE { get; private set; }
|
||||
public CornerFill LastCornerSW { get; private set; }
|
||||
@@ -65,19 +70,22 @@ namespace Content.Client.GameObjects.Components
|
||||
{
|
||||
base.CalculateNewSprite();
|
||||
|
||||
if (Sprite == null || SnapGrid == null || _overlaySprite == null)
|
||||
if (Sprite == null || !Owner.Transform.Anchored || _overlaySprite == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var (n, nl) = MatchingWall(SnapGrid.GetInDir(Direction.North));
|
||||
var (ne, nel) = MatchingWall(SnapGrid.GetInDir(Direction.NorthEast));
|
||||
var (e, el) = MatchingWall(SnapGrid.GetInDir(Direction.East));
|
||||
var (se, sel) = MatchingWall(SnapGrid.GetInDir(Direction.SouthEast));
|
||||
var (s, sl) = MatchingWall(SnapGrid.GetInDir(Direction.South));
|
||||
var (sw, swl) = MatchingWall(SnapGrid.GetInDir(Direction.SouthWest));
|
||||
var (w, wl) = MatchingWall(SnapGrid.GetInDir(Direction.West));
|
||||
var (nw, nwl) = MatchingWall(SnapGrid.GetInDir(Direction.NorthWest));
|
||||
var grid = _mapManager.GetGrid(Owner.Transform.GridID);
|
||||
var coords = Owner.Transform.Coordinates;
|
||||
|
||||
var (n, nl) = MatchingWall(grid.GetInDir(coords, Direction.North));
|
||||
var (ne, nel) = MatchingWall(grid.GetInDir(coords, Direction.NorthEast));
|
||||
var (e, el) = MatchingWall(grid.GetInDir(coords, Direction.East));
|
||||
var (se, sel) = MatchingWall(grid.GetInDir(coords, Direction.SouthEast));
|
||||
var (s, sl) = MatchingWall(grid.GetInDir(coords, Direction.South));
|
||||
var (sw, swl) = MatchingWall(grid.GetInDir(coords, Direction.SouthWest));
|
||||
var (w, wl) = MatchingWall(grid.GetInDir(coords, Direction.West));
|
||||
var (nw, nwl) = MatchingWall(grid.GetInDir(coords, Direction.NorthWest));
|
||||
|
||||
// ReSharper disable InconsistentNaming
|
||||
var cornerNE = CornerFill.None;
|
||||
@@ -194,9 +202,9 @@ namespace Content.Client.GameObjects.Components
|
||||
LastCornerSW = cornerSW;
|
||||
LastCornerNW = cornerNW;
|
||||
|
||||
foreach (var entity in SnapGrid.GetLocal())
|
||||
foreach (var entity in grid.GetLocal(coords))
|
||||
{
|
||||
if (entity.TryGetComponent(out WindowComponent? window))
|
||||
if (Owner.EntityManager.ComponentManager.TryGetComponent(entity, out WindowComponent? window))
|
||||
{
|
||||
window.UpdateSprite();
|
||||
}
|
||||
@@ -204,11 +212,11 @@ namespace Content.Client.GameObjects.Components
|
||||
}
|
||||
|
||||
[Pure]
|
||||
private (bool connected, bool lowWall) MatchingWall(IEnumerable<IEntity> candidates)
|
||||
private (bool connected, bool lowWall) MatchingWall(IEnumerable<EntityUid> candidates)
|
||||
{
|
||||
foreach (var entity in candidates)
|
||||
{
|
||||
if (!entity.TryGetComponent(out IconSmoothComponent? other))
|
||||
if (!Owner.EntityManager.ComponentManager.TryGetComponent(entity, out IconSmoothComponent? other))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Content.Client.GameObjects.EntitySystems;
|
||||
using Content.Shared.GameObjects.Components;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using static Content.Client.GameObjects.Components.IconSmoothing.IconSmoothComponent;
|
||||
|
||||
@@ -12,18 +15,18 @@ namespace Content.Client.GameObjects.Components
|
||||
[ComponentReference(typeof(SharedWindowComponent))]
|
||||
public sealed class WindowComponent : SharedWindowComponent
|
||||
{
|
||||
[Dependency] private readonly IMapManager _mapManager = default!;
|
||||
|
||||
[DataField("base")]
|
||||
private string? _stateBase;
|
||||
|
||||
private ISpriteComponent? _sprite;
|
||||
private SnapGridComponent? _snapGrid;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
_sprite = Owner.GetComponent<ISpriteComponent>();
|
||||
_snapGrid = Owner.GetComponent<SnapGridComponent>();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -31,11 +34,6 @@ namespace Content.Client.GameObjects.Components
|
||||
{
|
||||
base.Startup();
|
||||
|
||||
if (_snapGrid != null)
|
||||
{
|
||||
_snapGrid.OnPositionChanged += SnapGridOnPositionChanged;
|
||||
}
|
||||
|
||||
Owner.EntityManager.EventBus.RaiseEvent(EventSource.Local, new WindowSmoothDirtyEvent(Owner));
|
||||
|
||||
if (_sprite != null)
|
||||
@@ -67,18 +65,7 @@ namespace Content.Client.GameObjects.Components
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Shutdown()
|
||||
{
|
||||
if (_snapGrid != null)
|
||||
{
|
||||
_snapGrid.OnPositionChanged -= SnapGridOnPositionChanged;
|
||||
}
|
||||
|
||||
base.Shutdown();
|
||||
}
|
||||
|
||||
private void SnapGridOnPositionChanged()
|
||||
public void SnapGridOnPositionChanged()
|
||||
{
|
||||
Owner.EntityManager.EventBus.RaiseEvent(EventSource.Local, new WindowSmoothDirtyEvent(Owner));
|
||||
}
|
||||
@@ -102,14 +89,14 @@ namespace Content.Client.GameObjects.Components
|
||||
|
||||
private LowWallComponent? FindLowWall()
|
||||
{
|
||||
if (_snapGrid == null)
|
||||
{
|
||||
if (!Owner.Transform.Anchored)
|
||||
return null;
|
||||
}
|
||||
|
||||
foreach (var entity in _snapGrid.GetLocal())
|
||||
var grid = _mapManager.GetGrid(Owner.Transform.GridID);
|
||||
var coords = Owner.Transform.Coordinates;
|
||||
foreach (var entity in grid.GetLocal(coords))
|
||||
{
|
||||
if (entity.TryGetComponent(out LowWallComponent? lowWall))
|
||||
if (Owner.EntityManager.ComponentManager.TryGetComponent(entity, out LowWallComponent? lowWall))
|
||||
{
|
||||
return lowWall;
|
||||
}
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
using System;
|
||||
using System;
|
||||
using Content.Shared.GameObjects.Components;
|
||||
using Content.Shared.Utility;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Map;
|
||||
|
||||
namespace Content.Client.GameObjects.Components
|
||||
{
|
||||
@@ -15,10 +17,10 @@ namespace Content.Client.GameObjects.Components
|
||||
base.OnChangeData(component);
|
||||
|
||||
var sprite = component.Owner.GetComponent<ISpriteComponent>();
|
||||
if (!component.Owner.TryGetComponent(out SnapGridComponent? snapGrid))
|
||||
if (!component.Owner.Transform.Anchored)
|
||||
return;
|
||||
|
||||
var lowWall = FindLowWall(snapGrid);
|
||||
var lowWall = FindLowWall(IoCManager.Resolve<IMapManager>(), component.Owner.Transform);
|
||||
if (lowWall == null)
|
||||
return;
|
||||
|
||||
@@ -48,11 +50,13 @@ namespace Content.Client.GameObjects.Components
|
||||
}
|
||||
}
|
||||
|
||||
private static LowWallComponent? FindLowWall(SnapGridComponent snapGrid)
|
||||
private static LowWallComponent? FindLowWall(IMapManager mapManager, ITransformComponent transform)
|
||||
{
|
||||
foreach (var entity in snapGrid.GetLocal())
|
||||
var grid = mapManager.GetGrid(transform.GridID);
|
||||
var coords = transform.Coordinates;
|
||||
foreach (var entity in grid.GetLocal(coords))
|
||||
{
|
||||
if (entity.TryGetComponent(out LowWallComponent? lowWall))
|
||||
if (transform.Owner.EntityManager.ComponentManager.TryGetComponent(entity, out LowWallComponent? lowWall))
|
||||
{
|
||||
return lowWall;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user