From 82c9db90e5bdb9b3d89453c7a96a415ea6e97fe3 Mon Sep 17 00:00:00 2001 From: aonkeeper4 Date: Fri, 6 Jun 2025 22:39:43 +0100 Subject: [PATCH 1/3] Add reskinnability to Switch Blocks and Color Switches; add Switch Block Color Controller --- Code/Entities/ColorSwitch.cs | 55 ++++++++------ Code/Entities/SwitchBlock.cs | 23 +++--- Code/Entities/SwitchBlockColorController.cs | 25 +++++++ Code/Misc/Extensions/EnumExt.cs | 24 ++++--- .../onoff/colorcontroller/blue.png | Bin 0 -> 227 bytes .../onoff/colorcontroller/lime.png | Bin 0 -> 218 bytes .../onoff/colorcontroller/orange.png | Bin 0 -> 223 bytes .../onoff/colorcontroller/outline.png | Bin 0 -> 172 bytes .../onoff/colorcontroller/rose.png | Bin 0 -> 229 bytes Loenn/entities/color_switch.lua | 8 ++- Loenn/entities/switch_block.lua | 6 +- .../switch_block_color_controller.lua | 68 ++++++++++++++++++ Loenn/lang/en_gb.lang | 11 +++ 13 files changed, 177 insertions(+), 43 deletions(-) create mode 100644 Code/Entities/SwitchBlockColorController.cs create mode 100644 Graphics/Atlases/Gameplay/objects/VortexHelper/onoff/colorcontroller/blue.png create mode 100644 Graphics/Atlases/Gameplay/objects/VortexHelper/onoff/colorcontroller/lime.png create mode 100644 Graphics/Atlases/Gameplay/objects/VortexHelper/onoff/colorcontroller/orange.png create mode 100644 Graphics/Atlases/Gameplay/objects/VortexHelper/onoff/colorcontroller/outline.png create mode 100644 Graphics/Atlases/Gameplay/objects/VortexHelper/onoff/colorcontroller/rose.png create mode 100644 Loenn/entities/switch_block_color_controller.lua diff --git a/Code/Entities/ColorSwitch.cs b/Code/Entities/ColorSwitch.cs index f8817ca..e79450b 100644 --- a/Code/Entities/ColorSwitch.cs +++ b/Code/Entities/ColorSwitch.cs @@ -15,11 +15,13 @@ public class ColorSwitch : Solid private readonly MTexture[,] edges = new MTexture[3, 3]; - private static readonly Color defaultBackgroundColor = Calc.HexToColor("191919"); - private static readonly Color defaultEdgeColor = Calc.HexToColor("646464"); + public static readonly Color DefaultBackgroundColor = Calc.HexToColor("191919"); + public static readonly Color DefaultEdgeColor = Calc.HexToColor("646464"); + private static Color RoomDefaultBackgroundColor(Level level) => level.Tracker.GetEntity()?.SwitchBackgroundColor ?? DefaultBackgroundColor; + private static Color RoomDefaultEdgeColor(Level level) => level.Tracker.GetEntity()?.SwitchEdgeColor ?? DefaultEdgeColor; - private Color BackgroundColor = defaultBackgroundColor; - private Color EdgeColor = defaultEdgeColor; + private Color BackgroundColor; + private Color EdgeColor; private Color currentEdgeColor, currentBackgroundColor; private Vector2 scale = Vector2.One; @@ -31,10 +33,10 @@ public class ColorSwitch : Solid public ColorSwitch(EntityData data, Vector2 offset) : this(data.Position + offset, data.Width, data.Height, - data.Bool("blue"), data.Bool("rose"), data.Bool("orange"), data.Bool("lime"), data.Bool("random")) + data.Bool("blue"), data.Bool("rose"), data.Bool("orange"), data.Bool("lime"), data.Bool("random"), data.Attr("spriteDir", "").Trim().TrimEnd('/')) { } - public ColorSwitch(Vector2 position, int width, int height, bool blue, bool rose, bool orange, bool lime, bool random) + public ColorSwitch(Vector2 position, int width, int height, bool blue, bool rose, bool orange, bool lime, bool random, string spriteDir) : base(position, width, height, true) { this.SurfaceSoundIndex = SurfaceIndex.ZipMover; @@ -43,7 +45,7 @@ public ColorSwitch(Vector2 position, int width, int height, bool blue, bool rose if (!blue && !rose && !orange && !lime) blue = rose = orange = lime = true; - string block = "objects/VortexHelper/onoff/switch"; + string block = string.IsNullOrEmpty(spriteDir) ? "objects/VortexHelper/onoff/switch" : spriteDir + "/switch"; for (int i = 0; i < 3; i++) for (int j = 0; j < 3; j++) this.edges[i, j] = GFX.Game[block].GetSubtexture(i * 8, j * 8, 8, 8); @@ -61,8 +63,6 @@ public ColorSwitch(Vector2 position, int width, int height, bool blue, bool rose if (colorBools[i]) this.colors[arrIdx++] = (VortexHelperSession.SwitchBlockColor) i; - NextColor(this.colors[this.nextColorIndex], true); - Add(new LightOcclude()); Add(new SoundSource(SFX.game_01_console_static_loop) { @@ -74,13 +74,23 @@ public ColorSwitch(Vector2 position, int width, int height, bool blue, bool rose if (height > 32) this.scaleStrength.Y = height / 32f; - Color col = this.colors[this.nextColorIndex].IsActive() ? defaultBackgroundColor : this.colors[this.nextColorIndex].GetColor(); - SetEdgeColor(this.EdgeColor, this.EdgeColor); - SetBackgroundColor(col, col); - this.OnDashCollide = Dashed; } + public override void Awake(Scene scene) + { + base.Awake(scene); + + Level level = SceneAs(); + + Color bgCol = this.colors[this.nextColorIndex].IsActive() ? RoomDefaultBackgroundColor(level) : this.colors[this.nextColorIndex].GetColor(level); + Color edgeCol = RoomDefaultEdgeColor(level); + SetBackgroundColor(bgCol, bgCol); + SetEdgeColor(edgeCol, edgeCol); + + NextColor(this.colors[this.nextColorIndex], true); + } + public override void Render() { Vector2 position = this.Position; @@ -92,9 +102,10 @@ public override void Render() int rectH = (int) ((this.Height - 2) * this.scale.Y); var rect = new Rectangle(x, y, rectW, rectH); + Color defaultCol = RoomDefaultBackgroundColor(SceneAs()); Color col = this.random - ? Color.Lerp(defaultBackgroundColor, Color.White, (float) (0.05f * Math.Sin(this.Scene.TimeActive * 5f)) + 0.05f) - : this.BackgroundColor != defaultBackgroundColor + ? Color.Lerp(defaultCol, Color.White, (float) (0.05f * Math.Sin(this.Scene.TimeActive * 5f)) + 0.05f) + : this.BackgroundColor != defaultCol ? Color.Lerp(this.currentBackgroundColor, Color.Black, 0.2f) : this.currentBackgroundColor; @@ -176,6 +187,8 @@ private DashCollisionResults Dashed(Player player, Vector2 direction) public void Switch(Vector2 direction) { + Level level = SceneAs(); + this.scale = new Vector2( 1f + (Math.Abs(direction.Y) * 0.5f - Math.Abs(direction.X) * 0.5f) / this.scaleStrength.X, 1f + (Math.Abs(direction.X) * 0.5f - Math.Abs(direction.Y) * 0.5f) / this.scaleStrength.Y @@ -185,10 +198,10 @@ public void Switch(Vector2 direction) this.nextColorIndex = Calc.Random.Next(0, this.colors.Length); VortexHelperModule.SessionProperties.SessionSwitchBlockColor = this.colors[this.nextColorIndex]; - Color col = VortexHelperModule.SessionProperties.SessionSwitchBlockColor.GetColor(); + Color col = VortexHelperModule.SessionProperties.SessionSwitchBlockColor.GetColor(level); UpdateColorSwitches(this.Scene, this.colors[this.nextColorIndex]); - SetEdgeColor(defaultEdgeColor, col); + SetEdgeColor(RoomDefaultEdgeColor(level), col); this.currentBackgroundColor = Color.White; Audio.Play(CustomSFX.game_colorSwitch_hit, this.Center); @@ -196,7 +209,7 @@ public void Switch(Vector2 direction) Audio.Play(CustomSFX.game_switchBlock_switch, "tone", VortexHelperModule.SessionProperties.SessionSwitchBlockColor.GetSoundParam()); Input.Rumble(RumbleStrength.Strong, RumbleLength.Long); - SceneAs().DirectionalShake(direction, 0.25f); + level.DirectionalShake(direction, 0.25f); StartShaking(0.25f); ParticleType p = LightningBreakerBox.P_Smash; @@ -213,6 +226,8 @@ public static void UpdateColorSwitches(Scene scene, VortexHelperSession.SwitchBl private void NextColor(VortexHelperSession.SwitchBlockColor colorNext, bool start) { + Level level = SceneAs(); + if (colorNext == this.colors[this.nextColorIndex] && !this.singleColor) { if (!start) @@ -224,8 +239,8 @@ private void NextColor(VortexHelperSession.SwitchBlockColor colorNext, bool star if (this.colors[this.nextColorIndex].IsActive()) this.nextColorIndex++; } - - this.BackgroundColor = this.colors[this.nextColorIndex].IsActive() ? defaultBackgroundColor : this.colors[this.nextColorIndex].GetColor(); + + this.BackgroundColor = this.colors[this.nextColorIndex].IsActive() ? RoomDefaultBackgroundColor(level) : this.colors[this.nextColorIndex].GetColor(level); } private void SmashParticles(Vector2 dir, ParticleType smashParticle) diff --git a/Code/Entities/SwitchBlock.cs b/Code/Entities/SwitchBlock.cs index 3b76c3a..4523cba 100644 --- a/Code/Entities/SwitchBlock.cs +++ b/Code/Entities/SwitchBlock.cs @@ -2,6 +2,7 @@ using Celeste.Mod.VortexHelper.Misc.Extensions; using Microsoft.Xna.Framework; using Monocle; +using System; using System.Collections.Generic; namespace Celeste.Mod.VortexHelper.Entities; @@ -33,7 +34,8 @@ public override void Render() private bool Activated; private readonly VortexHelperSession.SwitchBlockColor switchBlockColor; private readonly int index; - private readonly Color color; + private readonly string spriteDir; + private Color color; private readonly LightOcclude occluder; private Wiggler wiggler; @@ -50,13 +52,14 @@ public override void Render() private readonly int blockHeight = 2; public SwitchBlock(EntityData data, Vector2 offset) - : this(data.Position + offset, data.Width, data.Height, data.Int("index", 0)) { } + : this(data.Position + offset, data.Width, data.Height, data.Int("index", 0), data.Attr("spriteDir", "").Trim().TrimEnd('/')) { } - public SwitchBlock(Vector2 position, int width, int height, int index) + public SwitchBlock(Vector2 position, int width, int height, int index, string spriteDir) : base(position, width, height, true) { this.SurfaceSoundIndex = SurfaceIndex.CassetteBlock; this.index = index; + this.spriteDir = string.IsNullOrEmpty(spriteDir) ? "objects/VortexHelper/onoff" : spriteDir; this.switchBlockColor = this.index switch { @@ -66,15 +69,16 @@ public SwitchBlock(Vector2 position, int width, int height, int index) _ => VortexHelperSession.SwitchBlockColor.Blue, }; - this.color = this.switchBlockColor.GetColor(); - this.Activated = this.Collidable = this.switchBlockColor.IsActive(); - Add(this.occluder = new LightOcclude()); } public override void Awake(Scene scene) { base.Awake(scene); + + this.color = this.switchBlockColor.GetColor(SceneAs()); + this.Activated = this.Collidable = this.switchBlockColor.IsActive(); + Color color = Calc.HexToColor("667da5"); var disabledColor = new Color(color.R / 255f * (this.color.R / 255f), color.G / 255f * (this.color.G / 255f), color.B / 255f * (this.color.B / 255f), 1f); @@ -151,10 +155,11 @@ public override void Awake(Scene scene) string idx = this.index switch { + 0 => "blue", 1 => "red", 2 => "orange", 3 => "green", - _ => "blue", + _ => throw new ArgumentOutOfRangeException() }; // cassette block autotiling @@ -231,8 +236,8 @@ private bool CheckForSame(float x, float y) private void SetImage(float x, float y, int tx, int ty, string idx) { - this.pressed.Add(CreateImage(x, y, tx, ty, GFX.Game["objects/VortexHelper/onoff/outline_" + idx])); - this.solid.Add(CreateImage(x, y, tx, ty, GFX.Game["objects/VortexHelper/onoff/solid"])); + this.pressed.Add(CreateImage(x, y, tx, ty, GFX.Game[this.spriteDir + "/outline_" + idx])); + this.solid.Add(CreateImage(x, y, tx, ty, GFX.Game[this.spriteDir + "/solid"])); } private Image CreateImage(float x, float y, int tx, int ty, MTexture tex) diff --git a/Code/Entities/SwitchBlockColorController.cs b/Code/Entities/SwitchBlockColorController.cs new file mode 100644 index 0000000..c195ca0 --- /dev/null +++ b/Code/Entities/SwitchBlockColorController.cs @@ -0,0 +1,25 @@ +using Celeste.Mod.Entities; +using Celeste.Mod.VortexHelper.Misc.Extensions; +using Microsoft.Xna.Framework; +using Monocle; + +namespace Celeste.Mod.VortexHelper.Entities; + +[CustomEntity("VortexHelper/SwitchBlockColorController")] +[Tracked] +public class SwitchBlockColorController : Entity +{ + public readonly Color BlueColor, RoseColor, OrangeColor, LimeColor; + public readonly Color SwitchBackgroundColor, SwitchEdgeColor; + + public SwitchBlockColorController(EntityData data, Vector2 offset) : base(data.Position + offset) + { + BlueColor = data.HexColor("blueColor", EnumExt.SwitchBlockBlue); + RoseColor = data.HexColor("roseColor", EnumExt.SwitchBlockRose); + OrangeColor = data.HexColor("orangeColor", EnumExt.SwitchBlockOrange); + LimeColor = data.HexColor("limeColor", EnumExt.SwitchBlockLime); + + SwitchBackgroundColor = data.HexColor("switchBackgroundColor", ColorSwitch.DefaultBackgroundColor); + SwitchEdgeColor = data.HexColor("switchEdgeColor", ColorSwitch.DefaultEdgeColor); + } +} \ No newline at end of file diff --git a/Code/Misc/Extensions/EnumExt.cs b/Code/Misc/Extensions/EnumExt.cs index 541f716..b49c1dc 100644 --- a/Code/Misc/Extensions/EnumExt.cs +++ b/Code/Misc/Extensions/EnumExt.cs @@ -1,5 +1,7 @@ -using Microsoft.Xna.Framework; +using Celeste.Mod.VortexHelper.Entities; +using Microsoft.Xna.Framework; using Monocle; +using System; namespace Celeste.Mod.VortexHelper.Misc.Extensions; @@ -10,20 +12,26 @@ public static class EnumExt public static readonly Color SwitchBlockOrange = Calc.HexToColor("ff9532"); public static readonly Color SwitchBlockLime = Calc.HexToColor("9cff32"); - public static Color GetColor(this VortexHelperSession.SwitchBlockColor color) => color switch + public static Color GetColor(this VortexHelperSession.SwitchBlockColor color, Level level) { - VortexHelperSession.SwitchBlockColor.Rose => SwitchBlockRose, - VortexHelperSession.SwitchBlockColor.Orange => SwitchBlockOrange, - VortexHelperSession.SwitchBlockColor.Lime => SwitchBlockLime, - _ => SwitchBlockBlue, - }; + SwitchBlockColorController controller = level.Tracker.GetEntity(); + return color switch + { + VortexHelperSession.SwitchBlockColor.Blue => controller?.BlueColor ?? SwitchBlockBlue, + VortexHelperSession.SwitchBlockColor.Rose => controller?.RoseColor ?? SwitchBlockRose, + VortexHelperSession.SwitchBlockColor.Orange => controller?.OrangeColor ?? SwitchBlockOrange, + VortexHelperSession.SwitchBlockColor.Lime => controller?.LimeColor ?? SwitchBlockLime, + _ => throw new ArgumentOutOfRangeException() + }; + } public static int GetSoundParam(this VortexHelperSession.SwitchBlockColor color) => color switch { + VortexHelperSession.SwitchBlockColor.Blue => 0, VortexHelperSession.SwitchBlockColor.Rose => 1, VortexHelperSession.SwitchBlockColor.Orange => 2, VortexHelperSession.SwitchBlockColor.Lime => 3, - _ => 0, + _ => throw new ArgumentOutOfRangeException() }; public static bool IsActive(this VortexHelperSession.SwitchBlockColor color) => color == VortexHelperModule.SessionProperties.SessionSwitchBlockColor; diff --git a/Graphics/Atlases/Gameplay/objects/VortexHelper/onoff/colorcontroller/blue.png b/Graphics/Atlases/Gameplay/objects/VortexHelper/onoff/colorcontroller/blue.png new file mode 100644 index 0000000000000000000000000000000000000000..8072935c3e35d4a14aabfa3614f277957da00160 GIT binary patch literal 227 zcmeAS@N?(olHy`uVBq!ia0vp^5+KaM1|%Pp+x`GjjKx9jP7LeL$-D$|=6bp~hIn)) zCrEgFkmss;KL6i;5O^}XzVnx`RRey-#k1#PmZ&5Gcz+g-)}Om z5M`}CF*()Z4pS0O#O}w6kzxi$1_lOS&e{7KoE2A{VPIrrG%59@h6L;41QDKU28IvE W9Zm8j_Z$N{l)=;0&t;ucLK6U_>{6Wo literal 0 HcmV?d00001 diff --git a/Graphics/Atlases/Gameplay/objects/VortexHelper/onoff/colorcontroller/lime.png b/Graphics/Atlases/Gameplay/objects/VortexHelper/onoff/colorcontroller/lime.png new file mode 100644 index 0000000000000000000000000000000000000000..63da1bc74ad61b50642b623b5a4db1231eeb93d5 GIT binary patch literal 218 zcmeAS@N?(olHy`uVBq!ia0vp^5+KaM1|%Pp+x`GjjKx9jP7LeL$-D$|rg*wIhIn+o zow$*g$xwjhc!$`869Td|oF*Q;Ar5|SjPe&4A8>Flf8x!cZ+pyW(qE-rp6|D8Ue0{j zfJeDsCFDWXZtqD9&$jZ(EB$WPUo$0b|0UJj^1Xe_i(d*bo_S@u;pMgU>l7b3pLu7( z+4e!^oF)5L`yUBgV^R($HgRA2FeT0L)Q-O@O%K`M`C8?R#T|8;RO0{u literal 0 HcmV?d00001 diff --git a/Graphics/Atlases/Gameplay/objects/VortexHelper/onoff/colorcontroller/orange.png b/Graphics/Atlases/Gameplay/objects/VortexHelper/onoff/colorcontroller/orange.png new file mode 100644 index 0000000000000000000000000000000000000000..b861b7704abef6a2a538fe1dadcffa6096a0a45c GIT binary patch literal 223 zcmeAS@N?(olHy`uVBq!ia0vp^5+KaM1|%Pp+x`GjjKx9jP7LeL$-D$|W_r3fhIn+o zy||Z`Nl~KVq4;Aim69X8G6yf++gZYT_Xwj&A+zl&kghcBldRNf~h49CxY%wKev7NZF&8h;So#Pj`c}c zGi``mzll$l(W&FfRofsQAHlUMQ70drRaOY)RbjHT4K+QWEVt?xyXK3;`9}|&uV%Du WPf(uXzDF47NCr<=KbLh*2~7ZQYgPRK literal 0 HcmV?d00001 diff --git a/Graphics/Atlases/Gameplay/objects/VortexHelper/onoff/colorcontroller/outline.png b/Graphics/Atlases/Gameplay/objects/VortexHelper/onoff/colorcontroller/outline.png new file mode 100644 index 0000000000000000000000000000000000000000..7e1e163c863d9ba7dd17a37d8b5d38c0f3b7a03c GIT binary patch literal 172 zcmeAS@N?(olHy`uVBq!ia0vp^5+KaM1|%Pp+x`GjjKx9jP7LeL$-D$|(mY)pLp(a) zPBY{?V8Fqg{qKMJCX=8jR~Dt}!^(=~(hcezyQ{z0F*D5E$8W){|2_QS(t7g;Ce4iZ zH}>$}_uRt7S~GP9m)+$iu`LgJi$ZSfKhQG2+lSG6(ygpbQ!BMQe;qDvF5Jc=snb6( TUM;H?Xd{ECtDnm{r-UW|$?H7n literal 0 HcmV?d00001 diff --git a/Graphics/Atlases/Gameplay/objects/VortexHelper/onoff/colorcontroller/rose.png b/Graphics/Atlases/Gameplay/objects/VortexHelper/onoff/colorcontroller/rose.png new file mode 100644 index 0000000000000000000000000000000000000000..ee144a3258e8553ffa51bfc7e057c2dbc4c16a31 GIT binary patch literal 229 zcmeAS@N?(olHy`uVBq!ia0vp^5+KaM1|%Pp+x`GjjKx9jP7LeL$-D$|=6kw0hIn)) zCrI=>_zwit&*%T+XZ~@;DDbq?tjG@^j%M#ry`ht|@JiEf{e25Q$lKI^jdu*{5j?is zOWMZiQ+mkkB>1rP0-n;VtFy#E1BoIeo=-dJ#an~)x{ z`?2ETo!t2!S0x|O?q>dS&i=3c4d;0atXMq_Kh*?GNjP+4`vabPJZ4;O2Q?&Em4V)H Ycz Date: Sat, 7 Jun 2025 11:26:14 +0100 Subject: [PATCH 2/3] Make Switch Block Color Controllers work inside Loenn --- Loenn/entities/color_switch.lua | 21 ++++++------ Loenn/entities/switch_block.lua | 36 +++++++-------------- Loenn/libraries/vortex_helper.lua | 53 +++++++++++++++++++++++++++++++ 3 files changed, 75 insertions(+), 35 deletions(-) create mode 100644 Loenn/libraries/vortex_helper.lua diff --git a/Loenn/entities/color_switch.lua b/Loenn/entities/color_switch.lua index d1b41f5..b0b804e 100644 --- a/Loenn/entities/color_switch.lua +++ b/Loenn/entities/color_switch.lua @@ -1,5 +1,6 @@ -local drawableRectangle = require "structs.drawable_rectangle" -local drawableNinePatch = require "structs.drawable_nine_patch" +local drawableRectangle = require("structs.drawable_rectangle") +local drawableNinePatch = require("structs.drawable_nine_patch") +local vortexHelper = require("mods").requireFromPlugin("libraries.vortex_helper") local colorSwitch = {} @@ -36,20 +37,20 @@ colorSwitch.placements = { } } -local nine_patch_options = { - mode = "border", - borderMode = "repeat", - color = {0.5, 0.5, 0.5, 1.0} -} -local bgColor = {40 / 255, 40 / 255, 40 / 255, 1.0} - function colorSwitch.sprite(room, entity) local x, y = entity.x or 0, entity.y or 0 local width, height = entity.width or 16, entity.height or 16 + + local colors = vortexHelper.colorSwitchRoomColors(room) local frame = (entity.spriteDir or "") ~= "" and (entity.spriteDir .. "/switch") or "objects/VortexHelper/onoff/switch" + local nine_patch_options = { + mode = "border", + borderMode = "repeat", + color = colors.edgeColor + } return { - drawableRectangle.fromRectangle("fill", x + 1, y + 1, width - 2, height - 2, bgColor):getDrawableSprite(), + drawableRectangle.fromRectangle("fill", x + 1, y + 1, width - 2, height - 2, colors.bgColor):getDrawableSprite(), drawableNinePatch.fromTexture(frame, nine_patch_options, x, y, width, height) } end diff --git a/Loenn/entities/switch_block.lua b/Loenn/entities/switch_block.lua index 8bddda8..5b26ca8 100644 --- a/Loenn/entities/switch_block.lua +++ b/Loenn/entities/switch_block.lua @@ -1,20 +1,7 @@ -local utils = require "utils" -local drawableSprite = require "structs.drawable_sprite" -local connectedEntities = require "helpers.connected_entities" - -local colors = { - {50 / 255, 50 / 255, 255 / 255, 255 / 255}, - {255 / 255, 50 / 255, 101 / 255, 255 / 255}, - {255 / 255, 149 / 255, 50 / 255, 255 / 255}, - {156 / 255, 255 / 255, 50 / 255, 255 / 255} -} - -local colorNames = { - ["Blue"] = 0, - ["Rose"] = 1, - ["Orange"] = 2, - ["Lime"] = 3 -} +local utils = require("utils") +local drawableSprite = require("structs.drawable_sprite") +local connectedEntities = require("helpers.connected_entities") +local vortexHelper = require("mods").requireFromPlugin("libraries.vortex_helper") local switchBlock = {} @@ -23,19 +10,19 @@ switchBlock.minimumSize = {16, 16} switchBlock.fieldInformation = { index = { fieldType = "integer", - options = colorNames, + options = vortexHelper.switchBlockColorNames, editable = false } } switchBlock.placements = {} -for i, _ in ipairs(colors) do - switchBlock.placements[i] = { - name = string.format("switch_block_%s", i - 1), +for _, i in pairs(vortexHelper.switchBlockColorNames) do + switchBlock.placements[i + 1] = { + name = string.format("switch_block_%s", i), data = { width = 16, height = 16, - index = i - 1, + index = i, spriteDir = "" } } @@ -108,9 +95,7 @@ end function switchBlock.sprite(room, entity) local relevantBlocks = utils.filter(getSearchPredicate(entity), room.entities) - connectedEntities.appendIfMissing(relevantBlocks, entity) - local rectangles = connectedEntities.getEntityRectangles(relevantBlocks) local sprites = {} @@ -119,7 +104,8 @@ function switchBlock.sprite(room, entity) local tileWidth, tileHeight = math.ceil(width / 8), math.ceil(height / 8) local index = entity.index or 0 - local color = colors[index + 1] or colors[1] + local colors = vortexHelper.switchBlockRoomColors(room) + local color = colors[index] or colors[0] for x = 1, tileWidth do for y = 1, tileHeight do diff --git a/Loenn/libraries/vortex_helper.lua b/Loenn/libraries/vortex_helper.lua new file mode 100644 index 0000000..1979336 --- /dev/null +++ b/Loenn/libraries/vortex_helper.lua @@ -0,0 +1,53 @@ +local utils = require("utils") + +local vortexHelper = {} + +vortexHelper.switchBlockColorNames = { + ["Blue"] = 0, + ["Rose"] = 1, + ["Orange"] = 2, + ["Lime"] = 3 +} + +vortexHelper.switchBlockDefaultColors = { + [0] = {50 / 255, 50 / 255, 255 / 255, 255 / 255}, + [1] = {255 / 255, 50 / 255, 101 / 255, 255 / 255}, + [2] = {255 / 255, 149 / 255, 50 / 255, 255 / 255}, + [3] = {156 / 255, 255 / 255, 50 / 255, 255 / 255} +} + +function vortexHelper.getSwitchBlockColorController(room) + local switchBlockColorControllers = utils.filter(function(entity) + return entity._name == "VortexHelper/SwitchBlockColorController" + end, room.entities) + return switchBlockColorControllers[1] +end + +function vortexHelper.switchBlockRoomColors(room) + local controller = vortexHelper.getSwitchBlockColorController(room) + if controller == nil then return vortexHelper.switchBlockDefaultColors end + + return { + [0] = utils.getColor(controller.blueColor or vortexHelper.switchBlockDefaultColors[0]), + [1] = utils.getColor(controller.roseColor or vortexHelper.switchBlockDefaultColors[1]), + [2] = utils.getColor(controller.orangeColor or vortexHelper.switchBlockDefaultColors[2]), + [3] = utils.getColor(controller.limeColor or vortexHelper.switchBlockDefaultColors[3]) + } +end + +vortexHelper.colorSwitchDefaultColors = { + bgColor = {40 / 255, 40 / 255, 40 / 255, 1.0}, + edgeColor = {0.5, 0.5, 0.5, 1.0} +} + +function vortexHelper.colorSwitchRoomColors(room) + local controller = vortexHelper.getSwitchBlockColorController(room) + if controller == nil then return vortexHelper.colorSwitchDefaultColors end + + return { + bgColor = utils.getColor(controller.switchBackgroundColor or vortexHelper.colorSwitchDefaultColors.bg), + edgeColor = utils.getColor(controller.switchEdgeColor or vortexHelper.colorSwitchDefaultColors.edge) + } +end + +return vortexHelper \ No newline at end of file From f744612b38804e32080f1cadb5ac5f18b343cfed Mon Sep 17 00:00:00 2001 From: aonkeeper4 Date: Sat, 7 Jun 2025 11:38:25 +0100 Subject: [PATCH 3/3] Fix typo in Loenn plugin --- Loenn/libraries/vortex_helper.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Loenn/libraries/vortex_helper.lua b/Loenn/libraries/vortex_helper.lua index 1979336..b6e0ceb 100644 --- a/Loenn/libraries/vortex_helper.lua +++ b/Loenn/libraries/vortex_helper.lua @@ -45,8 +45,8 @@ function vortexHelper.colorSwitchRoomColors(room) if controller == nil then return vortexHelper.colorSwitchDefaultColors end return { - bgColor = utils.getColor(controller.switchBackgroundColor or vortexHelper.colorSwitchDefaultColors.bg), - edgeColor = utils.getColor(controller.switchEdgeColor or vortexHelper.colorSwitchDefaultColors.edge) + bgColor = utils.getColor(controller.switchBackgroundColor or vortexHelper.colorSwitchDefaultColors.bgColor), + edgeColor = utils.getColor(controller.switchEdgeColor or vortexHelper.colorSwitchDefaultColors.edgeColor) } end