Last active
November 8, 2020 17:13
-
-
Save blopa/d893a61e5065aa5ddf853497d5e7f4fb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class HtmlFileInput { | |
constructor({ | |
scene, | |
spriteKey, | |
}) { | |
// Phaser's parent HTML element | |
const mainElement = scene.sys.game.canvas.parentElement; | |
// create html input type | |
const fileInput = document.createElement('input'); | |
fileInput.setAttribute('type', 'file'); | |
fileInput.setAttribute('accept', '.json'); | |
fileInput.setAttribute('id', spriteKey); | |
// TODO this stylings | |
fileInput.style.position = 'absolute'; | |
fileInput.style.top = 0; | |
fileInput.style.display = 'block'; | |
fileInput.style.marginTop = '-400px'; | |
mainElement.appendChild(fileInput); | |
this.setFileInput(fileInput); | |
this.setScene(scene); | |
} | |
setFileInput = (fileInput) => { | |
this.fileInput = fileInput; | |
} | |
setScene = (scene) => { | |
this.scene = scene; | |
} | |
} | |
export default HtmlFileInput; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment