Skip to content

Commit 63150fe

Browse files
committed
Add filter by name (no menu entry yet)
1 parent 0e29831 commit 63150fe

File tree

8 files changed

+46
-10
lines changed

8 files changed

+46
-10
lines changed

GhostMod/Content/Dialog/English.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
MODOPTIONS_GHOSTMODULE_MODE_PLAY= PLAY
2727
MODOPTIONS_GHOSTMODULE_MODE_ON= BOTH
2828
MODOPTIONS_GHOSTMODULE_NAME= Ghost Name
29-
MODOPTIONS_GHOSTMODULE_SHOWOTHERNAMES= Show Other's Names
29+
MODOPTIONS_GHOSTMODULE_NAMEFILTER= Filter By Name
30+
MODOPTIONS_GHOSTMODULE_SHOWNAMES= Show Names
3031
MODOPTIONS_GHOSTMODULE_INNEROPACITY= Near Ghost Visibility
3132
MODOPTIONS_GHOSTMODULE_INNERHAIROPACITY= Near Ghost Hair Visibility
3233
MODOPTIONS_GHOSTMODULE_OUTEROPACITY= Far Ghost Visibility

GhostMod/Ghost.cs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ public class Ghost : Actor {
2727

2828
public GhostName Name;
2929

30+
protected Color color;
31+
3032
protected float alpha;
3133
protected float alphaHair;
3234

@@ -57,7 +59,7 @@ public override void Added(Scene scene) {
5759
Hair.Start();
5860
UpdateHair();
5961

60-
if (Data != null && Data.Name != GhostModule.Settings.Name)
62+
if (Data != null)
6163
Scene.Add(Name = new GhostName(this, Data.Name));
6264
}
6365

@@ -105,6 +107,8 @@ public override void Update() {
105107
Visible &= Frame.HasData;
106108
if (Data != null && Data.Dead)
107109
Visible &= GhostModule.Settings.ShowDeaths;
110+
if (Data != null && !string.IsNullOrEmpty(GhostModule.Settings.NameFilter))
111+
Visible &= string.IsNullOrEmpty(Data.Name) || GhostModule.Settings.NameFilter.Equals(Data.Name, StringComparison.InvariantCultureIgnoreCase);
108112

109113
if (Player.InControl && AutoForward && ForcedFrame == null) {
110114
do {
@@ -116,9 +120,6 @@ public override void Update() {
116120
}
117121
playerHadControl = Player.InControl;
118122

119-
UpdateSprite();
120-
UpdateHair();
121-
122123
if (Data != null && Data.Opacity != null) {
123124
alpha = Data.Opacity.Value;
124125
alphaHair = Data.Opacity.Value;
@@ -136,6 +137,18 @@ public override void Update() {
136137
alphaHair = Calc.LerpClamp(GhostModule.Settings.InnerHairOpacityFactor, GhostModule.Settings.OuterHairOpacityFactor, dist);
137138
}
138139

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+
149+
UpdateSprite();
150+
UpdateHair();
151+
139152
Visible &= alpha > 0f;
140153

141154
if (Name != null)

GhostMod/GhostData.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public class GhostData {
1818
public readonly static string Magic = "everest-ghost\r\n";
1919
public readonly static char[] MagicChars = Magic.ToCharArray();
2020

21-
public readonly static int Version = 0;
21+
public readonly static int Version = 1;
2222

2323
public readonly static Regex PathVerifyRegex = new Regex("[\"`?* #" + Regex.Escape(new string(Path.GetInvalidFileNameChars()) + new string(Path.GetInvalidPathChars())) + "]", RegexOptions.Compiled);
2424

@@ -78,6 +78,8 @@ public static void ForAllGhosts(Session session, Func<int, GhostData, bool> cb)
7878

7979
public float? Opacity;
8080

81+
public Guid Run;
82+
8183
protected string _FilePath;
8284
public string FilePath {
8385
get {
@@ -103,6 +105,7 @@ public GhostFrame this[int i] {
103105

104106
public GhostData() {
105107
Date = DateTime.UtcNow;
108+
Run = Guid.NewGuid();
106109
}
107110
public GhostData(Session session)
108111
: this() {
@@ -173,6 +176,12 @@ public GhostData Read(BinaryReader reader) {
173176

174177
Opacity = reader.ReadBoolean() ? (float?) reader.ReadSingle() : null;
175178

179+
if (version >= 1) {
180+
Run = new Guid(reader.ReadBytes(16));
181+
} else {
182+
Run = Guid.Empty;
183+
}
184+
176185
int count = reader.ReadInt32();
177186
reader.ReadChar(); // \r
178187
reader.ReadChar(); // \n
@@ -225,6 +234,8 @@ public void Write(BinaryWriter writer) {
225234
writer.Write(false);
226235
}
227236

237+
writer.Write(Run.ToByteArray());
238+
228239
writer.Write(Frames.Count);
229240
writer.Write('\r');
230241
writer.Write('\n');

GhostMod/GhostModule.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ public class GhostModule : EverestModule {
2424
public List<Ghost> Ghosts = new List<Ghost>();
2525
public GhostRecorder GhostRecorder;
2626

27+
public Guid Run;
28+
2729
public GhostModule() {
2830
Instance = this;
2931

@@ -50,6 +52,7 @@ public void OnLoadLevel(Level level, Player.IntroTypes playerIntro, bool isFromL
5052
Ghosts.Clear();
5153
GhostRecorder?.RemoveSelf();
5254
GhostRecorder = null;
55+
Run = Guid.NewGuid();
5356
}
5457

5558
Step(level);
@@ -75,6 +78,7 @@ public void Step(Level level) {
7578
// Maybe we left the level prematurely earlier?
7679
if (GhostRecorder?.Data != null) {
7780
GhostRecorder.Data.Target = target;
81+
GhostRecorder.Data.Run = Run;
7882
GhostRecorder.Data.Write();
7983
}
8084

GhostMod/GhostModuleSettings.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ public class GhostModuleSettings : EverestModuleSettings {
1717
[SettingInGame(false)]
1818
public string Name { get; set; } = "";
1919

20-
public bool ShowOtherNames { get; set; } = true;
20+
[SettingIgnore] // Ignore on older builds of Everest which don't support custom entry creators.
21+
public string NameFilter { get; set; } = "";
22+
23+
public bool ShowNames { get; set; } = true;
2124

2225
public bool ShowDeaths { get; set; } = false;
2326

@@ -57,6 +60,10 @@ public class GhostModuleSettings : EverestModuleSettings {
5760
[SettingIgnore]
5861
public float BorderSizeDist => BorderSize * BorderSize * 64f;
5962

63+
public void ShowNameFilterEntry(TextMenu menu, bool inGame) {
64+
// TODO: Create a slider to choose between all available names.
65+
}
66+
6067
}
6168
public enum GhostModuleMode {
6269
Off = 0,

GhostMod/GhostName.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public override void Render() {
3232

3333
if ((GhostModule.Settings.Mode & GhostModuleMode.Play) != GhostModuleMode.Play)
3434
return;
35-
if (!GhostModule.Settings.ShowOtherNames ||
35+
if (!GhostModule.Settings.ShowNames ||
3636
Tracking == null)
3737
return;
3838

GhostMod/metadata.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Name: GhostMod
2-
Version: 1.0.1
2+
Version: 1.1.0
33
DLL: GhostMod.dll
44
Dependencies:
55
- Name: Everest

0 commit comments

Comments
 (0)