From 4b346e85bc9b576b5be1025c46a7b2df300f19e4 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Wed, 19 Jan 2022 11:51:59 +0100 Subject: [PATCH] replace lambdas with loops --- Illumilib/IllumilibLighting.cs | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/Illumilib/IllumilibLighting.cs b/Illumilib/IllumilibLighting.cs index c36a152..bb0390d 100644 --- a/Illumilib/IllumilibLighting.cs +++ b/Illumilib/IllumilibLighting.cs @@ -47,7 +47,8 @@ namespace Illumilib { public static void Dispose() { if (!Initialized) return; - ForEach(s => s.Dispose()); + foreach (var system in systems) + system.Dispose(); systems = null; } @@ -58,7 +59,9 @@ namespace Illumilib { /// The color's green value, between 0 and 1 /// The color's blue value, between 0 and 1 public static void SetAllLighting(float r, float g, float b) { - ForEach(s => s.SetAllLighting(r, g, b)); + EnsureInitialized(); + foreach (var system in systems) + system.SetAllLighting(r, g, b); } /// @@ -68,7 +71,9 @@ namespace Illumilib { /// The color's green value, between 0 and 1 /// The color's blue value, between 0 and 1 public static void SetKeyboardLighting(float r, float g, float b) { - ForEach(s => s.SetKeyboardLighting(r, g, b)); + EnsureInitialized(); + foreach (var system in systems) + system.SetKeyboardLighting(r, g, b); } /// @@ -82,11 +87,13 @@ namespace Illumilib { /// The color's blue value, between 0 and 1 /// Thrown if the positions are out of range in relation to and public static void SetKeyboardLighting(int x, int y, float r, float g, float b) { + EnsureInitialized(); if (x < 0 || x >= KeyboardWidth) throw new ArgumentOutOfRangeException(nameof(x)); if (y < 0 || y >= KeyboardHeight) throw new ArgumentOutOfRangeException(nameof(y)); - ForEach(s => s.SetKeyboardLighting(x, y, r, g, b)); + foreach (var system in systems) + system.SetKeyboardLighting(x, y, r, g, b); } /// @@ -103,11 +110,13 @@ namespace Illumilib { /// The color's blue value, between 0 and 1 /// Thrown if the positions are out of range in relation to and public static void SetKeyboardLighting(int x, int y, int width, int height, float r, float g, float b) { + EnsureInitialized(); if (x < 0 || x + width > KeyboardWidth) throw new ArgumentOutOfRangeException(nameof(x)); if (y < 0 || y + height > KeyboardHeight) throw new ArgumentOutOfRangeException(nameof(y)); - ForEach(s => s.SetKeyboardLighting(x, y, width, height, r, g, b)); + foreach (var system in systems) + system.SetKeyboardLighting(x, y, width, height, r, g, b); } /// @@ -119,7 +128,9 @@ namespace Illumilib { /// The color's green value, between 0 and 1 /// The color's blue value, between 0 and 1 public static void SetKeyboardLighting(KeyboardKeys key, float r, float g, float b) { - ForEach(s => s.SetKeyboardLighting(key, r, g, b)); + EnsureInitialized(); + foreach (var system in systems) + system.SetKeyboardLighting(key, r, g, b); } /// @@ -129,14 +140,14 @@ namespace Illumilib { /// The color's green value, between 0 and 1 /// The color's blue value, between 0 and 1 public static void SetMouseLighting(float r, float g, float b) { - ForEach(s => s.SetMouseLighting(r, g, b)); + EnsureInitialized(); + foreach (var system in systems) + system.SetMouseLighting(r, g, b); } - private static void ForEach(Action action) { + private static void EnsureInitialized() { if (!Initialized) throw new InvalidOperationException("Illumilib has not been initialized yet"); - foreach (var system in systems) - action(system); } }