-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathSprite.cs
More file actions
127 lines (101 loc) · 4.68 KB
/
Sprite.cs
File metadata and controls
127 lines (101 loc) · 4.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using YamlDotNet.Serialization;
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" },
{ SpriteType.Link, "Link" },
{ SpriteType.Ship, "Ships" }
};
public static readonly Sprite DefaultSamus = new("Default Samus", SpriteType.Samus, true, false, "default.png");
public static readonly Sprite DefaultLink = new("Default Link", SpriteType.Link, true, false, "default.png");
public static readonly Sprite DefaultShip = new("Default Ship", SpriteType.Ship, true, false, "default.png");
public static readonly Sprite RandomSamus = new("Random Sprite", SpriteType.Samus, false, true, "random.png");
public static readonly Sprite RandomLink = new("Random Sprite", SpriteType.Link, false, true, "random.png");
public static readonly Sprite RandomShip = new("Random Sprite", SpriteType.Ship, false, true, "random.png");
public Sprite()
{
Name = "";
Author = "";
PreviewPath = "";
}
public Sprite(string name, string author, string filePath, SpriteType spriteType, string previewPath, SpriteOptions spriteOption)
{
Name = name;
Author = author;
FilePath = filePath;
SpriteType = spriteType;
PreviewPath = previewPath;
SpriteOption = spriteOption;
IsUserSprite = filePath.StartsWith(RandomizerDirectories.UserSpritePath);
if (string.IsNullOrEmpty(filePath))
IsDefault = true;
}
private Sprite(string name, SpriteType spriteType, bool isDefault, bool isRandomSprite, string sprite)
{
Name = name;
Author = isDefault ? "Nintendo" : "";
SpriteType = spriteType;
IsDefault = isDefault;
IsRandomSprite = isRandomSprite;
PreviewPath = Path.Combine(RandomizerDirectories.SpritePath, s_folderNames[spriteType], sprite);
}
[YamlIgnore]
public string Name { get; set; }
[YamlIgnore]
public string Author { get; set; }
public string FilePath { get; } = "";
public SpriteType SpriteType { get; }
[YamlIgnore]
public string PreviewPath { get; set; }
public bool IsDefault { get; set; }
public bool IsRandomSprite { get; set; }
[YamlIgnore]
public SpriteOptions SpriteOption { get; set; }
public bool IsUserSprite { get; set; }
public bool MatchesFilter(string searchTerm, SpriteFilter spriteFilter) => (string.IsNullOrEmpty(searchTerm) ||
Name.Contains(searchTerm, StringComparison.OrdinalIgnoreCase) ||
Author.Contains(searchTerm, StringComparison.OrdinalIgnoreCase)) &&
((spriteFilter == SpriteFilter.Default && SpriteOption != SpriteOptions.Hide) ||
(spriteFilter == SpriteFilter.Favorited && SpriteOption == SpriteOptions.Favorite) ||
(spriteFilter == SpriteFilter.Hidden && SpriteOption == SpriteOptions.Hide) ||
(spriteFilter == SpriteFilter.User && IsUserSprite) ||
spriteFilter == SpriteFilter.All);
public static bool operator ==(Sprite? a, Sprite? b)
=> a is null && b is null || a?.Equals(b) == true;
public static bool operator !=(Sprite? a, Sprite? b)
=> !(a == b);
public override bool Equals(object? obj)
{
if (obj is not Sprite other)
return false;
return Equals(other);
}
public bool Equals(Sprite? other)
{
return FilePath == other?.FilePath
&& SpriteType == other.SpriteType
&& IsDefault == other.IsDefault
&& IsRandomSprite == other.IsRandomSprite;
}
public override int GetHashCode()
=> HashCode.Combine(FilePath, SpriteType);
public override string ToString()
{
if (IsDefault)
{
return $"Default";
}
else if (IsRandomSprite)
{
return $"Random {SpriteType} Sprite";
}
return string.IsNullOrEmpty(Author) ? Name : $"{Name} by {Author}";
}
}