action refactor proper ecs edition (#27422)
This commit is contained in:
@@ -4,8 +4,8 @@ using Content.Shared.Mapping;
|
||||
using Content.Shared.Maps;
|
||||
using Robust.Client.Placement;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Utility;
|
||||
using static Robust.Shared.Utility.SpriteSpecifier;
|
||||
|
||||
namespace Content.Client.Mapping;
|
||||
|
||||
@@ -14,16 +14,10 @@ public sealed partial class MappingSystem : EntitySystem
|
||||
[Dependency] private readonly IPlacementManager _placementMan = default!;
|
||||
[Dependency] private readonly ITileDefinitionManager _tileMan = default!;
|
||||
[Dependency] private readonly MetaDataSystem _metaData = default!;
|
||||
[Dependency] private readonly SharedActionsSystem _actions = default!;
|
||||
|
||||
/// <summary>
|
||||
/// The icon to use for space tiles.
|
||||
/// </summary>
|
||||
private readonly SpriteSpecifier _spaceIcon = new Texture(new ("Tiles/cropped_parallax.png"));
|
||||
|
||||
/// <summary>
|
||||
/// The icon to use for entity-eraser.
|
||||
/// </summary>
|
||||
private readonly SpriteSpecifier _deleteIcon = new Texture(new ("Interface/VerbIcons/delete.svg.192dpi.png"));
|
||||
public static readonly EntProtoId SpawnAction = "BaseMappingSpawnAction";
|
||||
public static readonly EntProtoId EraserAction = "ActionMappingEraser";
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
@@ -38,90 +32,46 @@ public sealed partial class MappingSystem : EntitySystem
|
||||
/// some entity or tile into an action. This is somewhat janky, but it seem to work well enough. Though I'd
|
||||
/// prefer if it were to function more like DecalPlacementSystem.
|
||||
/// </summary>
|
||||
private void OnFillActionSlot(FillActionSlotEvent ev)
|
||||
private void OnFillActionSlot(FillActionSlotEvent args)
|
||||
{
|
||||
if (!_placementMan.IsActive)
|
||||
return;
|
||||
|
||||
if (ev.Action != null)
|
||||
if (args.Action != null)
|
||||
return;
|
||||
|
||||
var actionEvent = new StartPlacementActionEvent();
|
||||
ITileDefinition? tileDef = null;
|
||||
|
||||
if (_placementMan.CurrentPermission != null)
|
||||
if (_placementMan.CurrentPermission is {} permission)
|
||||
{
|
||||
actionEvent.EntityType = _placementMan.CurrentPermission.EntityType;
|
||||
actionEvent.PlacementOption = _placementMan.CurrentPermission.PlacementOption;
|
||||
var ev = new StartPlacementActionEvent()
|
||||
{
|
||||
EntityType = permission.EntityType,
|
||||
PlacementOption = permission.PlacementOption,
|
||||
};
|
||||
|
||||
var action = Spawn(SpawnAction);
|
||||
if (_placementMan.CurrentPermission.IsTile)
|
||||
{
|
||||
tileDef = _tileMan[_placementMan.CurrentPermission.TileType];
|
||||
actionEvent.TileId = tileDef.ID;
|
||||
if (_tileMan[_placementMan.CurrentPermission.TileType] is not ContentTileDefinition tileDef)
|
||||
return;
|
||||
|
||||
if (!tileDef.MapAtmosphere && tileDef.Sprite is {} sprite)
|
||||
_actions.SetIcon(action, new SpriteSpecifier.Texture(sprite));
|
||||
ev.TileId = tileDef.ID;
|
||||
_metaData.SetEntityName(action, Loc.GetString(tileDef.Name));
|
||||
}
|
||||
else if (permission.EntityType is {} id)
|
||||
{
|
||||
_actions.SetIcon(action, new SpriteSpecifier.EntityPrototype(id));
|
||||
_metaData.SetEntityName(action, id);
|
||||
}
|
||||
|
||||
_actions.SetEvent(action, ev);
|
||||
args.Action = action;
|
||||
}
|
||||
else if (_placementMan.Eraser)
|
||||
{
|
||||
actionEvent.Eraser = true;
|
||||
args.Action = Spawn(EraserAction);
|
||||
}
|
||||
else
|
||||
return;
|
||||
|
||||
InstantActionComponent action;
|
||||
string name;
|
||||
|
||||
if (tileDef != null)
|
||||
{
|
||||
if (tileDef is not ContentTileDefinition contentTileDef)
|
||||
return;
|
||||
|
||||
var tileIcon = contentTileDef.MapAtmosphere
|
||||
? _spaceIcon
|
||||
: new Texture(contentTileDef.Sprite!.Value);
|
||||
|
||||
action = new InstantActionComponent
|
||||
{
|
||||
ClientExclusive = true,
|
||||
CheckCanInteract = false,
|
||||
Event = actionEvent,
|
||||
Icon = tileIcon
|
||||
};
|
||||
|
||||
name = Loc.GetString(tileDef.Name);
|
||||
}
|
||||
else if (actionEvent.Eraser)
|
||||
{
|
||||
action = new InstantActionComponent
|
||||
{
|
||||
ClientExclusive = true,
|
||||
CheckCanInteract = false,
|
||||
Event = actionEvent,
|
||||
Icon = _deleteIcon,
|
||||
};
|
||||
|
||||
name = Loc.GetString("action-name-mapping-erase");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(actionEvent.EntityType))
|
||||
return;
|
||||
|
||||
action = new InstantActionComponent
|
||||
{
|
||||
ClientExclusive = true,
|
||||
CheckCanInteract = false,
|
||||
Event = actionEvent,
|
||||
Icon = new EntityPrototype(actionEvent.EntityType),
|
||||
};
|
||||
|
||||
name = actionEvent.EntityType;
|
||||
}
|
||||
|
||||
var actionId = Spawn(null);
|
||||
AddComp<Component>(actionId, action);
|
||||
_metaData.SetEntityName(actionId, name);
|
||||
|
||||
ev.Action = actionId;
|
||||
}
|
||||
|
||||
private void OnStartPlacementAction(StartPlacementActionEvent args)
|
||||
|
||||
Reference in New Issue
Block a user