From 75a12a59f7dd6c3f7d045ca61dff1c700e199b6c Mon Sep 17 00:00:00 2001 From: PreFiXAUT Date: Sun, 27 Mar 2022 14:30:40 +0200 Subject: [PATCH] Fixed sm column output and madloy difficulty parsing --- src/rconv/cli.nim | 2 +- src/rconv/mapper.nim | 24 +++++++++++++++++++----- src/rconv/step_mania.nim | 3 +-- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/src/rconv/cli.nim b/src/rconv/cli.nim index 3fc425d..9ac22c6 100644 --- a/src/rconv/cli.nim +++ b/src/rconv/cli.nim @@ -102,7 +102,7 @@ try: for filePath in walkGlob(path): try: discard convert(filePath, none(FileType), to, some(convOptions)) - except malody.InvalidModeException: + except malody.InvalidModeException, InvalidTypeException, MissingTypeException, MissingConversionException: discard except: let e = newException(ConvertException, fmt"Failed to convert file '{filePath}'! Error: {getCurrentExceptionMsg()}", getCurrentException()) diff --git a/src/rconv/mapper.nim b/src/rconv/mapper.nim index b115e0c..382cd71 100644 --- a/src/rconv/mapper.nim +++ b/src/rconv/mapper.nim @@ -1,5 +1,7 @@ import std/[algorithm, math, sets, strutils, strformat, tables] +import pkg/regex + import ./common import ./private/utils @@ -16,6 +18,9 @@ type ## Tuple to join a memson-hold and malody-hold, to be able to set the ## `endBeat` field on the malody hold on time. +const + LevelRegex = re"(?:(?:[lL][vV])|(?:[lL][vV][lL])|(?:[lL][eE][vV][eE][lL]))?\s*\.*\s*([0-9]+[\.]?[0-9])" + proc getBeat(value: float): malody.Beat = ## Helper function to convert a fraction beat-index (1.5, 2.3, ...) to a ## indicative beat & snap position. @@ -416,27 +421,36 @@ func toStepMania*(chart: malody.Chart): sm.ChartFile = ) var output: sm.NoteData = nil var diff = sm.Difficulty.Edit + var level = 0 for part in chart.meta.version.stripSplit(" "): try: diff = parseEnum[sm.Difficulty](part.toLower) except: discard + try: + var match: RegexMatch + if part.match(LevelRegex, match): + level = int(parseFloat(match.groupFirstCapture(0, part))) + except: + discard case chart.meta.mode_ext.column: of 4: - output = sm.newNoteData(sm.ChartType.DanceSingle, chart.meta.creator, diff) + output = sm.newNoteData(sm.ChartType.DanceSingle, chart.meta.creator, diff, level) of 5: - output = sm.newNoteData(sm.ChartType.PumpSingle, chart.meta.creator, diff) + output = sm.newNoteData(sm.ChartType.PumpSingle, chart.meta.creator, diff, level) of 6: - output = sm.newNoteData(sm.ChartType.DanceSolo, chart.meta.creator, diff) + output = sm.newNoteData(sm.ChartType.DanceSolo, chart.meta.creator, diff, level) of 8: - output = sm.newNoteData(sm.ChartType.DanceDouble, chart.meta.creator, diff) + output = sm.newNoteData(sm.ChartType.DanceDouble, chart.meta.creator, diff, level) of 10: - output = sm.newNoteData(sm.ChartType.PumpDouble, chart.meta.creator, diff) + output = sm.newNoteData(sm.ChartType.PumpDouble, chart.meta.creator, diff, level) else: raise newException(ConvertException, fmt"The column-count {chart.meta.mode_ext.column} does not have a SM equivalent!") + result.noteData.add output + if not chart.meta.song.title.isEmptyOrWhitespace: if not chart.meta.song.titleorg.isEmptyOrWhitespace: result.title = chart.meta.song.titleorg diff --git a/src/rconv/step_mania.nim b/src/rconv/step_mania.nim index 6c34bf4..1fbaf10 100644 --- a/src/rconv/step_mania.nim +++ b/src/rconv/step_mania.nim @@ -160,7 +160,6 @@ type const SpecialNoteStart = 'D' - EmptyBeat = "0000\n0000\n0000\n0000\n" func newNoteError(msg: string, beat: int, note: Note): ref InvalidNoteError = result = newException(InvalidNoteError, msg) @@ -623,7 +622,7 @@ func write(notes: NoteData, withNoteExtras: bool = false): string = let bIndex = notes.beats.find(b => b.index == beatIndex, lastBeat) if bIndex == -1: # Empty 4th section - arr.add EmptyBeat + arr.add ($NoteType.Empty.repeat(columns).join("") & "\n").repeat(4).join("") continue lastBeat = bIndex