Hotfix revolver serialization (#8561)
* Hotfix revolver serialization * a
This commit is contained in:
@@ -30,8 +30,9 @@ public sealed class RevolverAmmoProviderComponent : AmmoProviderComponent
|
||||
// Like BallisticAmmoProvider we defer spawning until necessary
|
||||
// AmmoSlots is the instantiated ammo and Chambers is the unspawned ammo (that may or may not have been shot).
|
||||
|
||||
// TODO: Using an array would be better but this throws!
|
||||
[DataField("ammoSlots")]
|
||||
public EntityUid?[] AmmoSlots = Array.Empty<EntityUid?>();
|
||||
public List<EntityUid?> AmmoSlots = new();
|
||||
|
||||
[DataField("chambers")]
|
||||
public bool?[] Chambers = Array.Empty<bool?>();
|
||||
|
||||
@@ -55,13 +55,14 @@ public partial class SharedGunSystem
|
||||
var oldIndex = component.CurrentIndex;
|
||||
component.CurrentIndex = state.CurrentIndex;
|
||||
|
||||
component.AmmoSlots = new EntityUid?[state.AmmoSlots.Length];
|
||||
component.AmmoSlots.EnsureCapacity(state.AmmoSlots.Count);
|
||||
component.AmmoSlots.Clear();
|
||||
component.Chambers = new bool?[state.Chambers.Length];
|
||||
|
||||
DebugTools.Assert(component.AmmoSlots.Length == component.Chambers.Length);
|
||||
DebugTools.Assert(component.AmmoSlots.Count == component.Chambers.Length);
|
||||
|
||||
// Need to copy across the state rather than the ref.
|
||||
for (var i = 0; i < component.AmmoSlots.Length; i++)
|
||||
for (var i = 0; i < component.AmmoSlots.Count; i++)
|
||||
{
|
||||
component.AmmoSlots[i] = state.AmmoSlots[i];
|
||||
component.Chambers[i] = state.Chambers[i];
|
||||
@@ -298,7 +299,14 @@ public partial class SharedGunSystem
|
||||
private void OnRevolverInit(EntityUid uid, RevolverAmmoProviderComponent component, ComponentInit args)
|
||||
{
|
||||
component.AmmoContainer = Containers.EnsureContainer<Container>(uid, RevolverContainer);
|
||||
component.AmmoSlots = new EntityUid?[component.Capacity];
|
||||
component.AmmoSlots.EnsureCapacity(component.Capacity);
|
||||
var remainder = component.Capacity - component.AmmoSlots.Count;
|
||||
|
||||
for (var i = 0; i < remainder; i++)
|
||||
{
|
||||
component.AmmoSlots.Add(null);
|
||||
}
|
||||
|
||||
component.Chambers = new bool?[component.Capacity];
|
||||
|
||||
if (component.FillPrototype != null)
|
||||
@@ -320,7 +328,7 @@ public partial class SharedGunSystem
|
||||
protected sealed class RevolverAmmoProviderComponentState : ComponentState
|
||||
{
|
||||
public int CurrentIndex;
|
||||
public EntityUid?[] AmmoSlots = default!;
|
||||
public List<EntityUid?> AmmoSlots = default!;
|
||||
public bool?[] Chambers = default!;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user