Skip to content

Commit 4758cae

Browse files
committed
Room PB ghosts are gold
1 parent 6ff63dc commit 4758cae

File tree

4 files changed

+100
-29
lines changed

4 files changed

+100
-29
lines changed

GhostMod/Ghost.cs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
namespace Celeste.Mod.Ghost {
1313
public class Ghost : Actor {
1414

15+
public GhostManager Manager;
16+
1517
public Player Player;
1618

1719
public PlayerSprite Sprite;
@@ -27,7 +29,7 @@ public class Ghost : Actor {
2729

2830
public GhostName Name;
2931

30-
protected Color color;
32+
public Color Color = Color.White;
3133

3234
protected float alpha;
3335
protected float alphaHair;
@@ -73,7 +75,12 @@ public void UpdateHair() {
7375
if (!Frame.HasData)
7476
return;
7577

76-
Hair.Color = Frame.HairColor;
78+
Hair.Color = new Color(
79+
(Frame.HairColor.R * Color.R) / 255,
80+
(Frame.HairColor.G * Color.G) / 255,
81+
(Frame.HairColor.B * Color.B) / 255,
82+
(Frame.HairColor.A * Color.A) / 255
83+
);
7784
Hair.Alpha = alphaHair;
7885
Hair.Facing = Frame.Facing;
7986
Hair.SimulateMotion = Frame.HairSimulateMotion;
@@ -87,7 +94,12 @@ public void UpdateSprite() {
8794
Sprite.Rotation = Frame.Rotation;
8895
Sprite.Scale = Frame.Scale;
8996
Sprite.Scale.X = Sprite.Scale.X * (float) Frame.Facing;
90-
Sprite.Color = Frame.Color * alpha;
97+
Sprite.Color = new Color(
98+
(Frame.Color.R * Color.R) / 255,
99+
(Frame.Color.G * Color.G) / 255,
100+
(Frame.Color.B * Color.B) / 255,
101+
(Frame.Color.A * Color.A) / 255
102+
) * alpha;
91103

92104
Sprite.Rate = Frame.SpriteRate;
93105
Sprite.Justify = Frame.SpriteJustify;
@@ -137,15 +149,6 @@ public override void Update() {
137149
alphaHair = Calc.LerpClamp(GhostModule.Settings.InnerHairOpacityFactor, GhostModule.Settings.OuterHairOpacityFactor, dist);
138150
}
139151

140-
if (Data != null) {
141-
/* Proposed colors:
142-
* blue - full run PB
143-
* silver - chapter PB
144-
* gold - room PB
145-
*/
146-
// TODO: Ghost colors based on time.
147-
}
148-
149152
UpdateSprite();
150153
UpdateHair();
151154

GhostMod/GhostManager.cs

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
using FMOD.Studio;
2+
using Microsoft.Xna.Framework;
3+
using Monocle;
4+
using System;
5+
using System.Collections;
6+
using System.Collections.Generic;
7+
using System.Linq;
8+
using System.Text;
9+
using System.Threading.Tasks;
10+
using YamlDotNet.Serialization;
11+
12+
namespace Celeste.Mod.Ghost {
13+
public class GhostManager : Entity {
14+
15+
public List<Ghost> Ghosts = new List<Ghost>();
16+
17+
public Player Player;
18+
19+
public readonly static Color ColorGold = new Color(1f, 1f, 0f, 1f);
20+
public readonly static Color ColorNeutral = new Color(1f, 1f, 1f, 1f);
21+
22+
public GhostManager(Player player, Level level)
23+
: base(Vector2.Zero) {
24+
Player = player;
25+
26+
Tag = Tags.HUD;
27+
28+
// Read and add all ghosts.
29+
GhostData.ForAllGhosts(level.Session, (i, ghostData) => {
30+
Ghost ghost = new Ghost(player, ghostData);
31+
level.Add(ghost);
32+
Ghosts.Add(ghost);
33+
return true;
34+
});
35+
}
36+
37+
public override void Removed(Scene scene) {
38+
base.Removed(scene);
39+
40+
// Remove any dead ghosts (heh)
41+
for (int i = Ghosts.Count - 1; i > -1; --i) {
42+
Ghost ghost = Ghosts[i];
43+
if (ghost.Player != Player)
44+
ghost.RemoveSelf();
45+
}
46+
Ghosts.Clear();
47+
}
48+
49+
public override void Render() {
50+
/* Proposed colors:
51+
* blue - full run PB (impossible)
52+
* silver - chapter PB (feasible)
53+
* gold - room PB (done)
54+
*/
55+
56+
// Gold is the easiest: Find fastest active ghost.
57+
Ghost fastest = null;
58+
foreach (Ghost ghost in Ghosts) {
59+
// While we're at it, reset all colors.
60+
ghost.Color = ColorNeutral;
61+
62+
if (!ghost.Frame.HasData)
63+
continue;
64+
65+
if (fastest == null || ghost.Data.Frames.Count < fastest.Data.Frames.Count) {
66+
fastest = ghost;
67+
}
68+
}
69+
70+
if (fastest != null) {
71+
fastest.Color = ColorGold;
72+
}
73+
74+
base.Render();
75+
}
76+
77+
}
78+
}

GhostMod/GhostMod.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
</Reference>
6565
</ItemGroup>
6666
<ItemGroup>
67+
<Compile Include="GhostManager.cs" />
6768
<Compile Include="GhostName.cs" />
6869
<Compile Include="GhostInputReplayer.cs" />
6970
<Compile Include="GhostRecorder.cs" />

GhostMod/GhostModule.cs

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public class GhostModule : EverestModule {
2121

2222
public static string PathGhosts { get; internal set; }
2323

24-
public List<Ghost> Ghosts = new List<Ghost>();
24+
public GhostManager GhostManager;
2525
public GhostRecorder GhostRecorder;
2626

2727
public Guid Run;
@@ -49,7 +49,8 @@ public override void Unload() {
4949

5050
public void OnLoadLevel(Level level, Player.IntroTypes playerIntro, bool isFromLoader) {
5151
if (isFromLoader) {
52-
Ghosts.Clear();
52+
GhostManager?.RemoveSelf();
53+
GhostManager = null;
5354
GhostRecorder?.RemoveSelf();
5455
GhostRecorder = null;
5556
Run = Guid.NewGuid();
@@ -82,21 +83,9 @@ public void Step(Level level) {
8283
GhostRecorder.Data.Write();
8384
}
8485

85-
// Remove any dead ghosts (heh)
86-
for (int i = Ghosts.Count - 1; i > -1; --i) {
87-
Ghost ghost = Ghosts[i];
88-
if (ghost.Player != player)
89-
ghost.RemoveSelf();
90-
}
91-
Ghosts.Clear();
92-
93-
// Read and add all ghosts.
94-
GhostData.ForAllGhosts(level.Session, (i, ghostData) => {
95-
Ghost ghost = new Ghost(player, ghostData);
96-
level.Add(ghost);
97-
Ghosts.Add(ghost);
98-
return true;
99-
});
86+
GhostManager?.RemoveSelf();
87+
88+
level.Add(GhostManager = new GhostManager(player, level));
10089

10190
if (GhostRecorder != null)
10291
GhostRecorder.RemoveSelf();

0 commit comments

Comments
 (0)