mirror of
https://github.com/Yonokid/PyTaiko.git
synced 2026-02-04 11:40:13 +01:00
working very hard on graphics wrapper
This commit is contained in:
@@ -112,8 +112,6 @@ class FadeAnimation(BaseAnimation):
|
||||
def update(self, current_time_ms: float) -> None:
|
||||
if not self.is_started:
|
||||
return
|
||||
else:
|
||||
self.is_started = not self.is_finished
|
||||
elapsed_time = current_time_ms - self.start_ms
|
||||
|
||||
if elapsed_time <= self.delay:
|
||||
@@ -160,8 +158,6 @@ class MoveAnimation(BaseAnimation):
|
||||
def update(self, current_time_ms: float) -> None:
|
||||
if not self.is_started:
|
||||
return
|
||||
else:
|
||||
self.is_started = not self.is_finished
|
||||
elapsed_time = current_time_ms - self.start_ms
|
||||
if elapsed_time < self.delay:
|
||||
self.attribute = self.start_position
|
||||
@@ -187,13 +183,12 @@ class TextureChangeAnimation(BaseAnimation):
|
||||
self.textures = textures
|
||||
self.delay = delay
|
||||
self.delay_saved = delay
|
||||
self.attribute = textures[0][2]
|
||||
|
||||
def update(self, current_time_ms: float) -> None:
|
||||
super().update(current_time_ms)
|
||||
if not self.is_started:
|
||||
return
|
||||
else:
|
||||
self.is_started = not self.is_finished
|
||||
elapsed_time = current_time_ms - self.start_ms
|
||||
if elapsed_time < self.delay:
|
||||
return
|
||||
@@ -212,8 +207,6 @@ class TextStretchAnimation(BaseAnimation):
|
||||
def update(self, current_time_ms: float) -> None:
|
||||
if not self.is_started:
|
||||
return
|
||||
else:
|
||||
self.is_started = not self.is_finished
|
||||
elapsed_time = current_time_ms - self.start_ms
|
||||
if elapsed_time <= self.duration:
|
||||
self.attribute = 2 + 5 * (elapsed_time // 25)
|
||||
|
||||
@@ -114,7 +114,7 @@ class TextureWrapper:
|
||||
raise Exception(f"Texture {tex_name} was not found in {zip}")
|
||||
|
||||
|
||||
def draw_texture(self, subset: str, texture: str, color: ray.Color=ray.WHITE, frame: int = 0, scale: float = 1.0, center: bool = False, mirror: str = '', x: int | float = 0, y: int | float = 0, x2: int | float = 0, y2: int | float = 0) -> None:
|
||||
def draw_texture(self, subset: str, texture: str, color: ray.Color=ray.WHITE, frame: int = 0, scale: float = 1.0, center: bool = False, mirror: str = '', x: float = 0, y: float = 0, x2: float = 0, y2: float = 0, origin: ray.Vector2 = ray.Vector2(0,0), rotation: float = 0) -> None:
|
||||
mirror_x = -1 if mirror == 'horizontal' else 1
|
||||
mirror_y = -1 if mirror == 'vertical' else 1
|
||||
tex_object = self.textures[subset][texture]
|
||||
@@ -128,10 +128,10 @@ class TextureWrapper:
|
||||
raise Exception("Texture was marked as multiframe but is only 1 texture")
|
||||
if frame >= len(tex_object.texture):
|
||||
raise Exception(f"Frame {frame} not available in iterable texture {tex_object.name}")
|
||||
ray.draw_texture_pro(tex_object.texture[frame], source_rect, dest_rect, ray.Vector2(0, 0), 0, color)
|
||||
ray.draw_texture_pro(tex_object.texture[frame], source_rect, dest_rect, origin, rotation, color)
|
||||
else:
|
||||
if isinstance(tex_object.texture, list):
|
||||
raise Exception("Texture is multiframe but was called as 1 texture")
|
||||
ray.draw_texture_pro(tex_object.texture, source_rect, dest_rect, ray.Vector2(0, 0), 0, color)
|
||||
ray.draw_texture_pro(tex_object.texture, source_rect, dest_rect, origin, rotation, color)
|
||||
|
||||
tex = TextureWrapper()
|
||||
|
||||
@@ -340,7 +340,7 @@ class TJAParser:
|
||||
3: 5,
|
||||
4: 6,
|
||||
5: 7,
|
||||
6: 14,
|
||||
6: 8,
|
||||
7: 9,
|
||||
8: 10,
|
||||
9: 11
|
||||
|
||||
@@ -39,34 +39,6 @@ def force_dedicated_gpu():
|
||||
except Exception as e:
|
||||
print(e)
|
||||
|
||||
def get_zip_filenames(zip_path: Path) -> list[str]:
|
||||
result = []
|
||||
with zipfile.ZipFile(zip_path, 'r') as zip_ref:
|
||||
file_list = zip_ref.namelist()
|
||||
for file_name in file_list:
|
||||
result.append(file_name)
|
||||
return result
|
||||
|
||||
def load_image_from_zip(zip_path: Path, filename: str) -> ray.Image:
|
||||
with zipfile.ZipFile(zip_path, 'r') as zip_ref:
|
||||
with zip_ref.open(filename) as image_file:
|
||||
with tempfile.NamedTemporaryFile(delete=False, suffix='.png') as temp_file:
|
||||
temp_file.write(image_file.read())
|
||||
temp_file_path = temp_file.name
|
||||
image = ray.load_image(temp_file_path)
|
||||
os.remove(temp_file_path)
|
||||
return image
|
||||
|
||||
def load_texture_from_zip(zip_path: Path, filename: str) -> ray.Texture:
|
||||
with zipfile.ZipFile(zip_path, 'r') as zip_ref:
|
||||
with zip_ref.open(filename) as image_file:
|
||||
with tempfile.NamedTemporaryFile(delete=False, suffix='.png') as temp_file:
|
||||
temp_file.write(image_file.read())
|
||||
temp_file_path = temp_file.name
|
||||
texture = ray.load_texture(temp_file_path)
|
||||
os.remove(temp_file_path)
|
||||
return texture
|
||||
|
||||
def load_all_textures_from_zip(zip_path: Path) -> dict[str, list[ray.Texture]]:
|
||||
result_dict = dict()
|
||||
with zipfile.ZipFile(zip_path, 'r') as zip_ref:
|
||||
@@ -250,7 +222,6 @@ def reset_session():
|
||||
@dataclass
|
||||
class GlobalData:
|
||||
selected_song: Path = Path()
|
||||
textures: dict[str, list[ray.Texture]] = field(default_factory=lambda: dict())
|
||||
tex: TextureWrapper = field(default_factory=lambda: TextureWrapper())
|
||||
songs_played: int = 0
|
||||
config: dict = field(default_factory=lambda: dict())
|
||||
|
||||
Reference in New Issue
Block a user