From 988243fc4a61cf251dfaf241ede744e62bbc8363 Mon Sep 17 00:00:00 2001 From: Nikolaj Date: Mon, 20 Jan 2025 15:28:32 +0100 Subject: [PATCH] :sparkles: --- data.json | 20 ++++++++--------- main.py | 67 ++++++++++++++++++++++++++++++++++++++++++------------- 2 files changed, 62 insertions(+), 25 deletions(-) diff --git a/data.json b/data.json index db8afdc..6a2cfb4 100644 --- a/data.json +++ b/data.json @@ -102,23 +102,23 @@ "pages": [ [ "The Party (Before Session)", - "- [Adrian/0] [Goldenleaf/0], a [high/4] [elf/1] [rogue/7] from [Volantis/5] and owner of the [Goldenleaf/0] [inn/1].", - "- [Andromedes/0] [Moklus/0], a [dwarf/1] [artificer/7] from [Hammerhome/5] and [diplomat/1] in [Dragonsong/5].", - "- [Aslak/0], an [orc/1] [barbarian/7]/[monk/7] from [The%Westerlands/5] and [trainee/1] of [Nix/0] [McGalloway/0].", - "- [Marigold/0] [Sagemonger/0], a [high/4] [elf/1] [wizard/7] from [The%Empire/5] and owner of [Sagemonger/0]'s.", - "- [Nix/0] [McGalloway/0], a [changeling/1] [monk/7] from [The%Westerlands/5] and owner of the [flying/4] [pegasus/1].", + "- [Adrian/0+6] [Goldenleaf/0], a [high/4] [elf/1] [rogue/7] from [Volantis/5] and owner of the [Goldenleaf/0] [inn/1].", + "- [Andromedes/0+6] [Moklus/0], a [dwarf/1] [artificer/7] from [Hammerhome/5] and [diplomat/1] in [Dragonsong/5].", + "- [Aslak/0], an [orc/1] [barbarian/7]/[monk/7] from [The%Westerlands/5] and [trainee/1] of [Nix/0+6] [McGalloway/0].", + "- [Marigold/0+6] [Sagemonger/0], a [high/4] [elf/1] [wizard/7] from [The%Empire/5] and owner of [Sagemonger/0]'s.", + "- [Nix/0+6] [McGalloway/0], a [changeling/1] [monk/7] from [The%Westerlands/5] and owner of the [flying/4] [pegasus/1].", "- [Sam/0], a [satyr/1] [cleric/7] from [The%Feywilds/5].", - "- [Silvan/0], a [human/1] [fighter/7] from [The%Empire/5] and formerly a [trainee/1] of [Paterius/0] [Enkelton/0]." + "- [Silvan/0], a [human/1] [fighter/7] from [The%Empire/5] and formerly a [trainee/1] of [Paterius/0+6] [Enkelton/0]." ], [ "Present Threats", - "- [Lord/6] [Edgar/0] [Darkwood/0] is [gathering/3] [power/1] in his [tower/1], far away from civilization.", + "- [Lord+Edgar/0+6] [Darkwood/0] is [gathering/3] [power/1] in his [tower/1], far away from civilization.", "- [Volynthia/0], a [green/2] [dragon/1], is trying to [escape/3] from [The%Feywilds/5], helped by a group of [orc/1]s.", - "- A [war/1] is raging between [Lady/6] [Valeria/0] [Argyn/0] and the [giant/1]s, for control of [Giant's%Heart/5]." + "- A [war/1] is raging between [Lady+Valeria/0+6] [Argyn/0] and the [giant/1]s, for control of [Giant's%Heart/5]." ], [ "Before the Session", - "The [purple/2] [rose/1], also known as the [soup/1] [bandit/1]s, have been [terrorizing/3] the citizens of [Dragonsong/5] by [eating/3] all of their [soup/1]. They also [kidnapped/3] [Galinndan/0], friend of [Adrian/0] [Goldenleaf/0] and chef of the [Goldenleaf/0] [inn/1]. They are lead by [Valindis/0] [Half-ear/0] and are headquartered in the [Dragonsong/5] [sewers/1]." + "The [purple/2] [rose/1], also known as the [soup/1] [bandit/1]s, have been [terrorizing/3] the citizens of [Dragonsong/5] by [eating/3] all of their [soup/1]. They also [kidnapped/3] [Galinndan/0], friend of [Adrian/0+6] [Goldenleaf/0] and chef of the [Goldenleaf/0] [inn/1]. They are lead by [Valindis/0+6] [Half-ear/0] and are headquartered in the [Dragonsong/5] [sewers/1]." ], [ "Into the Dark", @@ -126,7 +126,7 @@ ], [ "The Plan", - "The party [trick/3] [Valindis/0] [Half-ear/0] by \"[capturing/3]\" [Nix/0] [McGalloway/0] [disguised/3] as [Adrian/0] [Goldenleaf/0]." + "The party [trick/3] [Valindis/0+6] [Half-ear/0] by \"[capturing/3]\" [Nix/0+6] [McGalloway/0] [disguised/3] as [Adrian/0+6] [Goldenleaf/0]." ] ] } \ No newline at end of file diff --git a/main.py b/main.py index 4a73c2b..40b32e4 100644 --- a/main.py +++ b/main.py @@ -55,6 +55,7 @@ TEXT_HEIGHT = TEXT_PAGE_HEIGHT - PAGE_BORDER_WIDTH*2 - TEXT_MARGIN*2 WORD_SLOT_SPACING = " "*16 WORD_SLOT_NUDGING = 25 WORD_SLOT_NUDGE_DOWN = -5 +SLANT = 80 INDICATOR_SIZE = 80 INDICATOR_BORDER = 20 @@ -95,14 +96,14 @@ class Page(): text: None|str position: Vector2 size: Vector2 - slots: list[tuple[str,WordSlot]] + slots: list[tuple[list[str],WordSlot]] def solved(self): if any([s[1].word is None for s in self.slots]): return SolvedState.NotFinished - elif all([s[1].word.word == s[0] for s in self.slots]): + elif all([s[1].word.word in s[0] for s in self.slots]): return SolvedState.Correct - elif sum([s[1].word.word == s[0] for s in self.slots]) >= len(self.slots)-2: + elif sum([s[1].word.word in s[0] for s in self.slots]) >= len(self.slots)-2: return SolvedState.AlmostCorrect else: return SolvedState.Wrong @@ -120,7 +121,7 @@ class Word(): @dataclass class WordSlot(): - color: None|WordColor + colors: None|list[WordColor] page: Page position: Vector2 word: None|Word = None @@ -185,10 +186,10 @@ def draw_page(page: Page, screen: pygame.surface.Surface, font: pygame.font.Font def draw_word_slot(word_slot: WordSlot, screen: pygame.surface.Surface): pos = word_slot.page.position+word_slot.position - if word_slot.color is None: + if word_slot.colors is None: color = "#00000000" else: - color = word_slot.color.color() + color = word_slot.colors[0].color() pygame.draw.rect( screen, @@ -202,6 +203,42 @@ def draw_word_slot(word_slot: WordSlot, screen: pygame.surface.Surface): border_radius=WORD_BORDER_RADIUS ) + if len(word_slot.colors) > 1: + pygame.draw.rect( + screen, + word_slot.colors[1].color(), + pygame.Rect( + pos.x + WORD_BORDER_WIDTH + WORD_WIDTH//4, + pos.y + WORD_BORDER_WIDTH, + (WORD_WIDTH*3)//4 - WORD_BORDER_WIDTH*2, + WORD_HEIGHT - WORD_BORDER_WIDTH*2 + ), + border_radius=WORD_BORDER_RADIUS + ) + + pygame.draw.polygon( + screen, + color, + [ + ( + pos.x + WORD_BORDER_WIDTH + WORD_WIDTH//4, + pos.y + WORD_BORDER_WIDTH + ), + ( + pos.x + WORD_BORDER_WIDTH + WORD_WIDTH//2 + SLANT//2, + pos.y + WORD_BORDER_WIDTH + ), + ( + pos.x + WORD_BORDER_WIDTH + WORD_WIDTH//2 - SLANT//2, + pos.y + WORD_BORDER_WIDTH + WORD_HEIGHT - WORD_BORDER_WIDTH*2 - 1 + ), + ( + pos.x + WORD_BORDER_WIDTH + WORD_WIDTH//4, + pos.y + WORD_BORDER_WIDTH + WORD_HEIGHT - WORD_BORDER_WIDTH*2 - 1 + ), + ] + ) + def draw_word(word: Word, screen: pygame.surface.Surface, font: pygame.font.Font): if word.page is not None: pos = word.page.position+word.position @@ -340,7 +377,7 @@ def main(data: dict): new_text.append("") text_words = t.split(" ") for w in text_words: - res = re.findall(r"([^\] ]*)\[(.*?)\/(\d)\]([^\[ ]*)",w) + res = re.findall(r"([^\] ]*)\[(.*?)\/([\d\+]+)\]([^\[ ]*)",w) if res == []: new_text = add_to_text(new_text,w) else: @@ -358,9 +395,9 @@ def main(data: dict): ) # if new_text[-1] != WORD_SLOT_SPACING+slot[2]: pos.x += WORD_SLOT_NUDGING - new_slot = WordSlot(WordColor(int(slot[2])),p,pos) + new_slot = WordSlot([WordColor(int(i)) for i in slot[2].split("+")],p,pos) word_slots.append(new_slot) - p.slots.append((slot[1].replace("%"," "),new_slot)) + p.slots.append((slot[1].replace("%"," ").split("+"),new_slot)) p.text = new_text @@ -375,7 +412,7 @@ def main(data: dict): all_words = [w.word for w in words] for p in pages: - not_present = [s[0] for s in p.slots if s[0] not in all_words] + not_present = [word for s in p.slots for word in s[0] if word not in all_words] if not_present: print(not_present) @@ -436,7 +473,7 @@ def main(data: dict): break if slot is None: - if held_word is not None and held_word.slot.color is not None: + if held_word is not None and held_word.slot.colors is not None: words.remove(held_word) held_word = None return @@ -446,11 +483,11 @@ def main(data: dict): held_word.page = None slot.word = None elif held_word is not None and slot.word is None: - if slot.color is not None and slot.color != held_word.color: + if slot.colors is not None and held_word.color not in slot.colors: return slot.word = held_word - if slot.color is not None and held_word.slot.color is None: + if slot.colors is not None and held_word.slot.colors is None: new_word = slot.word.copy() new_word.page = slot.word.slot.page new_word.position = slot.word.slot.position @@ -458,7 +495,7 @@ def main(data: dict): new_word.slot.word = new_word words.append(new_word) - if slot.word.slot.color is None or slot.color is not None: + if slot.word.slot.colors is None or slot.colors is not None: slot.word.position = slot.position slot.word.page = slot.page slot.word.slot = slot @@ -501,7 +538,7 @@ def main(data: dict): # drawing word slots for w in word_slots: - if not w.page.visible or w.color is None: + if not w.page.visible or w.colors is None: continue draw_word_slot(w, drawer)