diff --git a/templates/edit.html b/templates/edit.html
index 28b814b..00f5ecf 100644
--- a/templates/edit.html
+++ b/templates/edit.html
@@ -22,18 +22,47 @@
var current_group_id = 1;
var selected = undefined;
- function resizeEditor() {
- var width = document.getElementById('board_width').value;
- var height = document.getElementById('board_height').value;
- if (editor === undefined) {
- var displayer = new WebDisplayer(document.getElementById('screen'), undefined);
- editor = new WebEditor(displayer, width, height);
+ function readHash() {
+ var hash = window.location.hash.substring(1);
+ var map_strings = hash.split(",");
+
+ if (map_strings.length == 2) {
+ var raw_data = MazeGame.stringsToRawData(map_strings);
+ var width = raw_data[0].length;
+ var height = raw_data.length;
+ document.getElementById('board_width').value = width;
+ document.getElementById('board_height').value = height;
+ if (editor === undefined) {
+ var displayer = new WebDisplayer(document.getElementById('screen'), undefined);
+ editor = new WebEditor(displayer, width, height);
+
+ }
+ editor.reset(raw_data);
}
else {
- editor.resize(width, height);
+ var width = document.getElementById('board_width').value;
+ var height = document.getElementById('board_height').value;
+ if (editor === undefined) {
+ var displayer = new WebDisplayer(document.getElementById('screen'), undefined);
+ editor = new WebEditor(displayer, width, height);
+ }
+ else {
+ editor.resize(width, height);
+ }
}
}
+ function updateHash() {
+ var map_strings = editor.buildMapStrings();
+ window.location.hash = "#" + map_strings[0] + "," + map_strings[1];
+ }
+
+ function resizeEditor() {
+ var width = document.getElementById('board_width').value;
+ var height = document.getElementById('board_height').value;
+ editor.resize(width, height);
+ }
+
function refreshGroupCells() {
current_group_id = parseInt(document.getElementById('board_group_id').value);
@@ -52,8 +81,9 @@
}
function initEditor() {
- resizeEditor();
+ readHash();
refreshGroupCells();
+ updateHash();
}
function select(choosen, value) {
@@ -75,6 +105,7 @@
else if (event.button == 2) {
editor.set(event, ' ', current_group_id);
}
+ updateHash();
}
function preventRightClick(event) {
diff --git a/templates/index.html b/templates/index.html
index 0b94c93..81a5d92 100644
--- a/templates/index.html
+++ b/templates/index.html
@@ -19,15 +19,25 @@
var game = undefined;
var initGame = function() {
- var raw = [
- [99, 0, 2, 0, 0],
- [11,97,12,97, 0],
- [ 0,97,-2,97,-2],
- [-1,97, 1,97, 0],
- [98, 0, 0, 2, 1]];
- var door_times = {1: 10, 2: 4};
var displayer = new WebDisplayer(document.getElementById('screen'), document.getElementById('more'));
- game = new GameRunner(displayer, raw, 18, door_times);
+ var hash = window.location.hash.substring(1);
+ var map_strings = hash.split(",");
+
+ if (map_strings.length == 2) {
+ var raw = MazeGame.stringsToRawData(map_strings);
+ var door_times = {};
+ game = new GameRunner(displayer, raw, 100, door_times);
+ }
+ else {
+ var raw = [
+ [99, 0, 2, 0, 0],
+ [11,97,12,97, 0],
+ [ 0,97,-2,97,-2],
+ [-1,97, 1,97, 0],
+ [98, 0, 0, 2, 1]];
+ var door_times = {1: 10, 2: 4};
+ game = new GameRunner(displayer, raw, 18, door_times);
+ }
}
window.addEventListener("keydown", function(e) {