Skip to content

Commit

Permalink
🐛 Fix slide connector coord bug
Browse files Browse the repository at this point in the history
  • Loading branch information
yhs0602 committed Jun 29, 2020
1 parent 9dd3438 commit 59932d4
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 10 deletions.
55 changes: 46 additions & 9 deletions app/src/main/java/com/kyhsgeekcode/dereinfo/FumenRenderer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ class FumenRenderer(
}
val pkgName = context.packageName
for (note in notes) {
fun calcPos(theNote: Note): Pair<Float, Float> {
fun calcPos(theNote: Note): Triple<Float, Float, Int> {
val totalHeightPos = heightPerSec * theNote.time
val linenumber = (totalHeightPos / maxHeight).toInt()
val realWidthPos = calcNoteX(linenumber, widthPerSubLane, theNote)
val realHeightPos = calcNoteY(totalHeightPos)
return Pair(realWidthPos, realHeightPos)
return Triple(realWidthPos, realHeightPos, linenumber)
}

val realX: Float
Expand All @@ -80,13 +80,50 @@ class FumenRenderer(
if (!note.nextNotes.isNullOrEmpty()) {
val nextNote = note.nextNotes[0]
val nextNoteCoord = calcPos(nextNote)
canvas.drawLine(
realX,
realY,
nextNoteCoord.first,
nextNoteCoord.second,
connectPaint
)
var leftDy = (nextNote.time - note.time) * heightPerSec
if (coord.third < nextNoteCoord.third) {
// stop & cut and continue
val dxdy = (widthPerSubLane * (nextNote.endline - note.endline)).rem(width.toFloat()) / leftDy
var beforeX = realX
val destX = nextNoteCoord.first
var afterX: Float = beforeX + realY * dxdy
canvas.drawLine(
realX,
realY,
afterX,
0.0f,
connectPaint
)
leftDy -= realY
beforeX = afterX + width
while (leftDy >= maxHeight) {
afterX = beforeX + maxHeight * dxdy
canvas.drawLine(
beforeX,
maxHeight.toFloat(),
afterX,
0.0f,
connectPaint
)
leftDy -= maxHeight
beforeX = afterX + width
}
canvas.drawLine(
beforeX, // x dest just before
maxHeight.toFloat(),
nextNoteCoord.first,
nextNoteCoord.second,
connectPaint
)
} else {
canvas.drawLine(
realX,
realY,
nextNoteCoord.first,
nextNoteCoord.second,
connectPaint
)
}
}
}
// if(note.isLong() || note.isSlide()) {
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/kyhsgeekcode/dereinfo/model/Note.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Note(
val startline: Float,
val endline: Float,
val previds: Array<Int>,
val sync : Boolean = false,
val sync: Boolean = false,
val tick: Int = 10
) {
val nextNotes = arrayListOf<Note>()
Expand Down

0 comments on commit 59932d4

Please sign in to comment.