Skip to content

Commit

Permalink
chore: typing improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
ntamas committed Jul 14, 2023
1 parent 1d94747 commit fcb62ae
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/modules/sbstudio/plugin/model/light_effects.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from functools import partial
from operator import itemgetter
from typing import Callable, Iterable, List, Optional, Sequence
from typing import cast, Callable, Iterable, List, Optional, Sequence

from bpy.props import (
BoolProperty,
Expand Down Expand Up @@ -452,7 +452,8 @@ def contains_frame(self, frame: int) -> bool:
return 0 <= (frame - self.frame_start) < self.duration

def create_color_image(self, name: str, width: int, height: int) -> Image:
"""Create a new color image for the light effect (and delete old).
"""Creates a new color image for the light effect (and deletes the old
one if it already has one).
Args:
name: the name of the image to create
Expand All @@ -466,7 +467,6 @@ def create_color_image(self, name: str, width: int, height: int) -> Image:
"""
self.color_image = bpy.data.images.new(name=name, width=width, height=height)

return self.color_image

@property
Expand Down Expand Up @@ -568,7 +568,7 @@ def _get_spatial_effect_predicate(self) -> Optional[Callable[[Coordinate3D], boo
plane = self._get_plane_from_mesh()
return partial(test_is_in_front_of, plane)

def _create_texture(self) -> None:
def _create_texture(self) -> ImageTexture:
"""Creates the texture associated to the light effect."""
tex = bpy.data.textures.new(
name=f"Texture for light effect {self.name!r}", type="IMAGE"
Expand All @@ -582,6 +582,7 @@ def _create_texture(self) -> None:
elt.color[3] = 1.0

self.texture = tex
return self.texture

def _remove_texture(self) -> None:
"""Removes the texture associated to the light effect from the Textures
Expand Down Expand Up @@ -650,16 +651,17 @@ def append_new_entry(
if duration is None or duration <= 0:
duration = fps * DEFAULT_LIGHT_EFFECT_DURATION

entry = self.entries.add()
entry: LightEffect = cast(LightEffect, self.entries.add())
entry.frame_start = frame_start
entry.duration = duration
entry.name = name

entry._create_texture()
texture = entry._create_texture()

# Copy default colors from the LED Control panel
if hasattr(scene, "skybrush") and hasattr(scene.skybrush, "led_control"):
led_control = scene.skybrush.led_control
elts = texture.color_ramp.elements
last_elt = len(elts) - 1
for i in range(3):
elts[0].color[i] = led_control.primary_color[i]
Expand Down

0 comments on commit fcb62ae

Please sign in to comment.