Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 35 additions & 20 deletions Code/Entities/ColorSwitch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<SwitchBlockColorController>()?.SwitchBackgroundColor ?? DefaultBackgroundColor;
private static Color RoomDefaultEdgeColor(Level level) => level.Tracker.GetEntity<SwitchBlockColorController>()?.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;
Expand All @@ -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;
Expand All @@ -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);
Expand All @@ -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)
{
Expand All @@ -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<Level>();

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;
Expand All @@ -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<Level>());
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;

Expand Down Expand Up @@ -176,6 +187,8 @@ private DashCollisionResults Dashed(Player player, Vector2 direction)

public void Switch(Vector2 direction)
{
Level level = SceneAs<Level>();

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
Expand All @@ -185,18 +198,18 @@ 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);
if (SwitchBlock.RoomHasSwitchBlock(this.Scene, VortexHelperModule.SessionProperties.SessionSwitchBlockColor))
Audio.Play(CustomSFX.game_switchBlock_switch, "tone", VortexHelperModule.SessionProperties.SessionSwitchBlockColor.GetSoundParam());

Input.Rumble(RumbleStrength.Strong, RumbleLength.Long);
SceneAs<Level>().DirectionalShake(direction, 0.25f);
level.DirectionalShake(direction, 0.25f);
StartShaking(0.25f);

ParticleType p = LightningBreakerBox.P_Smash;
Expand All @@ -213,6 +226,8 @@ public static void UpdateColorSwitches(Scene scene, VortexHelperSession.SwitchBl

private void NextColor(VortexHelperSession.SwitchBlockColor colorNext, bool start)
{
Level level = SceneAs<Level>();

if (colorNext == this.colors[this.nextColorIndex] && !this.singleColor)
{
if (!start)
Expand All @@ -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)
Expand Down
23 changes: 14 additions & 9 deletions Code/Entities/SwitchBlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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
{
Expand All @@ -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<Level>());
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);

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
25 changes: 25 additions & 0 deletions Code/Entities/SwitchBlockColorController.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}
24 changes: 16 additions & 8 deletions Code/Misc/Extensions/EnumExt.cs
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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<SwitchBlockColorController>();
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;
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 changes: 16 additions & 13 deletions Loenn/entities/color_switch.lua
Original file line number Diff line number Diff line change
@@ -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 = {}

Expand All @@ -17,7 +18,8 @@ colorSwitch.placements = {
rose = true,
orange = true,
lime = true,
random = false
random = false,
spriteDir = ""
}
},
{
Expand All @@ -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
Expand Down
Loading
Loading