Bake mappings into JS itself

This commit is contained in:
Alexander Yakovlev 2017-09-22 15:00:42 +07:00
parent 0b71eb99a9
commit 3284fd81ea
2 changed files with 16 additions and 17 deletions

View File

@ -19,21 +19,25 @@ task 'compile', 'Compile all CoffeeScript files', ->
# prepare lib directory
if not fs.existsSync 'lib'
fs.mkdirSync 'lib'
# run coffee-script compile
exec "cat #{sourcestring} > lib/index.coffee"
files = glob.sync('src/mappings/*.json')
mappings = []
for file in files
data = JSON.parse(fs.readFileSync(file))
mappings.push data
fs.writeFileSync('lib/mappings.json', JSON.stringify(mappings))
code = fs.readFileSync("lib/index.coffee")
writestr = "mappings = JSON.parse('#{JSON.stringify(mappings)}')"
code = writestr + "\n\n" + code
fs.writeFileSync("lib/index.coffee", code)
# run coffee-script compile
exec "cat #{sourcestring} > lib/index.coffee"
exec "node_modules/coffeescript/bin/coffee --compile --map --no-header lib/index.coffee", (err, stdout, stderr) ->
if err
util.log err
process.exit 1 # abort npm packaging
fs.unlink("lib/index.coffee", () -> )
#fs.unlink("lib/index.coffee", () -> )
util.log "Compiled CoffeeScript."
task 'build', 'Compile and minify all CoffeeScript files', ->

View File

@ -45,19 +45,14 @@ joystick = () ->
$(document).on("viewinit", () ->
# Connected gamepads (see Gamepad class)
salet.view.gamepads = {}
jQuery.ajax({
dataType: 'json',
url: salet.view.gamepadmappings,
success: (data) ->
salet.view.gamepadmappings = data
window.addEventListener("gamepadconnected", (e) ->
salet.view.gamepads[e.gamepad.id] = new Gamepad(e.gamepad)
)
window.addEventListener("gamepaddisconnected", (e) ->
salet.view.gamepads[e.gamepad.id] = undefined
)
setInterval(joystick, 50) # 50 = 1000 / 20 fps
})
salet.view.gamepadmappings = mappings
window.addEventListener("gamepadconnected", (e) ->
salet.view.gamepads[e.gamepad.id] = new Gamepad(e.gamepad)
)
window.addEventListener("gamepaddisconnected", (e) ->
salet.view.gamepads[e.gamepad.id] = undefined
)
setInterval(joystick, 50) # 50 = 1000 / 20 fps
)
window.selectedoption ?= 1