Compare commits

..

No commits in common. "4d9a5c1ca3f9483de543d546442b326089a41ff7" and "b835afcf71fc35bc9b200c6dc2c424121de534d4" have entirely different histories.

4 changed files with 47 additions and 201 deletions

View file

@ -18,18 +18,12 @@ if (isset($_GET['function'])) {
} else } else
show_error(); show_error();
/**
* Get the selectors of the map from the database
* A selector is the name/identifier of a building *
*/
function get_map_selectors() { function get_map_selectors() {
header('Content-Type: application/json'); header('Content-Type: application/json');
$dao = new Dao(); $dao = new Dao();
echo json_encode($dao->get_map_selectors()); echo json_encode($dao->get_map_selectors());
} }
function get_scores() { function get_scores() {
if (isset($_GET['team'])) { if (isset($_GET['team'])) {
header('Content-Type: application/json'); header('Content-Type: application/json');
@ -65,13 +59,6 @@ function get_activities_of_day() {
// Section pour les énigmes // Section pour les énigmes
// //
/**
* Tells if the team is the first to solve the enigma
* @param Array $score_data = { $team = Name of the team who posted
* $text = Name of the enigma
* }
* @return Bool = true if this team is the first, false otherwise
*/
function isFirstTeamToSolve($score_data) { function isFirstTeamToSolve($score_data) {
$team = $score_data['team']; $team = $score_data['team'];
$enigme = $score_data['text']; $enigme = $score_data['text'];
@ -88,12 +75,6 @@ function isFirstTeamToSolve($score_data) {
return true; return true;
} }
/**
* Tells if the team has already solved the enigma
* @param String $team = Name of the team
* @param String $enigme = Name of the enigma
* @return Bool = true if already solved, false otherwise
*/
function isAlreadySolved($team, $enigme) { function isAlreadySolved($team, $enigme) {
$dao = new Dao(); $dao = new Dao();
@ -101,18 +82,12 @@ function isAlreadySolved($team, $enigme) {
foreach($score as $value) { foreach($score as $value) {
if ($value['text'] == $enigme) if ($value['text'] == $enigme)
return true; return false;
} }
return false; return true;
} }
function isLastEnigmaSolved($enigme) {
/**
* Tells if an enigma is solved
* @param String $enigme = Name of the enigma
* @return Bool = true if the enigma is solved, false otherwise
*/
function isEnigmaSolved($enigme) {
$dao = new Dao(); $dao = new Dao();
$scorePek = $dao->get_score_team('pek'); $scorePek = $dao->get_score_team('pek');
$scoreBoo = $dao->get_score_team('boo'); $scoreBoo = $dao->get_score_team('boo');
@ -128,20 +103,8 @@ function isEnigmaSolved($enigme) {
// TODO : passer ça sous DB // TODO : passer ça sous DB
/**
* Get the enigma code posted and processes it
* @example ../../enigma.php
* @todo Improve it by adding an 'enigmes' table into the database
*/
function get_enigma_code() { function get_enigma_code() {
if (isset($_GET['code'])) { if (isset($_GET['code'])) {
/**
* Array that contains the data to display
* @var Array $data {
* @var String $name = Name of the enigma
* @var String $info = Displayed Content
* }
*/
$data = array( $data = array(
"name" => $_GET['code'], "name" => $_GET['code'],
"info" => null, "info" => null,
@ -151,14 +114,6 @@ function get_enigma_code() {
$time = new DateTime(); $time = new DateTime();
$date = $time->getTimestamp(); $date = $time->getTimestamp();
/**
* Array that contains the data to update the scores
* @var Array $score_data {
* @var String $text = Name of the enigma
* @var Int $points = Enigma's points
* @var String $team = Team who solved
* }
*/
$score_data = array( $score_data = array(
"text" => null, "text" => null,
"points" => 0, "points" => 0,
@ -166,9 +121,6 @@ function get_enigma_code() {
); );
// One case responds to a code found
// Bonus : See case Jean Jaurès for explanation
// Malus : See case 0712 for explanation
switch ($_GET['code']) { switch ($_GET['code']) {
case '501432' : case '501432' :
$data["name"] = "enigme-1"; $data["name"] = "enigme-1";
@ -396,17 +348,11 @@ function get_enigma_code() {
break; break;
case 'Jean Jaurès' : case 'Jean Jaurès' :
$data["name"] = "enigme-liberation-2";
$data["name"] = "enigme-liberation-2"; // Name of the div (must be unique) $score_data["text"] = 'Énigme Libération 2';
$score_data["text"] = 'Énigme Libération 2'; // Name of the enigma displayed (scores and pages) $score_data["points"] = 100;
$score_data["points"] = 100; // Add this amount of points to the team who first found this code if(isLastEnigmaSolved('Énigme Libération 1')) {
if($date < 1628613000) {
// This enigma must be solved if another has been solved
// It avoids enigmas found by accident and assure consistency in the resolution
if(isEnigmaSolved('Énigme Libération 1')) {
// Used to display what happens next at a specific time (timestamp UTC, check server time)
if($date < 1628613000) {
$data["info"] = "<h2>Énigme Libération 2</h2> $data["info"] = "<h2>Énigme Libération 2</h2>
<p>Vous avez compris le message des informateurs, aller dans le centre de la capitale de Panem vous parait évident maintenant. </p> <p>Vous avez compris le message des informateurs, aller dans le centre de la capitale de Panem vous parait évident maintenant. </p>
<p>Mais un virus tourne, il ne faudrait pas faire retentir le canon et perdre des tributs, alors ne passez pas trop de temps dans la ville ! <p>Mais un virus tourne, il ne faudrait pas faire retentir le canon et perdre des tributs, alors ne passez pas trop de temps dans la ville !
@ -418,12 +364,11 @@ function get_enigma_code() {
</p>"; </p>";
} }
// Give the points to the first team who solved the enigma
if(isFirstTeamToSolve($score_data)) { if(isFirstTeamToSolve($score_data)) {
$dao = new Dao(); $dao = new Dao();
$dao->add_score($score_data); $dao->add_score($score_data);
} }
echo json_encode($data, JSON_FORCE_OBJECT); // Display the new content echo json_encode($data, JSON_FORCE_OBJECT);
} }
break; break;
@ -431,7 +376,7 @@ function get_enigma_code() {
$data["name"] = "enigme-liberation-3-1"; $data["name"] = "enigme-liberation-3-1";
$score_data["text"] = 'Énigme Libération 3-1'; $score_data["text"] = 'Énigme Libération 3-1';
$score_data["points"] = 50; $score_data["points"] = 50;
if(isEnigmaSolved('Énigme Libération 2')) { if(isLastEnigmaSolved('Énigme Libération 2')) {
if($date < 1628613000) { if($date < 1628613000) {
$data["info"] = "<h2>Énigme Libération 3-1</h2> $data["info"] = "<h2>Énigme Libération 3-1</h2>
<p>Aucune perte du côté de votre district, tout va bien, vous avancez prudemment dans la ville…</p> <p>Aucune perte du côté de votre district, tout va bien, vous avancez prudemment dans la ville…</p>
@ -461,7 +406,7 @@ function get_enigma_code() {
$data["name"] = "enigme-liberation-3-2"; $data["name"] = "enigme-liberation-3-2";
$score_data["text"] = 'Énigme Libération 3-2'; $score_data["text"] = 'Énigme Libération 3-2';
$score_data["points"] = 50; $score_data["points"] = 50;
if(isEnigmaSolved('Énigme Libération 2')) { if(isLastEnigmaSolved('Énigme Libération 2')) {
if($date < 1628613000) { if($date < 1628613000) {
$data["info"] = "<h2>Énigme Libération 3-2</h2> $data["info"] = "<h2>Énigme Libération 3-2</h2>
<p>Aucune perte du côté de votre district, tout va bien, vous avancez prudemment dans la ville…</p> <p>Aucune perte du côté de votre district, tout va bien, vous avancez prudemment dans la ville…</p>
@ -493,7 +438,7 @@ function get_enigma_code() {
$data["name"] = "enigme-liberation-3-3"; $data["name"] = "enigme-liberation-3-3";
$score_data["text"] = 'Énigme Libération 3-3'; $score_data["text"] = 'Énigme Libération 3-3';
$score_data["points"] = 0; $score_data["points"] = 0;
if(isEnigmaSolved('Énigme Libération 3-2') || isEnigmaSolved('Énigme Libération 3-1')) { if(isLastEnigmaSolved('Énigme Libération 3-2') || isLastEnigmaSolved('Énigme Libération 3-1')) {
if($date < 1628613000) { if($date < 1628613000) {
$data["info"] = "<h2>Énigme Libération 3-3</h2> $data["info"] = "<h2>Énigme Libération 3-3</h2>
<a href=\"\">Je t'embarque au poste.</a>"; <a href=\"\">Je t'embarque au poste.</a>";
@ -514,7 +459,7 @@ function get_enigma_code() {
case 'Saint des seins' : case 'Saint des seins' :
$score_data["text"] = 'Malus Énigme Libération 1'; $score_data["text"] = 'Malus Énigme Libération 1';
$score_data["points"] = -25; $score_data["points"] = -25;
if(!isAlreadySolved($team, $score_data["text"])) { if(isAlreadySolved($team, $score_data["text"])) {
$dao = new Dao(); $dao = new Dao();
$dao->add_score($score_data); $dao->add_score($score_data);
} }
@ -524,7 +469,7 @@ function get_enigma_code() {
case 'La Couleur de la Culotte' : case 'La Couleur de la Culotte' :
$score_data["text"] = 'Malus Énigme Libération 2'; $score_data["text"] = 'Malus Énigme Libération 2';
$score_data["points"] = -25; $score_data["points"] = -25;
if(!isAlreadySolved($team, $score_data["text"])) { if(isAlreadySolved($team, $score_data["text"])) {
$dao = new Dao(); $dao = new Dao();
$dao->add_score($score_data); $dao->add_score($score_data);
} }
@ -532,20 +477,17 @@ function get_enigma_code() {
case '0712' : case '0712' :
$score_data["text"] = 'Malus Énigme Libération 3'; $score_data["text"] = 'Malus Énigme Libération 3';
$score_data["points"] = -25; // Malus points $score_data["points"] = -25;
if(isAlreadySolved($team, $score_data["text"])) {
// Give the points only if the team hasn't had the Malus yet
if(!isAlreadySolved($team, $score_data["text"])) {
$dao = new Dao(); $dao = new Dao();
$dao->add_score($score_data); $dao->add_score($score_data);
} }
break; break;
case '1108' : case '1108' :
$score_data["text"] = 'Malus Énigme Libération 4'; $score_data["text"] = 'Malus Énigme Libération 4';
$score_data["points"] = -25; $score_data["points"] = -25;
if(!isAlreadySolved($team, $score_data["text"])) { if(isAlreadySolved($team, $score_data["text"])) {
$dao = new Dao(); $dao = new Dao();
$dao->add_score($score_data); $dao->add_score($score_data);
} }
@ -555,7 +497,7 @@ function get_enigma_code() {
$data["name"] = "enigme-liberation-4"; $data["name"] = "enigme-liberation-4";
$score_data["text"] = 'Énigme Libération 4'; $score_data["text"] = 'Énigme Libération 4';
$score_data["points"] = 100; $score_data["points"] = 100;
if(isEnigmaSolved('Énigme Libération 3-1') && isEnigmaSolved('Énigme Libération 3-2')) { if(isLastEnigmaSolved('Énigme Libération 3-1') && isLastEnigmaSolved('Énigme Libération 3-2')) {
if($date < 1628613000) { if($date < 1628613000) {
$data["info"] = "<h2>Énigme Libération 4</h2> $data["info"] = "<h2>Énigme Libération 4</h2>
<p><a href=\"assets/enigmes/Liberation/FinE.png\">On vous demande un mot de passe pour rentrer</a></p>"; <p><a href=\"assets/enigmes/Liberation/FinE.png\">On vous demande un mot de passe pour rentrer</a></p>";
@ -576,34 +518,13 @@ function get_enigma_code() {
$data["name"] = "enigme-liberation-5"; $data["name"] = "enigme-liberation-5";
$score_data["text"] = 'Énigme Libération 5'; $score_data["text"] = 'Énigme Libération 5';
$score_data["points"] = 50; $score_data["points"] = 50;
if(isEnigmaSolved('Énigme Libération 4')) { if(isLastEnigmaSolved('Énigme Libération 4')) {
if($date < 1628613000) { if($date < 1628613000) {
$data["info"] = "<h2>Énigme Libération 5</h2> $data["info"] = "<h2>Énigme Libération 5</h2>
<p>Bien joué ! Attendez demain pour la suite !</p>"; <p>Bien joué ! Attendez demain pour la suite !</p>";
} else { } else {
$data["info"] = "<h2>Énigme Libération 5</h2> $data["info"] = "<h2>Énigme Libération 5</h2>
<p>Revenez aux sources..</p>";
}
if(isFirstTeamToSolve($score_data)) {
$dao = new Dao();
$dao->add_score($score_data);
}
echo json_encode($data, JSON_FORCE_OBJECT);
}
break;
case 'Le Trou' :
$data["name"] = "enigme-liberation-6";
$score_data["text"] = 'Énigme Libération 6';
$score_data["points"] = 200;
if(isEnigmaSolved('Énigme Libération 5')) {
if($date < 1628613000) {
$data["info"] = "<h2>Énigme Libération 6</h2>
<p>Bien joué ! Attendez demain pour la suite !</p>"; <p>Bien joué ! Attendez demain pour la suite !</p>";
} else {
$data["info"] = "<h2>Énigme Libération 6</h2>
<p>Suite à la libération de Paul et Cécile vous décidez de fêter ça...
</p>";
} }
if(isFirstTeamToSolve($score_data)) { if(isFirstTeamToSolve($score_data)) {
@ -613,29 +534,7 @@ function get_enigma_code() {
echo json_encode($data, JSON_FORCE_OBJECT); echo json_encode($data, JSON_FORCE_OBJECT);
} }
break; break;
case 'Allies comme Katniss et Peeta' :
$data["name"] = "enigme-liberation-7";
$score_data["text"] = 'Énigme Libération 7';
$score_data["points"] = 100;
if(isEnigmaSolved('Énigme Libération 6')) {
if($date < 1628613000) {
$data["info"] = "<h2>Énigme Libération 7</h2>
<p>Bien joué ! Attendez demain pour la suite !</p>";
} else {
$data["info"] = "<h2>Énigme Libération 7</h2>
<p>Les dirigeants du Capitole ont décidé dunir les équipes, les Boomiflores et les Peksureaux !
Ils préparent la prochaine énigme!
</p>";
}
if(isFirstTeamToSolve($score_data)) {
$dao = new Dao();
$dao->add_score($score_data);
}
echo json_encode($data, JSON_FORCE_OBJECT);
}
break;
default: default:
$data["name"] = null; $data["name"] = null;
$points_data["points"] = 0; $points_data["points"] = 0;
@ -647,10 +546,6 @@ function get_enigma_code() {
} }
} }
/**
* Same as get_code, but for the plaquette enigma
*/
function get_plaquette_code() { function get_plaquette_code() {
if (isset($_GET['code'])) { if (isset($_GET['code'])) {
$data = array( $data = array(

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.4 KiB

View file

@ -12,6 +12,10 @@ import {
import { import {
GLTFLoader GLTFLoader
} from 'https://cdn.jsdelivr.net/npm/three@0.119.1/examples/jsm/loaders/GLTFLoader.js'; } from 'https://cdn.jsdelivr.net/npm/three@0.119.1/examples/jsm/loaders/GLTFLoader.js';
import {
RGBELoader
} from 'https://cdn.jsdelivr.net/npm/three@0.119.1/examples/jsm/loaders/RGBELoader.js';
var container, stats, controls; var container, stats, controls;
var camera, scene, renderer; var camera, scene, renderer;
@ -23,16 +27,9 @@ render();
var height, width; var height, width;
/**
* Initializes the 3D plan
* Creates and loads every needed things
*/
function init() { function init() {
//
// Creates HTML
//
container = document.createElement('div'); container = document.createElement('div');
container.id = 'map3d'; container.id = 'map3d';
@ -40,18 +37,14 @@ function init() {
width = document.querySelector('#maps').clientWidth; width = document.querySelector('#maps').clientWidth;
var svg = document.querySelector('#maps #map'); var svg = document.querySelector('#maps #map');
document.querySelector('#maps').insertBefore(container, svg); document.querySelector('#maps').insertBefore(container, svg);
//
// Creates cameras and scene
//
camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.75, 20000); camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.75, 20000);
camera.position.set(500,1500,500); camera.position.set(500,1500,500);
scene = new THREE.Scene(); scene = new THREE.Scene();
//
// LIGHTS // LIGHTS
//
let sol = new THREE.AmbientLight(0x404040, 1.0); let sol = new THREE.AmbientLight(0x404040, 1.0);
scene.add(sol); scene.add(sol);
@ -65,23 +58,16 @@ function init() {
//scene.background = new THREE.Color( 0xff0000 ); //scene.background = new THREE.Color( 0xff0000 );
raycaster = new THREE.Raycaster(); raycaster = new THREE.Raycaster();
mouse = new THREE.Vector2() mouse = new THREE.Vector2()
//
// Loading screen // Loading screen
//
const loadingManager = new THREE.LoadingManager( () => { const loadingManager = new THREE.LoadingManager( () => {
const loadingScreen = document.getElementById('loading-screen'); const loadingScreen = document.getElementById('loading-screen');
loadingScreen.classList.add('fade-out'); loadingScreen.classList.add('fade-out');
loadingScreen.addEventListener('transitionend', onTransitionEnd); loadingScreen.addEventListener('transitionend', onTransitionEnd);
}); });
//
// Load the 3D model
//
var loader = new GLTFLoader(loadingManager); var loader = new GLTFLoader(loadingManager);
loader.load('assets/images/map3D.glb', function(gltf) { loader.load('assets/images/map3D.glb', function(gltf) {
@ -99,9 +85,6 @@ function init() {
//
// RENDERER
//
renderer = new THREE.WebGLRenderer({ renderer = new THREE.WebGLRenderer({
antialias: true, antialias: true,
}); });
@ -117,9 +100,6 @@ function init() {
var pmremGenerator = new THREE.PMREMGenerator(renderer); var pmremGenerator = new THREE.PMREMGenerator(renderer);
pmremGenerator.compileEquirectangularShader(); pmremGenerator.compileEquirectangularShader();
//
// CONTROLS
//
controls = new OrbitControls(camera, renderer.domElement); controls = new OrbitControls(camera, renderer.domElement);
controls.addEventListener('change', render); // use if there is no animation loop controls.addEventListener('change', render); // use if there is no animation loop
controls.minDistance = 0; controls.minDistance = 0;
@ -129,9 +109,7 @@ function init() {
controls.maxPolarAngle = Math.PI/2.05; controls.maxPolarAngle = Math.PI/2.05;
controls.update(); controls.update();
//
// Load Light // Load Light
//
var ambientLight = new THREE.AmbientLight( 0xcccccc ); var ambientLight = new THREE.AmbientLight( 0xcccccc );
scene.add( ambientLight ); scene.add( ambientLight );
@ -139,11 +117,9 @@ function init() {
directionalLight.position.set( 0, 1, 1 ).normalize(); directionalLight.position.set( 0, 1, 1 ).normalize();
scene.add( directionalLight ); scene.add( directionalLight );
window.addEventListener('resize', onWindowResize, false);
//
// EVENTS
//
window.addEventListener('resize', onWindowResize, false);
renderer.domElement.addEventListener('click', onClick, false); // Mouse renderer.domElement.addEventListener('click', onClick, false); // Mouse
//renderer.domElement.addEventListener('mousemove', onMouseOver,false); //renderer.domElement.addEventListener('mousemove', onMouseOver,false);
@ -151,10 +127,7 @@ function init() {
} }
/** // Return all the selectors in the database
* Get all the selectors (buildings identifiers)
* @returns Array with all the selectors
*/
function getSelectors() { function getSelectors() {
let info = {}; let info = {};
let object = { let object = {
@ -187,8 +160,9 @@ function handleClickOnBuilding(x,y) {
// If we clicked on a building // If we clicked on a building
if (intersects.length > 0) { if (intersects.length > 0) {
// console.log(intersects);
var selector = intersects[0].object.name.toString().toLowerCase(); // Name of the building we clicked on //console.log( intersects[0].object.name.toString());
var selector = intersects[0].object.name.toString().toLowerCase();
// Wait for getSelectors() to be done // Wait for getSelectors() to be done
// If we do not wait, everything will be executed before checking what is inside the database // If we do not wait, everything will be executed before checking what is inside the database
@ -229,9 +203,9 @@ function handleClickOnBuilding(x,y) {
} }
} }
/** //
* Get the position where the user clicked (mouse) on a building and process it // When the user clicks on a building with a mouse
*/ //
function onClick() { function onClick() {
event.preventDefault(); event.preventDefault();
@ -247,9 +221,9 @@ function onClick() {
} }
/** //
* Get the position where the user clicked (smartphone) on a building and process it // When the user clicks on a building on a smartphone
*/ //
function onTouchEnd() { function onTouchEnd() {
var clientX, clientY; var clientX, clientY;
@ -263,11 +237,6 @@ function onTouchEnd() {
handleClickOnBuilding(mouse.x, mouse.y); handleClickOnBuilding(mouse.x, mouse.y);
} }
/**
* Process something when the user moved the mouse over a building
* @todo add text over the building
*/
function onMouseOver() { function onMouseOver() {
event.preventDefault(); event.preventDefault();
@ -344,10 +313,9 @@ function makeLabelCanvas(baseWidth, size, name) {
return ctx.canvas; return ctx.canvas;
} }
//
/** // Auto-resize the canvas
* Auto-resizes the canvas when window size is updated //
*/
function onWindowResize() { function onWindowResize() {
height = document.querySelector('#main-content .inner').clientHeight; height = document.querySelector('#main-content .inner').clientHeight;
@ -355,22 +323,19 @@ function onWindowResize() {
camera.aspect = window.innerWidth / window.innerHeight; camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix(); camera.updateProjectionMatrix();
renderer.setSize(width * 0.9, window.innerHeight * 0.75); // 0.9 and 0.75 so it looks comfortable on the screen renderer.setSize(width * 0.9, window.innerHeight * 0.75);
render(); render();
} }
/**
* Render the scene
*/
function render() { function render() {
renderer.render(scene, camera); renderer.render(scene, camera);
} }
/* /*
* Remove the loader when the model loaded * When the model finished loading
*/ */
function onTransitionEnd( event) { function onTransitionEnd( event) {
event.target.remove(); event.target.remove();

View file

@ -107,39 +107,25 @@ class Dao
} }
} }
/**
* Add a building in the database
* @param String $title = Name of the building displayed
* @param String $description = Description of the building
* @param String $selector = Identifier of the building (unique)
* @return Mixed = if error : false
* else : Array of the row added as an array indexed by column name
*/
public function create_building($title, $description, $selector) { public function create_building($title, $description, $selector) {
$sql = 'INSERT INTO map_insa (title, description, selector) VALUES(:title, :description, :selector)'; $sql = 'INSERT INTO map_insa (title, description, selector) VALUES(:title, :description, :selector)';
//var_dump($title, $description, $selector);
$query = $this->conn->prepare($sql); $query = $this->conn->prepare($sql);
$query->execute(array( $query->execute(array(
':title' => $title, ':title' => $title,
':description' => $description, ':description' => $description,
':selector' => $selector, ':selector' => $selector,
)); ));
//var_dump($query->errorInfo());
return $query->fetch(PDO::FETCH_ASSOC); return $query->fetch(PDO::FETCH_ASSOC);
} }
/**
* Remove a building in the database
* @param String $selector = Identifier of the building (unique)
* @return Mixed = if error : false
* else : Array with the selector used to remove from the database
*/
public function delete_building($selector) { public function delete_building($selector) {
$sql = 'DELETE FROM map_insa WHERE selector=?'; $sql = 'DELETE FROM map_insa WHERE selector=?';
//var_dump($selector);
$query = $this->conn->prepare($sql); $query = $this->conn->prepare($sql);
$query->execute([$selector]); $query->execute([$selector]);
//var_dump($query->errorInfo());
return $query->fetch(PDO::FETCH_ASSOC); return $query->fetch(PDO::FETCH_ASSOC);
} }
} }