Editor/Modules/ArchDockToggles.cs
namespace Sunless.Architecture;
// A toggle the GAME hangs on the Plan Layers action row, contributed through IArchAddon.Contributes() like any other
// table entry. The fourth thing an addon may bring, and the only one that is a control rather than a subtool part:
// a game-side view mode the author wants to flip while working in the plan, without leaving the tool to find it.
public interface IArchDockToggle {
// Classic Material Icons only - the editor's font has no Material Symbols glyphs, and a missing one renders as
// an empty box rather than failing.
string Icon { get; }
string ToolTip { get; }
bool Held { get; }
void Pressed( bool held );
}
public static class ArchDockToggles {
public static IArchDockToggle[] Contributed() {
return ArchAddons.Load().Contributed<IArchDockToggle>();
}
// An addon that throws is reported and walked past, the way ArchAddons treats one that throws while contributing:
// a broken game-side view mode must not be the whole action row refusing to press.
public static bool Held( IArchDockToggle toggle ) {
try {
return toggle.Held;
} catch ( Exception fault ) {
Log.Warning( $"Architecture dock toggle {toggle.Icon} threw while reading its state: {fault.Message}" );
return false;
}
}
public static void Press( IArchDockToggle toggle, bool held ) {
try {
toggle.Pressed( held );
} catch ( Exception fault ) {
Log.Warning( $"Architecture dock toggle {toggle.Icon} threw while pressed: {fault.Message}" );
}
}
}