Compare commits

..

3 commits

Author SHA1 Message Date
Ronan
4d9a5c1ca3 Documented code 2021-08-25 22:54:50 +02:00
Ronan
0878258425 Enigma liberation more pics 2021-08-25 22:54:33 +02:00
Ronan
b1ad5fcffa Enigma Liberation end 2021-08-25 22:53:42 +02:00
4 changed files with 202 additions and 48 deletions

View file

@ -18,12 +18,18 @@ 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');
@ -59,6 +65,13 @@ 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'];
@ -75,6 +88,12 @@ 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();
@ -82,12 +101,18 @@ function isAlreadySolved($team, $enigme) {
foreach($score as $value) { foreach($score as $value) {
if ($value['text'] == $enigme) if ($value['text'] == $enigme)
return false; return true;
} }
return true; return false;
} }
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');
@ -103,8 +128,20 @@ function isLastEnigmaSolved($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,
@ -114,6 +151,14 @@ 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,
@ -121,6 +166,9 @@ 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";
@ -348,10 +396,16 @@ function get_enigma_code() {
break; break;
case 'Jean Jaurès' : case 'Jean Jaurès' :
$data["name"] = "enigme-liberation-2";
$score_data["text"] = 'Énigme Libération 2'; $data["name"] = "enigme-liberation-2"; // Name of the div (must be unique)
$score_data["points"] = 100; $score_data["text"] = 'Énigme Libération 2'; // Name of the enigma displayed (scores and pages)
if(isLastEnigmaSolved('Énigme Libération 1')) { $score_data["points"] = 100; // Add this amount of points to the team who first found this code
// 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) { 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>
@ -364,11 +418,12 @@ 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); echo json_encode($data, JSON_FORCE_OBJECT); // Display the new content
} }
break; break;
@ -376,7 +431,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(isLastEnigmaSolved('Énigme Libération 2')) { if(isEnigmaSolved('É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>
@ -406,7 +461,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(isLastEnigmaSolved('Énigme Libération 2')) { if(isEnigmaSolved('É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>
@ -438,7 +493,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(isLastEnigmaSolved('Énigme Libération 3-2') || isLastEnigmaSolved('Énigme Libération 3-1')) { if(isEnigmaSolved('Énigme Libération 3-2') || isEnigmaSolved('É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>";
@ -459,7 +514,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);
} }
@ -469,7 +524,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);
} }
@ -477,17 +532,20 @@ 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; $score_data["points"] = -25; // Malus points
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);
} }
@ -497,7 +555,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(isLastEnigmaSolved('Énigme Libération 3-1') && isLastEnigmaSolved('Énigme Libération 3-2')) { if(isEnigmaSolved('Énigme Libération 3-1') && isEnigmaSolved('É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>";
@ -518,13 +576,34 @@ 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(isLastEnigmaSolved('Énigme Libération 4')) { if(isEnigmaSolved('É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)) {
@ -535,6 +614,28 @@ function get_enigma_code() {
} }
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;
@ -546,6 +647,10 @@ 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.

After

Width:  |  Height:  |  Size: 9.4 KiB

View file

@ -12,10 +12,6 @@ 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;
@ -27,9 +23,16 @@ 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';
@ -37,14 +40,18 @@ 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);
@ -58,16 +65,23 @@ 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) {
@ -85,6 +99,9 @@ function init() {
//
// RENDERER
//
renderer = new THREE.WebGLRenderer({ renderer = new THREE.WebGLRenderer({
antialias: true, antialias: true,
}); });
@ -100,6 +117,9 @@ 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;
@ -109,7 +129,9 @@ 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 );
@ -117,17 +139,22 @@ function init() {
directionalLight.position.set( 0, 1, 1 ).normalize(); directionalLight.position.set( 0, 1, 1 ).normalize();
scene.add( directionalLight ); scene.add( directionalLight );
//
// EVENTS
//
window.addEventListener('resize', onWindowResize, false); 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);
renderer.domElement.addEventListener('touchend', onTouchEnd, false); // Smartphone renderer.domElement.addEventListener('touchend', onTouchEnd, false); // Smartphone
} }
// 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 = {
@ -160,9 +187,8 @@ 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);
//console.log( intersects[0].object.name.toString()); var selector = intersects[0].object.name.toString().toLowerCase(); // Name of the building we clicked on
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
@ -203,9 +229,9 @@ function handleClickOnBuilding(x,y) {
} }
} }
// /**
// When the user clicks on a building with a mouse * Get the position where the user clicked (mouse) on a building and process it
// */
function onClick() { function onClick() {
event.preventDefault(); event.preventDefault();
@ -221,9 +247,9 @@ function onClick() {
} }
// /**
// When the user clicks on a building on a smartphone * Get the position where the user clicked (smartphone) on a building and process it
// */
function onTouchEnd() { function onTouchEnd() {
var clientX, clientY; var clientX, clientY;
@ -237,6 +263,11 @@ 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();
@ -313,9 +344,10 @@ 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;
@ -323,19 +355,22 @@ 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); renderer.setSize(width * 0.9, window.innerHeight * 0.75); // 0.9 and 0.75 so it looks comfortable on the screen
render(); render();
} }
/**
* Render the scene
*/
function render() { function render() {
renderer.render(scene, camera); renderer.render(scene, camera);
} }
/* /*
* When the model finished loading * Remove the loader when the model loaded
*/ */
function onTransitionEnd( event) { function onTransitionEnd( event) {
event.target.remove(); event.target.remove();

View file

@ -107,25 +107,39 @@ 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);
} }
} }