-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathClsColorSet.cs
More file actions
94 lines (80 loc) · 2.28 KB
/
ClsColorSet.cs
File metadata and controls
94 lines (80 loc) · 2.28 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
using System;
using System.Collections.Generic;
using System.IO;
using CLSEncoderDecoder.Export;
using CLSEncoderDecoder.Import;
namespace CLSEncoderDecoder;
public class ClsColorSet
{
private string asciiName;
private string utf8Name;
protected bool Equals(ClsColorSet other)
{
if (!(AsciiName == other.AsciiName && Utf8Name == other.Utf8Name && Colors.Count == other.Colors.Count))
return false;
for (int i = 0; i < Colors.Count; i++)
{
if (Colors[i] != other.Colors[i])
return false;
}
return true;
}
public override bool Equals(object? obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
if (obj.GetType() != this.GetType()) return false;
return Equals((ClsColorSet)obj);
}
public ClsColorSet(List<ClsColor> colors, string asciiName, string utf8Name)
{
Colors = colors;
this.asciiName = asciiName;
this.utf8Name = utf8Name;
}
public ClsColorSet(List<ClsColor> colors, string name)
{
Colors = colors;
this.asciiName = "";
this.utf8Name = "";
SetBothNames(name);
}
public string AsciiName
{
get => asciiName;
set
{
if (value.Length > 64)
throw new InvalidOperationException("Max name length is 64");
asciiName = value;
}
}
public string Utf8Name
{
get => utf8Name;
set
{
if (value.Length > 64)
throw new InvalidOperationException("Max name length is 64");
utf8Name = value;
}
}
public void SetBothNames(string name)
{
AsciiName = name;
Utf8Name = name;
}
public List<ClsColor> Colors { get; set; }
public static ClsColorSet Load(string path)
{
using var stream = File.OpenRead(path);
return ClsImporter.Import(stream);
}
public static ClsColorSet Load(byte[] fileBytes)
{
using var stream = new MemoryStream(fileBytes);
return ClsImporter.Import(stream);
}
public byte[] SaveToArray() => ClsExporter.SaveToArray(this);
public void Save(string path) => ClsExporter.Save(this, path);
}