Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Converter rework #16

Merged
merged 11 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 25 additions & 25 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
# This workflow will build a .NET project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net
# # This workflow will build a .NET project
# # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net

name: .NET
# name: .NET

on:
pull_request:
branches: [ "master" ]
workflow_dispatch:
# on:
# pull_request:
# branches: [ "master" ]
# workflow_dispatch:

jobs:
build:
name: Multi-build
runs-on: ubuntu-latest, macos-latest, windows-latest
# jobs:
# build:
# name: Multi-build
# runs-on: ubuntu-latest, macos-latest, windows-latest

steps:
- uses: actions/checkout@v3
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 8.0.x
- name: Restore dependencies
run: dotnet restore
# -name: Update MaiLib
# run: git submodule update --init --remote --recursive
- name: Build
run: dotnet build --no-restore
# - name: Test
# run: dotnet test --no-build --verbosity normal
# steps:
# - uses: actions/checkout@v3
# - name: Setup .NET
# uses: actions/setup-dotnet@v3
# with:
# dotnet-version: 8.0.x
# - name: Restore dependencies
# run: dotnet restore
# # -name: Update MaiLib
# # run: git submodule update --init --remote --recursive
# - name: Build
# run: dotnet build --no-restore
# # - name: Test
# # run: dotnet test --no-build --verbosity normal
2 changes: 1 addition & 1 deletion .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@
"problemMatcher": "$msCompile"
}
]
}
}
121 changes: 55 additions & 66 deletions Commands/CompileDatabase.cs

Large diffs are not rendered by default.

