mirror of
https://github.com/Yonokid/PyTaiko.git
synced 2026-02-04 11:40:13 +01:00
add crop data
This commit is contained in:
@@ -45,6 +45,7 @@ class Texture:
|
|||||||
self.x2: list[int] = [self.width]
|
self.x2: list[int] = [self.width]
|
||||||
self.y2: list[int] = [self.height]
|
self.y2: list[int] = [self.height]
|
||||||
self.controllable: list[bool] = [False]
|
self.controllable: list[bool] = [False]
|
||||||
|
self.crop_data: Optional[list[tuple[float, float, float, float]]] = None
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return f"{self.__dict__}"
|
return f"{self.__dict__}"
|
||||||
@@ -65,6 +66,7 @@ class FramedTexture:
|
|||||||
self.x2: list[int] = [self.width]
|
self.x2: list[int] = [self.width]
|
||||||
self.y2: list[int] = [self.height]
|
self.y2: list[int] = [self.height]
|
||||||
self.controllable: list[bool] = [False]
|
self.controllable: list[bool] = [False]
|
||||||
|
self.crop_data: Optional[list[tuple[float, float, float, float]]] = None
|
||||||
|
|
||||||
class TextureWrapper:
|
class TextureWrapper:
|
||||||
"""Texture wrapper class for managing textures and animations."""
|
"""Texture wrapper class for managing textures and animations."""
|
||||||
@@ -145,14 +147,24 @@ class TextureWrapper:
|
|||||||
tex_object.x2.append(tex_mapping[i].get("x2", tex_object.width))
|
tex_object.x2.append(tex_mapping[i].get("x2", tex_object.width))
|
||||||
tex_object.y2.append(tex_mapping[i].get("y2", tex_object.height))
|
tex_object.y2.append(tex_mapping[i].get("y2", tex_object.height))
|
||||||
tex_object.controllable.append(tex_mapping[i].get("controllable", False))
|
tex_object.controllable.append(tex_mapping[i].get("controllable", False))
|
||||||
|
if "frame_order" in tex_mapping[i]:
|
||||||
|
tex_object.texture = list(map(lambda j: tex_object.texture[j], tex_mapping[i]["frame_order"]))
|
||||||
|
if "crop" in tex_mapping[0]:
|
||||||
|
tex_object.crop_data = tex_mapping[0]["crop"]
|
||||||
|
tex_object.x2[i] = tex_object.crop_data[0][2]
|
||||||
|
tex_object.y2[i] = tex_object.crop_data[0][3]
|
||||||
else:
|
else:
|
||||||
tex_object.x = [tex_mapping.get("x", 0)]
|
tex_object.x = [tex_mapping.get("x", 0)]
|
||||||
tex_object.y = [tex_mapping.get("y", 0)]
|
tex_object.y = [tex_mapping.get("y", 0)]
|
||||||
tex_object.x2 = [tex_mapping.get("x2", tex_object.width)]
|
tex_object.x2 = [tex_mapping.get("x2", tex_object.width)]
|
||||||
tex_object.y2 = [tex_mapping.get("y2", tex_object.height)]
|
tex_object.y2 = [tex_mapping.get("y2", tex_object.height)]
|
||||||
tex_object.controllable = [tex_mapping.get("controllable", False)]
|
tex_object.controllable = [tex_mapping.get("controllable", False)]
|
||||||
if "frame_order" in tex_mapping:
|
if "frame_order" in tex_mapping and isinstance(tex_object, FramedTexture):
|
||||||
tex_object.texture = list(map(lambda i: tex_object.texture[i], tex_mapping["frame_order"]))
|
tex_object.texture = list(map(lambda i: tex_object.texture[i], tex_mapping["frame_order"]))
|
||||||
|
if "crop" in tex_mapping:
|
||||||
|
tex_object.crop_data = tex_mapping["crop"]
|
||||||
|
tex_object.x2 = [tex_object.crop_data[0][2]]
|
||||||
|
tex_object.y2 = [tex_object.crop_data[0][3]]
|
||||||
|
|
||||||
def load_animations(self, screen_name: str):
|
def load_animations(self, screen_name: str):
|
||||||
"""Load animations for a screen, falling back to parent if not found."""
|
"""Load animations for a screen, falling back to parent if not found."""
|
||||||
@@ -317,13 +329,14 @@ class TextureWrapper:
|
|||||||
tex_object = self.textures[subset][texture]
|
tex_object = self.textures[subset][texture]
|
||||||
if src is not None:
|
if src is not None:
|
||||||
source_rect = src
|
source_rect = src
|
||||||
|
elif tex_object.crop_data is not None:
|
||||||
|
source_rect = tex_object.crop_data[frame]
|
||||||
else:
|
else:
|
||||||
source_rect = (0, 0, tex_object.width * mirror_x, tex_object.height * mirror_y)
|
source_rect = (0, 0, tex_object.width * mirror_x, tex_object.height * mirror_y)
|
||||||
if center:
|
if center:
|
||||||
dest_rect = (tex_object.x[index] + (tex_object.width//2) - ((tex_object.width * scale)//2) + x, tex_object.y[index] + (tex_object.height//2) - ((tex_object.height * scale)//2) + y, tex_object.x2[index]*scale + x2, tex_object.y2[index]*scale + y2)
|
dest_rect = (tex_object.x[index] + (tex_object.width//2) - ((tex_object.width * scale)//2) + x, tex_object.y[index] + (tex_object.height//2) - ((tex_object.height * scale)//2) + y, tex_object.x2[index]*scale + x2, tex_object.y2[index]*scale + y2)
|
||||||
else:
|
else:
|
||||||
dest_rect = (tex_object.x[index] + x, tex_object.y[index] + y, tex_object.x2[index]*scale + x2, tex_object.y2[index]*scale + y2)
|
dest_rect = (tex_object.x[index] + x, tex_object.y[index] + y, tex_object.x2[index]*scale + x2, tex_object.y2[index]*scale + y2)
|
||||||
|
|
||||||
if isinstance(tex_object, FramedTexture):
|
if isinstance(tex_object, FramedTexture):
|
||||||
if frame >= len(tex_object.texture):
|
if frame >= len(tex_object.texture):
|
||||||
raise Exception(f"Frame {frame} not available in iterable texture {tex_object.name}")
|
raise Exception(f"Frame {frame} not available in iterable texture {tex_object.name}")
|
||||||
|
|||||||
@@ -68,6 +68,7 @@ class DanGameScreen(GameScreen):
|
|||||||
for branch in branch_n:
|
for branch in branch_n:
|
||||||
self.total_notes += sum(1 for note in branch.play_notes if note.type < 5)
|
self.total_notes += sum(1 for note in branch.play_notes if note.type < 5)
|
||||||
song, genre_index, difficulty, level = songs[self.song_index]
|
song, genre_index, difficulty, level = songs[self.song_index]
|
||||||
|
self.total_notes //= 2
|
||||||
session_data.selected_difficulty = difficulty
|
session_data.selected_difficulty = difficulty
|
||||||
self.init_tja(song.file_path)
|
self.init_tja(song.file_path)
|
||||||
self.color = session_data.dan_color
|
self.color = session_data.dan_color
|
||||||
|
|||||||
Reference in New Issue
Block a user