Doors! (#12)
* Doors WiP * Kinda seem to work now? * Finished * Oh yeah maybe enable that. * It works except it doesn't * Undo formatting changes * BuildChecker too
This commit is contained in:
committed by
GitHub
parent
ec3e7968a6
commit
7f196fc415
@@ -63,6 +63,7 @@
|
|||||||
<Compile Include="Prototypes\DiscoBall.cs" />
|
<Compile Include="Prototypes\DiscoBall.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="GameObjects\Components\Items\ClientHandsComponent.cs" />
|
<Compile Include="GameObjects\Components\Items\ClientHandsComponent.cs" />
|
||||||
|
<Compile Include="GameObjects\Components\Doors\ClientDoorComponent.cs" />
|
||||||
<Compile Include="Interfaces\GameObjects\Components\Items\IHandsComponent.cs" />
|
<Compile Include="Interfaces\GameObjects\Components\Items\IHandsComponent.cs" />
|
||||||
<Compile Include="UserInterface\HandsGui.cs" />
|
<Compile Include="UserInterface\HandsGui.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|||||||
@@ -21,6 +21,8 @@ namespace Content.Client
|
|||||||
|
|
||||||
factory.Register<HandsComponent>();
|
factory.Register<HandsComponent>();
|
||||||
factory.RegisterReference<HandsComponent, IHandsComponent>();
|
factory.RegisterReference<HandsComponent, IHandsComponent>();
|
||||||
|
|
||||||
|
factory.Register<ClientDoorComponent>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,71 @@
|
|||||||
|
using Content.Shared.GameObjects;
|
||||||
|
using Lidgren.Network;
|
||||||
|
using SS14.Client.GameObjects;
|
||||||
|
using SS14.Shared.GameObjects;
|
||||||
|
using SS14.Shared.Utility;
|
||||||
|
using YamlDotNet.RepresentationModel;
|
||||||
|
|
||||||
|
namespace Content.Client.GameObjects
|
||||||
|
{
|
||||||
|
public class ClientDoorComponent : SharedDoorComponent
|
||||||
|
{
|
||||||
|
public bool Opened { get; private set; }
|
||||||
|
private SpriteComponent spriteComponent;
|
||||||
|
|
||||||
|
private string OpenSprite = "door_ewo";
|
||||||
|
private string CloseSprite = "door_ew";
|
||||||
|
|
||||||
|
public override void Initialize()
|
||||||
|
{
|
||||||
|
base.Initialize();
|
||||||
|
|
||||||
|
spriteComponent = Owner.GetComponent<SpriteComponent>();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Open()
|
||||||
|
{
|
||||||
|
Opened = true;
|
||||||
|
spriteComponent.SetSpriteByKey(OpenSprite);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Close()
|
||||||
|
{
|
||||||
|
Opened = false;
|
||||||
|
spriteComponent.SetSpriteByKey(CloseSprite);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void HandleComponentState(ComponentState state)
|
||||||
|
{
|
||||||
|
var castState = (DoorComponentState)state;
|
||||||
|
if (castState.Opened == Opened)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (castState.Opened)
|
||||||
|
{
|
||||||
|
Open();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void LoadParameters(YamlMappingNode mapping)
|
||||||
|
{
|
||||||
|
base.LoadParameters(mapping);
|
||||||
|
|
||||||
|
YamlNode node;
|
||||||
|
if (mapping.TryGetNode("openstate", out node))
|
||||||
|
{
|
||||||
|
OpenSprite = node.AsString();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mapping.TryGetNode("closestate", out node))
|
||||||
|
{
|
||||||
|
CloseSprite = node.AsString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -56,6 +56,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="EntryPoint.cs"/>
|
<Compile Include="EntryPoint.cs"/>
|
||||||
|
<Compile Include="GameObjects\Components\Doors\ServerDoorComponent.cs" />
|
||||||
<Compile Include="GameObjects\Components\Interactable\InteractableComponent.cs" />
|
<Compile Include="GameObjects\Components\Interactable\InteractableComponent.cs" />
|
||||||
<Compile Include="Interfaces\GameObjects\Components\Interactable\IInteractableComponent.cs" />
|
<Compile Include="Interfaces\GameObjects\Components\Interactable\IInteractableComponent.cs" />
|
||||||
<Compile Include="Interfaces\GameObjects\Components\Items\IHandsComponent.cs"/>
|
<Compile Include="Interfaces\GameObjects\Components\Items\IHandsComponent.cs"/>
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ namespace Content.Server
|
|||||||
factory.Register<DamageableComponent>();
|
factory.Register<DamageableComponent>();
|
||||||
factory.Register<DestructibleComponent>();
|
factory.Register<DestructibleComponent>();
|
||||||
factory.Register<TemperatureComponent>();
|
factory.Register<TemperatureComponent>();
|
||||||
|
factory.Register<ServerDoorComponent>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,104 @@
|
|||||||
|
using Content.Server.Interfaces.GameObjects;
|
||||||
|
using Content.Shared.GameObjects;
|
||||||
|
using SS14.Server.GameObjects;
|
||||||
|
using SS14.Shared.GameObjects;
|
||||||
|
using SS14.Shared.Interfaces.GameObjects.Components;
|
||||||
|
using SS14.Shared.Log;
|
||||||
|
using SS14.Shared.Maths;
|
||||||
|
|
||||||
|
namespace Content.Server.GameObjects
|
||||||
|
{
|
||||||
|
public class ServerDoorComponent : SharedDoorComponent
|
||||||
|
{
|
||||||
|
public bool Opened { get; private set; }
|
||||||
|
|
||||||
|
private float OpenTimeCounter;
|
||||||
|
|
||||||
|
private IInteractableComponent interactableComponent;
|
||||||
|
private CollidableComponent collidableComponent;
|
||||||
|
|
||||||
|
public override void Initialize()
|
||||||
|
{
|
||||||
|
base.Initialize();
|
||||||
|
|
||||||
|
interactableComponent = Owner.GetComponent<IInteractableComponent>();
|
||||||
|
interactableComponent.OnAttackHand += OnAttackHand;
|
||||||
|
collidableComponent = Owner.GetComponent<CollidableComponent>();
|
||||||
|
collidableComponent.OnBump += OnBump;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void OnRemove()
|
||||||
|
{
|
||||||
|
interactableComponent.OnAttackHand -= OnAttackHand;
|
||||||
|
interactableComponent = null;
|
||||||
|
collidableComponent.OnBump -= OnBump;
|
||||||
|
collidableComponent = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnAttackHand(object sender, AttackHandEventArgs args)
|
||||||
|
{
|
||||||
|
if (Opened)
|
||||||
|
{
|
||||||
|
Close();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Open();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnBump(object sender, BumpEventArgs args)
|
||||||
|
{
|
||||||
|
Logger.Info("Bump!");
|
||||||
|
if (Opened)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Open();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Open()
|
||||||
|
{
|
||||||
|
Opened = true;
|
||||||
|
collidableComponent.IsHardCollidable = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Close()
|
||||||
|
{
|
||||||
|
if (collidableComponent.TryCollision(Vector2.Zero))
|
||||||
|
{
|
||||||
|
// Do nothing, somebody's in the door.
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
Opened = false;
|
||||||
|
OpenTimeCounter = 0;
|
||||||
|
collidableComponent.IsHardCollidable = true;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override ComponentState GetComponentState()
|
||||||
|
{
|
||||||
|
return new DoorComponentState(Opened);
|
||||||
|
}
|
||||||
|
|
||||||
|
private const float AUTO_CLOSE_DELAY = 5;
|
||||||
|
public override void Update(float frameTime)
|
||||||
|
{
|
||||||
|
if (!Opened)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
OpenTimeCounter += frameTime;
|
||||||
|
if (OpenTimeCounter > AUTO_CLOSE_DELAY)
|
||||||
|
{
|
||||||
|
if (!Close())
|
||||||
|
{
|
||||||
|
// Try again in 2 seconds if it's jammed or something.
|
||||||
|
OpenTimeCounter -= 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -55,6 +55,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="EntryPoint.cs" />
|
<Compile Include="EntryPoint.cs" />
|
||||||
|
<Compile Include="GameObjects\Components\Doors\SharedDoorComponent.cs" />
|
||||||
<Compile Include="GameObjects\ContentNetIDs.cs" />
|
<Compile Include="GameObjects\ContentNetIDs.cs" />
|
||||||
<Compile Include="GameObjects\PhysicalConstants.cs" />
|
<Compile Include="GameObjects\PhysicalConstants.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
using System;
|
||||||
|
using SS14.Shared.GameObjects;
|
||||||
|
|
||||||
|
namespace Content.Shared.GameObjects
|
||||||
|
{
|
||||||
|
public abstract class SharedDoorComponent : Component
|
||||||
|
{
|
||||||
|
public override string Name => "Door";
|
||||||
|
public override uint? NetID => ContentNetIDs.DOOR;
|
||||||
|
public override Type StateType => typeof(DoorComponentState);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Serializable]
|
||||||
|
public class DoorComponentState : ComponentState
|
||||||
|
{
|
||||||
|
public readonly bool Opened;
|
||||||
|
|
||||||
|
public DoorComponentState(bool opened) : base(ContentNetIDs.DOOR)
|
||||||
|
{
|
||||||
|
Opened = opened;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,5 +7,6 @@
|
|||||||
public const uint DESTRUCTIBLE = 1001;
|
public const uint DESTRUCTIBLE = 1001;
|
||||||
public const uint TEMPERATURE = 1002;
|
public const uint TEMPERATURE = 1002;
|
||||||
public const uint HANDS = 1003;
|
public const uint HANDS = 1003;
|
||||||
|
public const uint DOOR = 1004;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,9 @@
|
|||||||
sprite: player_shoes
|
sprite: player_shoes
|
||||||
notWornSprite: shoes
|
notWornSprite: shoes
|
||||||
|
|
||||||
|
- type: Icon
|
||||||
|
icon: shoes
|
||||||
|
|
||||||
- type: entity
|
- type: entity
|
||||||
parent: BaseItem
|
parent: BaseItem
|
||||||
id: JanitorUniformItem
|
id: JanitorUniformItem
|
||||||
@@ -15,3 +18,6 @@
|
|||||||
- type: WearableAnimatedSprite
|
- type: WearableAnimatedSprite
|
||||||
sprite: player_jumpsuit_gray
|
sprite: player_jumpsuit_gray
|
||||||
notWornSprite: janitorsuit
|
notWornSprite: janitorsuit
|
||||||
|
|
||||||
|
- type: Icon
|
||||||
|
icon: janitorsuit
|
||||||
|
|||||||
25
Resources/Prototypes/Entities/Door.yml
Normal file
25
Resources/Prototypes/Entities/Door.yml
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
- type: entity
|
||||||
|
id: DoorContent
|
||||||
|
name: Actual door
|
||||||
|
components:
|
||||||
|
- type: Transform
|
||||||
|
- type: Clickable
|
||||||
|
- type: Interactable
|
||||||
|
- type: Sprite
|
||||||
|
drawdepth: FloorPlaceable
|
||||||
|
sprites:
|
||||||
|
- door_ew
|
||||||
|
- door_ewo
|
||||||
|
|
||||||
|
- type: Icon
|
||||||
|
icon: door_ew
|
||||||
|
|
||||||
|
- type: BoundingBox
|
||||||
|
sizeX: 1.9
|
||||||
|
offsetY: 1.5
|
||||||
|
- type: Collidable
|
||||||
|
- type: Door
|
||||||
|
|
||||||
|
placement:
|
||||||
|
snap:
|
||||||
|
- Wall
|
||||||
Reference in New Issue
Block a user