space_engineers/MechanicalDoor/Door.cs
2025-02-08 21:26:21 -05:00

62 lines
1.4 KiB
C#

using Sandbox.ModAPI.Ingame;
using System.Collections.Generic;
namespace IngameScript
{
public class Door
{
private PrefixedConsole _console;
private List<DoorHinge> _hinges;
public bool Locked
{
get
{
foreach (DoorHinge hinge in _hinges)
{
if (!hinge.Locked) return false;
}
return true;
}
}
public Door(Console console, string name)
{
_console = new PrefixedConsole(console, name);
_hinges = new List<DoorHinge>();
}
// Add a hinge to the door
public void AddHinge(IMyMotorStator hinge)
{
_hinges.Add(new DoorHinge(_console, hinge));
}
public void OpenDoor()
{
foreach (DoorHinge hinge in _hinges)
{
hinge.OpenDoorHinge();
}
}
public void CloseDoor()
{
foreach (DoorHinge hinge in _hinges)
{
hinge.CloseDoorHinge();
}
}
// Process the door's movement. This will return true when the door is done moving.
public bool Actuate()
{
bool done = true;
foreach (DoorHinge hinge in _hinges)
{
if (!hinge.Actuate()) done = false;
}
return done;
}
}
}