FNFGirlfriendBot/ChomensJS/util/txt_song_parser.js
2024-02-20 17:04:49 +00:00

15 lines
653 B
JavaScript

const { instrumentsArray } = require('minecraft-data')('1.15.2') // chip hardcoding moment
function parseTXTSong (data) {
let length = 0
const notes = String(data).split(/\r\n|\r|\n/).map(line => {
const [tick, pitch, instrument] = line.split(':').map(Number)
if (tick === undefined || pitch === undefined || instrument === undefined) return undefined
const time = tick * 50
length = Math.max(length, time)
return { time, pitch, instrument: instrumentsArray[instrument].name, volume: 1 }
}).filter(note => note !== undefined)
return { name: '', notes, loop: false, loopPosition: 0, length }
}
module.exports = parseTXTSong