This repository has been archived by the owner on Oct 24, 2021. It is now read-only.
forked from null7323/QMidiCore-Quaver-Stream-Renderer
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathPFAConfigrationLoader.cs
70 lines (67 loc) · 2.51 KB
/
PFAConfigrationLoader.cs
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
using QQS_UI.Core;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
namespace QQS_UI
{
public static class PFAConfigrationLoader
{
public static string ConfigurationPath
{
get
{
string path = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
path += "\\Piano From Above\\Config.xml";
return File.Exists(path) ? path : null;
}
}
/// <summary>
/// 判断PFA配置文件是否可用.<br/>
/// Determines whether PFA configuration is available.
/// </summary>
public static bool IsConfigurationAvailable => ConfigurationPath != null;
/// <summary>
/// 加载 PFA Config的颜色.<br/>
/// Load colors from PFA configuration if possible.
/// </summary>
/// <returns>
/// 如果无法加载配置, 返回<see langword="null"/>;<br/>
/// 如果加载成功, 则以数组的形式返回这些颜色.<br/>
/// If it fails to load PFA configuration, <see langword="null"/> will be returned.<br/>
/// If it succeeds in loading config, then an array containing these colors will be returned.
/// </returns>
public static RGBAColor[] LoadPFAConfigurationColors()
{
if (!IsConfigurationAvailable)
{
return null;
}
XmlDocument doc = new XmlDocument();
doc.Load(ConfigurationPath);
XmlNode rootNode = doc.SelectSingleNode("PianoFromAbove");
XmlNode visualNode = rootNode.SelectSingleNode("Visual");
XmlNode colors = visualNode.SelectSingleNode("Colors");
XmlNodeList actualColors = colors.SelectNodes("Color");
List<RGBAColor> retColors = new List<RGBAColor>();
foreach (XmlNode node in actualColors)
{
byte r = byte.Parse(node.Attributes[0].Value);
byte g = byte.Parse(node.Attributes[1].Value);
byte b = byte.Parse(node.Attributes[2].Value);
retColors.Add(new RGBAColor
{
R = r,
G = g,
B = b,
A = 0xFF
});
}
Console.WriteLine("Loaded PFA palette. Loaded {0} colours.", retColors.Count);
return retColors.ToArray();
}
}
}