Skip to content

Commit

Permalink
Fixed separator, removed compile utage database, version update
Browse files Browse the repository at this point in the history
  • Loading branch information
Neskol committed Jan 18, 2024
1 parent b55065a commit 74513d4
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 478 deletions.
31 changes: 2 additions & 29 deletions Commands/CompileMa2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,40 +115,13 @@ 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(""))
{
string targetMaidataLocation = $"{Destination}/result.ma2";
StreamWriter sw = new StreamWriter(targetMaidataLocation, false);
{
sw.WriteLine(result);
}
sw.Close();
if (File.Exists(targetMaidataLocation))
{
Console.WriteLine("Successfully compiled at: {0}", targetMaidataLocation);
}
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(""))
Expand Down
60 changes: 46 additions & 14 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,65 +93,85 @@ 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";
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";
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
{
throw new FileNotFoundException("THE FILE IS NOT SUCCESSFULLY COMPILED.");
}
}
else Console.WriteLine(result);

break;
}

Expand All @@ -154,5 +187,4 @@ public override int Run(string[] remainingArguments)
}
}
}

}
}
Loading

0 comments on commit 74513d4

Please sign in to comment.