Added support of previous / next in replay

This commit is contained in:
Thomas FORGIONE
2015-05-20 16:28:53 +02:00
parent e4e920a817
commit e841075b0d
7 changed files with 154 additions and 25 deletions

View File

@@ -8,9 +8,30 @@ BD.Private.sendData = function(url, data) {
var xhr = new XMLHttpRequest();
xhr.open("POST", url, true);
xhr.setRequestHeader("Content-type", "application/json;charset=UTF-8");
xhr.onreadystatechange = function() {
if(xhr.readyState == 4 && xhr.status == 200) {
console.log(xhr.responseText);
}
}
xhr.send(JSON.stringify(data));
}
BD.Private.compactCamera = function(camera) {
return {
position: {
x: camera.position.x,
y: camera.position.y,
z: camera.position.z
},
target: {
x: camera.target.x,
y: camera.target.y,
z: camera.target.z
}
};
}
BD.Event = {};
BD.Event.ArrowClicked = function() {};
@@ -30,21 +51,11 @@ BD.Event.CoinClicked.prototype.send = function() {
BD.Event.KeyboardEvent = function() {};
BD.Event.KeyboardEvent.prototype.send = function() {
var url = "/keyboard-event";
var data = {
camera: {
// Compact camera
position: {
x: this.camera.position.x,
y: this.camera.position.y,
z: this.camera.position.z
},
target: {
x: this.camera.target.x,
y: this.camera.target.y,
z: this.camera.target.z
}
}
};
camera: BD.Private.compactCamera(this.camera)
}
BD.Private.sendData(url, data);
}
@@ -54,3 +65,15 @@ BD.Event.ResetClicked.prototype.send = function() {
var data = {};
BD.Private.sendData(url, data);
}
BD.Event.PreviousNextClicked = function() {};
BD.Event.PreviousNextClicked.prototype.send = function() {
var url = "/previous-next-clicked";
var data = {
// casts previous to boolean
previous: this.previous,
camera: BD.Private.compactCamera(this.camera)
};
BD.Private.sendData(url, data);
}

View File

@@ -350,14 +350,26 @@ PointerCamera.prototype.save = function() {
PointerCamera.prototype.undo = function() {
var move = this.history.undo();
if (move !== undefined)
if (move !== undefined) {
var event = new BD.Event.PreviousNextClicked();
event.previous = true;
event.camera = move;
event.send();
this.move(move, false);
}
}
PointerCamera.prototype.redo = function() {
var move = this.history.redo();
if (move !== undefined)
if (move !== undefined) {
var event = new BD.Event.PreviousNextClicked();
event.previous = false;
event.camera = move;
event.send();
this.move(move, false);
}
}
PointerCamera.prototype.undoable = function() {

View File

@@ -45,11 +45,14 @@ ReplayCamera.prototype.update = function(time) {
if (this.started) {
if (this.event.type == 'camera') {
this.linearMotion(time);
} else if (this.event.type == 'previousnext') {
this.linearMotion(time / 5);
} else if (this.event.type == 'arrow') {
this.hermiteMotion(time);
} else if (this.event.type == 'coin') {
// Nothing to do
} else if (this.event.type == 'reset') {
// Nothing to do
}
}
}
@@ -112,6 +115,8 @@ ReplayCamera.prototype.nextEvent = function() {
self.nextEvent();
},500);
})(this);
} else if (this.event.type == 'previousnext') {
this.move(this.event);
}
}