Skip to content

Commit

Permalink
Fixed sm column output and madloy difficulty parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
prefixaut committed Mar 27, 2022
1 parent d79b579 commit 75a12a5
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/rconv/cli.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
24 changes: 19 additions & 5 deletions src/rconv/mapper.nim
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import std/[algorithm, math, sets, strutils, strformat, tables]

import pkg/regex

import ./common
import ./private/utils

Expand All @@ -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.
Expand Down Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions src/rconv/step_mania.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 75a12a5

Please sign in to comment.