mirror of
https://gitlab.com/Oreolek/salet-gamepad-module.git
synced 2024-04-28 23:29:37 +03:00
Bake mappings into JS itself
This commit is contained in:
parent
0b71eb99a9
commit
3284fd81ea
12
Cakefile
12
Cakefile
|
@ -19,21 +19,25 @@ task 'compile', 'Compile all CoffeeScript files', ->
|
||||||
# prepare lib directory
|
# prepare lib directory
|
||||||
if not fs.existsSync 'lib'
|
if not fs.existsSync 'lib'
|
||||||
fs.mkdirSync 'lib'
|
fs.mkdirSync 'lib'
|
||||||
|
|
||||||
|
# run coffee-script compile
|
||||||
|
exec "cat #{sourcestring} > lib/index.coffee"
|
||||||
|
|
||||||
files = glob.sync('src/mappings/*.json')
|
files = glob.sync('src/mappings/*.json')
|
||||||
mappings = []
|
mappings = []
|
||||||
for file in files
|
for file in files
|
||||||
data = JSON.parse(fs.readFileSync(file))
|
data = JSON.parse(fs.readFileSync(file))
|
||||||
mappings.push data
|
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) ->
|
exec "node_modules/coffeescript/bin/coffee --compile --map --no-header lib/index.coffee", (err, stdout, stderr) ->
|
||||||
if err
|
if err
|
||||||
util.log err
|
util.log err
|
||||||
process.exit 1 # abort npm packaging
|
process.exit 1 # abort npm packaging
|
||||||
fs.unlink("lib/index.coffee", () -> )
|
#fs.unlink("lib/index.coffee", () -> )
|
||||||
util.log "Compiled CoffeeScript."
|
util.log "Compiled CoffeeScript."
|
||||||
|
|
||||||
task 'build', 'Compile and minify all CoffeeScript files', ->
|
task 'build', 'Compile and minify all CoffeeScript files', ->
|
||||||
|
|
|
@ -45,19 +45,14 @@ joystick = () ->
|
||||||
$(document).on("viewinit", () ->
|
$(document).on("viewinit", () ->
|
||||||
# Connected gamepads (see Gamepad class)
|
# Connected gamepads (see Gamepad class)
|
||||||
salet.view.gamepads = {}
|
salet.view.gamepads = {}
|
||||||
jQuery.ajax({
|
salet.view.gamepadmappings = mappings
|
||||||
dataType: 'json',
|
window.addEventListener("gamepadconnected", (e) ->
|
||||||
url: salet.view.gamepadmappings,
|
salet.view.gamepads[e.gamepad.id] = new Gamepad(e.gamepad)
|
||||||
success: (data) ->
|
)
|
||||||
salet.view.gamepadmappings = data
|
window.addEventListener("gamepaddisconnected", (e) ->
|
||||||
window.addEventListener("gamepadconnected", (e) ->
|
salet.view.gamepads[e.gamepad.id] = undefined
|
||||||
salet.view.gamepads[e.gamepad.id] = new Gamepad(e.gamepad)
|
)
|
||||||
)
|
setInterval(joystick, 50) # 50 = 1000 / 20 fps
|
||||||
window.addEventListener("gamepaddisconnected", (e) ->
|
|
||||||
salet.view.gamepads[e.gamepad.id] = undefined
|
|
||||||
)
|
|
||||||
setInterval(joystick, 50) # 50 = 1000 / 20 fps
|
|
||||||
})
|
|
||||||
)
|
)
|
||||||
|
|
||||||
window.selectedoption ?= 1
|
window.selectedoption ?= 1
|
||||||
|
|
Loading…
Reference in a new issue