action refactor proper ecs edition (#27422)

This commit is contained in:
deltanedas
2025-05-28 19:52:11 +00:00
committed by GitHub
parent a9f7cfbcb6
commit b3825dce97
111 changed files with 1995 additions and 2901 deletions

View File

@@ -1,4 +1,5 @@
using Content.Shared.Actions;
using Content.Shared.Actions.Components;
using Content.Shared.Hands.Components;
using Content.Shared.Hands.EntitySystems;
using Content.Shared.IdentityManagement;
@@ -73,23 +74,21 @@ public abstract partial class SharedItemRecallSystem : EntitySystem
if (!Resolve(ent.Owner, ref ent.Comp, false))
return;
if (!TryComp<InstantActionComponent>(ent.Comp.MarkedByAction, out var instantAction))
if (_actions.GetAction(ent.Comp.MarkedByAction) is not {} action)
return;
var actionOwner = instantAction.AttachedEntity;
if (actionOwner == null)
if (action.Comp.AttachedEntity is not {} user)
return;
if (TryComp<EmbeddableProjectileComponent>(ent, out var projectile))
_proj.EmbedDetach(ent, projectile, actionOwner.Value);
_proj.EmbedDetach(ent, projectile, user);
_popups.PopupPredicted(Loc.GetString("item-recall-item-summon-self", ("item", ent)),
Loc.GetString("item-recall-item-summon-others", ("item", ent), ("name", Identity.Entity(actionOwner.Value, EntityManager))),
actionOwner.Value, actionOwner.Value);
_popups.PopupPredictedCoordinates(Loc.GetString("item-recall-item-disappear", ("item", ent)), Transform(ent).Coordinates, actionOwner.Value);
Loc.GetString("item-recall-item-summon-others", ("item", ent), ("name", Identity.Entity(user, EntityManager))),
user, user);
_popups.PopupPredictedCoordinates(Loc.GetString("item-recall-item-disappear", ("item", ent)), Transform(ent).Coordinates, user);
_hands.TryForcePickupAnyHand(actionOwner.Value, ent);
_hands.TryForcePickupAnyHand(user, ent);
}
private void OnRecallMarkerShutdown(Entity<RecallMarkerComponent> ent, ref ComponentShutdown args)
@@ -99,24 +98,22 @@ public abstract partial class SharedItemRecallSystem : EntitySystem
private void TryMarkItem(Entity<ItemRecallComponent> ent, EntityUid item)
{
if (!TryComp<InstantActionComponent>(ent, out var instantAction))
if (_actions.GetAction(ent.Owner) is not {} action)
return;
var actionOwner = instantAction.AttachedEntity;
if (actionOwner == null)
if (action.Comp.AttachedEntity is not {} user)
return;
AddToPvsOverride(item, actionOwner.Value);
AddToPvsOverride(item, user);
var marker = AddComp<RecallMarkerComponent>(item);
ent.Comp.MarkedEntity = item;
Dirty(ent);
marker.MarkedByAction = ent.Owner;
UpdateActionAppearance(ent);
var marker = AddComp<RecallMarkerComponent>(item);
marker.MarkedByAction = ent;
Dirty(item, marker);
UpdateActionAppearance((action, action, ent));
}
private void TryUnmarkItem(EntityUid item)
@@ -124,52 +121,47 @@ public abstract partial class SharedItemRecallSystem : EntitySystem
if (!TryComp<RecallMarkerComponent>(item, out var marker))
return;
if (!TryComp<InstantActionComponent>(marker.MarkedByAction, out var instantAction))
if (_actions.GetAction(marker.MarkedByAction) is not {} action)
return;
if (TryComp<ItemRecallComponent>(marker.MarkedByAction, out var action))
if (TryComp<ItemRecallComponent>(action, out var itemRecall))
{
// For some reason client thinks the station grid owns the action on client and this doesn't work. It doesn't work in PopupEntity(mispredicts) and PopupPredicted either(doesnt show).
// I don't have the heart to move this code to server because of this small thing.
// This line will only do something once that is fixed.
if (instantAction.AttachedEntity != null)
if (action.Comp.AttachedEntity is {} user)
{
_popups.PopupClient(Loc.GetString("item-recall-item-unmark", ("item", item)), instantAction.AttachedEntity.Value, instantAction.AttachedEntity.Value, PopupType.MediumCaution);
RemoveFromPvsOverride(item, instantAction.AttachedEntity.Value);
_popups.PopupClient(Loc.GetString("item-recall-item-unmark", ("item", item)), user, user, PopupType.MediumCaution);
RemoveFromPvsOverride(item, user);
}
action.MarkedEntity = null;
UpdateActionAppearance((marker.MarkedByAction.Value, action));
Dirty(marker.MarkedByAction.Value, action);
itemRecall.MarkedEntity = null;
UpdateActionAppearance((action, action, itemRecall));
Dirty(action, itemRecall);
}
RemCompDeferred<RecallMarkerComponent>(item);
}
private void UpdateActionAppearance(Entity<ItemRecallComponent> action)
private void UpdateActionAppearance(Entity<ActionComponent, ItemRecallComponent> action)
{
if (!TryComp<InstantActionComponent>(action, out var instantAction))
return;
if (action.Comp.MarkedEntity == null)
if (action.Comp2.MarkedEntity is {} marked)
{
if (action.Comp.InitialName != null)
_metaData.SetEntityName(action, action.Comp.InitialName);
if (action.Comp.InitialDescription != null)
_metaData.SetEntityDescription(action, action.Comp.InitialDescription);
_actions.SetEntityIcon(action, null, instantAction);
if (action.Comp2.WhileMarkedName is {} name)
_metaData.SetEntityName(action, Loc.GetString(name, ("item", marked)));
if (action.Comp2.WhileMarkedDescription is {} desc)
_metaData.SetEntityDescription(action, Loc.GetString(desc, ("item", marked)));
_actions.SetEntityIcon((action, action), marked);
}
else
{
if (action.Comp.WhileMarkedName != null)
_metaData.SetEntityName(action, Loc.GetString(action.Comp.WhileMarkedName,
("item", action.Comp.MarkedEntity.Value)));
if (action.Comp.WhileMarkedDescription != null)
_metaData.SetEntityDescription(action, Loc.GetString(action.Comp.WhileMarkedDescription,
("item", action.Comp.MarkedEntity.Value)));
_actions.SetEntityIcon(action, action.Comp.MarkedEntity, instantAction);
if (action.Comp2.InitialName is {} name)
_metaData.SetEntityName(action, name);
if (action.Comp2.InitialDescription is {} desc)
_metaData.SetEntityDescription(action, desc);
_actions.SetEntityIcon((action, action), null);
}
}