Skip to content

Commit 5201863

Browse files
committed
[+] 版本号机制
1 parent 544b7e5 commit 5201863

7 files changed

Lines changed: 84 additions & 27 deletions

File tree

MuConvert.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@
2828
<ItemGroup>
2929
<PackageReference Include="Antlr4.Runtime.Standard" Version="4.13.1" />
3030
<PackageReference Include="Antlr4BuildTasks" Version="12.14.0" />
31+
<PackageReference Include="MinVer" Version="7.0.0">
32+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
33+
<PrivateAssets>all</PrivateAssets>
34+
</PackageReference>
3135
<PackageReference Include="Rationals" Version="2.3.0" />
3236
</ItemGroup>
3337

Program.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
// See https://aka.ms/new-console-template for more information
22

3-
Console.WriteLine("Hello, World!");
3+
using MuConvert.utils;
4+
5+
Console.WriteLine("Hello, World!");
6+
Console.WriteLine(Utils.AppVersion);

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
MuConvert - 支持Simai与MA2谱面互转的新一代转谱器
22
================
33

4+
用户文档TODO
5+
46
## 开发者指南
57
> 以下内容是面向对于本程序感兴趣,想要了解技术细节/调试bug/参与开发的开发者的。如果你只是普通用户,可以不必阅读以下内容;如果你遇到了bug,请通过[issue](https://github.com/MuNet-OSS/MuConvert/issues)进行反馈。
68

chart/Note.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public class Hold : Tap
5353

5454
public Hold(Chart chart, Rational time) : base(chart, time) { Duration = new Duration(this); }
5555

56-
private string DebuggerDisplay() => $"{Key}h{Modifiers}{Duration.DebuggerDisplay()}";
56+
private new string DebuggerDisplay() => $"{Key}h{Modifiers}{Duration.DebuggerDisplay()}";
5757
}
5858

5959
[DebuggerDisplay("{DebuggerDisplay(),nq}")]

generator/MA2Generator.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ MET_DEF 4 4
2929
RESOLUTION {6}
3030
CLK_DEF {7}
3131
COMPATIBLE_CODE MA2
32-
GENERATED_BY MuConvert
32+
GENERATED_BY MuConvert v{8}
3333
3434
";
3535

@@ -87,7 +87,7 @@ private void AddTap(Tap tap, int bar, int tick)
8787
string head = string.Format(headTemplate,
8888
$"{MA2Version / 100}.{MA2Version % 100:D2}.00", chart.IsUtage?1:0,
8989
bpmStatistics.Item1, bpmStatistics.Item2, bpmStatistics.Item3, bpmStatistics.Item4,
90-
RSL, 96*ClockCount);
90+
RSL, 96*ClockCount, Utils.AppVersion);
9191
result.Append(head);
9292

