Enabled reset event for replay

This commit is contained in:
Thomas FORGIONE
2015-05-20 15:20:59 +02:00
parent c902b239e4
commit e4e920a817
10 changed files with 105 additions and 22 deletions

View File

@@ -47,3 +47,10 @@ BD.Event.KeyboardEvent.prototype.send = function() {
};
BD.Private.sendData(url, data);
}
BD.Event.ResetClicked = function() {};
BD.Event.ResetClicked.prototype.send = function() {
var url = "/reset-clicked";
var data = {};
BD.Private.sendData(url, data);
}

View File

@@ -155,6 +155,7 @@ PointerCamera.prototype.reset = function() {
this.resetBobomb();
this.moving = false;
this.movingHermite = false;
(new BD.Event.ResetClicked()).send();
// this.position.copy(new THREE.Vector3(-8.849933489419644, 9.050627639459208, 0.6192960680432451));
// this.target.copy(new THREE.Vector3(17.945323228767702, -15.156828589982375, -16.585740412769756));
// this.anglesFromVectors();
@@ -307,6 +308,7 @@ PointerCamera.prototype.onMouseDown = function(event) {
this.mouse.y = - ( ( event.clientY - renderer.domElement.offsetTop ) / renderer.domElement.height ) * 2 + 1;
this.dragging = true;
this.mouseMoved = false;
}
PointerCamera.prototype.onMouseMove = function(event) {
@@ -317,11 +319,20 @@ PointerCamera.prototype.onMouseMove = function(event) {
this.mouseMove.x = this.mouse.x - mouse.x;
this.mouseMove.y = this.mouse.y - mouse.y;
this.mouseMoved = true;
}
}
PointerCamera.prototype.onMouseUp = function(event) {
this.onMouseMove(event);
// Send log to DB
if (this.dragging && this.mouseMoved && !this.moving && !this.movingHermite) {
var event = new BD.Event.KeyboardEvent();
event.camera = this;
event.send();
}
this.dragging = false;
}

View File

@@ -19,14 +19,7 @@ var ReplayCamera = function() {
xhr.onreadystatechange = function() {
if (xhr.readyState == 4 && xhr.status == 200) {
self.path = JSON.parse(xhr.responseText);
self.position.x = self.path[0].position.x;
self.position.y = self.path[0].position.y;
self.position.z = self.path[0].position.z;
self.target = new THREE.Vector3(
self.path[0].target.x,
self.path[0].target.y,
self.path[0].target.z
);
self.reset();
self.started = true;
self.nextEvent();
}
@@ -56,6 +49,7 @@ ReplayCamera.prototype.update = function(time) {
this.hermiteMotion(time);
} else if (this.event.type == 'coin') {
// Nothing to do
} else if (this.event.type == 'reset') {
}
}
}
@@ -111,6 +105,13 @@ ReplayCamera.prototype.nextEvent = function() {
})(this);
} else if (this.event.type == 'arrow') {
this.moveHermite(cameras.cameras[this.event.id]);
} else if (this.event.type == 'reset') {
this.reset();
(function (self) {
setTimeout(function() {
self.nextEvent();
},500);
})(this);
}
}

View File

@@ -33,7 +33,11 @@ var ButtonManager = function(cameras, previewer) {
self.collisionElement.onchange = function() {self.cameras.mainCamera().collisions = self.collisionElement.checked;}
self.showarrowsElement.onchange = function() {self.showArrows = self.showarrowsElement.checked;}
self.resetElement.onclick = function() {self.cameras.mainCamera().reset();}
self.resetElement.onclick = function() {
// Reinit camera
self.cameras.mainCamera().reset();
}
self.recommendationElement.onchange = function() {
previewer.fixedRecommendation(self.recommendationElement.checked);

View File

@@ -8,6 +8,7 @@ var _toto = new Audio();
Coin.extension = _toto.canPlayType("audio/x-vorbis") === "" ? ".ogg" : ".mp3";
Coin.prototype.init = function(x,y,z) {
Coin.nextSound = new Audio(static_path + 'data/music/redcoins/1' + Coin.extension);
if (Coin.BASIC_MESH !== null) {
this.mesh = Coin.BASIC_MESH.clone();
this.mesh.position.x = x;
@@ -19,7 +20,6 @@ Coin.prototype.init = function(x,y,z) {
(function(self,x,y,z) {
setTimeout(function() {
self.init(x,y,z);
Coin.nextSound = new Audio(static_path + 'data/music/redcoins/1' + Coin.extension);
},1000);
})(this,x,y,z);
}
@@ -41,7 +41,9 @@ Coin.prototype.update = function() {
Coin.prototype.get = function() {
if (!this.got) {
this.got = true;
this.mesh.visible = false;
if (this.mesh) {
this.mesh.visible = false;
}
Coin.total ++;
Coin.nextSound.play();
if (Coin.total === 9) {