Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
dustdustinthewind committed Mar 2, 2020
2 parents fe4e338 + ad7a795 commit dc442fe
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 87 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Fixed
- The handling of Intralism maps with config v3, encrypted data, and/or Unlock Conditions.
- A game crash when converting invalid maps.

## [1.4.0-alpha] - 2020-02-24

### Added
Expand Down
11 changes: 7 additions & 4 deletions Pulsarc/Beatmaps/BeatmapHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -224,14 +224,18 @@ static public void Save(Beatmap beatmap, string file_path)
file.WriteLine("Events:");

foreach (Event evt in beatmap.Events)
{
file.WriteLine(evt.ToString());
}

// Write Timing Points
file.WriteLine("");
file.WriteLine("TimingPoints:");

foreach (TimingPoint timingPoint in beatmap.TimingPoints)
{
file.WriteLine(timingPoint.ToString());
}

// Write Speed Variations
file.WriteLine("");
Expand All @@ -242,7 +246,9 @@ static public void Save(Beatmap beatmap, string file_path)
file.WriteLine("Arcs:");

foreach (Arc arc in beatmap.Arcs)
{
file.WriteLine(arc.ToString());
}
}
}

Expand Down Expand Up @@ -271,10 +277,7 @@ static private void WriteProperty(StreamWriter file, Beatmap beatmap, string pro
/// <param name="arc">The arc to check</param>
/// <param name="column">The column to check in (in binary format)</param>
/// <returns></returns>
static public bool IsColumn(Arc arc, int column)
{
return ((arc.Type >> column) & 1) != 0;
}
static public bool IsColumn(Arc arc, int column) => ((arc.Type >> column) & 1) != 0;

/// <summary>
/// Makes a new Event based on the data found in line
Expand Down
19 changes: 16 additions & 3 deletions Pulsarc/Pulsarc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -259,14 +259,27 @@ private async void ConvertMaps()
{
for (int i = 0; i < directories.Length; i++)
{
converter.Save(directories[i]);
try
{
converter.Save(directories[i]);
}
catch
{
PulsarcLogger.Warning($"Couldn't convert {directories[i]}");
}
}
}

// Otherwise convert one map
else
{
converter.Save(toConvert);
try
{
converter.Save(toConvert);
}
catch
{
PulsarcLogger.Warning($"Couldn't convert {toConvert}");
}
}

((SongSelection)ScreenManager.Screens.Peek()).RescanBeatmaps();
Expand Down
4 changes: 2 additions & 2 deletions Pulsarc/Pulsarc.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
<AssemblyName>Pulsarc</AssemblyName>
<ApplicationIcon>Icon.ico</ApplicationIcon>
<StartupObject></StartupObject>
<AssemblyVersion>1.4.0.0</AssemblyVersion>
<FileVersion>1.4.0.0</FileVersion>
<AssemblyVersion>1.4.1.0</AssemblyVersion>
<FileVersion>1.4.1.0</FileVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
5 changes: 4 additions & 1 deletion Pulsarc/Utils/BeatmapConversion/IntralismBeatmap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class IntralismBeatmap

// ¯\_(ツ)_/¯
// Seemed to be used to "unlock" maps in an earlier version of Intralism
public List<Dictionary<string, string>> UnlockConditions { get; set; }
public List<string> UnlockConditions { get; set; }
// Probably related to above
public bool Hidden { get; set; }

Expand All @@ -56,6 +56,9 @@ class IntralismBeatmap

// A list of all the Events in the map
public List<Event> Events { get; set; }

// The encryted data of a map
public string e { get; set; }
}

/// <summary>
Expand Down
169 changes: 92 additions & 77 deletions Pulsarc/Utils/BeatmapConversion/IntralismToPulsarc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,56 +34,64 @@ public List<Beatmap> Convert(string folder_path)
string backgroundImage = Config.Get["Converting"]["BGImage"];

// See if the provided path exists
if (Directory.Exists(folder_path))
if (!Directory.Exists(folder_path)) { return null; }

string configPath = $"{folder_path}/config.txt";

// See if the a "config.txt" file exists
if (!File.Exists(configPath)) { return null; }

// Convert the config file to an IntrlaismBeatmap
IntralismBeatmap beatmap = JsonConvert.DeserializeObject<IntralismBeatmap>(File.ReadAllText(configPath, Encoding.UTF8));

// If there are no arc events (either from v3 or bad mapping), stop converting.
if (beatmap.Events.Where(x => x.Data[0].Equals("SpawnObj")).Count() <= 0)
{ return null; }

string name = "";

// If the user specified an image path to use, use that path.
if (backgroundImage != null && !backgroundImage.Equals(""))
{
string configPath = $"{folder_path}/config.txt";
name = backgroundImage;
}

// See if the a "config.txt" file exists
if (File.Exists(configPath))
// If there's an average of 1 image per 10 seconds of map time or less
// and the user-defined path doesn't exist, grab the first image path in
// the beatmap.
if (!File.Exists($"{folder_path}/{name}") && beatmap.LevelResources.Count > 0 && beatmap.LevelResources.Count < Math.Ceiling(beatmap.MusicTime / 10))
{
beatmap.LevelResources[0].TryGetValue("path", out name);
}

result.Background = name;

