commit 27cb33ff5e7f34ad55ae433774a2ababa08beb31
parent 0fd014b6553f04aec424cffac38db88ae9fa614f
Author: Friedel Schön <[email protected]>
Date: Sun, 18 Jun 2023 23:14:22 +0200
inleveren
Diffstat:
5 files changed, 65 insertions(+), 30 deletions(-)
diff --git a/css/main.css b/css/main.css
@@ -20,7 +20,7 @@ body{
}
.menu{
- display: none;
+ display: flex;
flex-direction: column;
}
diff --git a/memory.html b/memory.html
@@ -5,7 +5,7 @@
<link rel="stylesheet" href="css/main.css" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
</head>
- <body onload="OnLoad()">
+ <body>
<div class ="container">
<div class ="header">
<div class ="menu_btn" onclick="menu()">
@@ -28,7 +28,9 @@
</div>
<div id="card_color">
<input type="color" id="closed_card" name="closed_card" value="#df9a06" onchange="colorChange()">
- <label for="closed_card">Closed card</label>
+ <label for="closed_card">Closed card</label><br>
+ <input type="color" id="found_card" name="found_card" value="#df9a06" onchange="colorChange()">
+ <label for="found_card">Found card</label>
</div>
</div>
<div class="game_state">
@@ -53,6 +55,5 @@
</div>
<script type="text/javascript" src="backend.js"></script>
<script type="text/javascript" src="memory.js"></script>
- <script type='text/javascript' src='settings.js'></script>
- </body>
-</html>
-\ No newline at end of file
+ ></script>
+ </b
+\ No newline at end of file
diff --git a/memory.js b/memory.js
@@ -1,6 +1,19 @@
// UTILITIES
// =========
+function toFullColor(col) {
+ // expecting either '#rrggbb' or '#rgb' and converting to '#rrggbb'
+
+ if (col.length == 7)
+ return col;
+
+ let r = col[1],
+ g = col[2],
+ b = col[3];
+
+ return '#' + r + r + g + g + b + b;
+}
+
function shuffleArray(array) {
let currentIndex = array.length,
randomIndex;
@@ -104,30 +117,15 @@ function onSelect() {
}
}
-function OnLoad(){
- let board = document.getElementById("game_board");
- board.innerHTML = '';
-
- buttons = {};
- openButton = null;
- done = [];
- pairs = 0;
- let promises = [];
- for (let i = 0; i < BOARD_SIZE / 2; i++) {
- promises.push(fetch(DOG_API).then(res => res.json()).then(res => res.message));
- }
- Promise.all(promises).then(makeBoard);
-}
-
function menu(){
- let menu = document.getElementById('menu');
- if(menu.style.display == 'flex'){
- menu.style.display = 'none';
+ let m = document.getElementById('menu');
+ if(m.style.display == 'flex'){
+ m.style.display = 'none';
}else{
- menu.style.display = 'flex';
+ m.style.display = 'flex';
}
- console.log(menu.getPropertyValue());
+ console.log(m.getPropertyValue());
}
function onCardClick(evt) {
@@ -160,9 +158,13 @@ function onCardClick(evt) {
function colorChange() {
let color = document.getElementById("closed_card").value;
+// let fcolor = document.getElementById("found_card").value;
for (let x of document.getElementsByClassName("card"))
x.style.backgroundColor = color;
+
+// for (let x of document.getElementsByClassName("done"))
+// x.style.backgroundColor = fcolor;
}
function updateTop() {
@@ -190,5 +192,26 @@ function updateLogin() {
});
}
+function updatePref() {
+ getUser().then(user =>
+ callBackend('GET', `api/player/${user.id}/preferences`).then(({ color_found, color_closed, preferred_api }) => {
+ if (!preferred_api)
+ preferred_api = 'none';
+ if (!color_found)
+ color_found = '#00ff00';
+ if (!color_closed)
+ color_closed = '#ffff00';
+
+ document.getElementById('found_card').value = toFullColor(color_found);
+ document.getElementById('closed_card').value = toFullColor(color_closed);
+ document.getElementById('picture-select').value = preferred_api;
+
+ onSelect();
+ setTimeout(colorChange, 500);
+ })
+ );
+}
+
updateTop();
-updateLogin();
-\ No newline at end of file
+updateLogin();
+updatePref();
+\ No newline at end of file
diff --git a/readme.md b/readme.md
@@ -0,0 +1,10 @@
+# READ ME
+
+memory.html bevat het spel
+> als je niet bent ingelogd, wordt je doorgestuurd naar login.html
+
+settings.html bevat de voorkeuren
+
+login.html bevat login/logout/register
+
+het backend moet op localhost:8000 draaien
+\ No newline at end of file
diff --git a/settings.js b/settings.js
@@ -13,7 +13,7 @@ function toFullColor(col) {
function updateLogin() {
let span = document.getElementById('login');
-
+
getUser().then(user => {
if (!user) {
window.location.href = 'login.html?m=restricted';