* Default grids go poof * Address review * Update submodule * Fix DoAfterSystem for entities without grid. * Fix SubFloorHideSystem for entities without grid. * Fix ExplosionHelper for coordinates that aren't in a grid * Fix TurfHelpers' GetWorldTileBox crash in the case of invalid grid * Fix tile prying component crash when trying to pry space. * Spill fixes when passing coordinates without grids. * Are you static'in, son? * Change SaveLoadSaveTest grid Id hardcoded value It's still hardcoded, but at least now it's correct! * Only send debug AI thing if grid is not invalid * Update submodule. Co-authored-by: Pieter-Jan Briers <pieterjan.briers+git@gmail.com>
101 lines
3.3 KiB
C#
101 lines
3.3 KiB
C#
using Content.Client.GameObjects.Components;
|
|
using Content.Shared.Maps;
|
|
using Robust.Client.Interfaces.GameObjects.Components;
|
|
using Robust.Shared.GameObjects.Components.Transform;
|
|
using Robust.Shared.GameObjects.Systems;
|
|
using Robust.Shared.Interfaces.Map;
|
|
using Robust.Shared.IoC;
|
|
using Robust.Shared.Map;
|
|
using Robust.Shared.Maths;
|
|
using Robust.Shared.ViewVariables;
|
|
|
|
namespace Content.Client.GameObjects.EntitySystems
|
|
{
|
|
/// <summary>
|
|
/// Entity system backing <see cref="SubFloorHideComponent"/>.
|
|
/// </summary>
|
|
internal sealed class SubFloorHideSystem : EntitySystem
|
|
{
|
|
[Dependency] private readonly IMapManager _mapManager = default!;
|
|
[Dependency] private readonly ITileDefinitionManager _tileDefinitionManager = default!;
|
|
|
|
private bool _enableAll;
|
|
|
|
[ViewVariables(VVAccess.ReadWrite)]
|
|
public bool EnableAll
|
|
{
|
|
get => _enableAll;
|
|
set
|
|
{
|
|
_enableAll = value;
|
|
|
|
UpdateAll();
|
|
}
|
|
}
|
|
|
|
private void UpdateAll()
|
|
{
|
|
foreach (var comp in EntityManager.ComponentManager.EntityQuery<SubFloorHideComponent>())
|
|
{
|
|
if (!_mapManager.TryGetGrid(comp.Owner.Transform.GridID, out var grid)) return;
|
|
|
|
var snapPos = comp.Owner.GetComponent<SnapGridComponent>();
|
|
UpdateTile(grid, snapPos.Position);
|
|
}
|
|
}
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
|
|
IoCManager.InjectDependencies(this);
|
|
|
|
_mapManager.GridChanged += MapManagerOnGridChanged;
|
|
_mapManager.TileChanged += MapManagerOnTileChanged;
|
|
|
|
SubscribeLocalEvent<SubFloorHideDirtyEvent>(HandleDirtyEvent);
|
|
}
|
|
|
|
private void HandleDirtyEvent(SubFloorHideDirtyEvent ev)
|
|
{
|
|
if (!_mapManager.TryGetGrid(ev.Sender.Transform.GridID, out var grid))
|
|
{
|
|
return;
|
|
}
|
|
|
|
var indices = grid.WorldToTile(ev.Sender.Transform.WorldPosition);
|
|
UpdateTile(grid, indices);
|
|
}
|
|
|
|
private void MapManagerOnTileChanged(object sender, TileChangedEventArgs e)
|
|
{
|
|
UpdateTile(_mapManager.GetGrid(e.NewTile.GridIndex), e.NewTile.GridIndices);
|
|
}
|
|
|
|
private void MapManagerOnGridChanged(object sender, GridChangedEventArgs e)
|
|
{
|
|
foreach (var modified in e.Modified)
|
|
{
|
|
UpdateTile(e.Grid, modified.position);
|
|
}
|
|
}
|
|
|
|
private void UpdateTile(IMapGrid grid, Vector2i position)
|
|
{
|
|
var tile = grid.GetTileRef(position);
|
|
var tileDef = (ContentTileDefinition) _tileDefinitionManager[tile.Tile.TypeId];
|
|
foreach (var snapGridComponent in grid.GetSnapGridCell(position, SnapGridOffset.Center))
|
|
{
|
|
var entity = snapGridComponent.Owner;
|
|
if (!entity.TryGetComponent(out SubFloorHideComponent subFloorComponent) ||
|
|
!entity.TryGetComponent(out ISpriteComponent spriteComponent))
|
|
{
|
|
continue;
|
|
}
|
|
|
|
spriteComponent.Visible = EnableAll || !subFloorComponent.Running || tileDef.IsSubFloor;
|
|
}
|
|
}
|
|
}
|
|
}
|