+sparkmd5 = require 'sparkmd5'
+JSZip = require 'jszip'
+require 'x-game'
+
+settings = require './settings.json!'
+
 draghint = document.getElementById 'draghint'
 chooser = document.getElementById 'chooser'
 

    zip = new JSZip buffer
    for file in zip.file /.*/ # any way to predict name of file?
      [..., extension] = file.name.split '.'
      if cores[extension]
        rom = new Uint8Array file.asArrayBuffer()
        break
  else if cores[extension]
    rom = buffer
  if rom
    stop() if retro.running


navigator.serviceWorker.register 'worker.js' if navigator.serviceWorker

retro = document.createElement 'canvas', 'x-game'
document.body.appendChild retro

play = (rom, extension) ->
  retro.md5 = sparkmd5.ArrayBuffer.hash rom
  Promise.all([
    System.import settings.cores[extension]
  ]).then ([core, save]) ->
    retro.core = core
    retro.game = rom if rom
