Skip to content

Commit 1598b52

Browse files
committed
Buttons now functional
1 parent 69b8264 commit 1598b52

File tree

2 files changed

+30
-18
lines changed

2 files changed

+30
-18
lines changed

Magic_AI_Storybook/book.py

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import sys
66
import os
77
import time
8+
import math
89
from enum import Enum
910
import pygame
1011

@@ -27,10 +28,10 @@
2728

2829
# Delays to control the speed of the text
2930
# Default
30-
CHARACTER_DELAY = 0.03
31-
WORD_DELAY = 0.2
32-
SENTENCE_DELAY = 1
33-
PARAGRAPH_DELAY = 2
31+
#CHARACTER_DELAY = 0.03
32+
#WORD_DELAY = 0.2
33+
#SENTENCE_DELAY = 1
34+
#PARAGRAPH_DELAY = 2
3435

3536
# Letter by Letter
3637
# CHARACTER_DELAY = 0.1
@@ -45,10 +46,10 @@
4546
# PARAGRAPH_DELAY = 0
4647

4748
# No Delays
48-
# CHARACTER_DELAY = 0
49-
# WORD_DELAY = 0
50-
# SENTENCE_DELAY = 0
51-
# PARAGRAPH_DELAY = 0
49+
CHARACTER_DELAY = 0
50+
WORD_DELAY = 0
51+
SENTENCE_DELAY = 0
52+
PARAGRAPH_DELAY = 0
5253

5354

5455
# Whitespace Settings in Pixels
@@ -182,14 +183,25 @@ def handle_events(self):
182183
raise SystemExit
183184
if event.type == pygame.MOUSEBUTTONDOWN:
184185
if event.button == 1:
185-
# If clicked in text area and book is still rendering, skip to the end
186-
print(f"Left mouse button pressed at {event.pos}")
187186
# If button pressed while visible, trigger action
188-
if self.back_button.is_in_bounds(event.pos):
189-
self.back_button.action()
190-
elif event.type == pygame.MOUSEBUTTONUP:
191-
# Not sure if we will need this
192-
print("Mouse button has been released")
187+
coords = self.rotate_mouse_pos(event.pos)
188+
for button in [self.back_button, self.next_button]:
189+
if button.is_in_bounds(coords):
190+
button.action()
191+
192+
def rotate_mouse_pos(self, point):
193+
# Recalculate the mouse position based on the rotation of the screen
194+
# So that we have the coordinates relative to the upper left corner of the screen
195+
angle = 360 - self.rotation
196+
y, x = point
197+
x -= self.width // 2
198+
y -= self.height // 2
199+
x, y = x * math.sin(math.radians(angle)) + y * math.cos(
200+
math.radians(angle)
201+
), x * math.cos(math.radians(angle)) - y * math.sin(math.radians(angle))
202+
x += self.width // 2
203+
y += self.height // 2
204+
return (round(x), round(y))
193205

194206
def add_page(self, paragraph=0, word=0):
195207
# Add rendered page information to make flipping between them easier

Magic_AI_Storybook/story.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
import openai
1313

14-
#from listener import Listener
14+
# from listener import Listener
1515
from book import Book
1616

1717
STORY_WORD_LENGTH = 800
@@ -34,8 +34,8 @@
3434

3535
# TODO: Tweak this to fix the issue of missing words
3636
STORY_PROMPT = (
37-
f'Write a complete story with a title and a body of approximately '
38-
f'{STORY_WORD_LENGTH} words long and a happy ending. The specific '
37+
f"Write a complete story with a title and a body of approximately "
38+
f"{STORY_WORD_LENGTH} words long and a happy ending. The specific "
3939
f'story request is "{STORY_REQUEST}". '
4040
)
4141

0 commit comments

Comments
 (0)