Wires are now actually hidden by floor tiles. (#181)

This commit is contained in:
Pieter-Jan Briers
2019-04-04 15:09:06 +02:00
committed by GitHub
parent 3b0ec7f695
commit 9f3f09871e
10 changed files with 192 additions and 3 deletions

View File

@@ -86,6 +86,7 @@
<Compile Include="GameObjects\Components\Power\PowerCellVisualizer2D.cs" /> <Compile Include="GameObjects\Components\Power\PowerCellVisualizer2D.cs" />
<Compile Include="GameObjects\Components\Sound\SoundComponent.cs" /> <Compile Include="GameObjects\Components\Sound\SoundComponent.cs" />
<Compile Include="GameObjects\Components\Storage\ClientStorageComponent.cs" /> <Compile Include="GameObjects\Components\Storage\ClientStorageComponent.cs" />
<Compile Include="GameObjects\Components\SubFloorHideComponent.cs" />
<Compile Include="GameObjects\Components\Weapons\Ranged\BallisticMagazineVisualizer2D.cs" /> <Compile Include="GameObjects\Components\Weapons\Ranged\BallisticMagazineVisualizer2D.cs" />
<Compile Include="GameObjects\Components\Weapons\Ranged\BallisticMagazineWeaponVisualizer2D.cs" /> <Compile Include="GameObjects\Components\Weapons\Ranged\BallisticMagazineWeaponVisualizer2D.cs" />
<Compile Include="GameObjects\Components\Weapons\Ranged\ClientRangedWeaponComponent.cs" /> <Compile Include="GameObjects\Components\Weapons\Ranged\ClientRangedWeaponComponent.cs" />
@@ -93,6 +94,7 @@
<Compile Include="GameObjects\EntitySystems\ClientNotifySystem.cs" /> <Compile Include="GameObjects\EntitySystems\ClientNotifySystem.cs" />
<Compile Include="GameObjects\EntitySystems\IconSmoothSystem.cs" /> <Compile Include="GameObjects\EntitySystems\IconSmoothSystem.cs" />
<Compile Include="GameObjects\EntitySystems\RangedWeaponSystem.cs" /> <Compile Include="GameObjects\EntitySystems\RangedWeaponSystem.cs" />
<Compile Include="GameObjects\EntitySystems\SubFloorHideSystem.cs" />
<Compile Include="GameObjects\EntitySystems\VerbSystem.cs" /> <Compile Include="GameObjects\EntitySystems\VerbSystem.cs" />
<Compile Include="GameTicking\ClientGameTicker.cs" /> <Compile Include="GameTicking\ClientGameTicker.cs" />
<Compile Include="Graphics\Overlays\CircleMaskOverlay.cs" /> <Compile Include="Graphics\Overlays\CircleMaskOverlay.cs" />

View File

@@ -25,6 +25,7 @@ using SS14.Shared.Interfaces.GameObjects;
using SS14.Shared.IoC; using SS14.Shared.IoC;
using SS14.Shared.Prototypes; using SS14.Shared.Prototypes;
using System; using System;
using Content.Client.GameObjects.Components;
using Content.Client.GameObjects.Components.Mobs; using Content.Client.GameObjects.Components.Mobs;
using Content.Client.GameObjects.Components.Sound; using Content.Client.GameObjects.Components.Sound;
using Content.Client.UserInterface; using Content.Client.UserInterface;
@@ -107,6 +108,8 @@ namespace Content.Client
factory.Register<CameraRecoilComponent>(); factory.Register<CameraRecoilComponent>();
factory.RegisterReference<CameraRecoilComponent, SharedCameraRecoilComponent>(); factory.RegisterReference<CameraRecoilComponent, SharedCameraRecoilComponent>();
factory.Register<SubFloorHideComponent>();
IoCManager.Register<IClientNotifyManager, ClientNotifyManager>(); IoCManager.Register<IClientNotifyManager, ClientNotifyManager>();
IoCManager.Register<ISharedNotifyManager, ClientNotifyManager>(); IoCManager.Register<ISharedNotifyManager, ClientNotifyManager>();
IoCManager.Register<IClientGameTicker, ClientGameTicker>(); IoCManager.Register<IClientGameTicker, ClientGameTicker>();

View File

@@ -0,0 +1,50 @@
using Content.Shared.Maps;
using SS14.Client.Interfaces.GameObjects.Components;
using SS14.Shared.GameObjects;
using SS14.Shared.GameObjects.Components.Transform;
namespace Content.Client.GameObjects.Components
{
/// <summary>
/// Simple component that automatically hides the sibling <see cref="ISpriteComponent"/> when the tile it's on
/// is not a sub floor (plating).
/// </summary>
/// <seealso cref="ContentTileDefinition.IsSubFloor"/>
public sealed class SubFloorHideComponent : Component
{
private SnapGridComponent _snapGridComponent;
public override string Name => "SubFloorHide";
public override void Initialize()
{
base.Initialize();
_snapGridComponent = Owner.GetComponent<SnapGridComponent>();
}
public override void Startup()
{
base.Startup();
_snapGridComponent.OnPositionChanged += SnapGridOnPositionChanged;
Owner.EntityManager.RaiseEvent(Owner, new SubFloorHideDirtyEvent());
}
public override void Shutdown()
{
base.Shutdown();
_snapGridComponent.OnPositionChanged -= SnapGridOnPositionChanged;
}
private void SnapGridOnPositionChanged()
{
Owner.EntityManager.RaiseEvent(Owner, new SubFloorHideDirtyEvent());
}
}
internal sealed class SubFloorHideDirtyEvent : EntitySystemMessage
{
}
}

View File

@@ -0,0 +1,80 @@
using Content.Client.GameObjects.Components;
using Content.Shared.Maps;
using SS14.Client.Interfaces.GameObjects.Components;
using SS14.Shared.GameObjects.Components.Transform;
using SS14.Shared.GameObjects.Systems;
using SS14.Shared.Interfaces.GameObjects;
using SS14.Shared.Interfaces.Map;
using SS14.Shared.IoC;
using SS14.Shared.Map;
namespace Content.Client.GameObjects.EntitySystems
{
/// <summary>
/// Entity system backing <see cref="SubFloorHideComponent"/>.
/// </summary>
internal sealed class SubFloorHideSystem : EntitySystem
{
#pragma warning disable 649
[Dependency] private readonly IMapManager _mapManager;
[Dependency] private readonly ITileDefinitionManager _tileDefinitionManager;
#pragma warning restore 649
public override void Initialize()
{
base.Initialize();
IoCManager.InjectDependencies(this);
_mapManager.GridChanged += MapManagerOnGridChanged;
_mapManager.TileChanged += MapManagerOnTileChanged;
SubscribeEvent<SubFloorHideDirtyEvent>(HandleDirtyEvent);
}
private void HandleDirtyEvent(object sender, SubFloorHideDirtyEvent ev)
{
if (!(sender is IEntity senderEnt))
{
return;
}
var sprite = senderEnt.GetComponent<ISpriteComponent>();
var grid = _mapManager.GetGrid(senderEnt.Transform.GridID);
var position = senderEnt.Transform.GridPosition;
var tileRef = grid.GetTile(position);
var tileDef = (ContentTileDefinition) _tileDefinitionManager[tileRef.Tile.TileId];
sprite.Visible = tileDef.IsSubFloor;
}
private void MapManagerOnTileChanged(object sender, TileChangedEventArgs e)
{
UpdateTile(_mapManager.GetGrid(e.NewTile.GridIndex), e.NewTile.GridTile);
}
private void MapManagerOnGridChanged(object sender, GridChangedEventArgs e)
{
foreach (var modified in e.Modified)
{
UpdateTile(e.Grid, modified.position);
}
}
private void UpdateTile(IMapGrid grid, MapIndices position)
{
var tile = grid.GetTile(position);
var tileDef = (ContentTileDefinition) _tileDefinitionManager[tile.Tile.TileId];
foreach (var snapGridComponent in grid.GetSnapGridCell(position, SnapGridOffset.Center))
{
var entity = snapGridComponent.Owner;
if (!entity.HasComponent<SubFloorHideComponent>() ||
!entity.TryGetComponent(out ISpriteComponent spriteComponent))
{
continue;
}
spriteComponent.Visible = tileDef.IsSubFloor;
}
}
}
}

View File

@@ -140,6 +140,9 @@ namespace Content.Server
factory.Register<CameraRecoilComponent>(); factory.Register<CameraRecoilComponent>();
factory.RegisterReference<CameraRecoilComponent, SharedCameraRecoilComponent>(); factory.RegisterReference<CameraRecoilComponent, SharedCameraRecoilComponent>();
factory.RegisterIgnore("IconSmooth");
factory.RegisterIgnore("SubFloorHide");
IoCManager.Register<ISharedNotifyManager, ServerNotifyManager>(); IoCManager.Register<ISharedNotifyManager, ServerNotifyManager>();
IoCManager.Register<IServerNotifyManager, ServerNotifyManager>(); IoCManager.Register<IServerNotifyManager, ServerNotifyManager>();
IoCManager.Register<IGameTicker, GameTicker>(); IoCManager.Register<IGameTicker, GameTicker>();

View File

@@ -1,10 +1,40 @@
namespace Content.Server.GameObjects.Components.Interactable.Tools using Content.Server.GameObjects.EntitySystems;
using Content.Shared.Maps;
using SS14.Server.GameObjects.EntitySystems;
using SS14.Shared.Interfaces.GameObjects;
using SS14.Shared.Interfaces.Map;
using SS14.Shared.IoC;
using SS14.Shared.Map;
namespace Content.Server.GameObjects.Components.Interactable.Tools
{ {
public class CrowbarComponent : ToolComponent public class CrowbarComponent : ToolComponent, IAfterAttack
{ {
#pragma warning disable 649
[Dependency] private readonly ITileDefinitionManager _tileDefinitionManager;
[Dependency] private readonly IEntitySystemManager _entitySystemManager;
#pragma warning restore 649
/// <summary> /// <summary>
/// Tool that can be used to crowbar things apart, such as deconstructing /// Tool that can be used to crowbar things apart, such as deconstructing
/// </summary> /// </summary>
public override string Name => "Crowbar"; public override string Name => "Crowbar";
public CrowbarComponent()
{
IoCManager.InjectDependencies(this);
}
public void Afterattack(IEntity user, GridCoordinates clicklocation, IEntity attacked)
{
var tile = clicklocation.Grid.GetTile(clicklocation);
var tileDef = (ContentTileDefinition) tile.TileDef;
if (tileDef.CanCrowbar)
{
var underplating = _tileDefinitionManager["underplating"];
clicklocation.Grid.SetTile(clicklocation, underplating.TileId);
_entitySystemManager.GetEntitySystem<AudioSystem>().Play("/Audio/items/crowbar.ogg", Owner);
}
}
} }
} }

View File

@@ -16,6 +16,8 @@ namespace Content.Shared.Maps
public ushort TileId { get; private set; } public ushort TileId { get; private set; }
public string DisplayName { get; private set; } public string DisplayName { get; private set; }
public string SpriteName { get; private set; } public string SpriteName { get; private set; }
public bool IsSubFloor { get; private set; }
public bool CanCrowbar { get; private set; }
public void AssignTileId(ushort id) public void AssignTileId(ushort id)
{ {
@@ -27,6 +29,16 @@ namespace Content.Shared.Maps
Name = mapping.GetNode("name").ToString(); Name = mapping.GetNode("name").ToString();
DisplayName = mapping.GetNode("display_name").ToString(); DisplayName = mapping.GetNode("display_name").ToString();
SpriteName = mapping.GetNode("texture").ToString(); SpriteName = mapping.GetNode("texture").ToString();
if (mapping.TryGetNode("is_subfloor", out var node))
{
IsSubFloor = node.AsBool();
}
if (mapping.TryGetNode("can_crowbar", out node))
{
CanCrowbar = node.AsBool();
}
} }
} }
} }

View File

@@ -20,6 +20,7 @@
base: cable_ base: cable_
key: power_cables key: power_cables
mode: CardinalFlags mode: CardinalFlags
- type: SubFloorHide
snap: snap:
- Wire - Wire

View File

@@ -2,13 +2,19 @@
name: floor name: floor
display_name: Floor display_name: Floor
texture: "floor_steel" texture: "floor_steel"
is_subfloor: false
can_crowbar: true
- type: tile - type: tile
name: floor_white name: floor_white
display_name: White Floor display_name: White Floor
texture: "floor_white" texture: "floor_white"
is_subfloor: false
can_crowbar: true
- type: tile - type: tile
name: floor_techmaint name: floor_techmaint
display_name: Techmaint Floor display_name: Techmaint Floor
texture: "floor_techmaint" texture: "floor_techmaint"
is_subfloor: false
can_crowbar: true

View File

@@ -2,8 +2,10 @@
name: plating name: plating
display_name: Plating display_name: Plating
texture: plating texture: plating
is_subfloor: true
- type: tile - type: tile
name: underplating name: underplating
display_name: Underplating display_name: Underplating
texture: underplating texture: underplating
is_subfloor: true