Update trivial components to use auto comp states (#20539)
This commit is contained in:
@@ -6,7 +6,6 @@ using Content.Shared.Verbs;
|
||||
using Content.Shared.Weapons.Ranged.Components;
|
||||
using Content.Shared.Weapons.Ranged.Events;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
@@ -29,29 +28,6 @@ public abstract partial class SharedGunSystem
|
||||
SubscribeLocalEvent<BallisticAmmoProviderComponent, AfterInteractEvent>(OnBallisticAfterInteract);
|
||||
SubscribeLocalEvent<BallisticAmmoProviderComponent, AmmoFillDoAfterEvent>(OnBallisticAmmoFillDoAfter);
|
||||
SubscribeLocalEvent<BallisticAmmoProviderComponent, UseInHandEvent>(OnBallisticUse);
|
||||
|
||||
SubscribeLocalEvent<BallisticAmmoProviderComponent, ComponentGetState>(OnBallisticGetState);
|
||||
SubscribeLocalEvent<BallisticAmmoProviderComponent, ComponentHandleState>(OnBallisticHandleState);
|
||||
}
|
||||
|
||||
private void OnBallisticGetState(EntityUid uid, BallisticAmmoProviderComponent component, ref ComponentGetState args)
|
||||
{
|
||||
args.State = new BallisticAmmoProviderComponentState()
|
||||
{
|
||||
UnspawnedCount = component.UnspawnedCount,
|
||||
Cycleable = component.Cycleable,
|
||||
Entities = GetNetEntityList(component.Entities),
|
||||
};
|
||||
}
|
||||
|
||||
private void OnBallisticHandleState(EntityUid uid, BallisticAmmoProviderComponent component, ref ComponentHandleState args)
|
||||
{
|
||||
if (args.Current is not BallisticAmmoProviderComponentState state)
|
||||
return;
|
||||
|
||||
component.UnspawnedCount = state.UnspawnedCount;
|
||||
component.Cycleable = state.Cycleable;
|
||||
component.Entities = EnsureEntityList<BallisticAmmoProviderComponent>(state.Entities, uid);
|
||||
}
|
||||
|
||||
private void OnBallisticUse(EntityUid uid, BallisticAmmoProviderComponent component, UseInHandEvent args)
|
||||
@@ -239,7 +215,7 @@ public abstract partial class SharedGunSystem
|
||||
{
|
||||
// TODO this should be part of the prototype, not set on map init.
|
||||
// Alternatively, just track spawned count, instead of unspawned count.
|
||||
if (component.FillProto != null)
|
||||
if (component.Proto != null)
|
||||
{
|
||||
component.UnspawnedCount = Math.Max(0, component.Capacity - component.Container.ContainedEntities.Count);
|
||||
UpdateBallisticAppearance(uid, component);
|
||||
@@ -269,7 +245,7 @@ public abstract partial class SharedGunSystem
|
||||
else if (component.UnspawnedCount > 0)
|
||||
{
|
||||
component.UnspawnedCount--;
|
||||
entity = Spawn(component.FillProto, args.Coordinates);
|
||||
entity = Spawn(component.Proto, args.Coordinates);
|
||||
args.Ammo.Add((entity, EnsureShootable(entity)));
|
||||
}
|
||||
}
|
||||
@@ -292,14 +268,6 @@ public abstract partial class SharedGunSystem
|
||||
Appearance.SetData(uid, AmmoVisuals.AmmoCount, GetBallisticShots(component), appearance);
|
||||
Appearance.SetData(uid, AmmoVisuals.AmmoMax, component.Capacity, appearance);
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
private sealed class BallisticAmmoProviderComponentState : ComponentState
|
||||
{
|
||||
public int UnspawnedCount;
|
||||
public List<NetEntity> Entities = new();
|
||||
public bool Cycleable = true;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user