From df04a1bbfb82207c22a70764a5db52a598a43037 Mon Sep 17 00:00:00 2001 From: Thomas FORGIONE Date: Tue, 19 May 2015 11:50:12 +0200 Subject: [PATCH] New sql files and improved Logger.js --- sql/backup.pgsql | 39 +++++++++++++++++++++++++++++++++++++-- sql/test.pgsql | 8 ++++++++ static/js/Logger.js | 20 ++++++++++++++++++++ 3 files changed, 65 insertions(+), 2 deletions(-) create mode 100644 sql/test.pgsql diff --git a/sql/backup.pgsql b/sql/backup.pgsql index 9543059..c46dc47 100644 --- a/sql/backup.pgsql +++ b/sql/backup.pgsql @@ -1,10 +1,37 @@ DROP TABLE IF EXISTS users CASCADE; DROP TABLE IF EXISTS arrowclicked CASCADE; DROP TABLE IF EXISTS coinclicked CASCADE; +DROP TABLE IF EXISTS keyboardevent CASCADE; -CREATE TABLE users ( +DROP TYPE IF EXISTS VECTOR3 CASCADE; +DROP TYPE IF EXISTS CAMERA CASCADE; +DROP TYPE IF EXISTS DIRECTION CASCADE; + +CREATE TYPE VECTOR3 AS( + x FLOAT, + y FLOAT, + z FLOAT +); + +CREATE TYPE CAMERA AS( + position VECTOR3, + target VECTOR3 +); + +CREATE TYPE DIRECTION AS ENUM( + 'n', + 'ne', + 'e', + 'se', + 's', + 'sw', + 'w', + 'nw' +); + +CREATE TABLE users( id SERIAL PRIMARY KEY, - name char(50) + name CHAR(50) ); CREATE TABLE arrowclicked( @@ -20,3 +47,11 @@ CREATE TABLE coinclicked( time TIMESTAMP DEFAULT NOW(), coin_id INTEGER ); + +CREATE TABLE keyboardevent( + id SERIAL PRIMARY KEY, + user_id SERIAL REFERENCES users (id), + time TIMESTAMP DEFAULT NOW(), + direction DIRECTION, + camera CAMERA +); diff --git a/sql/test.pgsql b/sql/test.pgsql new file mode 100644 index 0000000..1583dce --- /dev/null +++ b/sql/test.pgsql @@ -0,0 +1,8 @@ +INSERT INTO users(name) VALUES('Thomas'); +INSERT INTO keyboardevent(user_id, direction, camera) VALUES( + 1, + NULL, + ROW(ROW(0,0,0), ROW(0,0,0)) +); + +SELECT ((camera).position).x FROM keyboardevent; diff --git a/static/js/Logger.js b/static/js/Logger.js index 7d93d20..63411a3 100644 --- a/static/js/Logger.js +++ b/static/js/Logger.js @@ -24,3 +24,23 @@ BD.Event.CoinClicked.prototype.send = function() { BD.Private.sendData(url, data); } +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 + } + } + }; + BD.Private.sendData(url, data); +}