move source files

This commit is contained in:
Alex
2025-08-19 17:03:56 -07:00
parent feaa20aac5
commit 66c834e8be
21 changed files with 5 additions and 6 deletions
+119
View File
@@ -0,0 +1,119 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Data.Common;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Text.Json;
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;
namespace MercuryConverter.Data;
public static class Database
{
public static ObservableCollection<Song> Songs = new();
public static void SetupNew(string dataPath)
{
Dispatcher.UIThread.Invoke(() => Songs.Clear());
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)
{
if (data["AssetDirectory"].ToString()!.Contains("S99"))
{
continue;
}
var previewBegin = ((FloatPropertyData)data["PreviewBeginTime"]).Value;
var previewLen = ((FloatPropertyData)data["PreviewSeconds"]).Value;
string? cTxt = data["CopyrightMessage"].ToString();
var jacketPath = $"{Path.Combine(dataPath, "jackets", data["JacketAssetName"].ToString()!)}.png";
try
{
var song = new Song
{
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,
PreviewTime = previewBegin,
PreviewLen = previewLen,
Jacket = File.Exists(jacketPath) ? jacketPath : null,
Copyright = (cTxt == "-" || cTxt == "") ? null : cTxt,
};
foreach (Difficulty diff in Enum.GetValues(typeof(Difficulty)))
{
// skip non-canon difficulties
if (diff == Difficulty.None || diff == Difficulty.WorldsEnd) continue;
var lvl = ((FloatPropertyData)data[Consts.DIFF_LVL_KEY[diff]]).Value;
if (lvl == 0) continue; // skip nonexistent level
// check chart existence
var chartFilePath = Path.Combine(dataPath, "MusicData", song.Id, $"{song.Id}_{Consts.DIFF_FILENAME_PREPEND[diff]}.mer");
if (!File.Exists(chartFilePath))
{
// TODO: add warning message to DataScan
Console.WriteLine($"[MISSING CHART] {song.Id} {song.Artist} - {song.Name} / {diff}");
continue;
}
// TODO: check audio existence; add warning but don't skip
song.Levels[(int)diff] = lvl;
}
Dispatcher.UIThread.Post(() => Songs.Add(song));
}
catch (Exception e)
{
Console.WriteLine($"Couldn't construct a song!\n{e}");
}
}
Console.WriteLine("finished music table");
}
private static (Entry, Chart)? GetDiffPair(string dataPath, StructPropertyData song, Difficulty diff)
{
var level = ((FloatPropertyData)song[Consts.DIFF_LVL_KEY[diff]]).Value;
if (level == 0)
return null;
var id = song["AssetDirectory"].ToString()!;
var chartFilePath = Path.Combine(dataPath, "MusicData", id, $"{id}_{Consts.DIFF_FILENAME_PREPEND[diff]}.mer");
var clearThreshold = ((FloatPropertyData)song[Consts.DIFF_CLEAR_KEY[diff]]).Value;
var e = NotationSerializer.ToEntry(chartFilePath, new NotationReadArgs
{
InferClearThresholdFromDifficulty = false
});
e.ClearThreshold = clearThreshold;
e.Difficulty = diff;
var c = NotationSerializer.ToChart(chartFilePath, new NotationReadArgs
{
InferClearThresholdFromDifficulty = false
});
return (e, c);
}
}
+61
View File
@@ -0,0 +1,61 @@
using System;
using System.Collections.Generic;
using System.Linq;
using SaturnData.Notation.Core;
namespace MercuryConverter.Data;
public static class Consts
{
private static Dictionary<int, string> _CATEGORY_INDEX = new()
{
{ -1, "Unknown"},
{ 0, "Anime/Pop"},
{ 1, "Vocaloid"},
{ 2, "Touhou Project"},
{ 3, "2.5D" },
{ 4, "Variety" },
{ 5, "Original" },
{ 6, "HARDCORE TANO*C" },
{ 7, "VTuber" },
};
public static readonly IReadOnlyDictionary<int, string> CATEGORY_INDEX = _CATEGORY_INDEX;
private static Dictionary<uint, string> _NUM_SOURCE = new()
{
{ 1, string.Concat(new int[] {87, 65, 67, 67, 65}.Select(i => Convert.ToChar(i))) },
{ 2, string.Concat(new int[] {87, 65, 67, 67, 65, 32, 83}.Select(i => Convert.ToChar(i))) },
{ 3, string.Concat(new int[] {87, 65, 67, 67, 65, 32, 76, 73, 76, 89}.Select(i => Convert.ToChar(i))) },
{ 4, string.Concat(new int[] {87, 65, 67, 67, 65, 32, 76, 73, 76, 89, 32, 82}.Select(i => Convert.ToChar(i))) },
{ 5, string.Concat(new int[] {87, 65, 67, 67, 65, 32, 82, 101, 118, 101, 114, 115, 101}.Select(i => Convert.ToChar(i))) }
};
public static readonly IReadOnlyDictionary<uint, string> NUM_SOURCE = _NUM_SOURCE;
public static readonly IReadOnlyDictionary<string, uint> SOURCE_NUM = _NUM_SOURCE.ToDictionary(p => p.Value, p => p.Key);
private static readonly Dictionary<Difficulty, string> _DIFF_LVL_KEY = new()
{
{Difficulty.Normal, "DifficultyNormalLv"},
{Difficulty.Hard, "DifficultyHardLv"},
{Difficulty.Expert, "DifficultyExtremeLv"},
{Difficulty.Inferno, "DifficultyInfernoLv"},
};
public static readonly IReadOnlyDictionary<Difficulty, string> DIFF_LVL_KEY = _DIFF_LVL_KEY;
private static readonly Dictionary<Difficulty, string> _DIFF_FILENAME_PREPEND = new()
{
{Difficulty.Normal, "00"},
{Difficulty.Hard, "01"},
{Difficulty.Expert, "02"},
{Difficulty.Inferno, "03"},
};
public static readonly IReadOnlyDictionary<Difficulty, string> DIFF_FILENAME_PREPEND = _DIFF_FILENAME_PREPEND;
private static readonly Dictionary<Difficulty, string> _DIFF_CLEAR_KEY = new()
{
{Difficulty.Normal, "ClearNormaRateNormal"},
{Difficulty.Hard, "ClearNormaRateHard"},
{Difficulty.Expert, "ClearNormaRateExtreme"},
{Difficulty.Inferno, "ClearNormaRateInferno"},
};
public static readonly IReadOnlyDictionary<Difficulty, string> DIFF_CLEAR_KEY = _DIFF_CLEAR_KEY;
}
+30
View File
@@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;
using Avalonia.Controls;
using Avalonia.Media;
using SaturnData.Notation.Core;
namespace MercuryConverter.Data;
/// <summary>
/// Combining SaturnData's Entry & Chart.
/// </summary>
public class Song
{
public required string Id { get; set; } // Snn-nnn
public required string Name { get; set; }
public required string Artist { get; set; }
public required uint Source { get; set; }
public required string Rubi { get; set; }
public string? Copyright { get; set; } // May have never been used?
public required int Genre { get; set; }
public required string? Jacket { get; set; }
public required float PreviewTime { get; set; }
public required float PreviewLen { get; set; }
public string SourceName => Consts.NUM_SOURCE[Source];
public float?[] Levels { get; set; } = { null, null, null, null };
// TODO: For SaturnData.Entry instances, use this Guid format:
// MERCURY_[SONGID]_[DIFF] (each var is int)
}