Commit 899036f2 authored by Raphaël Bastide's avatar Raphaël Bastide

Hash tests

parent 15668c82
......@@ -36,10 +36,36 @@ function title(){
var t = d.getElementsByTagName('h1')[0]
window.setTimeout(function(){t.classList.add('hidden')},1000)
}
function testURL(){
// if (unit === undefined) {
// notifAlert('You have an undefined character in the URL')
// }else if(unit.length == null) {
// notifAlert('Try adding #bf at the end of this URL')
// }
function getAvailableChar(data){
var availableChar = []
var allUnits = data.units
for (var i = 0; i < allUnits.length; i++) {
var c = allUnits[i].char
availableChar.push(c)
}
return availableChar
}
function testHash(data){
var cleanHash = []
console.log(data);
var availableChar = getAvailableChar(data)
var hash = window.location.hash.substr(1)
// Extracting URL characters to build the hash
if(hash == "#" || hash == "") {
notifAlert('Try adding #bf at the end of this URL')
return false
}else{
hashChar = hash.split('')
for (var i = 0; i < hashChar.length; i++) {
if (availableChar.indexOf(hashChar[i]) <= -1) { // incompatible character
notifAlert(hashChar[i]+" is not a valid character")
// return false
}else {
cleanHash.push(hashChar[i])
}
}
return cleanHash
}
}
......@@ -31,21 +31,14 @@ function launch(units, isRefresh){
counterBonus = counterTime = counterZoom = 0,
bulletTime, bonusTime, isBackInTime, checkPoint, lastCollided = false
if (!debug || isRefresh) {
title()
title() // Do not show title if hashchange refresh
}
if (isRefresh) {
console.log('clear');
if (isRefresh) { // removes canvas when hashchange
var c = d.getElementsByTagName('canvas')[0]
c.parentElement.removeChild(c)
}
//
// if ("onhashchange" in window) {
// alert("Le navigateur prend en charge l'événement hashchange!");
// }
window.onhashchange = locationHashChanged;
function locationHashChanged() {
launch(units, true)
......@@ -68,19 +61,13 @@ function launch(units, isRefresh){
}
});
var terrain = window.location.hash.substr(1)
// Extracting URL characters to build the terrain
if (terrain.includes('%E')) {
urlshapes = true
terrain = terrain.split('%E')
}else {
terrain = terrain.split('')
}
for (var i = 0; i < terrain.length; i++) {
c = terrain[i]
if (!nextPos){nextPos = {x:startX,y:startY}}
buildUnit(c, nextPos)
var hash = testHash(data)
if (hash) {
for (var i = 0; i < hash.length; i++) {
c = hash[i]
if (!nextPos){nextPos = {x:startX,y:startY}}
buildUnit(c, nextPos)
}
}
// Building common objects
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment