This commit is contained in:
Simon Vieille 2020-10-31 18:34:26 +01:00
commit e1384e2272
Signed by: deblan
GPG key ID: 03383D15A1D31745
18 changed files with 4260 additions and 0 deletions

5
.gitignore vendored Normal file
View file

@ -0,0 +1,5 @@
/.mage.yml
/datas/*
!/datas/.gitkeep
/src
/etc/config.php

68
assets/css/app.css Normal file
View file

@ -0,0 +1,68 @@
body {
margin: 0;
font: normal 75% Arial, Helvetica, sans-serif;
overflow: hidden;
}
canvas {
display: block;
vertical-align: bottom;
}
img {
max-width: 100%;
}
@font-face {
font-family: 'Wendy LP Std';
src: url('../fonts/wendy.eot');
src: url('../fonts/wendy.eot?#iefix') format('embedded-opentype'),
url('../fonts/wendy.woff2') format('woff2'),
url('../fonts/wendy.woff') format('woff'),
url('../fonts/wendy.ttf') format('truetype'),
url('../fonts/wendy.svg#Wendy LP Std') format('svg');
}
.center {
text-align: center;
}
#particles-js {
position: absolute;
width: 100%;
height: 100%;
background-color: #b61924;
background-image: url('');
background-repeat: no-repeat;
background-size: cover;
background-position: 50% 50%;
}
#content-wrapper {
top: 0;
left: 0;
position: absolute;
height: 100vh;
width: 100%;
}
#content {
max-width: 880px;
margin: auto;
padding: 10px 0;
font-family: 'Wendy LP Std';
color: #fff;
}
#player {
font-size: 40px;
margin-top: 30px;
}
#balls {
padding: 10px;
}
#balls img {
max-height: calc(100vh - 100vh/2.5);
}

BIN
assets/fonts/wendy.eot Normal file

Binary file not shown.

1685
assets/fonts/wendy.svg Normal file

File diff suppressed because it is too large Load diff

After

Width:  |  Height:  |  Size: 140 KiB

BIN
assets/fonts/wendy.ttf Normal file

Binary file not shown.

BIN
assets/fonts/wendy.woff Normal file

Binary file not shown.

BIN
assets/fonts/wendy.woff2 Normal file

Binary file not shown.

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 30 KiB

497
assets/img/pot.svg Normal file

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 3.1 MiB

110
assets/js/app.js Normal file
View file

@ -0,0 +1,110 @@
particlesJS("particles-js", {
"particles": {
"number": {
"value": 100,
"density": {
"enable": false,
"value_area": 800
}
},
"color": {
"value": "#fff"
},
"shape": {
"type": "circle",
"stroke": {
"width": 0,
"color": "#000000"
},
"polygon": {
"nb_sides": 5
},
"image": {
"src": "img/github.svg",
"width": 100,
"height": 100
}
},
"opacity": {
"value": 0.5,
"random": true,
"anim": {
"enable": false,
"speed": 1,
"opacity_min": 0.1,
"sync": false
}
},
"size": {
"value": 10,
"random": true,
"anim": {
"enable": false,
"speed": 40,
"size_min": 0.1,
"sync": false
}
},
"line_linked": {
"enable": false,
"distance": 500,
"color": "#ffffff",
"opacity": 0.4,
"width": 2
},
"move": {
"enable": true,
"speed": 6,
"direction": "bottom",
"random": false,
"straight": false,
"out_mode": "out",
"bounce": false,
"attract": {
"enable": false,
"rotateX": 600,
"rotateY": 1200
}
}
},
"interactivity": {
"detect_on": "canvas",
"events": {
"onhover": {
"enable": false,
"mode": "bubble"
},
"onclick": {
"enable": false,
"mode": "repulse"
},
"resize": true
},
"modes": {
"grab": {
"distance": 400,
"line_linked": {
"opacity": 0.5
}
},
"bubble": {
"distance": 400,
"size": 4,
"duration": 0.3,
"opacity": 1,
"speed": 3
},
"repulse": {
"distance": 200,
"duration": 0.4
},
"push": {
"particles_nb": 4
},
"remove": {
"particles_nb": 2
}
}
},
"retina_detect": false
});

1541
assets/js/particles.js Normal file

File diff suppressed because it is too large Load diff

0
datas/.gitkeep Normal file
View file

19
etc/config.php.dist Normal file
View file

@ -0,0 +1,19 @@
<?php
$persons = [
'foo' => 'Name 1',
'bar' => 'Name 2',
'boo' => 'Name 3',
'bim' => 'Name 4',
'doo' => 'Name 5',
'dao' => 'Name 6',
'dao' => 'Name 7',
'fao' => 'Name 8',
'dfo' => 'Name 9',
'dap' => 'Name 10',
];
$restrictions = [
['Name 1', 'Name 4'],
['Name 2', 'Name 3'],
];

27
etc/database.php Normal file
View file

@ -0,0 +1,27 @@
<?php
$databasePath = __DIR__.'/../datas/results.json';
$database = [];
if (file_exists($databasePath)) {
$database = json_decode(file_get_contents($databasePath), true);
}
function getData($key, $default = null) {
global $database;
return $database[$key] ?? $default;
}
function setData($key, $value) {
global $database;
return $database[$key] = $value;
}
function saveDatabase() {
global $databasePath;
global $database;
file_put_contents($databasePath, json_encode($database));
}

58
index.php Normal file
View file

@ -0,0 +1,58 @@
<?php
require __DIR__.'/etc/config.php';
require __DIR__.'/etc/database.php';
$_ = [
'canPlay' => false,
'player' => null,
];
$personRequested = $_GET['p'] ?? null;
foreach ($persons as $hash => $person) {
if ($personRequested === $hash) {
$_['player'] = $person;
$_['hash'] = $personRequested;
}
}
if ($_['player']) {
$_['result'] = getData('result.'.$_['player']);
$_['canPlay'] = empty($_['result']);
$in = getData('in', $persons);
$out = getData('out', []);
if ($_['canPlay'] && isset($_GET['go'])) {
$result = null;
while ($result === null) {
$key = array_rand($in);
$value = $in[$key];
$ok = $value !== $_['player'];
foreach ($restrictions as $restriction) {
if (in_array($value, $restriction) && in_array($_['player'], $restriction)) {
$ok = false;
}
}
if ($ok) {
$result = $value;
setData('result.'.$_['player'], $result);
unset($in[$key]);
$out[] = $value;
$_['canPlay'] = false;
$_['result'] = $result;
}
}
setData('in', $in);
setData('out', $out);
saveDatabase();
}
}
require __DIR__.'/template/index.php';

10
links.php Normal file
View file

@ -0,0 +1,10 @@
<?php
require __DIR__.'/etc/config.php';
require __DIR__.'/etc/database.php';
$_ = [
'persons' => $persons,
];
require __DIR__.'/template/links.php';

56
template/index.php Normal file
View file

@ -0,0 +1,56 @@
<?php $cache = date('dmyHis'); ?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta charset="UTF-8">
<title>Le père noël secret</title>
<link rel="stylesheet" href="/assets/css/app.css?v=<?php echo $cache; ?>">
</head>
<body>
<div id="particles-js"></div>
<div id="content-wrapper">
<div id="content">
<div class="center">
<img src="/assets/img/le-pere-noel-secret.svg" width="500px">
</div>
<?php if ($_['canPlay']): ?>
<div class="center">
<div id="player">
À ton tour, <?php echo $_['player']; ?>&nbsp;!
</div>
</div>
<div class="center">
<div id="balls">
<a href="/?p=<?php echo $_['hash'] ?>&amp;go=1">
<img src="assets/img/pot.svg">
</a>
</div>
</div>
<?php endif; ?>
<?php if (!$_['canPlay'] && $_['player'] !== null): ?>
<div class="center">
<div id="player">
La personne à qui tu dois offrir un cadeau est <?php echo $_['result']; ?>&nbsp;!<br>
</div>
</div>
<?php endif; ?>
<?php if ($_['player'] === null): ?>
<div class="center">
<div id="player">
Oops, il y un bug dans la matrice !
</div>
</div>
<?php endif; ?>
</div>
</div>
<script src="/assets/js/particles.js?v=<?php echo $cache; ?>"></script>
<script src="/assets/js/app.js?v=<?php echo $cache; ?>"></script>
</body>
</html>

21
template/links.php Normal file
View file

@ -0,0 +1,21 @@
<?php $cache = date('dmyHis'); ?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta charset="UTF-8">
<title>Le père noël secret</title>
<link rel="stylesheet" href="/assets/css/app.css?v=<?php echo $cache; ?>">
</head>
<body>
<ul>
<?php foreach ($_['persons'] as $hash => $person): ?>
<li>
<a href="/?p=<?php echo $hash ?>">
<?php echo $person; ?>
</a>
</li>
<?php endforeach; ?>
</ul>
</body>
</html>