49 changes: 15 additions & 34 deletions Commands/CompileMa2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,18 +90,23 @@ public override int Run(string[] remainingArguments)
{
case null:
case "simai":
case "Simai":
case "SimaiFes":
Simai resultChart = new Simai(candidate);
resultChart.Update();
result = resultChart.Compose();
if (Destination != null && !Destination.Equals(""))
{
StreamWriter sw = new StreamWriter(Destination + Program.GlobalSep + "maidata.txt", false);
string targetMaidataLocation = $"{Destination}/maidata.txt";
if (!Directory.Exists(Destination)) Directory.CreateDirectory(Destination);
StreamWriter sw = new StreamWriter(targetMaidataLocation, false);
{
sw.WriteLine(result);
}
sw.Close();
if (File.Exists(Destination + Program.GlobalSep + "maidata.txt"))
if (File.Exists(targetMaidataLocation))
{
Console.WriteLine("Successfully compiled at: " + Destination + Program.GlobalSep + "result.ma2");
Console.WriteLine("Successfully compiled at: {0}", targetMaidataLocation);
}
else
{
Expand All @@ -111,51 +116,27 @@ public override int Run(string[] remainingArguments)
else Console.WriteLine(result);
break;
case "ma2":
case "MA2":
case "Ma2":
case "MA2":
case "Ma2_103":
if (result.Equals(""))
{
Ma2 defaultChart = new Ma2(candidate);
result = defaultChart.Compose();
}
if (Destination != null && !Destination.Equals(""))
{
StreamWriter sw = new StreamWriter(Destination + Program.GlobalSep + "result.ma2", false);
{
sw.WriteLine(result);
}
sw.Close();
if (File.Exists(Destination + Program.GlobalSep + "result.ma2"))
{
Console.WriteLine("Successfully compiled at: " + Destination + Program.GlobalSep + "result.ma2");
}
else
{
throw new FileNotFoundException("THE FILE IS NOT SUCCESSFULLY COMPILED.");
}
}
else Console.WriteLine(result);
break;
case "Ma2_104":
if (result.Equals(""))
{
Ma2 defaultChart = new Ma2(candidate)
{
ChartVersion = ChartEnum.ChartVersion.Ma2_104
};
Ma2 defaultChart = TargetFormat.Equals("Ma2_104")? new Ma2(candidate){ChartVersion = ChartEnum.ChartVersion.Ma2_104} : new Ma2(candidate);
result = defaultChart.Compose();
}
if (Destination != null && !Destination.Equals(""))
{
StreamWriter sw = new StreamWriter(Destination + Program.GlobalSep + "result.ma2", false);
string targetMaidataLocation = $"{Destination}/result.ma2";
if (!Directory.Exists(Destination)) Directory.CreateDirectory(Destination);
StreamWriter sw = new StreamWriter(targetMaidataLocation, false);
{
sw.WriteLine(result);
}
sw.Close();
if (File.Exists(Destination + Program.GlobalSep + "result.ma2"))
if (File.Exists(targetMaidataLocation))
{
Console.WriteLine("Successfully compiled at: " + Destination + Program.GlobalSep + "result.ma2");
Console.WriteLine("Successfully compiled at: {0}", targetMaidataLocation);
}
else
{
Expand Down
59 changes: 46 additions & 13 deletions Commands/CompileMa2ID.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public class CompileMa2ID : ConsoleCommand
/// Return when command successfully executed
/// </summary>
private const int Success = 0;

/// <summary>
/// Return when command failed to execute
/// </summary>
Expand All @@ -21,27 +22,33 @@ public class CompileMa2ID : ConsoleCommand
/// Source file path
/// </summary>
public string? FileLocation { get; set; }

/// <summary>
/// Difficulty
/// </summary>
public string? Difficulty { get; set; }

/// <summary>
/// ID
/// </summary>
public string? ID { get; set; }

/// <summary>
/// Destination of output
/// </summary>
public string? Destination { get; set; }

/// <summary>
/// Target Format of the file
/// </summary>
public string? TargetFormat { get; set; }

/// <summary>
/// Rotation option for charts
/// </summary>
/// <value>Clockwise90/180, Counterclockwise90/180, UpsideDown, LeftToRight</value>
public string? Rotate { get; set; }

/// <summary>
/// OverallTick Shift for the chart: if the shift tick exceeds the 0 Bar 0 Tick, any note before 0 bar 0 tick will be discarded.
/// </summary>
Expand All @@ -54,14 +61,20 @@ public class CompileMa2ID : ConsoleCommand
public CompileMa2ID()
{
IsCommand("CompileMa2ID", "Compile assigned Ma2 chart to assigned format");
HasLongDescription("This function enables user to compile ma2 chart specified to the format they want. By default is simai for ma2.");
HasRequiredOption("d|difficulty=", "REQUIRED: The number representing the difficulty of chart -- 0-4 for Basic to Re:Master", diff => Difficulty = diff);
HasLongDescription(
"This function enables user to compile ma2 chart specified to the format they want. By default is simai for ma2.");
HasRequiredOption("d|difficulty=",
"REQUIRED: The number representing the difficulty of chart -- 0-4 for Basic to Re:Master",
diff => Difficulty = diff);
HasRequiredOption("i|id=", "REQUIRED: The id of the ma2", id => ID = id);
HasRequiredOption("p|path=", "REQUIRED: Folder of A000 to override - end with a path separator", path => FileLocation = path);
HasRequiredOption("p|path=", "REQUIRED: Folder of A000 to override - end with a path separator",
path => FileLocation = path);
//FileLocation = GlobalPaths[0];
//HasOption("a|a000=", "Folder of A000 to override - end with a path separator", path => FileLocation = path);
HasOption("f|format=", "The target format - simai or ma2", format => TargetFormat = format);
HasOption("r|rotate=", "Rotating method to rotate a chart: Clockwise90/180, Counterclockwise90/180, UpsideDown, LeftToRight", rotate => Rotate = rotate);
HasOption("r|rotate=",
"Rotating method to rotate a chart: Clockwise90/180, Counterclockwise90/180, UpsideDown, LeftToRight",
rotate => Rotate = rotate);
HasOption("s|shift=", "Overall shift to the chart in unit of tick", tick => ShiftTick = int.Parse(tick));
HasOption("o|output=", "Export compiled chart to location specified", dest => Destination = dest);
}
Expand All @@ -80,58 +93,79 @@ public override int Run(string[] remainingArguments)
Ma2Parser parser = new Ma2Parser();
//Chart good = new Ma2(@"/Users/neskol/MaiAnalysis/A000/music/music" + musicID + "/" + musicID + "_0" + difficulty + ".ma2");
string tokenLocation = FileLocation ?? throw new FileNotFoundException();
Chart candidate = parser.ChartOfToken(tokenizer.Tokens(tokenLocation + "music" + Program.GlobalSep + "music" + Program.CompensateZero(ID ?? throw new NullReferenceException("ID shall not be null")) + Program.GlobalSep + Program.CompensateZero(ID ?? throw new NullReferenceException("ID shall not be null")) + "_0" + Difficulty + ".ma2"));
string compensatedId =
Program.CompensateZero(ID ?? throw new NullReferenceException("ID shall not be null"));
Chart candidate = parser.ChartOfToken(tokenizer.Tokens(
$"{tokenLocation}/music/music{compensatedId}/{compensatedId}_0{Difficulty}.ma2"));
if (Rotate != null)
{
bool rotationIsValid = Enum.TryParse(Rotate, out NoteEnum.FlipMethod rotateMethod);
if (!rotationIsValid) throw new Exception("Given rotation method is not valid. Given: " + Rotate);
candidate.RotateNotes(rotateMethod);
}

if (ShiftTick != null && ShiftTick != 0)
{
candidate.ShiftByOffset((int)ShiftTick);
}

string result = "";
switch (TargetFormat)
{
case null:
case "":
case "simai":
case "Simai":
case "SimaiFes":
Simai resultChart = new Simai(candidate);
// resultChart.Update();
result = resultChart.Compose();
if (Destination != null && !Destination.Equals(""))
{
StreamWriter sw = new StreamWriter(Destination + Program.GlobalSep + "maidata.txt", false);
string targetMaidataLocation = $"{Destination}/maidata.txt";
if (!Directory.Exists(Destination)) Directory.CreateDirectory(Destination);
StreamWriter sw = new StreamWriter(targetMaidataLocation, false);
{
sw.WriteLine(result);
}
sw.Close();
if (File.Exists(Destination + Program.GlobalSep + "maidata.txt"))
if (File.Exists(targetMaidataLocation))
{
Console.WriteLine("Successfully compiled at: " + Destination + Program.GlobalSep + "result.ma2");
Console.WriteLine("Successfully compiled at: {0}", targetMaidataLocation);
}
else
{
throw new FileNotFoundException("THE FILE IS NOT SUCCESSFULLY COMPILED.");
}
}
else Console.WriteLine(result);

break;
case "ma2":
case "Ma2":
case "MA2":
case "Ma2_103":
case "Ma2_104":
if (result.Equals(""))
{
Ma2 defaultChart = new Ma2(candidate);
Ma2 defaultChart = TargetFormat.Equals("Ma2_104")
? new Ma2(candidate) { ChartVersion = ChartEnum.ChartVersion.Ma2_104 }
: new Ma2(candidate);
result = defaultChart.Compose();
}

if (Destination != null && !Destination.Equals(""))
{
StreamWriter sw = new StreamWriter(Destination + Program.GlobalSep + "result.ma2", false);
string targetMaidataLocation = $"{Destination}/result.ma2";
if (!Directory.Exists(Destination)) Directory.CreateDirectory(Destination);
StreamWriter sw = new StreamWriter(targetMaidataLocation, false);
{
sw.WriteLine(result);
}
sw.Close();
if (File.Exists(Destination + Program.GlobalSep + "result.ma2"))
if (File.Exists(targetMaidataLocation))
{
Console.WriteLine("Successfully compiled at: " + Destination + Program.GlobalSep + "result.ma2");
Console.WriteLine("Successfully compiled at: {0}", targetMaidataLocation);
}
else
{
Expand All @@ -154,5 +188,4 @@ public override int Run(string[] remainingArguments)
}
}
}

}
Loading