// Fill in the missing metadata
result.FormatVersion = "1";
result.Mapper = "Intralism";
result.Artist = "Unknown";
result.Title = beatmap.Name;
result.Version = "Converted";
result.Audio = beatmap.MusicFile;
result.TimingPoints.Add(new TimingPoint(0, 120));
result.PreviewTime = 0;

// Go through each Intralism Event
foreach (Event evt in beatmap.Events)
{
// If the current event is an Arc, convert it to a Pulsarc Arc.
switch (evt.Data[0])
{
// Convert the config file to an IntrlaismBeatmap
IntralismBeatmap beatmap = JsonConvert.DeserializeObject<IntralismBeatmap>(File.ReadAllText(configPath, Encoding.UTF8));

string name = "";

// If the user specified an image path to use, use that path.
if (backgroundImage != null && !backgroundImage.Equals(""))
name = backgroundImage;

// If there's an average of 1 image per 10 seconds of map time or less
// and the user-defined path doesn't exist, grab the first image path in
// the beatmap.
if (!File.Exists($"{folder_path}/{name}") && beatmap.LevelResources.Count > 0 && beatmap.LevelResources.Count < Math.Ceiling(beatmap.MusicTime / 10))
beatmap.LevelResources[0].TryGetValue("path", out name);

result.Background = name;

// Fill in the missing metadata
result.FormatVersion = "1";
result.Mapper = "Intralism";
result.Artist = "Unknown";
result.Title = beatmap.Name;
result.Version = "Converted";
result.Audio = beatmap.MusicFile;
result.TimingPoints.Add(new TimingPoint(0, 120));
result.PreviewTime = 0;

// Go through each Intralism Event
foreach (Event evt in beatmap.Events)
// If the current event is an Arc, convert it to a Pulsarc Arc.
switch (evt.Data[0])
{
case "SpawnObj":
// Add the converted arc to the Beatmap
result.Arcs.Add(HandleSpawnObj(evt));
break;
case "SetPlayerDistance":
// Add the converted zoom to the Beatmap
result.Events.Add(HandleSetPlayerDistance(evt));
break;
default:
break;
}
case "SpawnObj":
// Add the converted arc to the Beatmap
result.Arcs.Add(HandleSpawnObj(evt));
break;
case "SetPlayerDistance":
// Add the converted zoom to the Beatmap
result.Events.Add(HandleSetPlayerDistance(evt));
break;
default:
break;
}
}

Expand Down Expand Up @@ -151,45 +159,52 @@ public void Save(string folder_path)
{
Beatmap map = Convert(folder_path).First();

if (map.Audio != null)
{
string audioPath = $"{folder_path}/{map.Audio}";

if (File.Exists(audioPath))
{
int id = 0;
// The folder name will look like "0 - Unknown - MapTitle - (Mapper)"
string folderName = string.Join("_", ($"{id} - {map.Artist} - {map.Title} ({map.Mapper})").Split(Path.GetInvalidFileNameChars()));
string dirName = $"Songs/{folderName}";
// If the map is null, or audio is null, stop saving.
if (map == null || map.Audio == null) { return; }

if (!Directory.Exists(dirName))
Directory.CreateDirectory(dirName);
string audioPath = $"{folder_path}/{map.Audio}";

// Copy Audio File
File.Copy(audioPath, $"{dirName}/{map.Audio}", true);
// If the path doesn't exist, stop saving.
if (!File.Exists(audioPath)) { return; }

// Copy Background Image
string backgroundPath = $"{folder_path}/{map.Background}";
int id = 0;
// The folder name will look like "0 - Unknown - MapTitle - (Mapper)"
string folderName = string.Join("_", ($"{id} - {map.Artist} - {map.Title} ({map.Mapper})").Split(Path.GetInvalidFileNameChars()));
string dirName = $"Songs/{folderName}";

if (File.Exists(backgroundPath))
try
{
File.Copy(backgroundPath, $"{dirName}/{map.Background}", true);
}
catch
{
PulsarcLogger.Debug("Converting the background failed! Converting wtihout background.", LogType.Runtime);
}
else
map.Background = "";
if (!Directory.Exists(dirName))
{
Directory.CreateDirectory(dirName);
}

// Copy Audio File
File.Copy(audioPath, $"{dirName}/{map.Audio}", true);

// The file name will look like "Unknown - MapTitle [Converted] (Mapper).psc"
string difficultyFileName = string.Join("_", ($"{map.Artist} - {map.Title} [{map.Version}] ({map.Mapper})").Split(Path.GetInvalidFileNameChars()));
// Copy Background Image
string backgroundPath = $"{folder_path}/{map.Background}";

BeatmapHelper.Save(map, $"{dirName}/{difficultyFileName}.psc");
// Find if the background exists and copy it.
if (File.Exists(backgroundPath))
{
try
{
File.Copy(backgroundPath, $"{dirName}/{map.Background}", true);
}
catch
{
PulsarcLogger.Debug("Converting the background failed! Converting wtihout background.", LogType.Runtime);
}
}
else
{
map.Background = "";
}


// The file name will look like "Unknown - MapTitle [Converted] (Mapper).psc"
string difficultyFileName = string.Join("_", ($"{map.Artist} - {map.Title} [{map.Version}] ({map.Mapper})").Split(Path.GetInvalidFileNameChars()));

BeatmapHelper.Save(map, $"{dirName}/{difficultyFileName}.psc");
}
}
}

0 comments on commit dc442fe

Please sign in to comment.