diff --git a/registration-system/view/signups/game1/js/svgUtils.js b/registration-system/view/signups/game1/js/svgUtils.js index 03b8f95997bbbb846223161f18e549f36f78a0c2..64b9ecf9c162031e2c76eba30e78e8539ae2ae26 100644 --- a/registration-system/view/signups/game1/js/svgUtils.js +++ b/registration-system/view/signups/game1/js/svgUtils.js @@ -20,12 +20,62 @@ function Path(svgPathData, offset) { this.edges = []; var currentPosition = [0,0]; + var lastPosition = null; if (!offset) offset = [0,0]; - var relativeCommand = true; var currentCommand = 'm'; var splitData = svgPathData.split(" "); - while (splitData.length > 0) { + + for (var i = 0; i < splitData.length; ++i) { + var d = splitData[i]; + var s = d.split(','); + var commandPart = s[0][0]; + var commandPartInt = commandPart.charCodeAt(0); + var isNumber = (commandPartInt >= 48 && commandPartInt <= 57) || commandPart == '-' || commandPart == '+' || commandPart == '.'; + + if (isNumber) { + currentPosition = currentPosition.slice(); + lastPosition = currentPosition.slice(); + switch (currentCommand) { + case 'm': + currentPosition[0] = Number(s[0]) + offset[0]; + currentPosition[1] = Number(s[1]) + offset[1]; + currentCommand = 'l'; + break; + case 'M': + currentPosition[0] = Number(s[0]) + offset[0]; + currentPosition[1] = Number(s[1]) + offset[1]; + currentCommand = 'L'; + break; + case 'l': + currentPosition[0] += Number(s[0]); + currentPosition[1] += Number(s[1]); + this.edges.push([lastPosition.slice(), currentPosition.slice()]); + break; + case 'L': + currentPosition[0] = offset[0] + Number(s[0]); + currentPosition[1] = offset[1] + Number(s[1]); + this.edges.push([lastPosition.slice(), currentPosition.slice()]); + break; + } + } else { + switch (commandPart) { + case 'm': + case 'M': + case 'l': + case 'L': + currentCommand = commandPart; + break; + case 'z': + this.edges.push([this.edges[this.edges.length-1][1].slice(), this.edges[0][0].slice()]); + break; + default: + currentCommand = 'l'; // fallback + } + } + } + + /*while (splitData.length > 0) { var lastPosition = currentPosition.slice(); var part = splitData.shift(); @@ -57,11 +107,11 @@ function Path(svgPathData, offset) { currentCommand = 'l'; // fallback } if (currentCommand == 'z') // close loop - this.edges.push([this.edges[this.edges.length-1][1], this.edges[0][0]]); + this.edges.push([this.edges[this.edges.length-1][1], this.edges[0][0]]); if (rest.length > 0) splitData.unshift(rest); } - } + }*/ } Path.prototype.lineIntersectionCount = function(fromX, fromY, x, y) { var hitCount = 0; diff --git a/registration-system/view/signups/game1/maps/castle_entrance.svg b/registration-system/view/signups/game1/maps/castle_entrance.svg index 49512a392d345d4e4a27c45bd87b936e4f82fc1e..44bbf7d30207b6b6409bf37c8dae780d5c96773e 100644 Binary files a/registration-system/view/signups/game1/maps/castle_entrance.svg and b/registration-system/view/signups/game1/maps/castle_entrance.svg differ diff --git a/registration-system/view/signups/game1/test.html b/registration-system/view/signups/game1/test.html index 696a405e209ddd98b73e3ccc96a1b394bdbd1b42..5b7d7c69a53620e5b4859aa7d9de486b083f1647 100644 --- a/registration-system/view/signups/game1/test.html +++ b/registration-system/view/signups/game1/test.html @@ -65,7 +65,7 @@ var game = new Game({ startMap: maps[UrlComponents.getValueOf('map') || 0], showEventLayers: UrlComponents.isSet('showEventLayers'), - pathFindingGridSize: UrlComponents.isSet('verbosePF') ? 18 : 5, + pathFindingGridSize: UrlComponents.isSet('verbosePF') ? 5 : 5, verbosePathFinder: UrlComponents.isSet('verbosePF'), usePathFinding: true, size: [800, 600]