2025-08-13 20:13:40 -07:00
|
|
|
using System;
|
2025-08-18 00:32:10 -07:00
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Collections.ObjectModel;
|
2025-08-19 00:27:53 -07:00
|
|
|
using System.Data.Common;
|
2025-08-13 20:13:40 -07:00
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
2025-08-18 00:32:10 -07:00
|
|
|
using System.Linq.Expressions;
|
2025-08-13 20:13:40 -07:00
|
|
|
using System.Text.Json;
|
2025-08-18 00:32:10 -07:00
|
|
|
using Avalonia.Threading;
|
|
|
|
|
using MercuryConverter.UI.Views;
|
|
|
|
|
using SaturnData.Notation.Core;
|
|
|
|
|
using SaturnData.Notation.Serialization;
|
|
|
|
|
using SaturnData.Notation.Serialization.Mer;
|
|
|
|
|
using UAssetAPI;
|
|
|
|
|
using UAssetAPI.ExportTypes;
|
|
|
|
|
using UAssetAPI.PropertyTypes.Objects;
|
|
|
|
|
using UAssetAPI.PropertyTypes.Structs;
|
|
|
|
|
using UAssetAPI.UnrealTypes;
|
2025-08-13 20:13:40 -07:00
|
|
|
|
|
|
|
|
namespace MercuryConverter.Data;
|
|
|
|
|
|
|
|
|
|
public static class Database
|
|
|
|
|
{
|
2025-08-18 00:32:10 -07:00
|
|
|
public static ObservableCollection<Song> Songs = new();
|
|
|
|
|
|
|
|
|
|
public static void SetupNew(string dataPath)
|
2025-08-13 20:13:40 -07:00
|
|
|
{
|
2025-08-18 00:32:10 -07:00
|
|
|
Dispatcher.UIThread.Invoke(() => Songs.Clear());
|
2025-08-13 20:13:40 -07:00
|
|
|
|
2025-08-18 00:32:10 -07:00
|
|
|
var metadataTablePath = Path.Combine(dataPath, "MusicParameterTable.uasset");
|
|
|
|
|
var metadataAsset = new UAsset(metadataTablePath, EngineVersion.VER_UE4_19);
|
|
|
|
|
var metadataTable = metadataAsset.Exports[0] as DataTableExport;
|
|
|
|
|
|
|
|
|
|
foreach (var data in metadataTable!.Table.Data)
|
2025-08-13 20:13:40 -07:00
|
|
|
{
|
2025-08-18 00:32:10 -07:00
|
|
|
if (data["AssetDirectory"].ToString()!.Contains("S99"))
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2025-08-13 20:13:40 -07:00
|
|
|
|
2025-08-18 00:32:10 -07:00
|
|
|
var previewBegin = ((FloatPropertyData)data["PreviewBeginTime"]).Value;
|
|
|
|
|
var previewLen = ((FloatPropertyData)data["PreviewSeconds"]).Value;
|
2025-08-13 20:13:40 -07:00
|
|
|
|
2025-08-18 00:32:10 -07:00
|
|
|
string? cTxt = data["CopyrightMessage"].ToString();
|
|
|
|
|
|
|
|
|
|
var jacketPath = $"{Path.Combine(dataPath, "jackets", data["JacketAssetName"].ToString()!)}.png";
|
|
|
|
|
|
|
|
|
|
try
|
2025-08-13 20:13:40 -07:00
|
|
|
{
|
2025-08-18 00:32:10 -07:00
|
|
|
var song = new Song
|
2025-08-13 20:13:40 -07:00
|
|
|
{
|
2025-08-18 00:32:10 -07:00
|
|
|
Id = data["AssetDirectory"].ToString()!,
|
|
|
|
|
Rubi = data["Rubi"].ToString()!,
|
|
|
|
|
Name = data["MusicMessage"].ToString()!,
|
|
|
|
|
Artist = data["ArtistMessage"].ToString()!,
|
|
|
|
|
Genre = ((IntPropertyData)data["ScoreGenre"]).Value,
|
|
|
|
|
Source = ((UInt32PropertyData)data["VersionNo"]).Value,
|
2025-08-20 15:59:03 -07:00
|
|
|
BpmMessage = data["Bpm"].ToString()!,
|
2025-08-18 00:32:10 -07:00
|
|
|
PreviewTime = previewBegin,
|
|
|
|
|
PreviewLen = previewLen,
|
|
|
|
|
Jacket = File.Exists(jacketPath) ? jacketPath : null,
|
|
|
|
|
Copyright = (cTxt == "-" || cTxt == "") ? null : cTxt,
|
2025-08-20 15:59:03 -07:00
|
|
|
assetData = data,
|
2025-08-18 00:32:10 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
foreach (Difficulty diff in Enum.GetValues(typeof(Difficulty)))
|
|
|
|
|
{
|
|
|
|
|
// skip non-canon difficulties
|
|
|
|
|
if (diff == Difficulty.None || diff == Difficulty.WorldsEnd) continue;
|
|
|
|
|
|
2025-08-19 00:27:53 -07:00
|
|
|
var lvl = ((FloatPropertyData)data[Consts.DIFF_LVL_KEY[diff]]).Value;
|
|
|
|
|
if (lvl == 0) continue; // skip nonexistent level
|
|
|
|
|
|
|
|
|
|
// check chart existence
|
2025-08-20 15:59:03 -07:00
|
|
|
var chartFilePath = Path.Combine(dataPath, "MusicData", song.Id, $"{song.Id}_{Consts.DIFF_FILENAME_APPEND[diff]}.mer");
|
2025-08-19 00:27:53 -07:00
|
|
|
if (!File.Exists(chartFilePath))
|
2025-08-18 00:32:10 -07:00
|
|
|
{
|
2025-08-19 00:27:53 -07:00
|
|
|
// TODO: add warning message to DataScan
|
|
|
|
|
Console.WriteLine($"[MISSING CHART] {song.Id} {song.Artist} - {song.Name} / {diff}");
|
|
|
|
|
continue;
|
2025-08-18 00:32:10 -07:00
|
|
|
}
|
2025-08-19 00:27:53 -07:00
|
|
|
|
2025-08-20 15:59:03 -07:00
|
|
|
// TODO: check audio existence; add warning but don't skip if missing
|
2025-08-19 19:30:37 -07:00
|
|
|
song.Levels[(int)diff] = (lvl, data[Consts.DIFF_DESIGNER_KEY[diff]].ToString()!);
|
2025-08-13 20:13:40 -07:00
|
|
|
}
|
|
|
|
|
|
2025-08-19 00:27:53 -07:00
|
|
|
Dispatcher.UIThread.Post(() => Songs.Add(song));
|
2025-08-18 00:32:10 -07:00
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine($"Couldn't construct a song!\n{e}");
|
|
|
|
|
}
|
2025-08-13 20:13:40 -07:00
|
|
|
}
|
2025-08-18 00:32:10 -07:00
|
|
|
Console.WriteLine("finished music table");
|
|
|
|
|
}
|
2025-08-13 20:13:40 -07:00
|
|
|
}
|