Switch
namespace Griff.Scenes;
public sealed class Switch : ComponentTurns things on and off with no code: levers, pressure plates, buttons, locks. While it’s on, its Targets are on (a mover moves, a spawner spawns, a door unlocks, anything else appears) and its Hides are hidden (a barrier, a wall of spikes). While it’s off, it’s the other way round, from the start of the game. Needs a collider, usually a trigger.
Names are looked for inside the switch first, so a locked block can hide itself; otherwise every entity in the scene with that name is switched. If several switches name the same entity, it’s on only while all of them are, so a gate can need two plates held down.
This is a component: its saved properties are on its component page.
Properties
Section titled “Properties”BeatOffset
Section titled “BeatOffset”public int BeatOffset { get; set; }Steps this many beats later: with two on every 2 beats, one 1 beat later, they take turns.
public int Beats { get; set; }Steps to the music of a BeatClock: flips itself on or off on every this many beats, as well as however it’s worked (though a plate stays as it’s held): spikes that come and go, a gate that opens on the bar. 0 doesn’t.
public string? Clock { get; set; }The entity whose BeatClock it steps to. Empty follows the first in the scene.
public string? Hides { get; set; }What it hides while it’s on, by name, separated by commas: a barrier, a locked block (even itself).
public bool IsOn { get; set; }True while it’s on. Tick it to start switched on; scripts can set it too.
public string? Key { get; set; }An item it needs to turn on, e.g. “Key”: whoever works it must have one in their Inventory, and it’s used up. It only takes it once; after that this is cleared and it works like any other switch.
Layers
Section titled “Layers”public string? Layers { get; set; }The collision layers that work it, e.g. “Player” or “Player, Crate”. Empty lets anything with a Body.
public SwitchMode Mode { get; set; }How it’s switched: a lever flipped with Interact, a plate held down by standing on it, or a button pressed once.
NeedsFlag
Section titled “NeedsFlag”public string? NeedsFlag { get; set; }A flag that has to be set before it can be worked, e.g. “PowerOn” (set by a trigger’s Set Flag, a dialogue’s “[set PowerOn]” or a script’s Game.SetFlag), or “not PowerOn” for while it isn’t. Until then levers, plates and buttons do nothing and its prompt stays hidden; a trigger’s or script’s On still turns it on.
OffMessage
Section titled “OffMessage”public string? OffMessage { get; set; }A message sent with Game.Send when it turns off, with this entity as its data.
OnFrame
Section titled “OnFrame”public int OnFrame { get; set; }The sprite-sheet frame its sprite shows while it’s on (a lever pulled the other way). -1 leaves it alone.
OnMessage
Section titled “OnMessage”public string? OnMessage { get; set; }A message sent with Game.Send when it turns on, with this entity as its data.
OnTime
Section titled “OnTime”public float OnTime { get; set; }Seconds it stays on before turning itself off again: a timed button. 0 stays on.
OnTint
Section titled “OnTint”public Color OnTint { get; set; }The color its sprite turns while it’s on. Transparent leaves it alone.
Prompt
Section titled “Prompt”public string? Prompt { get; set; }The name of an entity to show only while it can be worked with Interact, e.g. a “Press E” hint above a lever. It’s hidden the rest of the time.
public string? Sound { get; set; }A sound played when it turns on or off, e.g. “Sounds/click.wav”.
Targets
Section titled “Targets”public string? Targets { get; set; }What it turns on, by name, separated by commas: a Mover moves (a Once one slides back when it’s switched off again), a Spawner or Shooter runs, particles emit, an animation plays, a Door unlocks; anything else appears.
Methods
Section titled “Methods”AcceptsLayer
Section titled “AcceptsLayer”public bool AcceptsLayer(string? layer)True if something on collision layer layer can work it.
public static IEnumerable<Entity> Named(Entity owner, string? names)The entities a list of names (Targets or Hides) means: for each name, those inside owner (itself included) if there are any, else every entity in the scene called that.
Toggle
Section titled “Toggle”public void Toggle()Turns it on if it’s off, and off if it’s on.
TurnOff
Section titled “TurnOff”public void TurnOff()Turns it off.
TurnOn
Section titled “TurnOn”public void TurnOn()Turns it on, as working it does (sounding, sending its On Message and switching its targets).
Events
Section titled “Events”Changed
Section titled “Changed”public event Action<bool>? ChangedRaised when it turns on or off, with whether it’s now on.