Main menu and save function to json file implemented.

This commit is contained in:
Mal
2020-02-02 23:00:14 +01:00
parent 9c3aca1bc9
commit d893483da9
11 changed files with 252 additions and 7 deletions

View File

@@ -4,6 +4,12 @@ import TilorswiftEvent from "./events/TilorswiftEvent.js";
import Mouse from "./Mouse.js";
import Tileset from "./Tileset.js";
import ButtonTile from "./ButtonTile.js";
import Tilorswift from "./Tilorswift.js";
import TilorswiftSavedEvent from "./events/TilorswiftSavedEvent.js";
import MainMenu from "./menu/MainMenu.js";
import MenuGroup from "./menu/MenuGroup.js";
import MainMenuEntry from "./menu/MainMenuEntry.js";
import TilorswiftMenuSaveClickedEvent from "./events/TilorswiftMenuSaveClickedEvent.js";
let loader = new FileLoader('../levels/level.json');
@@ -26,6 +32,17 @@ image.onload = function () {
let mouse = new Mouse();
let mainbar = new MainMenu('mainbar');
let menuFile = new MenuGroup('Datei');
menuFile.addMenuEntry(
new MainMenuEntry('Speichern', TilorswiftMenuSaveClickedEvent)
);
mainbar.addMenuGroup(menuFile);
document.body.appendChild(mainbar.getElement());
window.addEventListener(
TilorswiftEvent.FIELD_CLICKED,
(event) => {
@@ -58,4 +75,28 @@ image.onload = function () {
}
}
);
document.addEventListener(
'dragstart',
function (event) {
event.preventDefault();
}
);
window.addEventListener(
'keydown', function (event) {
if (event.code === 'KeyS') {
Tilorswift.saveTerrainToFile(terrain);
window.dispatchEvent(new TilorswiftSavedEvent());
}
}
);
window.addEventListener(
TilorswiftEvent.MENU_SAVE_CLICKED,
function () {
Tilorswift.saveTerrainToFile(terrain);
window.dispatchEvent(new TilorswiftSavedEvent());
}
);
};