Fixes edge firelock serialization

This commit is contained in:
Víctor Aguilera Puerto
2020-10-10 19:43:50 +02:00
parent dd385a0511
commit 03b1a78238
3 changed files with 30 additions and 23 deletions

View File

@@ -26,7 +26,9 @@ namespace Content.Server.GameObjects.Components.Atmos
public override string Name => "Airtight";
[ViewVariables]
private int _airBlockedDirection;
private int _initialAirBlockedDirection;
[ViewVariables]
private int _currentAirBlockedDirection;
private bool _airBlocked = true;
private bool _fixVacuum = false;
@@ -50,10 +52,11 @@ namespace Content.Server.GameObjects.Components.Atmos
public AtmosDirection AirBlockedDirection
{
get => (AtmosDirection)_airBlockedDirection;
get => (AtmosDirection)_currentAirBlockedDirection;
set
{
_airBlockedDirection = (int) value;
_currentAirBlockedDirection = (int) value;
_initialAirBlockedDirection = (int)Rotate(AirBlockedDirection, -Owner.Transform.LocalRotation);
UpdatePosition();
}
@@ -68,7 +71,7 @@ namespace Content.Server.GameObjects.Components.Atmos
serializer.DataField(ref _airBlocked, "airBlocked", true);
serializer.DataField(ref _fixVacuum, "fixVacuum", true);
serializer.DataField(ref _airBlockedDirection, "airBlockedDirection", (int)AtmosDirection.All, WithFormat.Flags<AtmosDirectionFlags>());
serializer.DataField(ref _initialAirBlockedDirection, "airBlockedDirection", (int)AtmosDirection.All, WithFormat.Flags<AtmosDirectionFlags>());
serializer.DataField(ref _rotateAirBlocked, "rotateAirBlocked", true);
serializer.DataField(ref _fixAirBlockedDirectionInitialize, "fixAirBlockedDirectionInitialize", true);
}
@@ -88,31 +91,37 @@ namespace Content.Server.GameObjects.Components.Atmos
Owner.EntityManager.EventBus.SubscribeEvent<RotateEvent>(EventSource.Local, this, RotateEvent);
if(_fixAirBlockedDirectionInitialize)
RotateEvent(new RotateEvent(Owner, Angle.South, Owner.Transform.LocalRotation));
RotateEvent(new RotateEvent(Owner, Angle.Zero, Owner.Transform.LocalRotation));
UpdatePosition();
}
private void RotateEvent(RotateEvent ev)
{
if (!_rotateAirBlocked || ev.Sender != Owner || ev.NewRotation == ev.OldRotation || AirBlockedDirection == AtmosDirection.Invalid)
if (!_rotateAirBlocked || ev.Sender != Owner || _initialAirBlockedDirection == (int)AtmosDirection.Invalid)
return;
var diff = ev.NewRotation - ev.OldRotation;
_currentAirBlockedDirection = (int) Rotate((AtmosDirection)_initialAirBlockedDirection, ev.NewRotation);
}
private AtmosDirection Rotate(AtmosDirection myDirection, Angle myAngle)
{
var newAirBlockedDirs = AtmosDirection.Invalid;
if (myAngle == Angle.Zero)
return myDirection;
// TODO ATMOS MULTIZ When we make multiZ atmos, special case this.
for (var i = 0; i < Atmospherics.Directions; i++)
{
var direction = (AtmosDirection) (1 << i);
if (!AirBlockedDirection.HasFlag(direction)) continue;
if (!myDirection.HasFlag(direction)) continue;
var angle = direction.ToAngle();
angle += diff;
angle += myAngle;
newAirBlockedDirs |= angle.ToAtmosDirectionCardinal();
}
AirBlockedDirection = newAirBlockedDirs;
return newAirBlockedDirs;
}
public void MapInit()

View File

@@ -11,18 +11,18 @@ namespace Content.Shared.Atmos
[FlagsFor(typeof(AtmosDirectionFlags))]
public enum AtmosDirection
{
Invalid = 0,
North = 1 << 0,
South = 1 << 1,
East = 1 << 2,
West = 1 << 3,
Invalid = 0, // 0
North = 1 << 0, // 1
South = 1 << 1, // 2
East = 1 << 2, // 4
West = 1 << 3, // 8
NorthEast = North | East,
NorthWest = North | West,
SouthEast = South | East,
SouthWest = South | West,
NorthEast = North | East, // 5
SouthEast = South | East, // 6
NorthWest = North | West, // 9
SouthWest = South | West, // 10
All = North | South | East | West,
All = North | South | East | West, // 15
}
public static class AtmosDirectionHelpers

View File

@@ -76,7 +76,6 @@
id: FirelockEdge
parent: Firelock
name: firelock
prefix: south
components:
- type: Firelock
occludes: false
@@ -85,11 +84,10 @@
enabled: false
- type: Sprite
sprite: Constructible/Structures/Doors/edge_door_hazard.rsi
- type: Airtight
fixVacuum: true
airBlockedDirection:
- South
- East
- type: Collidable
shapes:
- !type:PhysShapeAabb