Skip to content

Commit 55c370a

Browse files
committed
feat: 转换为 ma2_103 格式
1 parent 928ca27 commit 55c370a

File tree

5 files changed

+59
-8
lines changed

5 files changed

+59
-8
lines changed

AquaDX

MaiChartManager/Controllers/Music/MusicTransferController.cs

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace MaiChartManager.Controllers.Music;
1515
[Route("MaiChartManagerServlet/[action]Api/{assetDir}/{id:int}")]
1616
public class MusicTransferController(StaticSettings settings, ILogger<MusicTransferController> logger) : ControllerBase
1717
{
18-
public record RequestCopyToRequest(MusicBatchController.MusicIdAndAssetDirPair[] music, bool removeEvents);
18+
public record RequestCopyToRequest(MusicBatchController.MusicIdAndAssetDirPair[] music, bool removeEvents, bool legacyFormat);
1919

2020
[HttpPost]
2121
[Route("/MaiChartManagerServlet/[action]Api")]
@@ -71,6 +71,16 @@ public void RequestCopyTo(RequestCopyToRequest request)
7171
xmlDoc.Save(Path.Combine(dest, $@"music\music{music.Id:000000}\Music.xml"));
7272
}
7373

74+
if (request.legacyFormat)
75+
{
76+
foreach (var file in Directory.EnumerateFiles(Path.Combine(dest, $@"music\music{music.Id:000000}"), "*.ma2", new EnumerationOptions() { MatchCasing = MatchCasing.CaseInsensitive }))
77+
{
78+
var ma2 = System.IO.File.ReadAllLines(file);
79+
var ma2_103 = new Ma2Parser().ChartOfToken(ma2).Compose(ChartEnum.ChartVersion.Ma2_103);
80+
System.IO.File.WriteAllText(file, ma2_103);
81+
}
82+
}
83+
7484
// copy jacket
7585
Directory.CreateDirectory(Path.Combine(dest, @"AssetBundleImages\jacket"));
7686
if (music.JacketPath is not null)
@@ -114,7 +124,7 @@ public void RequestCopyTo(RequestCopyToRequest request)
114124
}
115125

116126
[HttpGet]
117-
public void ExportOpt(int id, string assetDir, bool removeEvents = false)
127+
public void ExportOpt(int id, string assetDir, bool removeEvents = false, bool legacyFormat = false)
118128
{
119129
var music = settings.GetMusic(id, assetDir);
120130
if (music is null) return;
@@ -135,7 +145,20 @@ public void ExportOpt(int id, string assetDir, bool removeEvents = false)
135145
continue;
136146
}
137147

138-
zipArchive.CreateEntryFromFile(file, $"music/music{music.Id:000000}/{Path.GetFileName(file)}");
148+
if (legacyFormat)
149+
{
150+
var ma2 = System.IO.File.ReadAllLines(file);
151+
var ma2_103 = new Ma2Parser().ChartOfToken(ma2).Compose(ChartEnum.ChartVersion.Ma2_103);
152+
var entry = zipArchive.CreateEntry($"music/music{music.Id:000000}/{Path.GetFileName(file)}");
153+
using var stream = entry.Open();
154+
using var writer = new StreamWriter(stream);
155+
writer.Write(ma2_103);
156+
writer.Close();
157+
}
158+
else
159+
{
160+
zipArchive.CreateEntryFromFile(file, $"music/music{music.Id:000000}/{Path.GetFileName(file)}");
161+
}
139162
}
140163

141164
// copy jacket

MaiChartManager/Front/src/client/apiGen.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ export interface ConfigDto {
7272
}
7373

7474
export interface ConfigSaveDto {
75-
sectionStates?: Record<string, ISectionState>;
76-
entryStates?: Record<string, IEntryState>;
75+
sectionStates?: Record<string, SectionSaveDto>;
76+
entryStates?: Record<string, EntrySaveDto>;
7777
}
7878

