Commit 084add1b by Alexander Bazo

Handle gaze data from clients

parent 6e825baf
......@@ -14,7 +14,7 @@ var app = express(),
server = http.createServer(app),
gameServer;
Logger.enable();
// Logger.enable();
app.use(cors());
app.use(express.json());
......@@ -29,7 +29,9 @@ gameServer.define(Config.getGameRoomName(), StarGazerRoom);
app.use(Config.getSocialRoute(), socialRoutes);
app.use(Config.getMonitorRoute(), monitor(gameServer));
// Prrobably shoud be set after game server is created
app.use(Config.getGameRoute(), express.static(Config.getGamePath()));
app.use(Config.getGameRoute(), express.static(Config.getGamePath(), {
maxAge: 100
}));
gameServer.listen(Config.getPort());
Logger.log(`Listening on ws://localhost:${ Config.getPort() }`, "Server");
\ No newline at end of file
......@@ -3,11 +3,18 @@ const Schema = schema.Schema;
class GazePoint extends Schema {
constructor(screenX, screenY) {
constructor(screenX, screenY, createdAt, player, id) {
super();
this.screenX = screenX;
this.screenY = screenY;
this.createdAt = Date.now();
this.id = this.createdAt;
this.createdAt = createdAt;
this.player = player;
this.id = id;
this.relativeAge = 0;
}
static fromClientData(data) {
return new GazePoint(data.screenX, data.screenY, data.createdAt, data.player, data.id);
}
}
......@@ -16,7 +23,8 @@ schema.defineTypes(GazePoint, {
screenX: "number",
screenY: "number",
createdAt: "number",
player: "text",
relativeAge: "number",
player: "string",
id: "number",
});
......
......@@ -22,6 +22,10 @@ class StarGazerState extends Schema {
this.lastEnemySpawn = 0;
}
addGazePoint(gazePoint) {
this.gazePoints.push(gazePoint);
}
update(deltaTime) {
let now = Date.now(),
delta = now - this.lastUpdate;
......@@ -32,7 +36,7 @@ class StarGazerState extends Schema {
updateGazePoints(now) {
for (let i = this.gazePoints.length - 1; i >= 0; i--) {
let age = now - gazePoints[i].createdAt;
let age = now - this.gazePoints[i].createdAt;
if (age > GameConfig.getMaxGazePointAge()) {
this.gazePoints.splice(i, 1);
} else {
......
const colyseus = require("colyseus"),
Logger = require("../utils/Logger.js");
GazePoint = require("../game/GazePoint.js");
StarGazerState = require("../game/StarGazerState.js");
var deltaTime;
......@@ -6,26 +8,28 @@ var deltaTime;
class StarGazerRoom extends colyseus.Room {
onCreate(options) {
console.log("in: onCreate");
console.log(this);
Logger.log("Creating StarGazerRoom", "Game Room");
this.setSimulationInterval(this.update.bind(this));
this.setState(new StarGazerState());
}
onJoin(client, options) {
console.log("in: onJoin");
Logger.log(`Player ${client.sessionId} joined StarGazerRoom`, "Game Room");
}
onMessage(client, message) {
console.log("in: onMessage");
if(message.type === "gaze") {
message.data.player = client.id;
this.state.addGazePoint(GazePoint.fromClientData(message.data));
}
}
onLeave(client, consented) {
console.log("in: onLeave");
Logger.log(`Player ${client.sessionId} left StarGazerRoom`, "Game Room");
}
onDispose() {
console.log("in: onDispose");
Logger.log("Disposing StarGazerRoom", "Game Room");
}
startGame() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment