diff --git a/.gitignore b/.gitignore index 38380e2..298b9d5 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ /words/* /log/* !/cards/.placeholder +!/cards/skip.jpg !/words/.placeholder !/words/words.txt.example !/log/.placeholder diff --git a/cards/skip.jpg b/cards/skip.jpg new file mode 100644 index 0000000..a60c213 Binary files /dev/null and b/cards/skip.jpg differ diff --git a/game.py b/game.py index 665148a..8dae107 100644 --- a/game.py +++ b/game.py @@ -50,6 +50,7 @@ class Player: for i in range(0, len(self.game.cards)): cards.append({ "index": i, "name": self.game.cards[i], "my": self.selection == i, "friends": friendSelection == i }) return { + "vocabulary": self.game.vocabulary, "turn": self.game.turn, "score": self.game.score, "word": self.game.word, @@ -75,7 +76,9 @@ class Player: class Game: - def __init__(self, word): + def __init__(self, vocabulary, word): + self.vocabulary = vocabulary + self.words = words.get(vocabulary, ["no words for choose, sorry..."]) self.players = ( Player(self, "Player1"), Player(self, "Player2") ) self.turn = 1 self.score = 0 @@ -95,10 +98,11 @@ class Game: if not card in self.cards: self.cards.append(card) break + #self.cards.append(skipname) w0 = self.players[0].word w1 = self.players[1].word if not w0 and not w1: - self.word = random.choice(words) + self.word = random.choice(self.words) self.wordSource = "choosen by random" elif not w1: self.word = w0 @@ -138,21 +142,27 @@ class Game: def mergeCards(path): for f in os.scandir(path): - if f.is_file() and f.name.endswith(".jpg"): + if f.is_file() and f.name.endswith(".jpg") and f.name != skipname: cards.append(f.name) def mergeWords(path): - global words - ws = set(words) - with open(path, "r") as f: - for word in f.readlines(): - w = word.strip() - if w != "": - ws.add(w) - words.clear() - words += ws - + for f in os.scandir(path): + if f.is_file() and f.name.endswith(".txt"): + n = f.name[:-4] + ws = set(words.get(n, [])) + with open(path + "/" + f.name, "r") as ff: + for word in ff.readlines(): + w = word.strip() + if w != "": + ws.add(w) + if ws: + if not n in words: + words[n] = [] + words[n].clear() + words[n] += ws + +skipname = "skip.jpg" players = {} cards = [] -words = [] +words = {} diff --git a/server.py b/server.py index ee17460..1b06502 100755 --- a/server.py +++ b/server.py @@ -64,10 +64,13 @@ class Server(http.server.BaseHTTPRequestHandler): data = self.rfile.read(length) fields = urllib.parse.parse_qs(str(data,"UTF-8")) word = str(fields.get("word", [""])[0]) + vocabulary = str(fields.get("vocabulary", [""])[0]) with mutex: if not path: # create new game - g = game.Game(word) + if not vocabulary in game.words: + return self.err() + g = game.Game(vocabulary, word) self.send_response(303) self.send_header("Location", str(config.prefix) + "/" + str(g.players[0].id)) self.end_headers() @@ -117,7 +120,11 @@ class Server(http.server.BaseHTTPRequestHandler): self.send_response(200) self.send_header("Content-type", "text/html") self.end_headers() - tplStartpage.write(self, {"host": config.externalHost, "prefix": config.prefix}); + tplStartpage.write(self, { + "host": config.externalHost, + "prefix": config.prefix, + "vocabularies": list(sorted(game.words.keys())), + "waiting": False }); return with mutex: @@ -154,7 +161,7 @@ mutex = threading.Lock() loadTemplates() game.mergeCards("cards") -game.mergeWords("words/words.txt") +game.mergeWords("words") webServer = http.server.HTTPServer(( config.hostName, diff --git a/tpl/css.tpl b/tpl/css.tpl index e4cec8a..2eb19e9 100644 --- a/tpl/css.tpl +++ b/tpl/css.tpl @@ -90,7 +90,7 @@ img.top { border-radius: 16px 16px 0 0; } -input { +input, select { display: inline-block; font-size: 18px; height: 48px; diff --git a/tpl/startpage.tpl b/tpl/startpage.tpl index 35b0f44..f153a6c 100644 --- a/tpl/startpage.tpl +++ b/tpl/startpage.tpl @@ -1,5 +1,6 @@ {include:header.tpl}
+