9393
// bpm段
@@ -206,7 +206,7 @@ private void AddTap(Tap tap, int bar, int tick)
206206
var stNamesCvt = statsNameConversion();
207207
foreach (var key in stNamesCvt.Values.Select(x=>x?.Item1).Where(x=>x!=null).Distinct())
208208
{
209-
stats_rec[key] = 0;
209+
stats_rec[key!] = 0;
210210
}
211211
foreach (var l in lines)
212212
{

maidata/Maidata.cs

Lines changed: 64 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,24 @@
11
using System.Text;
2+
using MuConvert.utils;
23

34
namespace MuConvert.maidata;
45

5-
public record MaidataChart(string Level, string NoteDesigner, string Inote);
6+
public record MaidataChart(string? Level, string? NoteDesigner, string Inote);
67

78
public class Maidata : Dictionary<string, string>
89
{
910
/**
1011
* 便捷的获得一个maidata中的所有谱面的方法。
11-
* 除了铺面之外的信息,如title、artist、first等,仍可通过一般的dict方法加以获得。
12+
* 除了谱面之外的信息,如title、artist、first等,可通过Infos获取;
13+
* 而由于,如果用一般的Dict的方法遍历/访问Maidata对象的话,拿到的是整个maidata的、包含inote等在内的所有信息。
1214
*/
13-
public Dictionary<int, MaidataChart> Levels
14-
{
15-
get
16-
{
17-
var result = new Dictionary<int, MaidataChart>();
18-
foreach (var (k ,v) in this)
19-
{
20-
if (k.StartsWith("inote_"))
21-
{
22-
if (!int.TryParse(k.Replace("inote_", ""), out var id)) continue;
23-
var level = this.GetValueOrDefault($"lv_{id}", "");
24-
var noteDesigner = this.GetValueOrDefault($"des_{id}", "");
25-
result.Add(id, new MaidataChart(level, noteDesigner, v));
26-
}
27-
}
28-
return result;
29-
}
30-
}
15+
public Dictionary<int, MaidataChart> Levels => _splitLevels().Item1;
16+
17+
/**
18+
* 便捷的获得一个maidata中,除了谱面相关的所有信息字段的方法。
19+
* 而由于Maidata类继承自Dictionary,如果用一般的Dict的方法遍历/访问Maidata对象的话,拿到的是整个maidata的、包含inote等在内的所有信息。
20+
*/
21+
public Dictionary<string, string> Infos => _splitLevels().Item2;
3122

3223
/**
3324
* 将maidata.txt的文本传给此函数,即可构造Maidata对象。
@@ -65,6 +56,25 @@ private void _putKey(string? key, StringBuilder content)
6556
value = value.Trim(); // 对部分字段,要trim一下;但不能对所有的字段都trim,比如如果对title进行trim,如月车站就寄了。
6657
this[key] = value;
6758
}
59+
60+
private (Dictionary<int, MaidataChart>, Dictionary<string, string>) _splitLevels()
61+
{
62+
var levels = new Dictionary<int, MaidataChart>();
63+
var infos = new Dictionary<string, string>(this); // 复制一份,稍后删key
64+
foreach (var k in this.Keys)
65+
{
66+
if (k.StartsWith("inote_"))
67+
{
68+
if (!int.TryParse(k.Replace("inote_", ""), out var id)) continue;
69+
// 一边从info中移除内容,一边加到levels里去
70+
infos.Remove(k, out var v);
71+
infos.Remove($"lv_{id}", out var level);
72+
infos.Remove($"des_{id}", out var noteDesigner);
73+
levels.Add(id, new MaidataChart(level, noteDesigner, v!));
74+
}
75+
}
76+
return (levels, infos);
77+
}
6878

6979
public string Title => this.GetValueOrDefault("title", "");
7080
public string Artist => this.GetValueOrDefault("artist", "");
@@ -80,5 +90,38 @@ private void _putKey(string? key, StringBuilder content)
8090
return (demoStart, demoLen);
8191
}
8292
}
83-
93+
94+
public override string ToString()
95+
{
96+
var result = new StringBuilder();
97+
98+
string[] fixedKeys = ["title", "artist", "first", "des", "wholebpm"]; // 对这些键,优先、按这里指定的顺序输出。
99+
foreach (var k in fixedKeys)
100+
{
101+
if (TryGetValue(k, out var v)) result.AppendLine($"&{k}=v");
102+
}
103+
104+
var (levels, infos) = _splitLevels();
105+
foreach (var (k, v) in Infos)
106+
{
107+
if (fixedKeys.Contains(k)) continue; // 刚刚已经输出过了
108+
result.AppendLine($"&{k}={v}");
109+
}
110+
result.AppendLine("&ChartConvertTool=MuConvert");
111+
result.AppendLine($"&ChartConvertToolVersion={Utils.AppVersion}");
112+
result.AppendLine();
113+
114+
var levelIds = levels.Keys.ToList();
115+
levelIds.Sort();
116+
foreach (var id in levelIds)
117+
{
118+
var data = levels[id];
119+
if (data.Level != null) result.AppendLine($"&lv_{id}={data.Level}");
120+
if (data.NoteDesigner != null) result.AppendLine($"&des_{id}={data.NoteDesigner}");
121+
result.AppendLine($"&inote_{id}={data.Inote}");
122+
result.AppendLine();
123+
}
124+
125+
return result.ToString();
126+
}
84127
}

utils/Utils.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
namespace MuConvert.utils;
1+
using System.Diagnostics;
2+
using System.Reflection;
3+
4+
namespace MuConvert.utils;
25

36
public class Utils
47
{
@@ -11,4 +14,6 @@ public static Exception Fail(string msg = "")
1114
{
1215
return new Exception(string.Format(Locale.AssertionFailed, msg));
1316
}
17+
18+
public static string AppVersion => FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).ProductVersion?[..^33] ?? "unknown";
1419
}

0 commit comments

Comments
 (0)