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 0000000..8072935 Binary files /dev/null and b/Graphics/Atlases/Gameplay/objects/VortexHelper/onoff/colorcontroller/blue.png differ 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 0000000..63da1bc Binary files /dev/null and b/Graphics/Atlases/Gameplay/objects/VortexHelper/onoff/colorcontroller/lime.png differ 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 0000000..b861b77 Binary files /dev/null and b/Graphics/Atlases/Gameplay/objects/VortexHelper/onoff/colorcontroller/orange.png differ 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 0000000..7e1e163 Binary files /dev/null and b/Graphics/Atlases/Gameplay/objects/VortexHelper/onoff/colorcontroller/outline.png differ 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 0000000..ee144a3 Binary files /dev/null and b/Graphics/Atlases/Gameplay/objects/VortexHelper/onoff/colorcontroller/rose.png differ diff --git a/Loenn/entities/color_switch.lua b/Loenn/entities/color_switch.lua index ec6acca..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 = {} @@ -17,7 +18,8 @@ colorSwitch.placements = { rose = true, orange = true, lime = true, - random = false + random = false, + spriteDir = "" } }, { @@ -29,25 +31,26 @@ colorSwitch.placements = { rose = true, orange = true, lime = true, - random = true + random = true, + spriteDir = "" } } } -local frame = "objects/VortexHelper/onoff/switch" -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 5fc7076..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,25 +10,24 @@ 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 = "" } } end -local frame = "objects/VortexHelper/onoff/solid" - local function getSearchPredicate(entity) return function(target) return entity._name == target._name and entity.index == target.index @@ -94,6 +80,7 @@ local function getTileSprite(entity, x, y, color, rectangles) end if quadX and quadY then + local frame = (entity.spriteDir or "") ~= "" and (entity.spriteDir .. "/solid") or "objects/VortexHelper/onoff/solid" local sprite = drawableSprite.fromTexture(frame, entity) sprite:addPosition(drawX, drawY) @@ -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/entities/switch_block_color_controller.lua b/Loenn/entities/switch_block_color_controller.lua new file mode 100644 index 0000000..550a790 --- /dev/null +++ b/Loenn/entities/switch_block_color_controller.lua @@ -0,0 +1,68 @@ +local utils = require("utils") +local drawableSprite = require("structs.drawable_sprite") + +local switchBlockColorController = {} + +switchBlockColorController.name = "VortexHelper/SwitchBlockColorController" +switchBlockColorController.placements = { + name = "default", + data = { + blueColor = "3232ff", + roseColor = "ff3265", + orangeColor = "ff9532", + limeColor = "9cff32", + switchBackgroundColor = "191919", + switchEdgeColor = "646464" + } +} +switchBlockColorController.fieldInformation = { + blueColor = { + fieldType = "color" + }, + roseColor = { + fieldType = "color" + }, + orangeColor = { + fieldType = "color" + }, + limeColor = { + fieldType = "color" + }, + switchBackgroundColor = { + fieldType = "color" + }, + switchEdgeColor = { + fieldType = "color" + } +} +switchBlockColorController.fieldOrder = { + "x", "y", + "blueColor", "roseColor", "orangeColor", "limeColor", + "switchBackgroundColor", "switchEdgeColor" +} + +local spriteDir = "objects/VortexHelper/onoff/colorcontroller" +local outline = spriteDir .. "/outline" +local blockBlue = spriteDir .. "/blue" +local blockRose = spriteDir .. "/rose" +local blockOrange = spriteDir .. "/orange" +local blockLime = spriteDir .. "/lime" + +function switchBlockColorController.sprite(room, entity) + local blueSprite = drawableSprite.fromTexture(blockBlue, entity) + local roseSprite = drawableSprite.fromTexture(blockRose, entity) + local orangeSprite = drawableSprite.fromTexture(blockOrange, entity) + local limeSprite = drawableSprite.fromTexture(blockLime, entity) + + blueSprite:setColor(utils.getColor(entity.blueColor or "3232ff")) + roseSprite:setColor(utils.getColor(entity.roseColor or "ff3265")) + orangeSprite:setColor(utils.getColor(entity.orangeColor or "ff9532")) + limeSprite:setColor(utils.getColor(entity.limeColor or "9cff32")) + + return { + drawableSprite.fromTexture(outline, entity), + blueSprite, roseSprite, orangeSprite, limeSprite + } +end + +return switchBlockColorController \ No newline at end of file diff --git a/Loenn/lang/en_gb.lang b/Loenn/lang/en_gb.lang index cfc6e4f..0d30d02 100644 --- a/Loenn/lang/en_gb.lang +++ b/Loenn/lang/en_gb.lang @@ -35,6 +35,7 @@ entities.VortexHelper/ColorSwitch.attributes.description.rose=Enables switch to entities.VortexHelper/ColorSwitch.attributes.description.orange=Enables switch to ORANGE through this Color Switch. entities.VortexHelper/ColorSwitch.attributes.description.lime=Enables switch to LIME through this Color Switch. entities.VortexHelper/ColorSwitch.attributes.description.random=Makes this Color Switch randomly pick one of its enabled colors. +entities.VortexHelper/ColorSwitch.attributes.description.spriteDir=Directory relative to Graphics/Atlases/Gameplay to use for custom sprites.\nMust contain an image named "switch" that will be used for the sprites of this block. # Vortex Switch Gate entities.VortexHelper/VortexSwitchGate.placements.name.crush=Custom Switch Gate (Crush) @@ -85,6 +86,16 @@ entities.VortexHelper/SwitchBlock.placements.name.switch_block_1=Switch Block (1 entities.VortexHelper/SwitchBlock.placements.name.switch_block_2=Switch Block (2 - Orange) entities.VortexHelper/SwitchBlock.placements.name.switch_block_3=Switch Block (3 - Lime) entities.VortexHelper/SwitchBlock.attributes.description.index=Changes the index and color of this Switch Block. +entities.VortexHelper/ColorSwitch.attributes.description.spriteDir=Directory relative to Graphics/Atlases/Gameplay to use for custom sprites.\nMust contain images named "solid", "outline_blue", "outline_red", "outline_orange" and "outline_green" that will be used for the sprites of this block.\n"solid" is used for the activated state of this block, and "outline_blue", "outline_red", "outline_orange" and "outline_green" are used for the deactivated state of this block depending on its index. + +# Switch Block Color Controller +entities.VortexHelper/SwitchBlockColorController.placements.name.default=Switch Block Color Controller +entities.VortexHelper/SwitchBlockColorController.attributes.description.blueColor=The color to use for all Switch Blocks of the Blue index in this room. +entities.VortexHelper/SwitchBlockColorController.attributes.description.roseColor=The color to use for all Switch Blocks of the Rose index in this room. +entities.VortexHelper/SwitchBlockColorController.attributes.description.orangeColor=The color to use for all Switch Blocks of the Orange index in this room. +entities.VortexHelper/SwitchBlockColorController.attributes.description.limeColor=The color to use for all Switch Blocks of the Lime index in this room. +entities.VortexHelper/SwitchBlockColorController.attributes.description.switchBackgroundColor=The color to use for the default background of all Color Switches in this room. +entities.VortexHelper/SwitchBlockColorController.attributes.description.switchEdgeColor=The color to use for the edges of all Color Switches in this room. # Vortex Custom Bumper entities.VortexHelper/VortexCustomBumper.placements.name.green=Bumper (Green) diff --git a/Loenn/libraries/vortex_helper.lua b/Loenn/libraries/vortex_helper.lua new file mode 100644 index 0000000..b6e0ceb --- /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.bgColor), + edgeColor = utils.getColor(controller.switchEdgeColor or vortexHelper.colorSwitchDefaultColors.edgeColor) + } +end + +return vortexHelper \ No newline at end of file