This repository has been archived by the owner on Sep 12, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
370 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
app/src/main/java/com/rndash/mbheadunit/partytime/BeatSaberData.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.rndash.mbheadunit.partytime | ||
|
||
import android.media.MediaPlayer | ||
|
||
class BeatSaberData(val af: MediaPlayer, val levels: ArrayList<BeatSaberLevel>) |
87 changes: 87 additions & 0 deletions
87
app/src/main/java/com/rndash/mbheadunit/partytime/BeatSaberLevel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package com.rndash.mbheadunit.partytime | ||
|
||
import android.graphics.Color | ||
import org.json.JSONObject | ||
|
||
class BeatSaberLevel(name: String, bpm: Int, json: JSONObject) { | ||
companion object { | ||
const val EVENT_OFFSET_MS = 5 | ||
const val EVENT_RESOLUTION_MS = 5 | ||
} | ||
inner class LevelFailException(cause: String) : Exception(cause){} | ||
|
||
lateinit var instructions: Array<MutableList<Instruction>?> | ||
init { | ||
println("Processing $name") | ||
val msPerBeat = (60000.0 / bpm.toFloat()) | ||
val note_json = json.getJSONArray("_notes") | ||
val allevents = ArrayList<Pair<Int, Instruction>>() | ||
for (i in 0 until note_json.length()) { | ||
val note = JSONObject(note_json[i].toString()) | ||
val beatTimeStampMs = note.getDouble("_time") | ||
val ts = (((beatTimeStampMs * msPerBeat).toLong() / EVENT_RESOLUTION_MS).toInt() - EVENT_OFFSET_MS) | ||
val lineIndex = note.getInt("_lineIndex") | ||
val lineLayer = note.getInt("_lineLayer") | ||
val type = note.getInt("_type") | ||
if (type == 0 || type == 1) { | ||
allevents.add( | ||
Pair( | ||
ts, Instruction( | ||
OpCode.DISPLAY_NOTE, 10, lineIndex, lineLayer, | ||
if (type == 0) { | ||
Color.RED | ||
} else { | ||
Color.BLUE | ||
} | ||
) | ||
) | ||
) | ||
} | ||
} | ||
|
||
val event_json = json.getJSONArray("_events") | ||
if (event_json.length() != 0) { | ||
for (i in 0 until event_json.length()) { | ||
val note = JSONObject(event_json[i].toString()) | ||
val beatTimeStampMs = note.getDouble("_time") | ||
val type = note.getInt("_type") | ||
val value = note.getInt("_value") | ||
val ts = (((beatTimeStampMs * msPerBeat).toLong() / EVENT_RESOLUTION_MS).toInt() - EVENT_OFFSET_MS) | ||
var instruction: Instruction? = null | ||
when (type) { | ||
0 -> { // Back center Lazer | ||
var operand = 0L | ||
val colour = when (value) { | ||
1, 2, 3 -> { | ||
operand = 1L | ||
0x220000FF | ||
} // Is it blue? | ||
5, 6, 7 -> { | ||
operand = 2L | ||
0x22FF0000 | ||
} // Is it red? | ||
else -> 0x00000000 // No colour | ||
} | ||
instruction = Instruction(OpCode.BG_COLOUR_CHANGE, operand, 0, 0, colour) | ||
} | ||
else -> {} // Unknown, do nothing | ||
} | ||
instruction?.let { allevents.add(Pair(ts, it)) } | ||
} | ||
} | ||
|
||
if (allevents.size == 0) { | ||
throw LevelFailException("BeatMap has no events") | ||
} | ||
|
||
val elementsNeeded = ((allevents.last().first * msPerBeat).toLong() / EVENT_RESOLUTION_MS) | ||
instructions = Array(elementsNeeded.toInt()){null} | ||
allevents.forEach { e -> | ||
if (instructions[e.first] == null) { | ||
instructions[e.first] = mutableListOf(e.second) | ||
} else { | ||
instructions[e.first]!!.add(e.second) | ||
} | ||
} | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
app/src/main/java/com/rndash/mbheadunit/partytime/BeatSaberNote.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.rndash.mbheadunit.partytime | ||
|
||
import android.graphics.Color | ||
|
||
class BeatSaberNote(val beatTimestamp: Double, val lineIndex: Int, val lineLayer: Int, val cutDir: Int, val type: Int) { | ||
override fun toString(): String { | ||
return "[TS: $beatTimestamp - LOC: (${lineIndex}x${lineLayer}) - DIR: $cutDir - TYPE: $type]" | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
app/src/main/java/com/rndash/mbheadunit/partytime/MachineInstruction.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.rndash.mbheadunit.partytime | ||
|
||
import android.graphics.Color | ||
|
||
class Instruction(val opcode: OpCode, val operand: Long, val locx: Int, val locy: Int, val c: Int) { | ||
override fun toString(): String { | ||
return "Op: $opcode - V: $operand" | ||
} | ||
} | ||
|
||
enum class OpCode { | ||
DISPLAY_NOTE, | ||
BG_COLOUR_CHANGE, | ||
END_OF_SONG | ||
} | ||
|
||
val OpCodes = OpCode.values() |
Oops, something went wrong.