-
Notifications
You must be signed in to change notification settings - Fork 3
Add color customization options #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -8,9 +8,8 @@ namespace Celeste.Mod.Batteries { | |||||
|
|
||||||
| [CustomEntity("batteries/battery_switch")] | ||||||
| public class BatterySwitch : Solid { | ||||||
| public static ParticleType P_Signal = new(DashSwitch.P_PressAMirror); | ||||||
|
|
||||||
| private static bool particlesSetup = false; | ||||||
| private static ParticleType P_Signal_A = new(DashSwitch.P_PressA); | ||||||
| private static ParticleType P_Signal_B = new(DashSwitch.P_PressA); | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you probably intended this:
Suggested change
|
||||||
|
|
||||||
| private readonly Sides side; | ||||||
| private readonly bool persistent; | ||||||
|
|
@@ -19,20 +18,19 @@ public class BatterySwitch : Solid { | |||||
| private readonly bool alwaysFlag; | ||||||
| private bool pressed; | ||||||
| private Vector2 pressDirection; | ||||||
| private Color glowColor; | ||||||
| private EntityID id; | ||||||
|
|
||||||
| public BatterySwitch(Vector2 position, Sides side, bool persistent, bool allGates, bool alwaysFlag, EntityID id) | ||||||
| public BatterySwitch(Vector2 position, Sides side, bool persistent, bool allGates, bool alwaysFlag, Color glowColor, EntityID id) | ||||||
| : base(position, 0f, 0f, safe: true) { | ||||||
| if (!particlesSetup) { | ||||||
| SetupParticles(); | ||||||
| particlesSetup = true; | ||||||
| } | ||||||
|
|
||||||
| this.side = side; | ||||||
| this.persistent = persistent; | ||||||
| this.allGates = allGates; | ||||||
| this.id = id; | ||||||
| this.alwaysFlag = alwaysFlag; | ||||||
| this.glowColor = glowColor; | ||||||
|
|
||||||
| Add(sprite = BatteriesModule.SpriteBank.Create("battery_switch")); | ||||||
| if (side is Sides.Up or Sides.Down) { | ||||||
| Collider.Width = 16f; | ||||||
|
|
@@ -67,7 +65,10 @@ public BatterySwitch(Vector2 position, Sides side, bool persistent, bool allGate | |||||
| } | ||||||
|
|
||||||
| public BatterySwitch(EntityData data, Vector2 offset, EntityID id) | ||||||
| : this(data.Position + offset, direction(data), data.Bool("persistent"), data.Bool("allGates"), data.Bool("alwaysFlag"), id) { } | ||||||
| : this(data.Position + offset, direction(data), data.Bool("persistent"), data.Bool("allGates"), | ||||||
| data.Bool("alwaysFlag"), data.HexColor("glowColor", Color.Aqua), id) { | ||||||
| SetupParticles(data); | ||||||
| } | ||||||
|
|
||||||
| public enum Sides { | ||||||
| Up, | ||||||
|
|
@@ -104,12 +105,12 @@ public override void Update() { | |||||
| Level level = SceneAs<Level>(); | ||||||
| if (Scene.OnInterval(0.3f)) { | ||||||
| if (pressed) { | ||||||
| level.ParticlesFG.Emit(DashSwitch.P_PressA, 1, Collider.AbsolutePosition + Collider.Center, pressDirection.Perpendicular() * 6f, (pressDirection * -1).Angle()); | ||||||
| level.ParticlesFG.Emit(P_Signal_A, 1, Collider.AbsolutePosition + Collider.Center, pressDirection.Perpendicular() * 6f, (pressDirection * -1).Angle()); | ||||||
| } else { | ||||||
| Player player = level.Tracker.GetEntity<Player>(); | ||||||
| if (player?.Holding?.Entity is Battery battery) { | ||||||
| if (battery.onlyFits == id.ID) { | ||||||
| level.ParticlesFG.Emit(P_Signal, 8, Collider.AbsolutePosition + Collider.Center + (pressDirection * -28), pressDirection.Perpendicular() * 6f, pressDirection.Angle()); | ||||||
| level.ParticlesFG.Emit(P_Signal_A, 8, Collider.AbsolutePosition + Collider.Center + (pressDirection * -28), pressDirection.Perpendicular() * 6f, pressDirection.Angle()); | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
|
|
@@ -137,8 +138,8 @@ public void Hit(Battery battery, Vector2 direction) { | |||||
| player.Position += -5 * pressDirection; | ||||||
| } | ||||||
|
|
||||||
| SceneAs<Level>().ParticlesFG.Emit(DashSwitch.P_PressA, 10, Collider.AbsolutePosition + Collider.Center, direction.Perpendicular() * 6f, (pressDirection * -1).Angle()); | ||||||
| SceneAs<Level>().ParticlesFG.Emit(DashSwitch.P_PressB, 4, Collider.AbsolutePosition + Collider.Center, direction.Perpendicular() * 6f, (pressDirection * -1).Angle()); | ||||||
| SceneAs<Level>().ParticlesFG.Emit(P_Signal_A, 10, Collider.AbsolutePosition + Collider.Center, direction.Perpendicular() * 6f, (pressDirection * -1).Angle()); | ||||||
| SceneAs<Level>().ParticlesFG.Emit(P_Signal_B, 4, Collider.AbsolutePosition + Collider.Center, direction.Perpendicular() * 6f, (pressDirection * -1).Angle()); | ||||||
| if (allGates) { | ||||||
| foreach (BatteryGate entity in Scene.Tracker.GetEntities<BatteryGate>()) { | ||||||
| if (entity.entityID.Level == id.Level) { | ||||||
|
|
@@ -158,21 +159,26 @@ public void Hit(Battery battery, Vector2 direction) { | |||||
| } | ||||||
| } | ||||||
|
|
||||||
| private static void SetupParticles() { | ||||||
| P_Signal.Color = Color.Aqua; | ||||||
| P_Signal.ColorMode = ParticleType.ColorModes.Choose; | ||||||
| P_Signal.LifeMax = 0.6f; | ||||||
| P_Signal.LifeMin = 0.3f; | ||||||
| P_Signal.SpeedMultiplier = 0.1f; | ||||||
| P_Signal.DirectionRange = (float)(Math.PI / 5); | ||||||
| private static void SetupParticles(EntityData e) { | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should no longer be a
Suggested change
|
||||||
| P_Signal_A.Color = e.HexColor("particleColorA", Color.Lime); | ||||||
| P_Signal_A.ColorMode = ParticleType.ColorModes.Static; | ||||||
| P_Signal_A.LifeMax = 0.6f; | ||||||
| P_Signal_A.LifeMin = 0.3f; | ||||||
| P_Signal_A.SpeedMultiplier = 0.1f; | ||||||
| P_Signal_A.DirectionRange = (float)(Math.PI / 5); | ||||||
|
|
||||||
| P_Signal_B.Color = e.HexColor("particleColorB", Color.White); | ||||||
| P_Signal_B.ColorMode = ParticleType.ColorModes.Static; | ||||||
| P_Signal_B.LifeMax = 0.6f; | ||||||
| P_Signal_B.LifeMin = 0.3f; | ||||||
| P_Signal_B.SpeedMultiplier = 0.1f; | ||||||
| P_Signal_B.DirectionRange = (float)(Math.PI / 5); | ||||||
| } | ||||||
|
|
||||||
| private static Sides direction(EntityData data) { | ||||||
| return data.Bool("horizontal") ? data.Bool("rightSide") ? Sides.Right : Sides.Left : data.Bool("ceiling") ? Sides.Down : Sides.Up; | ||||||
| } | ||||||
|
|
||||||
|
|
||||||
|
|
||||||
| private void LitState() { | ||||||
| switch (side) { | ||||||
| case Sides.Up: | ||||||
|
|
@@ -203,7 +209,7 @@ private void LitState() { | |||||
| _ => Vector2.Zero | ||||||
| }; | ||||||
|
|
||||||
| Add(new VertexLight(offset, Color.Lime, 1f, 12, 24)); | ||||||
| Add(new VertexLight(offset, glowColor, 1f, 12, 24)); | ||||||
| } | ||||||
|
|
||||||
| private List<BatteryGate> GetGate() { | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,11 @@ | ||
| local battery = {} | ||
|
|
||
| local COLOR_CYAN = "00ffff" | ||
| local COLOR_FOREST_GREEN = "228b22" | ||
| local COLOR_LIGHT_GOLDENROD_YELLOW = "fafad2" | ||
| local COLOR_LIME = "00ff00" | ||
| local COLOR_ORANGE_RED = "ff4500" | ||
|
Comment on lines
+3
to
+7
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you don't need to redefine these XNA colors, they are available in you may import the constants and use them as follows local xna_colors = require "consts.xna_colors"
xna_colors.Cyan
xna_colors.ForestGreen
-- etc.. |
||
|
|
||
| battery.name = "batteries/battery" | ||
| battery.depth = 100 | ||
|
|
||
|
|
@@ -12,7 +18,12 @@ battery.placements = { | |
| dischargeRate = 80, | ||
| oneUse = false, | ||
| onlyFits = -1, | ||
| ignoreBarriers = false | ||
| ignoreBarriers = false, | ||
| particleColorInfinite = COLOR_CYAN, | ||
| particleColorFull = COLOR_LIME, | ||
| particleColorHalf = COLOR_LIGHT_GOLDENROD_YELLOW, | ||
| particleColorLow = COLOR_ORANGE_RED, | ||
| deathEffectColor = COLOR_FOREST_GREEN | ||
| } | ||
| }, | ||
| { | ||
|
|
@@ -23,17 +34,39 @@ battery.placements = { | |
| dischargeRate = 0, | ||
| oneUse = false, | ||
| onlyFits = -1, | ||
| ignoreBarriers = false | ||
| ignoreBarriers = false, | ||
| particleColorInfinite = COLOR_CYAN, | ||
| particleColorFull = COLOR_LIME, | ||
| particleColorHalf = COLOR_LIGHT_GOLDENROD_YELLOW, | ||
| particleColorLow = COLOR_ORANGE_RED, | ||
| deathEffectColor = COLOR_FOREST_GREEN | ||
| } | ||
| } | ||
| } | ||
|
|
||
| battery.fieldInformation = { | ||
| onlyFits = { | ||
| fieldType = "integer" | ||
| }, | ||
| particleColorInfinite = { | ||
| fieldType = "color" | ||
| }, | ||
| particleColorFull = { | ||
| fieldType = "color" | ||
| }, | ||
| particleColorHalf = { | ||
| fieldType = "color" | ||
| }, | ||
| particleColorLow = { | ||
| fieldType = "color" | ||
| }, | ||
| deathEffectColor = { | ||
| fieldType = "color" | ||
| } | ||
| } | ||
|
|
||
| battery.fieldOrder = {"x", "y", "maxCharge", "initalCharge", "dischargeRate", "onlyFits", "particleColorInfinite", "particleColorFull", "particleColorHalf", "particleColorLow", "deathEffectColor", "ignoreBarriers", "oneUse"} | ||
|
|
||
| battery.texture = "batteries/battery/full0" | ||
| battery.justification = {0.5, 1} | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,10 @@ local utils = require("utils") | |
|
|
||
| local battery_switch = {} | ||
|
|
||
| local COLOR_AQUA = "00ffff" | ||
| local COLOR_LIME = "00ff00" | ||
| local COLOR_WHITE = "ffffff" | ||
|
Comment on lines
+6
to
+8
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same comment about XNA colors here. |
||
|
|
||
| battery_switch.name = "batteries/battery_switch" | ||
|
|
||
| battery_switch.placements = { | ||
|
|
@@ -14,6 +18,9 @@ battery_switch.placements = { | |
| ceiling = false, | ||
| rightSide = false, | ||
| horizontal = false, | ||
| particleColorA = COLOR_AQUA, | ||
| particleColorB = COLOR_WHITE, | ||
| glowColor = COLOR_LIME | ||
| } | ||
| }, | ||
| { | ||
|
|
@@ -24,6 +31,9 @@ battery_switch.placements = { | |
| ceiling = true, | ||
| rightSide = false, | ||
| horizontal = false, | ||
| particleColorA = COLOR_AQUA, | ||
| particleColorB = COLOR_WHITE, | ||
| glowColor = COLOR_LIME | ||
| } | ||
| }, | ||
| { | ||
|
|
@@ -34,6 +44,9 @@ battery_switch.placements = { | |
| ceiling = false, | ||
| rightSide = false, | ||
| horizontal = true, | ||
| particleColorA = COLOR_LIME, | ||
| particleColorB = COLOR_WHITE, | ||
| glowColor = COLOR_AQUA | ||
| } | ||
| }, | ||
| { | ||
|
|
@@ -44,11 +57,26 @@ battery_switch.placements = { | |
| ceiling = false, | ||
| rightSide = true, | ||
| horizontal = true, | ||
| particleColorA = COLOR_LIME, | ||
| particleColorB = COLOR_WHITE, | ||
| glowColor = COLOR_AQUA | ||
| } | ||
| }, | ||
| } | ||
|
|
||
| battery_switch.fieldOrder = {"x", "y", "horizontal", "rightSide", "ceiling", "persistent", "alwaysFlag"} | ||
| battery_switch.fieldOrder = {"x", "y", "particleColorA", "particleColorB", "glowColor", "horizontal", "rightSide", "ceiling", "persistent", "alwaysFlag"} | ||
|
|
||
| battery_switch.fieldInformation = { | ||
| particleColorA = { | ||
| fieldType = "color" | ||
| }, | ||
| particleColorB = { | ||
| fieldType = "color" | ||
| }, | ||
| glowColor = { | ||
| fieldType = "color" | ||
| } | ||
| } | ||
|
|
||
| function battery_switch.sprite(room, entity) | ||
| local texture = "batteries/battery_switch/insert8" | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,29 +1,38 @@ | ||
| mods.batteries.name=Batteries | ||
|
|
||
| # Battery Switch | ||
| entities.batteries/battery_switch.placements.name.up=Battery Switch (Up) | ||
| entities.batteries/battery_switch.placements.name.down=Battery Switch (Down) | ||
| entities.batteries/battery_switch.placements.name.left=Battery Switch (Left) | ||
| entities.batteries/battery_switch.placements.name.right=Battery Switch (Right) | ||
| entities.batteries/battery_switch.attributes.name.particleColorA=Particle Color 1 | ||
| entities.batteries/battery_switch.attributes.name.particleColorB=Particle Color 2 | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (nit.) more precise description would be appreciated. |
||
| entities.batteries/battery_switch.attributes.description.horizontal=Whether the switch is horizontally aligned. Vertical if not ticked. | ||
| entities.batteries/battery_switch.attributes.description.alwaysFlag=If this is enabled, the switch will always set the flag "batterySwitch_(room name):(id)" when activated. Otherwise, it will only set the flag if persistent. | ||
| entities.batteries/battery_switch.attributes.description.rightSide=Whether the switch should be attached to the right side of the block as opposed to the left. Has no effect on vertical switches. | ||
| entities.batteries/battery_switch.attributes.description.persistent=If this is enabled, the switch will stay activated when the room is reset. | ||
| entities.batteries/battery_switch.attributes.description.ceiling=Whether the switch should be attached to the bottom side of the block as opposed to the top. Has no effect on horizontal switches. | ||
|
|
||
| # Battery | ||
|
|
||
| entities.batteries/battery.placements.name.default=Battery | ||
| entities.batteries/battery.placements.name.permanent=Battery (Permanent) | ||
| entities.batteries/battery.attributes.name.initalCharge=Initial Charge | ||
| entities.batteries/battery.attributes.name.particleColorInfinite=Particle Color (Infinite Charge) | ||
| entities.batteries/battery.attributes.name.particleColorFull=Particle Color (Full Charge) | ||
| entities.batteries/battery.attributes.name.particleColorHalf=Particle Color (Half Charge) | ||
| entities.batteries/battery.attributes.name.particleColorLow=Particle Color (Low Charge) | ||
| entities.batteries/battery.attributes.description.oneUse=If this is enabled, the battery will not respawn after it is used to activate a switch. | ||
| entities.batteries/battery.attributes.description.onlyFits=The entity id of the switch that this battery fits into. If unset or below 0, this battery will be able to fit into any switch. | ||
| entities.batteries/battery.attributes.description.ignoreBarriers=If this is enabled, this battery will be able to pass through seeker barriers without being destroyed. | ||
| entities.batteries/battery.attributes.description.maxCharge=The maximum charge that the battery can hold. | ||
| entities.batteries/battery.attributes.description.initalCharge=The charge that the battery starts with. | ||
| entities.batteries/battery.attributes.description.dischargeRate=The rate at which the battery loses charge (in units/second). | ||
| entities.batteries/battery.attributes.description.particleColorInfinite=The particle color of the battery when it has infinite charge. | ||
| entities.batteries/battery.attributes.description.particleColorFull=The particle color of the battery when it is at full charge. | ||
| entities.batteries/battery.attributes.description.particleColorHalf=The particle color of the battery when it has half charge. | ||
| entities.batteries/battery.attributes.description.particleColorLow=The particle color of the battery when it has low charge. | ||
|
|
||
| # Battery Power Refill | ||
|
|
||
| entities.batteries/power_refill.placements.name.default=Power Refill | ||
| entities.batteries/power_refill.attributes.description.oneUse=If this is enabled, the refill will not respawn after being used. | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since particles are now customizable for each BatterySwitch entity, these fields should be marked as
static.