7979
export interface DeleteAssetRequest {
@@ -89,6 +89,12 @@ export interface Entry {
8989
fieldType?: string | null;
9090
}
9191

92+
export interface EntrySaveDto {
93+
isDefault?: boolean;
94+
defaultValue?: any;
95+
value?: any;
96+
}
97+
9298
export interface GameModInfo {
9399
melonLoaderInstalled?: boolean;
94100
aquaMaiInstalled?: boolean;
@@ -254,6 +260,7 @@ export interface PutAssetDirTxtValueRequest {
254260
export interface RequestCopyToRequest {
255261
music?: MusicIdAndAssetDirPair[] | null;
256262
removeEvents?: boolean;
263+
legacyFormat?: boolean;
257264
}
258265

259266
export interface RequestPurchaseResult {
@@ -267,6 +274,12 @@ export interface Section {
267274
attribute?: IConfigSectionAttribute;
268275
}
269276

277+
export interface SectionSaveDto {
278+
isDefault?: boolean;
279+
defaultEnabled?: boolean;
280+
enabled?: boolean;
281+
}
282+
270283
export interface SetAudioPreviewRequest {
271284
/** @format double */
272285
startTime?: number;
@@ -1651,6 +1664,8 @@ export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDa
16511664
query?: {
16521665
/** @default false */
16531666
removeEvents?: boolean;
1667+
/** @default false */
1668+
legacyFormat?: boolean;
16541669
},
16551670
params: RequestParams = {},
16561671
) =>

MaiChartManager/Front/src/components/MusicList/BatchActionButton/ChooseAction.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export enum OPTIONS {
1414
CreateNewOptCompatible,
1515
ConvertToMaidata,
1616
ConvertToMaidataIgnoreVideo,
17+
CreateNewOptMa2_103,
1718
}
1819

1920
export default defineComponent({
@@ -41,7 +42,13 @@ export default defineComponent({
4142
case OPTIONS.CreateNewOptCompatible:
4243
if (location.hostname === '127.0.0.1') {
4344
props.continue(STEP.None);
44-
await api.RequestCopyTo({music: props.selectedMusic, removeEvents: selectedOption.value === OPTIONS.CreateNewOptCompatible});
45+
await api.RequestCopyTo({music: props.selectedMusic, removeEvents: selectedOption.value === OPTIONS.CreateNewOptCompatible, legacyFormat: false});
46+
break;
47+
}
48+
case OPTIONS.CreateNewOptMa2_103:
49+
if (location.hostname === '127.0.0.1') {
50+
props.continue(STEP.None);
51+
await api.RequestCopyTo({music: props.selectedMusic, removeEvents: true, legacyFormat: true});
4552
break;
4653
}
4754
case OPTIONS.ConvertToMaidata:
@@ -89,7 +96,10 @@ export default defineComponent({
8996
导出为 Opt(原始)
9097
</NRadio>
9198
<NRadio value={OPTIONS.CreateNewOptCompatible}>
92-
导出为 Opt(兼容任意版本游戏,移除 Event 等)
99+
导出为 Opt(保持谱面格式,移除 Event 等)
100+
</NRadio>
101+
<NRadio value={OPTIONS.CreateNewOptMa2_103}>
102+
导出为 Opt(Ma2 103 格式,移除 Event 等)
93103
</NRadio>
94104
<NRadio value={OPTIONS.ConvertToMaidata}>
95105
转换为 Maidata

MaiChartManager/Front/src/components/MusicList/BatchActionButton/remoteExport.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ export default async (setStep: (step: STEP) => void, musicList: MusicXmlWithABJa
3939
case OPTIONS.CreateNewOptCompatible:
4040
url = `ExportOptApi/${music.assetDir}/${music.id}?removeEvents=true`;
4141
break;
42+
case OPTIONS.CreateNewOptMa2_103:
43+
url = `ExportOptApi/${music.assetDir}/${music.id}?removeEvents=true&legacyFormat=true`;
44+
break;
4245
case OPTIONS.ConvertToMaidata:
4346
url = `ExportAsMaidataApi/${music.assetDir}/${music.id}`;
4447
break;

0 commit comments

Comments
 (0)