Skip to content

Commit

Permalink
Allow user to select categories
Browse files Browse the repository at this point in the history
  • Loading branch information
fbarbe00 committed Aug 17, 2023
1 parent 65fddf5 commit 785a331
Show file tree
Hide file tree
Showing 14 changed files with 510 additions and 483 deletions.
17 changes: 13 additions & 4 deletions client/main.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<link href="https://fonts.googleapis.com/css?family=Alef|Oswald|Open+Sans" rel="stylesheet" async media="none"
onload="if(media!='all')media='all'">

<!-- these CSS hrefs are wrong, and styles.css doesn't exist. Not sure what's going on here -->
<link rel="stylesheet" href="css/normalize.css" type="text/css" async media="none"
onload="if(media!='all')media='all'">
<link rel="stylesheet" href="css/skeleton.css" type="text/css" async media="none"
Expand Down Expand Up @@ -173,18 +174,26 @@ <h4>{{_ "ui.variants"}}</h4>
</div>
</td>
</tr>
<tr>
<td colspan="2">
{{_ "ui.choose categories"}}
<a class="btn-toggle-category-select" href="javascript:void(0);">{{_ "ui.show hide" }}</a>
<div class="category-select form-group" style="display: none;">
{{#each categories}}
<input type="checkbox" id="{{ this }}" name="category-name" value="{{ this }}" checked>
<label for="{{ this }}" style="display: inline;">{{ this }}</label>
{{/each}}
</div>
</td>
</tr>
<tr>
<td>
{{_ "ui.let us choose"}}
</td>
<td>


<button class="btn-start">{{_ "ui.start game" }}</button>

</td>
</tr>

</table>

<div class="button-container">
Expand Down
18 changes: 15 additions & 3 deletions client/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,9 @@ function getWordsProvider() {
return filteredWords;
}

function getRandomWordAndCategory() {
let filteredWords = getWordsProvider();
function getRandomWordAndCategory(excludedCategories) {
// heh, this should be optimized better.
let filteredWords = getWordsProvider().filter(word => !excludedCategories.includes(word.category));
let wordIndex = Math.floor(Math.random() * filteredWords.length);

return filteredWords[wordIndex];
Expand Down Expand Up @@ -530,6 +531,12 @@ Template.lobby.helpers({
player: function () {
return getCurrentPlayer();
},
categories: function () {
let words = getWordsProvider();
const uniqueCategories = [...new Set(words.map(word => word.category))];

return uniqueCategories;
},
players: function () {
let game = getCurrentGame();
let currentPlayer = getCurrentPlayer();
Expand All @@ -552,6 +559,9 @@ Template.lobby.helpers({

Template.lobby.events({
'click .btn-leave': leaveGame,
'click .btn-toggle-category-select': function () {
$(".category-select").toggle();
},
'click .btn-submit-user-word': function (event) {
let game = getCurrentGame();
let word = document.getElementById("user-word").value;
Expand Down Expand Up @@ -719,7 +729,9 @@ Template.lobby.events({
'click .btn-start': function () {

let game = getCurrentGame();
let wordAndCategory = getRandomWordAndCategory();
let excludedCategories = document.querySelectorAll('input[name="category-name"]:not(:checked)');
excludedCategories = Array.from(excludedCategories).map((category) => category.value);
let wordAndCategory = getRandomWordAndCategory(excludedCategories);

let currentPlayers = Array.from(Players.find({ gameID: game._id }));
let localEndTime = moment().add(game.lengthInMinutes, 'minutes');
Expand Down
1 change: 1 addition & 0 deletions i18n/de.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"submit user word": "Dieses Wort verwenden!",
"choose own word": "Verwende dein eigenes Wort",
"let us choose": "Oder lass uns eins für dich auswählen",
"choose categories": "Wähle Kategorien: ",
"bad category": "Kategorie melden",
"bad word": "Wort melden",
"github link": "https://github.com/alenros/fake-artist"
Expand Down
1 change: 1 addition & 0 deletions i18n/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"submit user word": "Use this word!",
"choose own word": "Use your own word",
"let us choose": "or let us choose it for you",
"choose categories": "Select categories: ",
"bad category": "report category",
"bad word": "report word",
"github link": "https://github.com/alenros/fake-artist"
Expand Down
1 change: 1 addition & 0 deletions i18n/es.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"submit user word": "¡Quiero usar esta palabra!",
"choose own word": "Usa tu propia palabra",
"let us choose": "o elegiremos una palabra al azar.",
"choose categories": "Selecciona categorías: ",
"bad category": "Denunciar categoría.",
"bad word": "Denunciar palabra."
}
Expand Down
11 changes: 6 additions & 5 deletions i18n/fr.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,15 @@
"Author": "Vous avez trouvé un bug ? Vous avez une suggestion ? Envoyez-moi un MP sur BGG : ",
"logo-file": "logo-en.png",
"locations-file": "locations_fr",
"enter word": "entrez votre mot",
"enter category": "entrez la catégorie du mot",
"enter word": "Entrez votre mot",
"enter category": "Entrez la catégorie du mot",
"submit user word": "Utilisez ce mot !",
"choose own word": "Utilisez votre propre mot",
"let us choose": "ou laissez-nous le choisir pour vous",
"let us choose": "Ou laissez-nous le choisir pour vous",
"choose categories": "Choisir categories: ",
"translation credits": "Traduction par <a href=\"https://fabiobarbero.eu\">fabiobarbero.eu</a>",
"bad category": "signaler la catégorie",
"bad word": "signaler le mot",
"bad category": "Signaler la catégorie",
"bad word": "Signaler le mot",
"github link": "https://github.com/alenros/fake-artist"
}
}
1 change: 1 addition & 0 deletions i18n/he.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"submit user word":"השתמש במילה הזו!",
"choose own word":"בחר מילה בעצמך",
"let us choose":"או תן לנו לבחור בשבילך",
"choose categories": "בחר נושאים",
"bad category":"report category",
"bad word":"report word"
}
Expand Down
1 change: 1 addition & 0 deletions i18n/it.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"submit user word": "Usa questa parola!",
"choose own word": "Usa la tua parola",
"let us choose": "Oppure lascia che scegliamo noi",
"choose categories": "Seleziona categorie: ",
"bad category": "Segnala categoria non valida",
"bad word": "Segnala parola non valida",
"github link": "https://github.com/alenros/fake-artist"
Expand Down
22 changes: 11 additions & 11 deletions lib/words-de.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,17 @@ words_de = [
{ text: 'Haargel', category: 'Toilettenartikel' },
{ text: 'Wimperntusche', category: 'Toilettenartikel' },

{ text: 'Computer', category: 'computing' },
{ text: 'facebook', category: 'computing' },
{ text: 'firewall', category: 'computing' },
{ text: 'Tastatur', category: 'computing' },
{ text: 'Passwort', category: 'computing' },
{ text: 'hashtag', category: 'computing' },
{ text: 'macbook', category: 'computing' },
{ text: 'twitter', category: 'computing' },
{ text: 'reddit', category: 'computing' },
{ text: 'snapchat', category: 'computing' },
{ text: 'instagram', category: 'computing' },
{ text: 'Computer', category: 'Computing' },
{ text: 'facebook', category: 'Computing' },
{ text: 'firewall', category: 'Computing' },
{ text: 'Tastatur', category: 'Computing' },
{ text: 'Passwort', category: 'Computing' },
{ text: 'hashtag', category: 'Computing' },
{ text: 'macbook', category: 'Computing' },
{ text: 'twitter', category: 'Computing' },
{ text: 'reddit', category: 'Computing' },
{ text: 'snapchat', category: 'Computing' },
{ text: 'instagram', category: 'Computing' },


{ category: 'Waffe', text: 'Kriegsaxt' },
Expand Down
Loading

0 comments on commit 785a331

Please sign in to comment.