Skip to content

Commit

Permalink
Merge pull request #53 from tillvit/development
Browse files Browse the repository at this point in the history
Better timing data handling
  • Loading branch information
tillvit committed Sep 25, 2023
2 parents 53fdca1 + 29feae9 commit bbd055d
Showing 1 changed file with 37 additions and 8 deletions.
45 changes: 37 additions & 8 deletions src/chart/sm/TimingData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,11 @@ export class TimingData {
.split("\n")
.map(line => line.trim())
.filter(line => line !== "")
if (
entries.length > 1 &&
!entries.slice(0, -1).some(line => !line.endsWith(","))
) {
// All lines ends with comma, split by comma
entries = entries.map(line => line.slice(0, -1))
}
entries = entries.map(line => {
if (line.endsWith(",")) line = line.slice(0, -1)
if (line.startsWith(",")) line = line.slice(1)
return line
})
console.log(entries, data)
this.events[type] ||= []

if (type == "ATTACKS") entries = [data.replaceAll(/[\n\r\t]/g, "")]
Expand Down Expand Up @@ -111,13 +104,21 @@ export class TimingData {
beat: parseFloat(temp[0]),
value: parseFloat(temp[1]),
}
if (isNaN(parseFloat(temp[0])) || isNaN(parseFloat(temp[1]))) {
console.warn(`Couldn't load ${type} event ` + str)
continue
}
break
case "LABELS":
event = {
type: type,
beat: parseFloat(temp[0]),
value: temp[1],
}
if (isNaN(parseFloat(temp[0]))) {
console.warn(`Couldn't load ${type} event ` + str)
continue
}
break
case "SPEEDS":
event = {
Expand All @@ -127,6 +128,14 @@ export class TimingData {
delay: parseFloat(temp[2]),
unit: temp[3] == "0" ? "B" : "T",
}
if (
isNaN(parseFloat(temp[0])) ||
isNaN(parseFloat(temp[1])) ||
isNaN(parseFloat(temp[2]))
) {
console.warn(`Couldn't load ${type} event ` + str)
continue
}
break
case "TIMESIGNATURES":
event = {
Expand All @@ -135,6 +144,14 @@ export class TimingData {
upper: parseInt(temp[1]),
lower: parseInt(temp[2]),
}
if (
isNaN(parseFloat(temp[0])) ||
isNaN(parseInt(temp[1])) ||
isNaN(parseInt(temp[2]))
) {
console.warn(`Couldn't load ${type} event ` + str)
continue
}
break
case "COMBOS":
event = {
Expand All @@ -143,6 +160,14 @@ export class TimingData {
hitMult: parseInt(temp[1]),
missMult: parseInt(temp[2] ?? temp[1]),
}
if (
isNaN(parseFloat(temp[0])) ||
isNaN(parseInt(temp[1])) ||
isNaN(parseInt(temp[2] ?? temp[1]))
) {
console.warn(`Couldn't load ${type} event ` + str)
continue
}
break
case "BGCHANGES":
case "FGCHANGES":
Expand All @@ -160,6 +185,10 @@ export class TimingData {
color1: temp[9] ?? "",
color2: temp[10] ?? "",
}
if (isNaN(parseFloat(temp[0])) || isNaN(parseFloat(temp[2]))) {
console.warn(`Couldn't load ${type} event ` + str)
continue
}
}
this._insert(type, event!, false)
}
Expand Down

0 comments on commit bbd055d

Please sign in to comment.