Browse Source

Bake mappings into JS itself

master
Alexander Yakovlev 5 years ago
parent
commit
3284fd81ea
  1. 12
      Cakefile
  2. 21
      src/init.coffee

12
Cakefile

@ -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', ->

21
src/init.coffee

@ -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

Loading…
Cancel
Save