Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dtx format support #1

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@

extends: bemuse
parserOptions:
ecmaVersion: 2017
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,6 @@ Icon
/data/
/index.js
/loader/

# JetBrains project config
/.idea
Expand Down
10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,18 @@
"babel-register": "^6.5.2",
"bluebird": "^3.4.6",
"chai": "^3.5.0",
"eslint": "^2.2.0",
"eslint-config-bemuse": "^2.1.0",
"eslint-plugin-standard": "^1.3.2",
"eslint": "^4.14.0",
"eslint-config-bemuse": "^4.0.2",
"eslint-plugin-standard": "^3.0.1",
"eslint-plugin-react": "^7.5.1",
"eslint-plugin-promise": "^3.6.0",
"isparta": "^4.0.0",
"istanbul": "^0.4.2",
"mocha": "^2.4.5",
"nyc": "^5.6.0"
},
"dependencies": {
"bms": "^2.0.0",
"bms": "^2.1.0-beta.1",
"bmson": "^3.0.0",
"lodash": "^4.5.1"
},
Expand Down
22 changes: 18 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import _ from 'lodash'
import invariant from 'invariant'
import BMS from 'bms'

import GameEvent from './data/GameEvent'
import GameNote from './data/GameNote'
Expand Down Expand Up @@ -32,7 +31,9 @@ export class Notechart {

this.expertJudgmentWindow = expertJudgmentWindow

bmsNotes = this._preTransform(bmsNotes, playerOptions)
if (!playerOptions.noShifting) {
bmsNotes = this._preTransform(bmsNotes, playerOptions)
}

this._timing = timing
this._positioning = positioning
Expand All @@ -47,6 +48,7 @@ export class Notechart {
note => [note, this._getNoteInfo(note)]))
this._songInfo = songInfo
this._images = images
this._columns = this._generateColumnsFromBMS(bmsNotes)
}

// An Array of note events.
Expand Down Expand Up @@ -76,7 +78,7 @@ export class Notechart {

// An Array of all column names in this notechart.
get columns () {
return ['SC', '1', '2', '3', '4', '5', '6', '7']
return this._columns
}

// Notechart's duration (time of last event)
Expand Down Expand Up @@ -125,7 +127,7 @@ export class Notechart {
return this._timing.secondsToBeat(seconds)
}

// Conerts the in-song position to in-game position.
// Converts the in-song position to in-game position.
secondsToPosition (seconds) {
return this.beatToPosition(this.secondsToBeat(seconds))
}
Expand Down Expand Up @@ -248,6 +250,18 @@ export class Notechart {
let combos = note.end ? 2 : 1
return { combos }
}

_generateColumnsFromBMS (bmsNotes) {
const usedColumns = {}
const columns = []
for (const note of bmsNotes) {
if (!usedColumns[note.column]) {
columns.push(note.column)
}
usedColumns[note.column] = true
}
return columns
}
}

export default Notechart
Expand Down
4 changes: 3 additions & 1 deletion src/loader/BMSNotechartLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import Notechart from '../'

// Returns a new Notechart from a BMSChart.
export function fromBMSChart (bms, playerOptions) {
let notes = BMS.Notes.fromBMSChart(bms).all()
playerOptions = playerOptions || { }
let options = { mapping: playerOptions.mapping }
let notes = BMS.Notes.fromBMSChart(bms, options).all()
let timing = BMS.Timing.fromBMSChart(bms)
let keysounds = BMS.Keysounds.fromBMSChart(bms)
let songInfo = BMS.SongInfo.fromBMSChart(bms)
Expand Down
7 changes: 5 additions & 2 deletions src/loader/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,18 @@ export class NotechartLoader {
load (arraybuffer, resource, options) {
if (resource.name.match(/\.bmson$/i)) {
return this.loadBmson(arraybuffer, resource, options)
} else if (resource.name.match(/\.dtx$/i)) {
return this.loadBMS(arraybuffer, resource, options, { format: 'dtx' })
} else {
return this.loadBMS(arraybuffer, resource, options)
}
}

async loadBMS (arraybuffer, resource, options) {
async loadBMS (arraybuffer, resource, options, compilerOptions) {
compilerOptions = compilerOptions || { }
let buffer = coerceToBuffer(arraybuffer)
let source = await Promise.promisify(BMS.Reader.readAsync)(buffer)
let compileResult = BMS.Compiler.compile(source)
let compileResult = BMS.Compiler.compile(source, compilerOptions)
let chart = compileResult.chart
let notechart = BMSNotechartLoader.fromBMSChart(chart, options)
return notechart
Expand Down
11 changes: 11 additions & 0 deletions test/loader-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,17 @@ describe('NotechartLoader', function () {
})
})

describe('with DTX file', function () {
it('should be able to read', function () {
let loader = new NotechartLoader()
let buffer = new Buffer(`#TITLE: meow`)

return loader.load(buffer, { name: 'wow.dtx' }, { }).then(notechart => {
expect(notechart.songInfo.title).to.equal('meow')
})
})
})

describe('with bmson file', function () {
it('should be able to read', function () {
let loader = new NotechartLoader()
Expand Down
69 changes: 67 additions & 2 deletions test/notechart-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,22 @@ describe('Notechart', function () {
void expect(subject.notes.filter(byColumn('1'))).to.be.empty
void expect(subject.notes.filter(byColumn('2'))).to.be.empty
})

describe('noShifting', function() {
it('should keep notes intact', function() {
var subject = notechart(src, {
scratch: 'right',
noShifting: true
})
void expect(subject.notes.filter(byColumn('1'))).not.to.be.empty
void expect(subject.notes.filter(byColumn('2'))).not.to.be.empty
void expect(subject.notes.filter(byColumn('3'))).not.to.be.empty
void expect(subject.notes.filter(byColumn('4'))).not.to.be.empty
void expect(subject.notes.filter(byColumn('5'))).not.to.be.empty
void expect(subject.notes.filter(byColumn('6'))).to.be.empty
void expect(subject.notes.filter(byColumn('7'))).to.be.empty
})
})
})
})

Expand Down Expand Up @@ -145,9 +161,58 @@ describe('Notechart', function () {

describe('#columns', function () {
it('should return columns in notechart', function () {
var subject = notechart('#00111:11')
var subject = notechart(`
#00111:01
#00112:01
#00113:01
#00114:01
#00115:01
#00116:01
#00118:01
#00119:01
`)

expect(subject.columns)
.to.have.members(['SC', '1', '2', '3', '4', '5', '6', '7'])
})

it('should return mapped columns in notechart', function () {
var subject = notechart(
`
#00111:01
#00112:01
#00113:01
#00114:01
#00115:01
#00116:01
#00117:01
#00118:01
#00119:01
#0011A:01
#0011B:01
#0011C:01
`,
{
mapping: {
'1A': 'LC',
'11': 'HC',
'18': 'HO',
'1C': 'LP',
'1B': 'LD',
'12': 'SD',
'13': 'BD',
'14': 'LT',
'15': 'HT',
'17': 'FT',
'16': 'RC',
'19': 'RD'
},
noShifting: true
}
)

expect(subject.columns)
.to.deep.equal(['SC', '1', '2', '3', '4', '5', '6', '7'])
.to.have.members(['LC', 'HO', 'HC', 'LP', 'LD', 'SD', 'BD', 'LT', 'HT', 'FT', 'RD', 'RC'])
})
})

Expand Down