Skip to content

Commit 7d0f943

Browse files
Merge pull request #622 from TheTrackerCouncil/tracker-speech-sprite-packs
Split tracker speech sprites from regular sprites and configs
2 parents 325afdd + e88d08c commit 7d0f943

23 files changed

+715
-418
lines changed

src/TrackerCouncil.Smz3.Data/Configuration/ConfigProvider.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ namespace TrackerCouncil.Smz3.Data.Configuration;
2222
/// </summary>
2323
public partial class ConfigProvider
2424
{
25+
public static HashSet<string> DeprecatedConfigProfiles = ["Halloween Tracker Sprites", "Plain Tracker Sprites"];
26+
2527
private static readonly JsonSerializerOptions s_options = new()
2628
{
2729
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingDefault,
@@ -40,6 +42,16 @@ public ConfigProvider(ILogger<ConfigProvider>? logger)
4042
{
4143
_basePath = RandomizerDirectories.ConfigPath;
4244
_logger = logger;
45+
46+
if (Directory.Exists(_basePath))
47+
{
48+
var toDelete = Directory.EnumerateDirectories(_basePath)
49+
.Where(directory => DeprecatedConfigProfiles.Contains(Path.GetFileName(directory))).ToList();
50+
foreach (var directory in toDelete)
51+
{
52+
Directory.Delete(directory, true);
53+
}
54+
}
4355
}
4456

4557
/// <summary>

src/TrackerCouncil.Smz3.Data/Options/GeneralOptions.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ public class GeneralOptions : INotifyPropertyChanged
5151

5252
public bool TrackerShadows { get; set; } = true;
5353

54+
public string TrackerSpeechImagePack { get; set; } = "Default";
55+
5456
public byte[] TrackerSpeechBGColor { get; set; } = [0xFF, 0x48, 0x3D, 0x8B];
5557

5658
public bool TrackerSpeechEnableBounce { get; set; } = true;

src/TrackerCouncil.Smz3.Data/Options/RandomizerOptions.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
using System;
22
using System.ComponentModel;
33
using System.IO;
4+
using System.Linq;
45
using System.Runtime.CompilerServices;
56
using System.Text.Json;
67
using System.Text.Json.Serialization;
78
using MSURandomizerLibrary;
89
using SnesConnectorLibrary;
10+
using TrackerCouncil.Smz3.Data.Configuration;
911
using TrackerCouncil.Smz3.Data.Logic;
1012
using TrackerCouncil.Smz3.Shared.Enums;
1113
using YamlDotNet.Serialization;
@@ -130,6 +132,13 @@ public static RandomizerOptions Load(string loadPath, string savePath, bool isYa
130132
: AutoMapUpdateBehavior.Disabled;
131133
}
132134

135+
// Remove deprecated config profiles
136+
if (options.GeneralOptions.SelectedProfiles.Any(p => p != null && ConfigProvider.DeprecatedConfigProfiles.Contains(p)))
137+
{
138+
options.GeneralOptions.SelectedProfiles = options.GeneralOptions.SelectedProfiles
139+
.Where(p => p != null && !ConfigProvider.DeprecatedConfigProfiles.Contains(p)).ToList();
140+
}
141+
133142
return options;
134143
}
135144
else

src/TrackerCouncil.Smz3.Data/Options/Sprite.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ namespace TrackerCouncil.Smz3.Data.Options;
88

99
public class Sprite : IEquatable<Sprite>
1010
{
11+
public static HashSet<string> ValidDownloadExtensions = [".png", ".rdc", ".ips", ".gif"];
12+
1113
private static readonly Dictionary<SpriteType, string> s_folderNames = new()
1214
{
1315
{ SpriteType.Samus, "Samus" },
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
using System.Collections.Generic;
2+
3+
namespace TrackerCouncil.Smz3.Data.Options;
4+
5+
/// <summary>
6+
/// Images for a single reaction
7+
/// </summary>
8+
public class TrackerSpeechReactionImages
9+
{
10+
/// <summary>
11+
/// Image for when tracker is not talking
12+
/// </summary>
13+
public required string IdleImage { get; set; }
14+
15+
/// <summary>
16+
/// Image for when tracker is saying something
17+
/// </summary>
18+
public required string TalkingImage { get; set; }
19+
}
20+
21+
/// <summary>
22+
/// A package of different sets of reaction images for Tracker
23+
/// </summary>
24+
public class TrackerSpeechImagePack
25+
{
26+
/// <summary>
27+
/// The name of the pack
28+
/// </summary>
29+
public required string Name { get; set; }
30+
31+
/// <summary>
32+
/// The default reaction images for the speech image pack
33+
/// </summary>
34+
public required TrackerSpeechReactionImages Default { get; set; }
35+
36+
/// <summary>
37+
/// A dictionary of all of the different reaction types for this pack
38+
/// </summary>
39+
public required Dictionary<string, TrackerSpeechReactionImages> Reactions { get; set; }
40+
41+
/// <summary>
42+
/// Gets the reaction images for a given reaction type. Will return the default reaction type if not specified
43+
/// or the requested reaction type is not present in this pack.
44+
/// </summary>
45+
/// <param name="reactionName">The name of the reaction</param>
46+
/// <returns>The appropriate images to use for the reaction</returns>
47+
public TrackerSpeechReactionImages GetReactionImages(string? reactionName = null)
48+
{
49+
if (reactionName == null)
50+
{
51+
return Default;
52+
}
53+
return Reactions.TryGetValue(reactionName.ToLower(), out var reaction) ? reaction : Default;
54+
}
55+
}

src/TrackerCouncil.Smz3.Data/RandomizerDirectories.cs

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace TrackerCouncil.Smz3.Data;
66

7-
public class RandomizerDirectories
7+
public static class RandomizerDirectories
88
{
99
public static string SolutionPath
1010
{
@@ -66,4 +66,40 @@ public static string SpritePath
6666
#endif
6767
}
6868
}
69+
70+
#if DEBUG
71+
public static string SpriteHashYamlFilePath => Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "SMZ3CasRandomizer", "sprite-hashes-debug.yml");
72+
#else
73+
public static string SpriteHashYamlFilePath => Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "SMZ3CasRandomizer", "sprite-hashes.yml");
74+
#endif
75+
76+
public static string SpriteInitialJsonFilePath => Path.Combine(SpritePath, "sprites.json");
77+
78+
public static string TrackerSpritePath
79+
{
80+
get
81+
{
82+
#if DEBUG
83+
var parentDir = new DirectoryInfo(SolutionPath).Parent;
84+
var spriteRepo = parentDir?.GetDirectories().FirstOrDefault(x => x.Name == "TrackerSprites");
85+
86+
if (spriteRepo?.Exists != true)
87+
{
88+
return Path.Combine(AppContext.BaseDirectory, "TrackerSprites");
89+
}
90+
91+
return spriteRepo.FullName;
92+
#else
93+
return Path.Combine(AppContext.BaseDirectory, "TrackerSprites");
94+
#endif
95+
}
96+
}
97+
98+
#if DEBUG
99+
public static string TrackerSpriteHashYamlFilePath => Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "SMZ3CasRandomizer", "tracker-sprite-hashes-debug.yml");
100+
#else
101+
public static string TrackerSpriteHashYamlFilePath => Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "SMZ3CasRandomizer", "tracker-sprite-hashes.yml");
102+
#endif
103+
104+
public static string TrackerSpriteInitialJsonFilePath => Path.Combine(SpritePath, "tracker-sprites.json");
69105
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System;
2+
3+
namespace TrackerCouncil.Smz3.Data.Services;
4+
5+
/// <summary>
6+
/// Event for the progress of a download of files from GitHub
7+
/// </summary>
8+
/// <param name="completed"></param>
9+
/// <param name="total"></param>
10+
public class GitHubFileDownloadUpdateEventArgs(int completed, int total) : EventArgs
11+
{
12+
/// <summary>
13+
/// How many files have been finished (either successful or failed)
14+
/// </summary>
15+
public int Completed => completed;
16+
17+
/// <summary>
18+
/// The total number of files to process
19+
/// </summary>
20+
public int Total => total;
21+
}

0 commit comments

Comments
 (0)