Skip to content

Commit

Permalink
Merge pull request #622 from TheTrackerCouncil/tracker-speech-sprite-…
Browse files Browse the repository at this point in the history
…packs

Split tracker speech sprites from regular sprites and configs
  • Loading branch information
MattEqualsCoder authored Dec 18, 2024
2 parents 325afdd + e88d08c commit 7d0f943
Show file tree
Hide file tree
Showing 23 changed files with 715 additions and 418 deletions.
12 changes: 12 additions & 0 deletions src/TrackerCouncil.Smz3.Data/Configuration/ConfigProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ namespace TrackerCouncil.Smz3.Data.Configuration;
/// </summary>
public partial class ConfigProvider
{
public static HashSet<string> DeprecatedConfigProfiles = ["Halloween Tracker Sprites", "Plain Tracker Sprites"];

private static readonly JsonSerializerOptions s_options = new()
{
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingDefault,
Expand All @@ -40,6 +42,16 @@ public ConfigProvider(ILogger<ConfigProvider>? logger)
{
_basePath = RandomizerDirectories.ConfigPath;
_logger = logger;

if (Directory.Exists(_basePath))
{
var toDelete = Directory.EnumerateDirectories(_basePath)
.Where(directory => DeprecatedConfigProfiles.Contains(Path.GetFileName(directory))).ToList();
foreach (var directory in toDelete)
{
Directory.Delete(directory, true);
}
}
}

/// <summary>
Expand Down
2 changes: 2 additions & 0 deletions src/TrackerCouncil.Smz3.Data/Options/GeneralOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ public class GeneralOptions : INotifyPropertyChanged

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

public string TrackerSpeechImagePack { get; set; } = "Default";

public byte[] TrackerSpeechBGColor { get; set; } = [0xFF, 0x48, 0x3D, 0x8B];

public bool TrackerSpeechEnableBounce { get; set; } = true;
Expand Down
9 changes: 9 additions & 0 deletions src/TrackerCouncil.Smz3.Data/Options/RandomizerOptions.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
using System;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text.Json;
using System.Text.Json.Serialization;
using MSURandomizerLibrary;
using SnesConnectorLibrary;
using TrackerCouncil.Smz3.Data.Configuration;
using TrackerCouncil.Smz3.Data.Logic;
using TrackerCouncil.Smz3.Shared.Enums;
using YamlDotNet.Serialization;
Expand Down Expand Up @@ -130,6 +132,13 @@ public static RandomizerOptions Load(string loadPath, string savePath, bool isYa
: AutoMapUpdateBehavior.Disabled;
}

// Remove deprecated config profiles
if (options.GeneralOptions.SelectedProfiles.Any(p => p != null && ConfigProvider.DeprecatedConfigProfiles.Contains(p)))
{
options.GeneralOptions.SelectedProfiles = options.GeneralOptions.SelectedProfiles
.Where(p => p != null && !ConfigProvider.DeprecatedConfigProfiles.Contains(p)).ToList();
}

return options;
}
else
Expand Down
2 changes: 2 additions & 0 deletions src/TrackerCouncil.Smz3.Data/Options/Sprite.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ namespace TrackerCouncil.Smz3.Data.Options;

public class Sprite : IEquatable<Sprite>
{
public static HashSet<string> ValidDownloadExtensions = [".png", ".rdc", ".ips", ".gif"];

private static readonly Dictionary<SpriteType, string> s_folderNames = new()
{
{ SpriteType.Samus, "Samus" },
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using System.Collections.Generic;

namespace TrackerCouncil.Smz3.Data.Options;

/// <summary>
/// Images for a single reaction
/// </summary>
public class TrackerSpeechReactionImages
{
/// <summary>
/// Image for when tracker is not talking
/// </summary>
public required string IdleImage { get; set; }

/// <summary>
/// Image for when tracker is saying something
/// </summary>
public required string TalkingImage { get; set; }
}

/// <summary>
/// A package of different sets of reaction images for Tracker
/// </summary>
public class TrackerSpeechImagePack
{
/// <summary>
/// The name of the pack
/// </summary>
public required string Name { get; set; }

/// <summary>
/// The default reaction images for the speech image pack
/// </summary>
public required TrackerSpeechReactionImages Default { get; set; }

/// <summary>
/// A dictionary of all of the different reaction types for this pack
/// </summary>
public required Dictionary<string, TrackerSpeechReactionImages> Reactions { get; set; }

/// <summary>
/// Gets the reaction images for a given reaction type. Will return the default reaction type if not specified
/// or the requested reaction type is not present in this pack.
/// </summary>
/// <param name="reactionName">The name of the reaction</param>
/// <returns>The appropriate images to use for the reaction</returns>
public TrackerSpeechReactionImages GetReactionImages(string? reactionName = null)
{
if (reactionName == null)
{
return Default;
}
return Reactions.TryGetValue(reactionName.ToLower(), out var reaction) ? reaction : Default;
}
}
38 changes: 37 additions & 1 deletion src/TrackerCouncil.Smz3.Data/RandomizerDirectories.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace TrackerCouncil.Smz3.Data;

public class RandomizerDirectories
public static class RandomizerDirectories
{
public static string SolutionPath
{
Expand Down Expand Up @@ -66,4 +66,40 @@ public static string SpritePath
#endif
}
}

#if DEBUG
public static string SpriteHashYamlFilePath => Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "SMZ3CasRandomizer", "sprite-hashes-debug.yml");
#else
public static string SpriteHashYamlFilePath => Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "SMZ3CasRandomizer", "sprite-hashes.yml");
#endif

public static string SpriteInitialJsonFilePath => Path.Combine(SpritePath, "sprites.json");

public static string TrackerSpritePath
{
get
{
#if DEBUG
var parentDir = new DirectoryInfo(SolutionPath).Parent;
var spriteRepo = parentDir?.GetDirectories().FirstOrDefault(x => x.Name == "TrackerSprites");

if (spriteRepo?.Exists != true)
{
return Path.Combine(AppContext.BaseDirectory, "TrackerSprites");
}

return spriteRepo.FullName;
#else
return Path.Combine(AppContext.BaseDirectory, "TrackerSprites");
#endif
}
}

#if DEBUG
public static string TrackerSpriteHashYamlFilePath => Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "SMZ3CasRandomizer", "tracker-sprite-hashes-debug.yml");
#else
public static string TrackerSpriteHashYamlFilePath => Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "SMZ3CasRandomizer", "tracker-sprite-hashes.yml");
#endif

public static string TrackerSpriteInitialJsonFilePath => Path.Combine(SpritePath, "tracker-sprites.json");
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;

namespace TrackerCouncil.Smz3.Data.Services;

/// <summary>
/// Event for the progress of a download of files from GitHub
/// </summary>
/// <param name="completed"></param>
/// <param name="total"></param>
public class GitHubFileDownloadUpdateEventArgs(int completed, int total) : EventArgs
{
/// <summary>
/// How many files have been finished (either successful or failed)
/// </summary>
public int Completed => completed;

/// <summary>
/// The total number of files to process
/// </summary>
public int Total => total;
}
Loading

0 comments on commit 7d0f943

Please sign in to comment.