Skip to content

Commit

Permalink
Load map from anchors
Browse files Browse the repository at this point in the history
  • Loading branch information
dubzzz committed Nov 11, 2015
1 parent 1cbe0f0 commit 7100e00
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 16 deletions.
47 changes: 39 additions & 8 deletions templates/edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -52,8 +81,9 @@
}

function initEditor() {
resizeEditor();
readHash();
refreshGroupCells();
updateHash();
}

function select(choosen, value) {
Expand All @@ -75,6 +105,7 @@
else if (event.button == 2) {
editor.set(event, ' ', current_group_id);
}
updateHash();
}

function preventRightClick(event) {
Expand Down
26 changes: 18 additions & 8 deletions templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 7100e00

Please sign in to comment.