Skip to content

Commit

Permalink
Stash
Browse files Browse the repository at this point in the history
  • Loading branch information
jinglemansweep committed Aug 4, 2023
1 parent 554ff90 commit ee52e16
Show file tree
Hide file tree
Showing 8 changed files with 274 additions and 86 deletions.
Binary file added images/night/chocolate.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions settings.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@

[paths]
# images_backgrounds = "images/background"
# images_backgrounds_night ="images/night"
# images_weather = "images/icons"
# images_icons = "images/icons"
# images_screenshots = "images/screenshots"
Expand Down
3 changes: 2 additions & 1 deletion wideboy/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from wideboy.scenes.credits import CreditsScene
from wideboy.scenes.default import DefaultScene
from wideboy.scenes.night import NightScene
from wideboy.scenes.starfield import StarfieldScene
from wideboy.utils.logger import setup_logger

load_dotenv(find_dotenv())
Expand All @@ -21,7 +22,7 @@
logger = logging.getLogger(AppMetadata.NAME)

# SCENES
SCENES: List[Type[BaseScene]] = [DefaultScene, NightScene, CreditsScene]
SCENES: List[Type[BaseScene]] = [NightScene, DefaultScene, StarfieldScene, CreditsScene]

# ENTITIES
ENTITIES: List[Type[HASSEntity]] = []
Expand Down
5 changes: 5 additions & 0 deletions wideboy/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,11 @@
default="images/backgrounds",
cast=Path,
),
Validator(
"PATHS__IMAGES_BACKGROUNDS_NIGHT",
default="images/night",
cast=Path,
),
Validator(
"PATHS__IMAGES_WEATHER",
default="images/weather",
Expand Down
1 change: 1 addition & 0 deletions wideboy/scenes/default/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def setup(self):
640,
self.height,
),
settings.paths.images_backgrounds,
255,
shuffle=True,
)
Expand Down
194 changes: 112 additions & 82 deletions wideboy/scenes/night/__init__.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
import logging
import random
from pygame import Clock, Color, Event, Rect, Vector2
from pygame import Clock, Color, Event, Rect, Vector2, JOYBUTTONUP
from typing import TYPE_CHECKING
from wideboy.constants import EVENT_EPOCH_SECOND, EVENT_ACTION_A
from wideboy.constants import EVENT_EPOCH_HOUR, EVENT_EPOCH_MINUTE, EVENT_ACTION_A, GAMEPAD
from wideboy.scenes.animation import Act, Animation
from wideboy.sprites.background import BackgroundSprite
from wideboy.sprites.calendar import CalendarSprite
from wideboy.sprites.clock import DateSprite, TimeSprite

# from wideboy.sprites.rotogrid import RotoGridSprite
# from wideboy.sprites.sphere import SphereSprite
from wideboy.sprites.starfield import StarfieldSprite
from wideboy.sprites.homeassistant.entity_row import HomeAssistantEntityRowSprite
from wideboy.sprites.notification import NotificationSprite
from wideboy.scenes.animation import Act, Animation
from wideboy.sprites.weather.animation import WeatherAnimationSprite
from wideboy.sprites.weather.temperature import WeatherTemperatureSprite
from wideboy.sprites.weather.wind import WeatherWindSprite
from wideboy.sprites.image_helpers import MaterialIcons
from wideboy.scenes.base import BaseScene

from wideboy.config import settings

if TYPE_CHECKING:
from wideboy.engine import Engine

logger = logging.getLogger("scenes.scene.night")
logger = logging.getLogger("scenes.scene.default")


class NightScene(BaseScene):
Expand All @@ -24,125 +28,151 @@ class NightScene(BaseScene):
def __init__(
self,
engine: "Engine",
bg_color: Color = (0, 0, 0, 255),
bg_color: Color = Color(0, 0, 0, 255),
) -> None:
super().__init__(engine, bg_color)

def setup(self):
super().setup()

# =====================================================================
# STARFIELD WIDGET
# ARTYFARTY BACKGROUND WIDGET
# =====================================================================

