mirror of
https://git.leinelab.org/Mal/mr-crocs-adventures.git
synced 2025-09-11 02:57:36 +02:00
Tilorswift levels can now be loaded into the running game
This commit is contained in:
42
js/ui/LoadLevelDialog.js
Normal file
42
js/ui/LoadLevelDialog.js
Normal file
@@ -0,0 +1,42 @@
|
||||
import Dialog from "../../tilorswift/js/dialog/Dialog.js";
|
||||
|
||||
export class LoadLevelDialog extends Dialog
|
||||
{
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.setMessage('Level laden');
|
||||
this.fileInput = this.createFileInput(['json']);
|
||||
|
||||
this.onClose = () => {};
|
||||
this.onLoad = () => {};
|
||||
|
||||
this.buttonLoad = this.createButton('Laden');
|
||||
this.buttonLoad.addEventListener(
|
||||
'click',
|
||||
() => {
|
||||
if (this.fileInput.files.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
const reader = new FileReader();
|
||||
reader.addEventListener(
|
||||
'load',
|
||||
(event) => {
|
||||
this.onClose();
|
||||
this.onLoad(event.target.result);
|
||||
}
|
||||
)
|
||||
reader.readAsBinaryString(this.fileInput.files[0]);
|
||||
}
|
||||
);
|
||||
|
||||
this.buttonCancel = this.createButton('Abbrechen');
|
||||
this.buttonCancel.addEventListener(
|
||||
'click',
|
||||
() => {
|
||||
this.onClose();
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user