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

Game loader #94

Merged
merged 23 commits into from
Feb 19, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
34e56be
feat(game/data): specify the data structure of game objects
dtinth Feb 13, 2015
239ec83
fix(app/index): expand the viewport
dtinth Feb 13, 2015
27bc227
feat(boot): add route to "game" module
dtinth Feb 16, 2015
69f30cc
feat(scene-manager): implement a scene manager
dtinth Feb 16, 2015
54e86b8
feat(view): introduce view system based on Ractive.js
dtinth Feb 16, 2015
caa5db5
feat(game/loading-scene): add animation to song info
dtinth Feb 16, 2015
c1e6778
feat(loading-scene): perform data-binding using ractive
dtinth Feb 16, 2015
d3471cb
feat(game/loading-scene): display subtitle in loading
dtinth Feb 16, 2015
fe3ded3
feat(game/game-loader): implement game loader with progress tracking
dtinth Feb 16, 2015
d89bee5
feat(scintillator/loader): more detailed progress reporting
dtinth Feb 16, 2015
850a0b1
feat(game/loading-scene): make progress text smaller
dtinth Feb 16, 2015
996054a
feat(game/loading-scene): fade-out on load complete
dtinth Feb 16, 2015
ba2cd68
feat(game/game-loader): parse the BMS
dtinth Feb 16, 2015
5a7cd4d
feat(polyfill): expose DEBUG
dtinth Feb 17, 2015
acd7f58
refactor(game/game-loader): move loading logic to different method
dtinth Feb 17, 2015
2dce466
feat(game/game-loader): load keysounds
dtinth Feb 18, 2015
8cf1917
feat(game/game-loader): notify progress on loading packages
dtinth Feb 18, 2015
6fc330d
chore(webpack): use absolute path in loader test
dtinth Feb 18, 2015
f6fbf24
chore(package): use latest Bluebird (2.9.10)
dtinth Feb 18, 2015
041ae08
refactor(game): use the Progress design pattern for progress reporting
dtinth Feb 19, 2015
052d7cf
test: increase code coverage
dtinth Feb 19, 2015
4ba3587
test(sampling-master): test the sampling master
dtinth Feb 19, 2015
db4bbd5
chore(tasks/support/test-runner): bump limit to 20 seconds
dtinth Feb 19, 2015
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
Binary file added assets/bg/a.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 23 additions & 7 deletions config/webpack.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ import ProgressPlugin from '../src/webpack-progress'
let config = {
context: path('src'),
resolve: {
alias: {
bemuse: path('src'),
assets: path('assets'),
},
},
resolveLoader: {
alias: {
bemuse: path('src'),
},
Expand All @@ -29,11 +35,8 @@ let config = {
module: {
loaders: [
{
test: /[\\\/]src[\\\/].*\.js$/,
loader: '6to5?modules=common&experimental=true',
},
{
test: /[\\\/]spec[\\\/].*\.js$/,
test: /\.js$/,
include: [path('src'), path('spec')],
loader: '6to5?modules=common&experimental=true',
},
{
Expand All @@ -53,6 +56,14 @@ let config = {
test: /\.jade/,
loader: 'jade',
},
{
test: /\.png$/,
loader: 'url-loader?limit=100000&mimetype=image/png',
},
{
test: /\.jpg$/,
loader: 'file-loader',
},
],
postLoaders: [],
},
Expand All @@ -63,8 +74,13 @@ let config = {

if (NODE_ENV === 'test' || process.env.COV === 'true') {
config.module.postLoaders.push({
test: /\/src\/.*\.js$/,
exclude: /\/src\/test\/.*\.js$|\/src\/boot\/loader\.js$/,
test: /\.js$/,
include: [path('src')],
exclude: [
path('src', 'test'),
path('src', 'polyfill'),
path('src', 'boot', 'loader.js'),
],
loader: 'istanbul-instrumenter',
})
}
Expand Down
19 changes: 15 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,45 +43,56 @@
"css-loader": "^0.9.0",
"exports-loader": "^0.6.2",
"express": "^4.10.6",
"file-loader": "^0.8.1",
"glob": "^4.3.2",
"gulp": "^3.8.10",
"gulp-gh-pages": "git://github.com/dtinth/gulp-gh-pages",
"gulp-jshint": "^1.9.0",
"gulp-util": "^3.0.1",
"istanbul": "^0.3.5",
"istanbul-instrumenter-loader": "^0.1.2",
"jade": "^1.8.2",
"jade": "^1.9.2",
"jade-loader": "^0.7.0",
"jasmine": "^2.1.1",
"js-yaml": "^3.2.5",
"jscs": "^1.9.0",
"jshint": "^2.5.11",
"jshint": "^2.6.0",
"jshint-stylish": "^1.0.0",
"merge-stream": "^0.1.6",
"mocha": "^2.1.0",
"node-env": "^0.1.6",
"node-notifier": "^4.0.3",
"pegjs-loader": "^0.1.1",
"ractive-loader": "^0.5.6",
"sass-loader": "^0.3.1",
"script-loader": "^0.6.1",
"sinon": "git://github.com/cjohansen/Sinon.JS#sinon-2.0",
"sinon-chai": "^2.7.0",
"style-loader": "^0.8.2",
"through2": "^0.6.3",
"url-loader": "^0.5.5",
"val-loader": "^0.5.0",
"web-audio-test-api": "^0.2.1",
"webpack": "^1.4.13",
"webpack-dev-server": "^1.6.6"
},
"dependencies": {
"audio-context": "^0.1.0",
"bluebird": "^2.9.6",
"bms": "^0.2.0",
"bluebird": "^2.9.10",
"bms": "^0.6.0",
"bytes": "^1.0.0",
"chance": "^0.7.3",
"co": "^4.3.1",
"data-structure": "^1.2.0",
"debug": "^2.1.1",
"jquery": "^2.1.3",
"keytime": "^0.1.0",
"lazy-property": "^1.0.0",
"once": "^1.3.1",
"pixi.js": "^2.2.3",
"ractive": "^0.6.1",
"ramda": "^0.9.1",
"throat": "^2.0.2",
"vue": "^0.11.4"
}
}
19 changes: 19 additions & 0 deletions spec/download/download_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

import download from 'bemuse/download'

describe('download', function() {

it('resolves with correct type', function() {
return expect(download('/spec/download/fixtures/hello.txt').as('text'))
.to.eventually.match(/hello world/)
})

it('rejects for 404', function() {
return expect(download('/nonexistant').as('blob')).to.be.rejected
})

it('rejects for bad url', function() {
return expect(download('file:///nonexistant').as('blob')).to.be.rejected
})

})
1 change: 1 addition & 0 deletions spec/download/fixtures/hello.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
hello world
52 changes: 52 additions & 0 deletions spec/game/audio-loader_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@

import AudioLoader from 'bemuse/game/audio-loader'

describe('AudioLoader', function() {

describe('load', function() {

var assets
var keysounds
var master
var loader

beforeEach(function() {
assets = { file: sinon.stub() }
keysounds = { files: sinon.stub() }
master = { sample: sinon.stub() }
loader = new AudioLoader(assets, master)
})

it('should load file when matches', function() {
keysounds.files.returns(['a.wav'])
assets.file.withArgs('a.wav').returns(Promise.resolve({
read: () => Promise.resolve('ok1')
}))
master.sample.withArgs('ok1').returns(Promise.resolve('ok2'))
return expect(loader.loadFrom(keysounds)).to.eventually.deep.eq({
'a.wav': 'ok2'
})
})

it('should try mp3', function() {
keysounds.files.returns(['a.wav'])
assets.file.withArgs('a.wav').returns(Promise.reject())
assets.file.withArgs('a.mp3').returns(Promise.resolve({
read: () => Promise.resolve('ok1')
}))
master.sample.withArgs('ok1').returns(Promise.resolve('ok2'))
return expect(loader.loadFrom(keysounds)).to.eventually.deep.eq({
'a.wav': 'ok2'
})
})

it('should not include failed matches', function() {
keysounds.files.returns(['a.wav'])
assets.file.withArgs('a.wav').returns(Promise.reject())
assets.file.withArgs('a.mp3').returns(Promise.reject())
return expect(loader.loadFrom(keysounds)).to.eventually.deep.eq({ })
})

})

})
53 changes: 53 additions & 0 deletions spec/progress/progress_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@

import Progress from 'bemuse/progress'

describe('Progress', function() {

describe('#watch', function() {
it('should report current progress when watched', function() {
let progress = new Progress()
let spy = sinon.spy()
progress.report(1, 10)
progress.watch(spy)
expect(spy).to.have.callCount(1)
expect(spy).to.have.been.calledWith(progress)
})
})

describe('#report', function() {
it('should fire to all watchers', function() {
let progress = new Progress()
let spy = sinon.spy()
progress.report(1, 10)
progress.report(2, 10)
progress.watch(spy)
progress.report(3, 10)
progress.report(4, 10)
expect(spy).to.have.callCount(3)
})
it('should return a function to unsubscribe', function() {
let progress = new Progress()
let spy = sinon.spy()
progress.report(1, 10)
progress.report(2, 10)
let unsubscribe = progress.watch(spy)
progress.report(3, 10)
unsubscribe()
progress.report(4, 10)
expect(spy).to.have.callCount(2)
})
})

describe('#progress', function() {
it('returns progress in fraction', function() {
let progress = new Progress()
progress.report(1, 10)
expect(progress.progress).to.equal(1 / 10)
})
it('returns null in unavailable', function() {
let progress = new Progress()
expect(progress.progress).to.equal(null)
})
})

})
51 changes: 51 additions & 0 deletions spec/progress/utils_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@

import Progress from 'bemuse/progress'
import * as ProgressUtils from 'bemuse/progress/utils'

describe('ProgressUtils', function() {

describe('.fixed', function() {
it('should report for fixed number of items', function() {
let progress = new Progress()
let advance = ProgressUtils.fixed(10, progress)
expect(progress.current).to.equal(0)
expect(progress.total).to.equal(10)
advance('wow')
expect(progress.current).to.equal(1)
expect(progress.total).to.equal(10)
expect(progress.extra).to.equal('wow')
})
})

describe('.wrapPromise', function() {
it('should report number of fulfilled promises', function() {
let progress = new Progress()
let f = ProgressUtils.wrapPromise(progress, promise => promise)
let a = f(new Promise(() => {}))
let b = f(Promise.resolve(1))
let c = f(Promise.reject(new Error('no')))
let d = f(Promise.resolve(3))
void a
void c
return Promise.all([b, d]).then(() => {
expect(progress.current).to.equal(2)
expect(progress.total).to.equal(4)
})
})
})

describe('.bind', function() {
it('should bind from one progress to another', function() {
let a = new Progress()
let b = new Progress()
a.report(10, 20)
ProgressUtils.bind(a, b)
expect(b.current).to.equal(10)
expect(b.total).to.equal(20)
a.report(15, 25)
expect(b.current).to.equal(15)
expect(b.total).to.equal(25)
})
})

})
1 change: 1 addition & 0 deletions spec/resources/fixtures/a/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"files":[{"name":"do.mp3","ref":[0,0,30093]},{"name":"mi.mp3","ref":[0,30093,60186]},{"name":"sol.mp3","ref":[0,60186,90279]}],"refs":[{"path":"mp3.0.ea6087c3.bemuse","hash":"ea6087c3379bce007e50c3100b99b83c"}]}
Binary file added spec/resources/fixtures/a/mp3.0.ea6087c3.bemuse
Binary file not shown.
1 change: 1 addition & 0 deletions spec/resources/fixtures/b/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"files":[{"name":"do.mp3","ref":[0,0,30093]},{"name":"mi.mp3","ref":[0,30093,60186]},{"name":"sol.mp3","ref":[0,60186,90279]}],"refs":[{"path":"mp3.0.ea6087c3.bemuse","hash":"ea6087c3379bce007e50c3100b99b83c"}]}
Loading