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) {
pg.connect(pgc.url, function(err, client, release) {
client.query(
@ -180,15 +199,17 @@ module.exports.replay_info = function(req, res) {
addCamerasFromId(client, req, res, function() {
addCoinsFromId(client, req, res, function() {
addArrowsFromId(client, req, res, function() {
res.locals.path.sort(function(elt1, elt2) {
// Dates as string can be compared
if (elt1.time < elt2.time)
return -1;
if (elt1.time > elt2.time)
return 1;
return 0;
});
res.send(JSON.stringify(res.locals.path));
addResetsFromId(client, req, res, function() {
res.locals.path.sort(function(elt1, elt2) {
// Dates as string can be compared
if (elt1.time < elt2.time)
return -1;
if (elt1.time > elt2.time)
return 1;
return 0;
});
res.send(JSON.stringify(res.locals.path));
}, id);
}, id);
}, id);
}, id);

View File

@ -8,8 +8,8 @@ module.exports.index = function(req, res) {
pg.connect(secret.url, function(err, client, release) {
client.query(
"INSERT INTO keyboardevent(user_id, direction, camera, time)" +
"VALUES($1, NULL, ROW(ROW($2,$3,$4),ROW($5,$6,$7)), to_timestamp($8));" ,
"INSERT INTO keyboardevent(user_id, camera, time)" +
"VALUES($1, ROW(ROW($2,$3,$4),ROW($5,$6,$7)), to_timestamp($8));" ,
[
user_id,
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 coinclicked CASCADE;
DROP TABLE IF EXISTS keyboardevent CASCADE;
DROP TABLE IF EXISTS resetclicked CASCADE;
DROP TYPE IF EXISTS VECTOR3 CASCADE;
DROP TYPE IF EXISTS CAMERA CASCADE;
@ -42,3 +43,9 @@ CREATE TABLE keyboardevent(
time TIMESTAMP DEFAULT NOW(),
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.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) {