Skip to content
Snippets Groups Projects
Commit 895f34e6 authored by Tim Repke's avatar Tim Repke
Browse files

added onclick walkto

parent 8fa96d45
No related branches found
No related tags found
No related merge requests found
...@@ -116,7 +116,11 @@ Char.prototype.animate = function() { ...@@ -116,7 +116,11 @@ Char.prototype.animate = function() {
this.frames[currentFrame].style.display = 'block'; this.frames[currentFrame].style.display = 'block';
}; };
Char.prototype.physics = function() { 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])) { if (Vec.equals(this.translation, this.moveTarget[0])) {
this.moveTarget.shift(); this.moveTarget.shift();
...@@ -152,7 +156,15 @@ Char.prototype.updatePosition = function() { ...@@ -152,7 +156,15 @@ Char.prototype.updatePosition = function() {
return translate.apply(null, self.translation); 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) if (Game.config.usePathFinding)
this.moveTarget = this.pathFinder.smoothPath(this.pathFinder.findPath(this.translation[0], this.translation[1], x, y)); this.moveTarget = this.pathFinder.smoothPath(this.pathFinder.findPath(this.translation[0], this.translation[1], x, y));
......
...@@ -4,7 +4,7 @@ function EventHandler(svg) { ...@@ -4,7 +4,7 @@ function EventHandler(svg) {
click: [], click: [],
walkon: [] walkon: []
}; };
this.svg = svg;
var self = this; var self = this;
svg.selectAll('g').each(function(d, i) { svg.selectAll('g').each(function(d, i) {
var label = this.getAttribute('inkscape:label'); var label = this.getAttribute('inkscape:label');
...@@ -22,7 +22,9 @@ function EventHandler(svg) { ...@@ -22,7 +22,9 @@ function EventHandler(svg) {
trigger: trigger, trigger: trigger,
target: this.getAttribute('target'), target: this.getAttribute('target'),
destination: this.getAttribute('destination'), 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) { ...@@ -82,9 +84,33 @@ EventHandler.prototype.handleEvent = function (event, context) {
case 'mapchange': case 'mapchange':
Game.instance.nextMap(event.destination, event.target); Game.instance.nextMap(event.destination, event.target);
break; break;
case 'special':
EventHandler.handleAction(event);
break;
} }
if (event.stopsWalk) { if (event.stopsWalk) {
Game.char.stopMovement(); 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
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment