10 Commits

Author SHA1 Message Date
gvcgael
6d92ccb908 new algorithm 2022-11-30 22:54:29 +01:00
gvcgael
487b6312f6 wip : shuffle at the init phase 2022-11-30 18:38:22 +01:00
gvcgael
1e7dbc61e9 add logs 2022-11-30 16:45:37 +01:00
f34980e28f Merge pull request 'feat(verif): add a confirm dialog for tocards' (#3) from feat/french_with_check into french
Reviewed-on: #3
2022-11-30 15:20:39 +00:00
qdegrandmaison
e5e23caab8 feat(verif): no need for a DOM node 2022-11-30 16:10:09 +01:00
qdegrandmaison
21bb6add65 feat(verif): add a confirm dialog for tocards 2022-11-30 16:08:41 +01:00
gvcgael
c39968865c french lang 2022-11-30 14:39:47 +01:00
qdegrandmaison
a17ce6ad8a fix(js): remove test data 2022-11-30 14:08:11 +01:00
qdegrandmaison
4358baa1b7 fix(css): dirty support of multiple viewports 2022-11-30 14:01:11 +01:00
qdegrandmaison
34314cbdfb feat(css): add customization 2022-11-30 13:20:25 +01:00
4 changed files with 850 additions and 58 deletions

91
Cargo.lock generated
View File

@@ -3,16 +3,36 @@
version = 3
[[package]]
name = "async-trait"
version = "0.1.58"
name = "aho-corasick"
version = "0.7.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e805d94e6b5001b651426cf4cd446b1ab5f319d27bab5c644f61de0a804360c"
checksum = "cc936419f96fa211c1b9166887b38e5e40b19958e5b895be7c1f93adec7071ac"
dependencies = [
"memchr",
]
[[package]]
name = "async-trait"
version = "0.1.59"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "31e6e93155431f3931513b243d371981bb2770112b370c82745a1d19d2f99364"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "atty"
version = "0.2.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
dependencies = [
"hermit-abi",
"libc",
"winapi",
]
[[package]]
name = "autocfg"
version = "1.1.0"
@@ -21,9 +41,9 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
[[package]]
name = "axum"
version = "0.6.0"
version = "0.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "744864363a200a5e724a7e61bc8c11b6628cf2e3ec519c8a1a48e609a8156b40"
checksum = "08b108ad2665fa3f6e6a517c3d80ec3e77d224c47d605167aefaa5d7ef97fa48"
dependencies = [
"async-trait",
"axum-core",
@@ -87,6 +107,19 @@ version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "env_logger"
version = "0.9.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a12e6657c4c97ebab115a42dcee77225f7f482cdd841cf7088c657a42e9e00e7"
dependencies = [
"atty",
"humantime",
"log",
"regex",
"termcolor",
]
[[package]]
name = "fnv"
version = "1.0.7"
@@ -195,6 +228,12 @@ version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421"
[[package]]
name = "humantime"
version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4"
[[package]]
name = "hyper"
version = "0.14.23"
@@ -256,9 +295,9 @@ dependencies = [
[[package]]
name = "matchit"
version = "0.6.0"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3dfc802da7b1cf80aefffa0c7b2f77247c8b32206cc83c270b61264f5b360a80"
checksum = "b87248edafb776e59e6ee64a79086f65890d3510f2c656c000bf2a7e8a0aea40"
[[package]]
name = "memchr"
@@ -414,6 +453,8 @@ version = "1.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e076559ef8e241f2ae3479e36f97bd5741c0330689e217ad51ce2c76808b868a"
dependencies = [
"aho-corasick",
"memchr",
"regex-syntax",
]
@@ -446,18 +487,18 @@ checksum = "4501abdff3ae82a1c1b477a17252eb69cee9e66eb915c1abaa4f44d873df9f09"
[[package]]
name = "serde"
version = "1.0.147"
version = "1.0.148"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d193d69bae983fc11a79df82342761dfbf28a99fc8d203dca4c3c1b590948965"
checksum = "e53f64bb4ba0191d6d0676e1b141ca55047d83b74f5607e6d8eb88126c52c2dc"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.147"
version = "1.0.148"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4f1d362ca8fc9c3e3a7484440752472d68a6caa98f1ab81d99b5dfe517cec852"
checksum = "a55492425aa53521babf6137309e7d34c20bbfbbfcfe2c7f3a047fd1f6b92c0c"
dependencies = [
"proc-macro2",
"quote",
@@ -501,6 +542,8 @@ name = "sesan"
version = "0.1.0"
dependencies = [
"axum",
"env_logger",
"log",
"once_cell",
"rand",
"serde",
@@ -535,9 +578,9 @@ dependencies = [
[[package]]
name = "syn"
version = "1.0.103"
version = "1.0.104"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a864042229133ada95abf3b54fdc62ef5ccabe9515b64717bcb9a1919e59445d"
checksum = "4ae548ec36cf198c0ef7710d3c230987c2d6d7bd98ad6edc0274462724c585ce"
dependencies = [
"proc-macro2",
"quote",
@@ -550,6 +593,15 @@ version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "20518fe4a4c9acf048008599e464deb21beeae3d3578418951a189c235a7a9a8"
[[package]]
name = "termcolor"
version = "1.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755"
dependencies = [
"winapi-util",
]
[[package]]
name = "thread_local"
version = "1.1.4"
@@ -577,9 +629,9 @@ dependencies = [
[[package]]
name = "tokio-macros"
version = "1.8.0"
version = "1.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9724f9a975fb987ef7a3cd9be0350edcbe130698af5b8f7a631e23d42d052484"
checksum = "d266c00fde287f55d3f1c3e96c500c362a2b8c695076ec180f27918820bc6df8"
dependencies = [
"proc-macro2",
"quote",
@@ -734,6 +786,15 @@ version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
[[package]]
name = "winapi-util"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178"
dependencies = [
"winapi",
]
[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"

View File

@@ -12,3 +12,5 @@ tracing-subscriber = { version = "0.3.16", features = ["env-filter"] }
serde = { version = "1.0", features = ["derive"] }
once_cell = "1.8.0"
rand = "0.8.4"
log = "0.4.0"
env_logger = "0.9.0"

View File

@@ -1,34 +1,740 @@
<!doctype html>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>Secret Santa</title>
<!-- Christmas tree from https://codepen.io/lenasta92579651/pen/xxERxBx -->
<!-- CSS snowflakes from https://pajasevi.github.io/CSSnowflakes/ -->
</head>
<body>
<!-- Content -->
<h1>Secret Santa</h1>
<select id="person">
<option selected disabled>Who is drawing?</option>
<option selected disabled>Qui es-tu?</option>
__OPTIONS__
</select>
<div id="result"></div>
<h2 id="result"></h2>
<!-- Christmas tree -->
<div id="christmas-container">
<div class="christmas">
<div class="tree">
<div class="chain"></div>
<div class="chain2"></div>
</div>
<div class="lights">
<div class="light1"></div>
<div class="light2"></div>
<div class="light3"></div>
<div class="light4"></div>
<div class="light5"></div>
<div class="light6"></div>
<div class="light7"></div>
<div class="light8"></div>
<div class="light9"></div>
<div class="light10"></div>
</div>
<div class="balls">
<div class="ball1"></div>
</div>
<div class="star"></div>
<div class="gift"></div>
<div class="ribbon"></div>
<div class="gift2"></div>
<div class="ribbon2"></div>
<div class="gift3"></div>
<div class="ribbon3"></div>
<div class="shadow"></div>
</div>
</div>
<!-- Snowflakes -->
<div class="snowflakes" aria-hidden="true">
<div class="snowflake"></div>
<div class="snowflake"></div>
<div class="snowflake"></div>
<div class="snowflake"></div>
<div class="snowflake"></div>
<div class="snowflake"></div>
<div class="snowflake"></div>
<div class="snowflake"></div>
<div class="snowflake"></div>
<div class="snowflake"></div>
<div class="snowflake"></div>
<div class="snowflake"></div>
</div>
<script>
document.getElementById("person").addEventListener('change', event => {
document.getElementById("person").addEventListener("change", (event) => {
if (
window.confirm(
`Vérification! Tu es ${event.target.value}, c'est bien ça?`
)
) {
const options = {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ "person": event.target.value })
body: JSON.stringify({ person: event.target.value }),
};
console.log(options);
fetch("api", options)
.then(response => response.text())
.then(text => {
document.getElementById("result").textContent = `Your draw: ${text}`;
.then((response) => response.text())
.then((text) => {
document.getElementById(
"result"
).textContent = `Hoho! Tu as pioché ${text} ;`;
document.getElementById("person").remove();
});
}
});
</script>
</body>
<style>
/** Page settings **/
body {
background-color: #3f69c7;
height: 100vh;
display: flex;
flex-direction: column;
justify-content: space-between;
align-items: center;
margin: 0;
padding: 0;
overflow: hidden;
}
h1 {
color: white;
font-family: Arial, Helvetica, sans-serif;
font-size: 5em;
text-align: center;
z-index: 10;
}
select {
z-index: 10;
}
h2 {
color: white;
font-family: Arial, Helvetica, sans-serif;
font-size: 3em;
text-align: center;
z-index: 10;
background: rgba(0, 0, 0, 0.5);
}
#christmas-container {
position: fixed;
right: 20%;
bottom: 30%;
}
/** Christmas tree **/
.christmas {
position: relative;
}
.tree {
position: relative;
background-color: #685044;
width: 30px;
height: 80px;
top: 100px;
transform-style: preserve-3d;
}
.tree:before {
content: "";
position: relative;
width: 0;
height: 0;
border-left: 90px solid transparent;
border-right: 90px solid transparent;
border-bottom: 270px solid #0e9594;
border-radius: 30px;
top: -250px;
left: -75px;
}
.chain {
width: 85px;
height: 85px;
border: solid 3px #333;
border-radius: 50%;
top: -185px;
left: -35px;
position: absolute;
transform: rotate3d(8, 0.1, -5, 75deg);
box-sizing: border-box;
backface-visibility: visible !important;
z-index: 5;
}
.chain2 {
width: 145px;
height: 135px;
border: solid 3px #333;
border-radius: 50%;
top: -115px;
left: -65px;
position: absolute;
transform: rotate3d(8, 0.1, -5, 75deg);
box-sizing: border-box;
backface-visibility: visible !important;
z-index: 5;
}
.shadow {
background-color: rgba(0, 0, 0, 0.07);
position: absolute;
width: 250px;
height: 30px;
border-radius: 50%;
top: 170px;
left: -115px;
z-index: -1;
}
.star {
margin: 50px 0;
position: absolute;
display: block;
width: 0px;
height: 0px;
border-right: 25px solid transparent;
border-bottom: 17.5px solid #f9dc5c;
border-left: 25px solid transparent;
transform: rotate(35deg);
top: -190px;
left: -9px;
}
.star:before {
border-bottom: 20px solid #f9dc5c;
border-left: 7.5px solid transparent;
border-right: 7.5px solid transparent;
position: absolute;
height: 0;
width: 0;
top: -12.5px;
left: -17.5px;
display: block;
content: "";
transform: rotate(-35deg);
}
.star:after {
position: absolute;
display: block;
top: 0.75px;
left: -26.25px;
width: 0px;
height: 0px;
border-right: 25px solid transparent;
border-bottom: 17.5px solid #f9dc5c;
border-left: 25px solid transparent;
transform: rotate(-70deg);
content: "";
}
.lights {
position: absolute;
}
.light1 {
position: absolute;
width: 15px;
height: 15px;
border-radius: 10px 150px 30px 150px;
}
.light1 {
background-color: #ff595e;
top: -100px;
left: -35px;
transform: rotate(40deg);
box-shadow: 1px 1px 15px #faf3dd;
}
.light2 {
position: absolute;
background-color: #ffca3a;
top: -95px;
left: -10px;
box-shadow: 1px 1px 15px #faf3dd;
width: 15px;
height: 15px;
border-radius: 10px 150px 30px 150px;
transform: rotate(40deg);
}
.light3 {
position: absolute;
background-color: #6a4c93;
top: -105px;
left: 15px;
box-shadow: 1px 1px 15px #faf3dd;
width: 15px;
height: 15px;
border-radius: 10px 150px 30px 150px;
transform: rotate(40deg);
}
.light4 {
position: absolute;
background-color: #1982c4;
top: -118px;
left: 35px;
box-shadow: 1px 1px 15px #faf3dd;
width: 15px;
height: 15px;
border-radius: 10px 150px 30px 150px;
transform: rotate(40deg);
}
.light5 {
position: absolute;
background-color: #1982c4;
top: 12px;
left: -55px;
box-shadow: 1px 1px 15px #faf3dd;
width: 15px;
height: 15px;
border-radius: 10px 150px 30px 150px;
transform: rotate(40deg);
}
.light6 {
position: absolute;
background-color: #8ac926;
top: 15px;
left: -25px;
box-shadow: 1px 1px 15px #faf3dd;
width: 15px;
height: 15px;
border-radius: 10px 150px 30px 150px;
transform: rotate(40deg);
}
.light7 {
position: absolute;
background-color: #ff595e;
top: 10px;
left: 2px;
box-shadow: 1px 1px 15px #faf3dd;
width: 15px;
height: 15px;
border-radius: 10px 150px 30px 150px;
transform: rotate(40deg);
}
.light8 {
position: absolute;
background-color: #ffca3a;
top: -2px;
left: 27px;
box-shadow: 1px 1px 15px #faf3dd;
width: 15px;
height: 15px;
border-radius: 10px 150px 30px 150px;
transform: rotate(40deg);
}
.light9 {
position: absolute;
background-color: #9e0059;
top: -17px;
left: 50px;
box-shadow: 1px 1px 15px #faf3dd;
width: 15px;
height: 15px;
border-radius: 10px 150px 30px 150px;
transform: rotate(40deg);
}
.light10 {
position: absolute;
background-color: #4361ee;
top: -40px;
left: 68px;
box-shadow: 1px 1px 15px #faf3dd;
width: 15px;
height: 15px;
border-radius: 10px 150px 30px 150px;
transform: rotate(40deg);
}
.gift {
position: absolute;
width: 60px;
height: 50px;
background-color: #ffc857;
top: 130px;
left: 30px;
box-shadow: inset -8px 0 0 rgba(0, 0, 0, 0.07);
}
.gift:before {
content: "";
position: absolute;
width: 70px;
height: 15px;
background-color: #ffc857;
left: -5px;
box-shadow: inset -8px -4px 0 rgba(0, 0, 0, 0.07);
}
.gift:after {
content: "";
background-color: #db3a34;
width: 10px;
height: 50px;
position: absolute;
left: 25px;
}
.ribbon {
position: absolute;
width: 20px;
height: 10px;
border: 3px solid #db3a34;
border-radius: 50%;
transform: skew(15deg, 15deg);
top: 116px;
left: 35px;
}
.ribbon:before {
content: "";
position: absolute;
width: 20px;
height: 10px;
border: 3px solid #db3a34;
border-radius: 50%;
transform: skew(-15deg, -20deg);
left: 22px;
top: -8px;
}
.gift2 {
position: absolute;
width: 50px;
height: 40px;
background-color: #08bdbd;
top: 140px;
left: -65px;
box-shadow: inset -8px 0 0 rgba(0, 0, 0, 0.07);
}
.gift2:before {
content: "";
position: absolute;
width: 60px;
height: 15px;
background-color: #08bdbd;
left: -5px;
box-shadow: inset -8px -4px 0 rgba(0, 0, 0, 0.07);
}
.gift2:after {
content: "";
background-color: #abff4f;
width: 10px;
height: 40px;
position: absolute;
left: 15px;
}
.gift3 {
position: absolute;
width: 40px;
height: 30px;
background-color: #7678ed;
top: 150px;
left: -85px;
box-shadow: inset -8px 0 0 rgba(0, 0, 0, 0.07);
}
.gift3:before {
content: "";
position: absolute;
width: 50px;
height: 10px;
background-color: #7678ed;
left: -5px;
box-shadow: inset -8px -4px 0 rgba(0, 0, 0, 0.07);
}
.gift3:after {
content: "";
background-color: #f7b801;
width: 7px;
height: 30px;
position: absolute;
left: 15px;
}
.ribbon2 {
position: absolute;
width: 15px;
height: 7px;
border: 3px solid #abff4f;
border-radius: 50%;
transform: skew(15deg, 15deg);
top: 129px;
left: -65px;
}
.ribbon2:before {
content: "";
position: absolute;
width: 15px;
height: 7px;
border: 3px solid #abff4f;
border-radius: 50%;
transform: skew(-15deg, -20deg);
left: 15px;
top: -8px;
}
.ribbon3 {
position: absolute;
width: 12px;
height: 5px;
border: 3px solid #f7b801;
border-radius: 50%;
transform: skew(15deg, 15deg);
top: 142px;
left: -85px;
}
.ribbon3:before {
content: "";
position: absolute;
width: 12px;
height: 5px;
border: 3px solid #f7b801;
border-radius: 50%;
transform: skew(-15deg, -20deg);
left: 15px;
top: -8px;
}
.balls {
position: absolute;
width: 20px;
height: 20px;
border-radius: 50%;
background-color: #db3a34;
top: 15px;
left: -15px;
}
.balls:before {
content: "";
position: absolute;
width: 20px;
height: 20px;
border-radius: 50%;
background-color: #ffc857;
top: 35px;
left: -15px;
}
.balls:after {
content: "";
position: absolute;
width: 20px;
height: 20px;
border-radius: 50%;
background-color: #f07167;
top: 20px;
left: 45px;
}
.ball1 {
position: absolute;
width: 20px;
height: 20px;
border-radius: 50%;
background-color: #fae588;
top: -90px;
left: 20px;
}
.ball1:before {
position: absolute;
width: 20px;
height: 20px;
border-radius: 50%;
background-color: #fae588;
content: "";
top: 170px;
left: 50px;
}
.light1,
.light2,
.light3,
.light4,
.light5,
.light6,
.light7,
.light8,
.light9,
.light10 {
-webkit-animation: flash 6s infinite;
}
@-webkit-keyframes flash {
20%,
24%,
55% {
box-shadow: none;
}
0%,
19%,
21%,
23%,
25%,
54%,
56%,
100% {
box-shadow: 0 0 5px #f5de93, 0 0 15px #f5de93, 0 0 20px #f5de93,
0 0 40px #f5de93, 0 0 60px #decea4, 0 0 10px #d6c0a5, 0 0 98px #ff0000;
}
}
/** Snowflakes */
.snowflake {
color: #fff;
font-size: 1em;
font-family: Arial, sans-serif;
text-shadow: 0 0 5px #000;
}
@-webkit-keyframes snowflakes-fall {
0% {
top: -10%;
}
100% {
top: 100%;
}
}
@-webkit-keyframes snowflakes-shake {
0%,
100% {
-webkit-transform: translateX(0);
transform: translateX(0);
}
50% {
-webkit-transform: translateX(80px);
transform: translateX(80px);
}
}
@keyframes snowflakes-fall {
0% {
top: -10%;
}
100% {
top: 100%;
}
}
@keyframes snowflakes-shake {
0%,
100% {
transform: translateX(0);
}
50% {
transform: translateX(80px);
}
}
.snowflake {
position: fixed;
top: -10%;
z-index: 9999;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
cursor: default;
-webkit-animation-name: snowflakes-fall, snowflakes-shake;
-webkit-animation-duration: 10s, 3s;
-webkit-animation-timing-function: linear, ease-in-out;
-webkit-animation-iteration-count: infinite, infinite;
-webkit-animation-play-state: running, running;
animation-name: snowflakes-fall, snowflakes-shake;
animation-duration: 10s, 3s;
animation-timing-function: linear, ease-in-out;
animation-iteration-count: infinite, infinite;
animation-play-state: running, running;
}
.snowflake:nth-of-type(0) {
left: 1%;
-webkit-animation-delay: 0s, 0s;
animation-delay: 0s, 0s;
}
.snowflake:nth-of-type(1) {
left: 10%;
-webkit-animation-delay: 1s, 1s;
animation-delay: 1s, 1s;
}
.snowflake:nth-of-type(2) {
left: 20%;
-webkit-animation-delay: 6s, 0.5s;
animation-delay: 6s, 0.5s;
}
.snowflake:nth-of-type(3) {
left: 30%;
-webkit-animation-delay: 4s, 2s;
animation-delay: 4s, 2s;
}
.snowflake:nth-of-type(4) {
left: 40%;
-webkit-animation-delay: 2s, 2s;
animation-delay: 2s, 2s;
}
.snowflake:nth-of-type(5) {
left: 50%;
-webkit-animation-delay: 8s, 3s;
animation-delay: 8s, 3s;
}
.snowflake:nth-of-type(6) {
left: 60%;
-webkit-animation-delay: 6s, 2s;
animation-delay: 6s, 2s;
}
.snowflake:nth-of-type(7) {
left: 70%;
-webkit-animation-delay: 2.5s, 1s;
animation-delay: 2.5s, 1s;
}
.snowflake:nth-of-type(8) {
left: 80%;
-webkit-animation-delay: 1s, 0s;
animation-delay: 1s, 0s;
}
.snowflake:nth-of-type(9) {
left: 90%;
-webkit-animation-delay: 3s, 1.5s;
animation-delay: 3s, 1.5s;
}
.snowflake:nth-of-type(10) {
left: 25%;
-webkit-animation-delay: 2s, 0s;
animation-delay: 2s, 0s;
}
.snowflake:nth-of-type(11) {
left: 65%;
-webkit-animation-delay: 4s, 2.5s;
animation-delay: 4s, 2.5s;
}
</style>
</html>

View File

@@ -5,13 +5,22 @@ use axum::{
};
use once_cell::sync::Lazy;
use rand::{thread_rng, Rng};
use rand::seq::SliceRandom;
use serde::Deserialize;
use std::net::SocketAddr;
use tokio::sync::Mutex;
use log::debug;
use log::error;
use log::info;
use log::warn;
#[macro_use]
extern crate log;
#[tokio::main]
async fn main() {
tracing_subscriber::fmt::init();
env_logger::init();
// tracing_subscriber::fmt::init();
// build our application with some routes
let app = Router::new()
@@ -38,8 +47,8 @@ static INDEX_HTML: Lazy<String> = Lazy::new(|| {
static STATE: Lazy<Mutex<State>> = Lazy::new(Mutex::default);
struct State {
rem_a: Vec<String>,
rem_b: Vec<String>,
participants: Vec<String>,
remaining: Vec<String>,
}
fn everyone() -> Vec<String> {
@@ -48,9 +57,12 @@ fn everyone() -> Vec<String> {
impl Default for State {
fn default() -> Self {
Self {
rem_a: everyone(),
rem_b: everyone(),
let mut p = everyone();
p.shuffle(&mut thread_rng());
info!("distribution : {:?}", p.join(" => "));
return Self {
participants: p,
remaining: everyone()
}
}
}
@@ -63,21 +75,32 @@ struct Input {
async fn input(Json(input): Json<Input>) -> String {
let mut state = STATE.lock().await;
if state.rem_a.is_empty() {
if state.remaining.is_empty() {
return "ERROR (everybody drew already)".into();
}
match state.rem_a.iter().position(|p| input.person == *p) {
info!("joueurs qui restent : {:?}", state.remaining.join(","));
match state.remaining.iter().position(|p| input.person == *p).map(|e| state.remaining.remove(e)) {
Some(rem) => {
match state.participants.iter().position(|p| input.person == *p) {
Some(pos) => {
state.rem_a.remove(pos);
info!("joueur qui pioche : {:?}", state.participants[pos]);
return match state.participants.iter().nth(pos+1) {
Some(x) => {
info!("joueur qui suit : {:?}", x);
return x.to_string();
}
None => return "ERROR (you drew already)".into(),
None => return match state.participants.first() {
Some(x) => {
info!("joueur qui suit : {:?}", x);
return x.to_string();
}
loop {
let num = thread_rng().gen_range(0..state.rem_b.len());
if state.rem_b[num] != input.person {
return state.rem_b.remove(num);
None => "ERROR".to_string()
}
}
}
None => "ERROR".to_string()
}
}
None => "Vous avez déja pioché !".to_string()
}
}