self.starfield_widget = StarfieldSprite(
self.background_widget = BackgroundSprite(
self,
Rect(0, 0, self.width, self.height),
color_fg=Color(255, 255, 255, 192),
)
self.group.add(self.starfield_widget)

# =====================================================================
# SPHERE WIDGET
# =====================================================================

"""
self.sphere_widget = SphereSprite(
self,
Rect(576, -32, 768 - 576, 128),
color_fg=Color(0, 0, 255, 64),
radius=100,
Rect(
0,
0,
self.width,
self.height,
),
settings.paths.images_backgrounds_night,
255,
shuffle=True,
)
self.group.add(self.sphere_widget)
"""
self.group.add(self.background_widget)

# =====================================================================
# CLOCK WIDGET
# =====================================================================

self.clock_time_pos: tuple[int, int] = (self.width - 128, -7)
self.clock_date_offset: tuple[int, int] = [0, 48]
CLOCK_POSITION = (self.width - 100, 0)
CLOCK_COLOR_FG = Color(0, 0, 0, 192)
CLOCK_COLOR_OUTLINE = Color(128, 255, 255, 255)

self.clock_time_widget = TimeSprite(
self,
Rect(self.clock_time_pos[0], self.clock_time_pos[1], 128, 48),
font_size=48,
color_fg=Color(0, 0, 0, 255),
color_outline=Color(255, 0, 255, 64),
rainbow="outline",
Rect(CLOCK_POSITION[0], CLOCK_POSITION[1], 96, 39),
color_fg=CLOCK_COLOR_FG,
color_outline=CLOCK_COLOR_OUTLINE,
font_size=38,
)
self.group.add(self.clock_time_widget)
self.clock_date_widget = DateSprite(
self,
Rect(
self.clock_time_pos[0] + self.clock_date_offset[0],
self.clock_time_pos[1] + self.clock_date_offset[1],
128,
24,
),
color_fg=Color(0, 0, 0, 255),
color_outline=Color(128, 0, 128, 255),
rainbow="outline",
Rect(CLOCK_POSITION[0], CLOCK_POSITION[1] + 39, 96, 16),
color_fg=CLOCK_COLOR_FG,
color_outline=CLOCK_COLOR_OUTLINE,
font_size=14,
)
self.group.add(self.clock_date_widget)

# =====================================================================
# HASS ENTITY ROW WIDGETS
# =====================================================================

hass_row_entities = [
dict(
entity_id="binary_sensor.back_door_contact_sensor_contact",
icon=MaterialIcons.MDI_DOOR,
icon_color=Color(255, 64, 64, 255),
template="Back",
cb_active=lambda state: state.state == "on",
),
dict(
entity_id="binary_sensor.front_door_contact_sensor_contact",
icon=MaterialIcons.MDI_DOOR,
icon_color=Color(255, 64, 64, 255),
template="Front",
cb_active=lambda state: state.state == "on",
)
]

self.hass_row = HomeAssistantEntityRowSprite(
self,
Rect(512, 48, 128, 16),
hass_row_entities,
color_bg=Color(0, 0, 0, 196),
)
self.group.add(self.hass_row)

# =====================================================================
# NOTIFICATION WIDGET
# =====================================================================

self.notification_widget = NotificationSprite(
self,
Rect(0, 0, 768, 64),
color_bg=Color(0, 0, 0, 128),
color_fg=Color(128, 128, 255, 255),
color_progress=Color(0, 0, 255, 255),
Rect(0, 0, 640, 64),
color_bg=Color(0, 0, 0, 192),
color_fg=Color(255, 255, 255, 255),
font_size=30,
font_padding=12,
)
self.group.add(self.notification_widget)

# =====================================================================
# SCENE STARTUP
# =====================================================================

self.act_background_change = self.build_background_change_act()
self.act_background_change.start()

# Update

def update(
self,
clock: Clock,
delta: float,
events: list[Event],
) -> None:
super().update(clock, delta, events)
self.hass_row.rect.topright = self.width - 128, 0

# Handle Events

def handle_events(self, events: list[Event]) -> None:
super().handle_events(events)
for event in events:
if event.type == EVENT_ACTION_A or (
event.type == EVENT_EPOCH_SECOND and event.unit % 30 == 0
):
self.animate_clock()

def animate_clock(self):
x = random.randint(
0,
(
self.width
- max(
self.clock_time_widget.rect.width, self.clock_date_widget.rect.width
)
),
)
y = random.randint(-11, -3)
self.animation_group.add(
Act(
64,
[
(0, Animation(self.clock_time_widget, Vector2(x, y), 64)),
(
0,
Animation(
self.clock_date_widget,
Vector2(
x + self.clock_date_offset[0],
y + self.clock_date_offset[1],
),
64,
),
if event.type == EVENT_EPOCH_HOUR:
self.run_background_change_act()

def run_background_change_act(self) -> None:
self.animation_group.add(self.build_background_change_act())

# Acts

def build_background_change_act(self) -> Act:
return Act(
64,
[
(
0,
Animation(
self.background_widget,
Vector2(0, 0 - self.height),
32,
),
],
)
),
(32, lambda: self.background_widget.render_next_image()),
(
32,
Animation(
self.background_widget,
Vector2(0, 0),
32,
Vector2(0, 0 - self.height),
),
),
],
)
Loading

0 comments on commit ee52e16

Please sign in to comment.