diff --git a/registration-system/view/signups/game1/js/character.js b/registration-system/view/signups/game1/js/character.js index 17ecc8f8fcf1b4830bc9e0f98c2bbccd6a61543f..73cdb113ae08d899db0a837c5e7bee786831bb5d 100644 --- a/registration-system/view/signups/game1/js/character.js +++ b/registration-system/view/signups/game1/js/character.js @@ -116,7 +116,11 @@ Char.prototype.animate = function() { this.frames[currentFrame].style.display = 'block'; }; Char.prototype.physics = function() { - if (this.moveTarget && this.moveTarget.length == 0) return; + if (this.moveTarget && this.moveTarget.length == 0) { + if (this.onArrivalCallback && typeof this.onArrivalCallback === 'function') this.onArrivalCallback(); + this.onArrivalCallback = null; + return; + } if (Vec.equals(this.translation, this.moveTarget[0])) { this.moveTarget.shift(); @@ -152,7 +156,15 @@ Char.prototype.updatePosition = function() { return translate.apply(null, self.translation); }); }; -Char.prototype.setMoveTarget = function(x,y) { +/** + * + * @param x coord + * @param y coord + * @param onArrival optional callback function + */ +Char.prototype.setMoveTarget = function(x, y, onArrival) { + + this.onArrivalCallback = onArrival; if (Game.config.usePathFinding) this.moveTarget = this.pathFinder.smoothPath(this.pathFinder.findPath(this.translation[0], this.translation[1], x, y)); diff --git a/registration-system/view/signups/game1/js/events.js b/registration-system/view/signups/game1/js/events.js index 9560ac3eb556da7b4a8aaa50527afa4206364c98..a63efa5110ad5f78fe4686823873b19292e5ce9d 100644 --- a/registration-system/view/signups/game1/js/events.js +++ b/registration-system/view/signups/game1/js/events.js @@ -4,7 +4,7 @@ function EventHandler(svg) { click: [], walkon: [] }; - + this.svg = svg; var self = this; svg.selectAll('g').each(function(d, i) { var label = this.getAttribute('inkscape:label'); @@ -22,7 +22,9 @@ function EventHandler(svg) { trigger: trigger, target: this.getAttribute('target'), destination: this.getAttribute('destination'), - stopsWalk: this.getAttribute('stopsWalk') === 'true' + stopsWalk: this.getAttribute('stopsWalk') === 'true', + action: this.getAttribute('action'), + walkTo: this.getAttribute('walkTo') }); } }); @@ -82,9 +84,33 @@ EventHandler.prototype.handleEvent = function (event, context) { case 'mapchange': Game.instance.nextMap(event.destination, event.target); break; + case 'special': + EventHandler.handleAction(event); + break; } if (event.stopsWalk) { Game.char.stopMovement(); } +}; + +EventHandler.handleAction = function(event) { + if (event.action && event.action in EventHandler.actions) { + if(event.walkTo) { + var spawn = Game.char.svg.select('#'+event.walkTo); + if (spawn[0][0]) { + var bbox = spawn[0][0].getBBox(); + var xy = Vec.add(getTranslation(spawn[0][0], Game.char.svg[0][0]), [bbox.x, bbox.y]); + Game.char.setMoveTarget(xy[0], xy[1], EventHandler.actions[event.action]); + } + } else { + EventHandler.actions[event.action](); + } + } +}; + +EventHandler.actions = { + 'fs_open_board': function() { + console.log('fuck yeah!') + } }; \ No newline at end of file diff --git a/registration-system/view/signups/game1/maps/castle_fs.svg b/registration-system/view/signups/game1/maps/castle_fs.svg index b6be7979fcf17e916b640b6278bb0375274f4597..328d9498a66463adcd7994c2a366108e480ceefe 100644 Binary files a/registration-system/view/signups/game1/maps/castle_fs.svg and b/registration-system/view/signups/game1/maps/castle_fs.svg differ