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

@ -112,6 +112,25 @@ var addArrowsFromId = function(client, req, res, callback, id) {
); );
} }
var addResetsFromId = function(client, req, res, callback, id) {
client.query(
"SELECT time FROM resetclicked WHERE user_id = $1",
[id],
function(err, result) {
res.locals.path = res.locals.path || [];
for (var i in result.rows) {
res.locals.path.push(
{
type: 'reset',
time: result.rows[i].time
}
);
}
callback();
}
);
}
var getAllUsers = function(req, res, callback) { var getAllUsers = function(req, res, callback) {
pg.connect(pgc.url, function(err, client, release) { pg.connect(pgc.url, function(err, client, release) {
client.query( client.query(
@ -180,15 +199,17 @@ module.exports.replay_info = function(req, res) {
addCamerasFromId(client, req, res, function() { addCamerasFromId(client, req, res, function() {
addCoinsFromId(client, req, res, function() { addCoinsFromId(client, req, res, function() {
addArrowsFromId(client, req, res, function() { addArrowsFromId(client, req, res, function() {
res.locals.path.sort(function(elt1, elt2) { addResetsFromId(client, req, res, function() {
// Dates as string can be compared res.locals.path.sort(function(elt1, elt2) {
if (elt1.time < elt2.time) // Dates as string can be compared
return -1; if (elt1.time < elt2.time)
if (elt1.time > elt2.time) return -1;
return 1; if (elt1.time > elt2.time)
return 0; return 1;
}); return 0;
res.send(JSON.stringify(res.locals.path)); });
res.send(JSON.stringify(res.locals.path));
}, id);
}, id); }, id);
}, id); }, id);
}, id); }, id);

View File

@ -8,8 +8,8 @@ module.exports.index = function(req, res) {
pg.connect(secret.url, function(err, client, release) { pg.connect(secret.url, function(err, client, release) {
client.query( client.query(
"INSERT INTO keyboardevent(user_id, direction, camera, time)" + "INSERT INTO keyboardevent(user_id, camera, time)" +
"VALUES($1, NULL, ROW(ROW($2,$3,$4),ROW($5,$6,$7)), to_timestamp($8));" , "VALUES($1, ROW(ROW($2,$3,$4),ROW($5,$6,$7)), to_timestamp($8));" ,
[ [
user_id, user_id,
camera.position.x, camera.position.x,

View File

@ -0,0 +1,27 @@
var pg = require('pg');
var secret = require('../../private');
module.exports.index = function(req, res) {
var user_id = req.session.user_id;
var camera = req.body.camera;
pg.connect(secret.url, function(err, client, release) {
client.query(
"INSERT INTO resetclicked(user_id, time)" +
"VALUES($1, to_timestamp($2));" ,
[
user_id,
req.body.time
],
function(err, result) {
console.log(err);
release();
}
);
});
res.setHeader('Content-Type', 'text/html');
res.send("user_id = " + user_id);
}

View File

@ -0,0 +1,3 @@
module.exports = {
'/reset-clicked': 'index'
}

View File

@ -2,6 +2,7 @@ DROP TABLE IF EXISTS users CASCADE;
DROP TABLE IF EXISTS arrowclicked CASCADE; DROP TABLE IF EXISTS arrowclicked CASCADE;
DROP TABLE IF EXISTS coinclicked CASCADE; DROP TABLE IF EXISTS coinclicked CASCADE;
DROP TABLE IF EXISTS keyboardevent CASCADE; DROP TABLE IF EXISTS keyboardevent CASCADE;
DROP TABLE IF EXISTS resetclicked CASCADE;
DROP TYPE IF EXISTS VECTOR3 CASCADE; DROP TYPE IF EXISTS VECTOR3 CASCADE;
DROP TYPE IF EXISTS CAMERA CASCADE; DROP TYPE IF EXISTS CAMERA CASCADE;
@ -42,3 +43,9 @@ CREATE TABLE keyboardevent(
time TIMESTAMP DEFAULT NOW(), time TIMESTAMP DEFAULT NOW(),
camera CAMERA camera CAMERA
); );
CREATE TABLE resetclicked(
id SERIAL PRIMARY KEY,
user_id SERIAL REFERENCES users (id),
time TIMESTAMP DEFAULT NOW()
);

View File

@ -47,3 +47,10 @@ BD.Event.KeyboardEvent.prototype.send = function() {
}; };
BD.Private.sendData(url, data); 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.resetBobomb();
this.moving = false; this.moving = false;
this.movingHermite = false; this.movingHermite = false;
(new BD.Event.ResetClicked()).send();
// this.position.copy(new THREE.Vector3(-8.849933489419644, 9.050627639459208, 0.6192960680432451)); // 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.target.copy(new THREE.Vector3(17.945323228767702, -15.156828589982375, -16.585740412769756));
// this.anglesFromVectors(); // 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.mouse.y = - ( ( event.clientY - renderer.domElement.offsetTop ) / renderer.domElement.height ) * 2 + 1;
this.dragging = true; this.dragging = true;
this.mouseMoved = false;
} }
PointerCamera.prototype.onMouseMove = function(event) { PointerCamera.prototype.onMouseMove = function(event) {
@ -317,11 +319,20 @@ PointerCamera.prototype.onMouseMove = function(event) {
this.mouseMove.x = this.mouse.x - mouse.x; this.mouseMove.x = this.mouse.x - mouse.x;
this.mouseMove.y = this.mouse.y - mouse.y; this.mouseMove.y = this.mouse.y - mouse.y;
this.mouseMoved = true;
} }
} }
PointerCamera.prototype.onMouseUp = function(event) { PointerCamera.prototype.onMouseUp = function(event) {
this.onMouseMove(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; this.dragging = false;
} }

View File

@ -19,14 +19,7 @@ var ReplayCamera = function() {
xhr.onreadystatechange = function() { xhr.onreadystatechange = function() {
if (xhr.readyState == 4 && xhr.status == 200) { if (xhr.readyState == 4 && xhr.status == 200) {
self.path = JSON.parse(xhr.responseText); self.path = JSON.parse(xhr.responseText);
self.position.x = self.path[0].position.x; self.reset();
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.started = true; self.started = true;
self.nextEvent(); self.nextEvent();
} }
@ -56,6 +49,7 @@ ReplayCamera.prototype.update = function(time) {
this.hermiteMotion(time); this.hermiteMotion(time);
} else if (this.event.type == 'coin') { } else if (this.event.type == 'coin') {
// Nothing to do // Nothing to do
} else if (this.event.type == 'reset') {
} }
} }
} }
@ -111,6 +105,13 @@ ReplayCamera.prototype.nextEvent = function() {
})(this); })(this);
} else if (this.event.type == 'arrow') { } else if (this.event.type == 'arrow') {
this.moveHermite(cameras.cameras[this.event.id]); 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.collisionElement.onchange = function() {self.cameras.mainCamera().collisions = self.collisionElement.checked;}
self.showarrowsElement.onchange = function() {self.showArrows = self.showarrowsElement.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() { self.recommendationElement.onchange = function() {
previewer.fixedRecommendation(self.recommendationElement.checked); 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.extension = _toto.canPlayType("audio/x-vorbis") === "" ? ".ogg" : ".mp3";
Coin.prototype.init = function(x,y,z) { Coin.prototype.init = function(x,y,z) {
Coin.nextSound = new Audio(static_path + 'data/music/redcoins/1' + Coin.extension);
if (Coin.BASIC_MESH !== null) { if (Coin.BASIC_MESH !== null) {
this.mesh = Coin.BASIC_MESH.clone(); this.mesh = Coin.BASIC_MESH.clone();
this.mesh.position.x = x; this.mesh.position.x = x;
@ -19,7 +20,6 @@ Coin.prototype.init = function(x,y,z) {
(function(self,x,y,z) { (function(self,x,y,z) {
setTimeout(function() { setTimeout(function() {
self.init(x,y,z); self.init(x,y,z);
Coin.nextSound = new Audio(static_path + 'data/music/redcoins/1' + Coin.extension);
},1000); },1000);
})(this,x,y,z); })(this,x,y,z);
} }
@ -41,7 +41,9 @@ Coin.prototype.update = function() {
Coin.prototype.get = function() { Coin.prototype.get = function() {
if (!this.got) { if (!this.got) {
this.got = true; this.got = true;
this.mesh.visible = false; if (this.mesh) {
this.mesh.visible = false;
}
Coin.total ++; Coin.total ++;
Coin.nextSound.play(); Coin.nextSound.play();
if (Coin.total === 9) { if (Coin.total === 9) {