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();
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -4,11 +4,12 @@ import UserInterfaceElement from "./UserInterfaceElement.js";
|
||||
|
||||
export default class TextBox extends UserInterfaceElement
|
||||
{
|
||||
constructor(text, width, context)
|
||||
constructor(text, width, context, paused = false)
|
||||
{
|
||||
super();
|
||||
this.text = text;
|
||||
this.width = width;
|
||||
this.paused = paused;
|
||||
this.colorText = 'red';
|
||||
this.colorShadow = 'black';
|
||||
this.colorBorder = 'black';
|
||||
@@ -115,4 +116,4 @@ export default class TextBox extends UserInterfaceElement
|
||||
|
||||
return line;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,9 +2,10 @@ import TextAlignment from "./TextAlignment.js";
|
||||
|
||||
export default class TextLine
|
||||
{
|
||||
constructor(text)
|
||||
constructor(text, paused)
|
||||
{
|
||||
this.text = text;
|
||||
this.paused = paused;
|
||||
this.estimatedTextWidth = null;
|
||||
this.colorText = 'red';
|
||||
this.colorShadow = 'black';
|
||||
@@ -24,6 +25,10 @@ export default class TextLine
|
||||
|
||||
let process = setInterval(
|
||||
() => {
|
||||
if (this.paused) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.chars++;
|
||||
|
||||
if (this.chars === this.text.length) {
|
||||
@@ -83,4 +88,4 @@ export default class TextLine
|
||||
context.fillText(this.text.substr(0, this.chars), x + 2, y + this.size + 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,8 +3,8 @@ import GeometryPoint from "../geometry/GeometryPoint.js";
|
||||
|
||||
export default class TextMessage extends TextBox
|
||||
{
|
||||
constructor(text, context) {
|
||||
super(text, window.innerWidth - 40, context);
|
||||
constructor(text, context, paused = false) {
|
||||
super(text, window.innerWidth - 40, context, paused);
|
||||
this.update();
|
||||
this.context = context;
|
||||
}
|
||||
@@ -21,4 +21,4 @@ export default class TextMessage extends TextBox
|
||||
this.setPosition(this.defaultPosition.x, this.defaultPosition.y);
|
||||
this.updateLines(this.defaultWidth, this.context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user