Reading and controlling gates
FloodGates reads and controls the flood gates in the scene you are in. Each gate is a FloodGateInfo, a snapshot of its state when you asked.
FloodGates read and control the flood gates
This is the class you start from. All() and Get(id) find gates, Open and Close move them, and Changed tells you when a gate has been told to open or to close.
public static class FloodGates
{
public static List<FloodGateInfo> All();
public static FloodGateInfo Get(string id);
public static bool IsOpen(string id);
public static bool IsPowered(string id);
public static bool Open(string id);
public static bool Close(string id);
public static bool SetPowered(string id, bool on);
public static event Action<FloodGateChangedArgs> Changed;
public static bool IsAvailable { get; }
}
| Method | Returns | What it does |
|---|---|---|
All() | List<FloodGateInfo> | Every flood gate in the scene you are in. |
Get(id) | FloodGateInfo | The gate with this id. null when none has it. |
IsOpen(id) | bool | true when the gate is open or opening. false when it is closed or the id is unknown. |
IsPowered(id) | bool | true when the gate has power. false when it has none or the id is unknown. |
Open(id) | bool | Tells the gate to open. true when it started to open. |
Close(id) | bool | Tells the gate to close. true when it started to close. |
SetPowered(id, on) | bool | Turns the gate’s power on or off. true when the power changed. |
| Event | Gives you | When it fires |
|---|---|---|
Changed | FloodGateChangedArgs | A gate has just been told to open or to close. |
| Property | Type | What it means |
|---|---|---|
IsAvailable | bool | false when the change event could not be set up. |
FloodGateInfo a snapshot of one flood gate
All() and Get(id) give you this. It is a copy of the gate’s state when you asked, so ask again for a current IsOpen. (It is filled from the game’s FloodGateControl on the gate’s object.)
public sealed class FloodGateInfo
{
public string Id { get; }
public string Name { get; }
public bool IsOpen { get; }
public bool IsPowered { get; }
}
| Property | Type | What it means |
|---|---|---|
Id | string | The gate’s id: its save id, or its place in the scene if it has none. |
Name | string | The name of the gate’s object in the scene. |
IsOpen | bool | true when the gate is open or is opening. |
IsPowered | bool | false when the gate’s power has been turned off. |
FloodGateChangedArgs what the Changed event tells you
Changed gives you this. The framework builds it from a hook on the game’s gate commands, and only when the open state really changes, so it is the framework’s own type.
public sealed class FloodGateChangedArgs
{
public string Id { get; }
public bool IsOpen { get; }
}
| Property | Type | What it means |
|---|---|---|
Id | string | The same id as FloodGateInfo.Id. |
IsOpen | bool | true when the gate was told to open, false when it was told to close. |
Things to know
All()lists the gates that are switched on in the scene you are in. A gate that is switched off in the scene does not appear. The id is how you point at one gate in the other calls. (The id is the object’s save GUID (see the glossary), or the scene path when it has none.Alllooks at activeFloodGateControlobjects only.)IsOpenfollows the command, not the gate’s position. It becomestruethe moment the gate is told to open, and it becomesfalsethe moment it is told to close. A gate that is still closing already reads as closed. (It reads the game’sopenflag.)IsPoweredisfalseonce the gate’s power has been turned off. (It is the game’spowerOffflag, turned around.)OpenandCloseask the gate to move, and they returntrueonly when the state really changed.SetPoweredturns the gate’s power on or off. It returnstruewhen the gate’s power is now what you asked for. It does not pretend to succeed when nothing changed. (It calls the game’sTurnOnorTurnOff.)- The power is saved with the game. A power state you set survives a save and a load. (The
powerOfffield is a[fsProperty]thatOnSavingGamewrites.) Changedfires when a gate is told to open or to close, no matter who caused it. It fires only whenIsOpenreally changes.- Changing the power does not fire
Changed. Only a change of open or closed does. But switching the power back on while a gate is half way can turn it around, and that does fireChanged. (See Turning the power back on.)
Limits
OpenandClosereturnfalsefor an unknown or empty id, for a gate that is already in that state, and while a save is loading or saving. The game also refuses in these cases, and then you getfalsetoo: the gate is in an alarm, it has no power, or it is moving and its “press while blinking” setting is off. (They call the game’sOpenFloodGateandCloseFloodGate. The game refuses whenalertorpowerOffis set, or whenisBlinkingis set andallowPressOnBlinkingis false.)SetPoweredreturnsfalsefor an unknown or empty id, when the gate already has that power state, and while a save is loading or saving.Changeddoes not fire while a save is loading.IsAvailableisfalsewhen the change event could not be set up. ThenChangednever fires. The reads,Open,CloseandSetPoweredkeep working.