changed color working, and beginned to do things for vieux

This commit is contained in:
catvayor 2023-06-10 09:22:02 +02:00
parent eb92a797cd
commit 81355eddf9
2 changed files with 35 additions and 37 deletions

View file

@ -2,11 +2,9 @@
{
"id" : string,
"pos" : [lat : float, long : float],
"color" : int,
"state" : {
"shown" : bool,
"tracker" : bool,
"tracked" : bool,
"npc" : bool
}
}
@ -14,8 +12,10 @@
Les messages à transmettre par le client :
- position, HTTP "/log?id=%ID&lat=%LAT&lon=%LON"
- code(code)
- (vieux) changeState (state)
Les messages à transmettre par le serveur :
- moving(id, color, position)
- (vieux) newState(state)
*/
// require = include
@ -32,7 +32,7 @@ var MSG_BAD = "Code Incorrect";
var MSG_TRACKED = "Vous êtes maintenant traqué.e.s !"
var MSG_TRACKER = "Vous pouvez maintenant traquer !";
var MSG_INVISIBLE = "Les autres équipes ne peuvent plus vous voir !";
var invisible_delay = 3*60*1000;
var invisible_delay = 10000;// 3*60*1000;
var equipes = {};
var invisi = {};
@ -98,8 +98,6 @@ var io = new Server(server);
//
// Everyone in this room is located
// sub-rooms :
// * "tracked" room for all tracked
// * "tracker" room for all tracker
// * "npc" room for non-player
// * "%ID" room of a team
//
@ -121,12 +119,20 @@ var tracking = io.to("Tracking");
// }
var admin = io.to("Admin");
// visible color of a team
function color(team){
if(!team.state.shown) return 2;
if(team.state.tracker) return 1;
if(team.state.npc != 0) return 2 + team.state.npc;
return 0;
}
// apparent information of a team, for other only
function apparent_info(equipe){
if(equipe.state.shown){
return {"id": equipe.id, "color": equipe.color, "position": equipe.pos};
return {"id": equipe.id, "color": color(equipe), "position": equipe.pos};
} else {
return {"id": equipe.id, "color": equipe.color, "position": [0,0]};
return {"id": equipe.id, "color": color(equipe), "position": [0,0]};
}
}
@ -134,7 +140,7 @@ function emit_update(team_id) {
var equipe = equipes[team_id];
tracking.except(team_id).emit('moving', apparent_info(equipe));
// the team and the admins always have the real informations
admin.to(team_id).emit('moving', {"id": team_id, "color": equipe.color, "position": equipe.pos});
admin.to(team_id).emit('moving', {"id": team_id, "color": color(equipe), "position": equipe.pos});
}
// produces a team object populated with default values
@ -143,11 +149,9 @@ function default_team(team_id) {
var state = {};
state.shown = true;
state.tracker = false;
state.tracked = true;
state.npc = false;
state.npc = 0;
equipe.state = state;
equipe.pos = [0,0];
equipe.color = 0;
equipe.id = team_id;
return equipe;
}
@ -156,10 +160,8 @@ function default_team(team_id) {
function team_join(team, socket){
socket.join(team.id);
var state = team.state;
if(state.tracker) socket.join("tracker");
if(state.tracked) socket.join("tracked");
if(state.npc) socket.join("npc");
socket.emit('moving', {"id": team.id, "color": team.color, "position": team.pos});
if(state.npc != 0) socket.join("npc");
socket.emit('moving', {"id": team.id, "color": color(team), "position": team.pos});
for(other_id in equipes)
if(other_id != team.id)
socket.emit('moving', apparent_info(equipes[other_id]));
@ -180,18 +182,19 @@ io.on('connection', function(socket){
socket.on("code", function(d){
var code = d.code;
if((code in invisi) && invisi[code]){
if(code == PWD_TRACKER){
equipe.state.tracker = true;
io.to(id).emit('popup', {"content": MSG_TRACKER});
emit_update(id);
} else if((code in invisi) && invisi[code]){
invisi[code] = false;
var old_color = equipe.color;
equipe.color = 2;
equipe.state.shown = false;
io.to(id).emit('popup', {"content": MSG_INVISIBLE});
emit_update(id);
setTimeout(function(eq, oc){
eq.color = oc;
setTimeout(function(eq){
eq.state.shown = true;
emit_update(eq.id);
}, invisible_delay, equipe, old_color);
}, invisible_delay, equipe);
} else {
socket.emit('popup', {"content": MSG_BAD});
return;
@ -200,13 +203,21 @@ io.on('connection', function(socket){
}
if(socket.handshake.auth.type == "vieux"){
//TODO
var id = socket.handshake.auth.id;
var equipe = equipes[id]
socket.on('changeState', function(d){
equipe.state = d;
io.to(id).emit('newState', d);
emit_update(id);
});
socket.emit('newState', equipe.state);
}
if(socket.handshake.auth.type == "Admin"){
socket.join("Admin");
//TODO
socket.on('newCode', function(d){
invisi[d.code] = true;
});
@ -221,25 +232,12 @@ io.on('connection', function(socket){
for(i in equipes){
var equipe = equipes[i];
socket.emit('moving', {"id": equipe.id, "color": equipe.color, "position": equipe.pos});
socket.emit('moving', {"id": equipe.id, "color": color(equipe), "position": equipe.pos});
}
}
//ici essentiellement tout est a refaire
// socket.on('changeColor', function(d){
// socket.color = d.color - 0;
// if(d.color == -1)
// socket.shown = false;
// else{
// if(!socket.shown)
// for(i in equipes)
// equipes[i].emit('moving', {"id": socket.id, "position": socket.position});
// socket.shown = true;
// }
// for(i in equipes)
// equipes[i].emit('changeColor', {"id": socket.id, "color": d.color});
// });
// socket.on('message', function(d){
// d.content = d.content.toLowerCase();
// if(d.content == PWD_TRACKED){