mirror of
https://github.com/Yonokid/PyTaiko.git
synced 2026-02-04 11:40:13 +01:00
Compare commits
12 Commits
5a5f9d9d0d
...
legacy-aud
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9397f28808 | ||
|
|
034be723c9 | ||
|
|
81d67a7ab3 | ||
|
|
1ba25d6ce6 | ||
|
|
0c9645bda7 | ||
|
|
f62201dbb5 | ||
|
|
027ef5408a | ||
|
|
29d3fdd289 | ||
|
|
0fa765e58b | ||
|
|
0e5100c3d0 | ||
|
|
7111677e0f | ||
|
|
a461a4efa9 |
@@ -297,7 +297,7 @@ def draw_fps(last_fps: int):
|
|||||||
elif last_fps < 60:
|
elif last_fps < 60:
|
||||||
pyray.draw_text_ex(global_data.font, f'{last_fps} FPS', (pos, pos), pos, 1, pyray.YELLOW)
|
pyray.draw_text_ex(global_data.font, f'{last_fps} FPS', (pos, pos), pos, 1, pyray.YELLOW)
|
||||||
else:
|
else:
|
||||||
pyray.draw_text_ex(global_data.font, f'{last_fps} FPS', (pos, pos), pos, 1, pyray.LIME)
|
pyray.draw_text_ex(pyray.get_font_default(), f'{last_fps} FPS', (pos, pos), pos, 1, pyray.LIME)
|
||||||
|
|
||||||
def draw_outer_border(screen_width: int, screen_height: int, last_color: pyray.Color):
|
def draw_outer_border(screen_width: int, screen_height: int, last_color: pyray.Color):
|
||||||
pyray.draw_rectangle(-screen_width, 0, screen_width, screen_height, last_color)
|
pyray.draw_rectangle(-screen_width, 0, screen_width, screen_height, last_color)
|
||||||
@@ -446,6 +446,8 @@ def main():
|
|||||||
audio.close_audio_device()
|
audio.close_audio_device()
|
||||||
if discord_connected:
|
if discord_connected:
|
||||||
RPC.close()
|
RPC.close()
|
||||||
|
global_tex.unload_textures()
|
||||||
|
screen_mapping[current_screen].on_screen_end("LOADING")
|
||||||
logger.info("Window closed and audio device shut down")
|
logger.info("Window closed and audio device shut down")
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
Submodule Skins/PyTaikoGreen updated: 1829a2538b...8cac9f3e0b
@@ -64,7 +64,7 @@ device_type = 0
|
|||||||
sample_rate = 44100
|
sample_rate = 44100
|
||||||
# buffer_size: Size in samples per audio buffer
|
# buffer_size: Size in samples per audio buffer
|
||||||
# - 0 = let driver choose (may result in very small buffers with ASIO, typically 64)
|
# - 0 = let driver choose (may result in very small buffers with ASIO, typically 64)
|
||||||
buffer_size = 32
|
buffer_size = 128
|
||||||
|
|
||||||
[volume]
|
[volume]
|
||||||
sound = 1.0
|
sound = 1.0
|
||||||
|
|||||||
@@ -3,17 +3,8 @@ from typing import Any, Optional
|
|||||||
|
|
||||||
from libs.global_data import global_data
|
from libs.global_data import global_data
|
||||||
|
|
||||||
|
def get_current_ms() -> float:
|
||||||
def rounded(num: float) -> int:
|
return time.time() * 1000
|
||||||
sign = 1 if (num >= 0) else -1
|
|
||||||
num = abs(num)
|
|
||||||
result = int(num)
|
|
||||||
if (num - result >= 0.5):
|
|
||||||
result += 1
|
|
||||||
return sign * result
|
|
||||||
|
|
||||||
def get_current_ms() -> int:
|
|
||||||
return rounded(time.time() * 1000)
|
|
||||||
|
|
||||||
|
|
||||||
class BaseAnimation():
|
class BaseAnimation():
|
||||||
@@ -84,6 +75,22 @@ class BaseAnimation():
|
|||||||
self.restart()
|
self.restart()
|
||||||
self.pause()
|
self.pause()
|
||||||
|
|
||||||
|
def copy(self):
|
||||||
|
"""Create a copy of the animation with reset state."""
|
||||||
|
new_anim = self.__class__.__new__(self.__class__)
|
||||||
|
new_anim.duration = self.duration
|
||||||
|
new_anim.delay = self.delay_saved
|
||||||
|
new_anim.delay_saved = self.delay_saved
|
||||||
|
new_anim.start_ms = get_current_ms()
|
||||||
|
new_anim.is_finished = False
|
||||||
|
new_anim.attribute = 0
|
||||||
|
new_anim.is_started = False
|
||||||
|
new_anim.is_reversing = False
|
||||||
|
new_anim.unlocked = False
|
||||||
|
new_anim.loop = self.loop
|
||||||
|
new_anim.lock_input = self.lock_input
|
||||||
|
return new_anim
|
||||||
|
|
||||||
def _ease_in(self, progress: float, ease_type: str) -> float:
|
def _ease_in(self, progress: float, ease_type: str) -> float:
|
||||||
if ease_type == "quadratic":
|
if ease_type == "quadratic":
|
||||||
return progress * progress
|
return progress * progress
|
||||||
@@ -133,6 +140,20 @@ class FadeAnimation(BaseAnimation):
|
|||||||
self.final_opacity = self.final_opacity_saved
|
self.final_opacity = self.final_opacity_saved
|
||||||
self.attribute = self.initial_opacity
|
self.attribute = self.initial_opacity
|
||||||
|
|
||||||
|
def copy(self):
|
||||||
|
"""Create a copy of the fade animation with reset state."""
|
||||||
|
new_anim = super().copy()
|
||||||
|
new_anim.initial_opacity = self.initial_opacity_saved
|
||||||
|
new_anim.initial_opacity_saved = self.initial_opacity_saved
|
||||||
|
new_anim.final_opacity = self.final_opacity_saved
|
||||||
|
new_anim.final_opacity_saved = self.final_opacity_saved
|
||||||
|
new_anim.ease_in = self.ease_in
|
||||||
|
new_anim.ease_out = self.ease_out
|
||||||
|
new_anim.reverse_delay = self.reverse_delay_saved
|
||||||
|
new_anim.reverse_delay_saved = self.reverse_delay_saved
|
||||||
|
new_anim.attribute = self.initial_opacity_saved
|
||||||
|
return new_anim
|
||||||
|
|
||||||
def update(self, current_time_ms: float) -> None:
|
def update(self, current_time_ms: float) -> None:
|
||||||
if not self.is_started:
|
if not self.is_started:
|
||||||
return
|
return
|
||||||
@@ -181,6 +202,20 @@ class MoveAnimation(BaseAnimation):
|
|||||||
self.start_position = self.start_position_saved
|
self.start_position = self.start_position_saved
|
||||||
self.attribute = self.start_position
|
self.attribute = self.start_position
|
||||||
|
|
||||||
|
def copy(self):
|
||||||
|
"""Create a copy of the move animation with reset state."""
|
||||||
|
new_anim = super().copy()
|
||||||
|
new_anim.reverse_delay = self.reverse_delay_saved
|
||||||
|
new_anim.reverse_delay_saved = self.reverse_delay_saved
|
||||||
|
new_anim.total_distance = self.total_distance_saved
|
||||||
|
new_anim.total_distance_saved = self.total_distance_saved
|
||||||
|
new_anim.start_position = self.start_position_saved
|
||||||
|
new_anim.start_position_saved = self.start_position_saved
|
||||||
|
new_anim.ease_in = self.ease_in
|
||||||
|
new_anim.ease_out = self.ease_out
|
||||||
|
new_anim.attribute = self.start_position_saved
|
||||||
|
return new_anim
|
||||||
|
|
||||||
def update(self, current_time_ms: float) -> None:
|
def update(self, current_time_ms: float) -> None:
|
||||||
if not self.is_started:
|
if not self.is_started:
|
||||||
return
|
return
|
||||||
@@ -217,6 +252,13 @@ class TextureChangeAnimation(BaseAnimation):
|
|||||||
super().reset()
|
super().reset()
|
||||||
self.attribute = self.textures[0][2]
|
self.attribute = self.textures[0][2]
|
||||||
|
|
||||||
|
def copy(self):
|
||||||
|
"""Create a copy of the texture change animation with reset state."""
|
||||||
|
new_anim = super().copy()
|
||||||
|
new_anim.textures = self.textures # List of tuples, can be shared
|
||||||
|
new_anim.attribute = self.textures[0][2]
|
||||||
|
return new_anim
|
||||||
|
|
||||||
def update(self, current_time_ms: float) -> None:
|
def update(self, current_time_ms: float) -> None:
|
||||||
if not self.is_started:
|
if not self.is_started:
|
||||||
return
|
return
|
||||||
@@ -234,6 +276,10 @@ class TextureChangeAnimation(BaseAnimation):
|
|||||||
self.is_finished = True
|
self.is_finished = True
|
||||||
|
|
||||||
class TextStretchAnimation(BaseAnimation):
|
class TextStretchAnimation(BaseAnimation):
|
||||||
|
def copy(self):
|
||||||
|
"""Create a copy of the text stretch animation with reset state."""
|
||||||
|
return super().copy()
|
||||||
|
|
||||||
def update(self, current_time_ms: float) -> None:
|
def update(self, current_time_ms: float) -> None:
|
||||||
if not self.is_started:
|
if not self.is_started:
|
||||||
return
|
return
|
||||||
@@ -275,6 +321,20 @@ class TextureResizeAnimation(BaseAnimation):
|
|||||||
self.initial_size = self.initial_size_saved
|
self.initial_size = self.initial_size_saved
|
||||||
self.final_size = self.final_size_saved
|
self.final_size = self.final_size_saved
|
||||||
|
|
||||||
|
def copy(self):
|
||||||
|
"""Create a copy of the texture resize animation with reset state."""
|
||||||
|
new_anim = super().copy()
|
||||||
|
new_anim.initial_size = self.initial_size_saved
|
||||||
|
new_anim.initial_size_saved = self.initial_size_saved
|
||||||
|
new_anim.final_size = self.final_size_saved
|
||||||
|
new_anim.final_size_saved = self.final_size_saved
|
||||||
|
new_anim.reverse_delay = self.reverse_delay_saved
|
||||||
|
new_anim.reverse_delay_saved = self.reverse_delay_saved
|
||||||
|
new_anim.ease_in = self.ease_in
|
||||||
|
new_anim.ease_out = self.ease_out
|
||||||
|
new_anim.attribute = self.initial_size_saved
|
||||||
|
return new_anim
|
||||||
|
|
||||||
|
|
||||||
def update(self, current_time_ms: float) -> None:
|
def update(self, current_time_ms: float) -> None:
|
||||||
if not self.is_started:
|
if not self.is_started:
|
||||||
|
|||||||
185
libs/audio.py
185
libs/audio.py
@@ -1,5 +1,6 @@
|
|||||||
import logging
|
import logging
|
||||||
import platform
|
import platform
|
||||||
|
import pyray as ray
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
import cffi
|
import cffi
|
||||||
@@ -92,6 +93,7 @@ ffi.cdef("""
|
|||||||
void resume_music_stream(music music);
|
void resume_music_stream(music music);
|
||||||
void stop_music_stream(music music);
|
void stop_music_stream(music music);
|
||||||
void seek_music_stream(music music, float position);
|
void seek_music_stream(music music, float position);
|
||||||
|
bool music_stream_needs_update(music music);
|
||||||
void update_music_stream(music music);
|
void update_music_stream(music music);
|
||||||
bool is_music_stream_playing(music music);
|
bool is_music_stream_playing(music music);
|
||||||
void set_music_volume(music music, float volume);
|
void set_music_volume(music music, float volume);
|
||||||
@@ -131,6 +133,7 @@ class AudioEngine:
|
|||||||
self.music_streams = {}
|
self.music_streams = {}
|
||||||
self.audio_device_ready = False
|
self.audio_device_ready = False
|
||||||
self.volume_presets = volume_presets
|
self.volume_presets = volume_presets
|
||||||
|
self.lib = lib
|
||||||
|
|
||||||
if sounds_path is None:
|
if sounds_path is None:
|
||||||
self.sounds_path = Path(f"Skins/{get_config()['paths']['skin']}/Sounds")
|
self.sounds_path = Path(f"Skins/{get_config()['paths']['skin']}/Sounds")
|
||||||
@@ -138,15 +141,15 @@ class AudioEngine:
|
|||||||
self.sounds_path = sounds_path
|
self.sounds_path = sounds_path
|
||||||
|
|
||||||
def set_log_level(self, level: int):
|
def set_log_level(self, level: int):
|
||||||
lib.set_log_level(level) # type: ignore
|
self.lib.set_log_level(level) # type: ignore
|
||||||
|
|
||||||
def list_host_apis(self):
|
def list_host_apis(self):
|
||||||
"""Prints a list of available host APIs to the console"""
|
"""Prints a list of available host APIs to the console"""
|
||||||
lib.list_host_apis() # type: ignore
|
self.lib.list_host_apis() # type: ignore
|
||||||
|
|
||||||
def get_host_api_name(self, api_id: int) -> str:
|
def get_host_api_name(self, api_id: int) -> str:
|
||||||
"""Returns the name of the host API with the given ID"""
|
"""Returns the name of the host API with the given ID"""
|
||||||
result = lib.get_host_api_name(api_id) # type: ignore
|
result = self.lib.get_host_api_name(api_id) # type: ignore
|
||||||
if result == ffi.NULL:
|
if result == ffi.NULL:
|
||||||
return ""
|
return ""
|
||||||
result = ffi.string(result)
|
result = ffi.string(result)
|
||||||
@@ -157,12 +160,12 @@ class AudioEngine:
|
|||||||
def init_audio_device(self) -> bool:
|
def init_audio_device(self) -> bool:
|
||||||
"""Initialize the audio device"""
|
"""Initialize the audio device"""
|
||||||
try:
|
try:
|
||||||
lib.init_audio_device(self.device_type, self.target_sample_rate, self.buffer_size) # type: ignore
|
self.lib.init_audio_device(self.device_type, self.target_sample_rate, self.buffer_size) # type: ignore
|
||||||
self.audio_device_ready = lib.is_audio_device_ready() # type: ignore
|
self.audio_device_ready = self.lib.is_audio_device_ready() # type: ignore
|
||||||
file_path_str = str(self.sounds_path / 'don.wav').encode('utf-8')
|
file_path_str = str(self.sounds_path / 'don.wav').encode('utf-8')
|
||||||
self.don = lib.load_sound(file_path_str) # type: ignore
|
self.don = self.lib.load_sound(file_path_str) # type: ignore
|
||||||
file_path_str = str(self.sounds_path / 'ka.wav').encode('utf-8')
|
file_path_str = str(self.sounds_path / 'ka.wav').encode('utf-8')
|
||||||
self.kat = lib.load_sound(file_path_str) # type: ignore
|
self.kat = self.lib.load_sound(file_path_str) # type: ignore
|
||||||
if self.audio_device_ready:
|
if self.audio_device_ready:
|
||||||
logger.info("Audio device initialized successfully")
|
logger.info("Audio device initialized successfully")
|
||||||
return self.audio_device_ready
|
return self.audio_device_ready
|
||||||
@@ -179,9 +182,9 @@ class AudioEngine:
|
|||||||
for music_id in list(self.music_streams.keys()):
|
for music_id in list(self.music_streams.keys()):
|
||||||
self.unload_music_stream(music_id)
|
self.unload_music_stream(music_id)
|
||||||
|
|
||||||
lib.unload_sound(self.don) # type: ignore
|
self.lib.unload_sound(self.don) # type: ignore
|
||||||
lib.unload_sound(self.kat) # type: ignore
|
self.lib.unload_sound(self.kat) # type: ignore
|
||||||
lib.close_audio_device() # type: ignore
|
self.lib.close_audio_device() # type: ignore
|
||||||
self.audio_device_ready = False
|
self.audio_device_ready = False
|
||||||
logger.info("Audio device closed")
|
logger.info("Audio device closed")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@@ -189,15 +192,15 @@ class AudioEngine:
|
|||||||
|
|
||||||
def is_audio_device_ready(self) -> bool:
|
def is_audio_device_ready(self) -> bool:
|
||||||
"""Check if audio device is ready"""
|
"""Check if audio device is ready"""
|
||||||
return lib.is_audio_device_ready() # type: ignore
|
return self.lib.is_audio_device_ready() # type: ignore
|
||||||
|
|
||||||
def set_master_volume(self, volume: float) -> None:
|
def set_master_volume(self, volume: float) -> None:
|
||||||
"""Set master volume (0.0 to 1.0)"""
|
"""Set master volume (0.0 to 1.0)"""
|
||||||
lib.set_master_volume(max(0.0, min(1.0, volume))) # type: ignore
|
self.lib.set_master_volume(max(0.0, min(1.0, volume))) # type: ignore
|
||||||
|
|
||||||
def get_master_volume(self) -> float:
|
def get_master_volume(self) -> float:
|
||||||
"""Get master volume"""
|
"""Get master volume"""
|
||||||
return lib.get_master_volume() # type: ignore
|
return self.lib.get_master_volume() # type: ignore
|
||||||
|
|
||||||
# Sound management
|
# Sound management
|
||||||
def load_sound(self, file_path: Path, name: str) -> str:
|
def load_sound(self, file_path: Path, name: str) -> str:
|
||||||
@@ -208,13 +211,13 @@ class AudioEngine:
|
|||||||
file_path_str = str(file_path).encode('cp932', errors='replace')
|
file_path_str = str(file_path).encode('cp932', errors='replace')
|
||||||
else:
|
else:
|
||||||
file_path_str = str(file_path).encode('utf-8')
|
file_path_str = str(file_path).encode('utf-8')
|
||||||
sound = lib.load_sound(file_path_str) # type: ignore
|
sound = self.lib.load_sound(file_path_str) # type: ignore
|
||||||
|
|
||||||
if not lib.is_sound_valid(sound): # type: ignore
|
if not self.lib.is_sound_valid(sound): # type: ignore
|
||||||
file_path_str = str(file_path).encode('utf-8')
|
file_path_str = str(file_path).encode('utf-8')
|
||||||
sound = lib.load_sound(file_path_str) # type: ignore
|
sound = self.lib.load_sound(file_path_str) # type: ignore
|
||||||
|
|
||||||
if lib.is_sound_valid(sound): # type: ignore
|
if self.lib.is_sound_valid(sound): # type: ignore
|
||||||
self.sounds[name] = sound
|
self.sounds[name] = sound
|
||||||
return name
|
return name
|
||||||
else:
|
else:
|
||||||
@@ -227,7 +230,7 @@ class AudioEngine:
|
|||||||
def unload_sound(self, name: str) -> None:
|
def unload_sound(self, name: str) -> None:
|
||||||
"""Unload a sound by name"""
|
"""Unload a sound by name"""
|
||||||
if name in self.sounds:
|
if name in self.sounds:
|
||||||
lib.unload_sound(self.sounds[name]) # type: ignore
|
self.lib.unload_sound(self.sounds[name]) # type: ignore
|
||||||
del self.sounds[name]
|
del self.sounds[name]
|
||||||
else:
|
else:
|
||||||
logger.warning(f"Sound {name} not found")
|
logger.warning(f"Sound {name} not found")
|
||||||
@@ -262,41 +265,41 @@ class AudioEngine:
|
|||||||
"""Play a sound"""
|
"""Play a sound"""
|
||||||
if name == 'don':
|
if name == 'don':
|
||||||
if volume_preset:
|
if volume_preset:
|
||||||
lib.set_sound_volume(self.don, self.volume_presets[volume_preset]) # type: ignore
|
self.lib.set_sound_volume(self.don, self.volume_presets[volume_preset]) # type: ignore
|
||||||
lib.play_sound(self.don) # type: ignore
|
self.lib.play_sound(self.don) # type: ignore
|
||||||
elif name == 'kat':
|
elif name == 'kat':
|
||||||
if volume_preset:
|
if volume_preset:
|
||||||
lib.set_sound_volume(self.kat, self.volume_presets[volume_preset]) # type: ignore
|
self.lib.set_sound_volume(self.kat, self.volume_presets[volume_preset]) # type: ignore
|
||||||
lib.play_sound(self.kat) # type: ignore
|
self.lib.play_sound(self.kat) # type: ignore
|
||||||
elif name in self.sounds:
|
elif name in self.sounds:
|
||||||
sound = self.sounds[name]
|
sound = self.sounds[name]
|
||||||
if volume_preset:
|
if volume_preset:
|
||||||
lib.set_sound_volume(sound, self.volume_presets[volume_preset]) # type: ignore
|
self.lib.set_sound_volume(sound, self.volume_presets[volume_preset]) # type: ignore
|
||||||
lib.play_sound(sound) # type: ignore
|
self.lib.play_sound(sound) # type: ignore
|
||||||
else:
|
else:
|
||||||
logger.warning(f"Sound {name} not found")
|
logger.warning(f"Sound {name} not found")
|
||||||
|
|
||||||
def stop_sound(self, name: str) -> None:
|
def stop_sound(self, name: str) -> None:
|
||||||
"""Stop a sound"""
|
"""Stop a sound"""
|
||||||
if name == 'don':
|
if name == 'don':
|
||||||
lib.stop_sound(self.don) # type: ignore
|
self.lib.stop_sound(self.don) # type: ignore
|
||||||
elif name == 'kat':
|
elif name == 'kat':
|
||||||
lib.stop_sound(self.kat) # type: ignore
|
self.lib.stop_sound(self.kat) # type: ignore
|
||||||
if name in self.sounds:
|
if name in self.sounds:
|
||||||
sound = self.sounds[name]
|
sound = self.sounds[name]
|
||||||
lib.stop_sound(sound) # type: ignore
|
self.lib.stop_sound(sound) # type: ignore
|
||||||
else:
|
else:
|
||||||
logger.warning(f"Sound {name} not found")
|
logger.warning(f"Sound {name} not found")
|
||||||
|
|
||||||
def is_sound_playing(self, name: str) -> bool:
|
def is_sound_playing(self, name: str) -> bool:
|
||||||
"""Check if a sound is playing"""
|
"""Check if a sound is playing"""
|
||||||
if name == 'don':
|
if name == 'don':
|
||||||
return lib.is_sound_playing(self.don) # type: ignore
|
return self.lib.is_sound_playing(self.don) # type: ignore
|
||||||
elif name == 'kat':
|
elif name == 'kat':
|
||||||
return lib.is_sound_playing(self.kat) # type: ignore
|
return self.lib.is_sound_playing(self.kat) # type: ignore
|
||||||
if name in self.sounds:
|
if name in self.sounds:
|
||||||
sound = self.sounds[name]
|
sound = self.sounds[name]
|
||||||
return lib.is_sound_playing(sound) # type: ignore
|
return self.lib.is_sound_playing(sound) # type: ignore
|
||||||
else:
|
else:
|
||||||
logger.warning(f"Sound {name} not found")
|
logger.warning(f"Sound {name} not found")
|
||||||
return False
|
return False
|
||||||
@@ -304,24 +307,24 @@ class AudioEngine:
|
|||||||
def set_sound_volume(self, name: str, volume: float) -> None:
|
def set_sound_volume(self, name: str, volume: float) -> None:
|
||||||
"""Set the volume of a specific sound"""
|
"""Set the volume of a specific sound"""
|
||||||
if name == 'don':
|
if name == 'don':
|
||||||
lib.set_sound_volume(self.don, volume) # type: ignore
|
self.lib.set_sound_volume(self.don, volume) # type: ignore
|
||||||
elif name == 'kat':
|
elif name == 'kat':
|
||||||
lib.set_sound_volume(self.kat, volume) # type: ignore
|
self.lib.set_sound_volume(self.kat, volume) # type: ignore
|
||||||
elif name in self.sounds:
|
elif name in self.sounds:
|
||||||
sound = self.sounds[name]
|
sound = self.sounds[name]
|
||||||
lib.set_sound_volume(sound, volume) # type: ignore
|
self.lib.set_sound_volume(sound, volume) # type: ignore
|
||||||
else:
|
else:
|
||||||
logger.warning(f"Sound {name} not found")
|
logger.warning(f"Sound {name} not found")
|
||||||
|
|
||||||
def set_sound_pan(self, name: str, pan: float) -> None:
|
def set_sound_pan(self, name: str, pan: float) -> None:
|
||||||
"""Set the pan of a specific sound"""
|
"""Set the pan of a specific sound"""
|
||||||
if name == 'don':
|
if name == 'don':
|
||||||
lib.set_sound_pan(self.don, pan) # type: ignore
|
self.lib.set_sound_pan(self.don, pan) # type: ignore
|
||||||
elif name == 'kat':
|
elif name == 'kat':
|
||||||
lib.set_sound_pan(self.kat, pan) # type: ignore
|
self.lib.set_sound_pan(self.kat, pan) # type: ignore
|
||||||
elif name in self.sounds:
|
elif name in self.sounds:
|
||||||
sound = self.sounds[name]
|
sound = self.sounds[name]
|
||||||
lib.set_sound_pan(sound, pan) # type: ignore
|
self.lib.set_sound_pan(sound, pan) # type: ignore
|
||||||
else:
|
else:
|
||||||
logger.warning(f"Sound {name} not found")
|
logger.warning(f"Sound {name} not found")
|
||||||
|
|
||||||
@@ -334,13 +337,13 @@ class AudioEngine:
|
|||||||
else:
|
else:
|
||||||
file_path_str = str(file_path).encode('utf-8')
|
file_path_str = str(file_path).encode('utf-8')
|
||||||
|
|
||||||
music = lib.load_music_stream(file_path_str) # type: ignore
|
music = self.lib.load_music_stream(file_path_str) # type: ignore
|
||||||
|
|
||||||
if not lib.is_music_valid(music): # type: ignore
|
if not self.lib.is_music_valid(music): # type: ignore
|
||||||
file_path_str = str(file_path).encode('utf-8')
|
file_path_str = str(file_path).encode('utf-8')
|
||||||
music = lib.load_music_stream(file_path_str) # type: ignore
|
music = self.lib.load_music_stream(file_path_str) # type: ignore
|
||||||
|
|
||||||
if lib.is_music_valid(music): # type: ignore
|
if self.lib.is_music_valid(music): # type: ignore
|
||||||
self.music_streams[name] = music
|
self.music_streams[name] = music
|
||||||
logger.info(f"Loaded music stream from {file_path} as {name}")
|
logger.info(f"Loaded music stream from {file_path} as {name}")
|
||||||
return name
|
return name
|
||||||
@@ -352,18 +355,26 @@ class AudioEngine:
|
|||||||
"""Play a music stream"""
|
"""Play a music stream"""
|
||||||
if name in self.music_streams:
|
if name in self.music_streams:
|
||||||
music = self.music_streams[name]
|
music = self.music_streams[name]
|
||||||
lib.seek_music_stream(music, 0) # type: ignore
|
self.lib.seek_music_stream(music, 0) # type: ignore
|
||||||
if volume_preset:
|
if volume_preset:
|
||||||
lib.set_music_volume(music, self.volume_presets[volume_preset]) # type: ignore
|
self.lib.set_music_volume(music, self.volume_presets[volume_preset]) # type: ignore
|
||||||
lib.play_music_stream(music) # type: ignore
|
self.lib.play_music_stream(music) # type: ignore
|
||||||
else:
|
else:
|
||||||
logger.warning(f"Music stream {name} not found")
|
logger.warning(f"Music stream {name} not found")
|
||||||
|
|
||||||
def update_music_stream(self, name: str) -> None:
|
def music_stream_needs_update(self, name: str) -> bool:
|
||||||
"""Update a music stream"""
|
"""Check if a music stream needs updating (buffers need refilling)"""
|
||||||
if name in self.music_streams:
|
if name in self.music_streams:
|
||||||
music = self.music_streams[name]
|
music = self.music_streams[name]
|
||||||
lib.update_music_stream(music) # type: ignore
|
return self.lib.music_stream_needs_update(music) # type: ignore
|
||||||
|
return False
|
||||||
|
|
||||||
|
def update_music_stream(self, name: str) -> None:
|
||||||
|
"""Update a music stream (only if buffers need refilling)"""
|
||||||
|
if name in self.music_streams:
|
||||||
|
music = self.music_streams[name]
|
||||||
|
if self.lib.music_stream_needs_update(music): # type: ignore
|
||||||
|
self.lib.update_music_stream(music) # type: ignore
|
||||||
else:
|
else:
|
||||||
logger.warning(f"Music stream {name} not found")
|
logger.warning(f"Music stream {name} not found")
|
||||||
|
|
||||||
@@ -371,7 +382,7 @@ class AudioEngine:
|
|||||||
"""Get the time length of a music stream"""
|
"""Get the time length of a music stream"""
|
||||||
if name in self.music_streams:
|
if name in self.music_streams:
|
||||||
music = self.music_streams[name]
|
music = self.music_streams[name]
|
||||||
return lib.get_music_time_length(music) # type: ignore
|
return self.lib.get_music_time_length(music) # type: ignore
|
||||||
else:
|
else:
|
||||||
logger.warning(f"Music stream {name} not found")
|
logger.warning(f"Music stream {name} not found")
|
||||||
return 0.0
|
return 0.0
|
||||||
@@ -380,7 +391,7 @@ class AudioEngine:
|
|||||||
"""Get the time played of a music stream"""
|
"""Get the time played of a music stream"""
|
||||||
if name in self.music_streams:
|
if name in self.music_streams:
|
||||||
music = self.music_streams[name]
|
music = self.music_streams[name]
|
||||||
return lib.get_music_time_played(music) # type: ignore
|
return self.lib.get_music_time_played(music) # type: ignore
|
||||||
else:
|
else:
|
||||||
logger.warning(f"Music stream {name} not found")
|
logger.warning(f"Music stream {name} not found")
|
||||||
return 0.0
|
return 0.0
|
||||||
@@ -389,7 +400,7 @@ class AudioEngine:
|
|||||||
"""Set the volume of a music stream"""
|
"""Set the volume of a music stream"""
|
||||||
if name in self.music_streams:
|
if name in self.music_streams:
|
||||||
music = self.music_streams[name]
|
music = self.music_streams[name]
|
||||||
lib.set_music_volume(music, volume) # type: ignore
|
self.lib.set_music_volume(music, volume) # type: ignore
|
||||||
else:
|
else:
|
||||||
logger.warning(f"Music stream {name} not found")
|
logger.warning(f"Music stream {name} not found")
|
||||||
|
|
||||||
@@ -397,7 +408,7 @@ class AudioEngine:
|
|||||||
"""Check if a music stream is playing"""
|
"""Check if a music stream is playing"""
|
||||||
if name in self.music_streams:
|
if name in self.music_streams:
|
||||||
music = self.music_streams[name]
|
music = self.music_streams[name]
|
||||||
return lib.is_music_stream_playing(music) # type: ignore
|
return self.lib.is_music_stream_playing(music) # type: ignore
|
||||||
else:
|
else:
|
||||||
logger.warning(f"Music stream {name} not found")
|
logger.warning(f"Music stream {name} not found")
|
||||||
return False
|
return False
|
||||||
@@ -406,7 +417,7 @@ class AudioEngine:
|
|||||||
"""Stop a music stream"""
|
"""Stop a music stream"""
|
||||||
if name in self.music_streams:
|
if name in self.music_streams:
|
||||||
music = self.music_streams[name]
|
music = self.music_streams[name]
|
||||||
lib.stop_music_stream(music) # type: ignore
|
self.lib.stop_music_stream(music) # type: ignore
|
||||||
else:
|
else:
|
||||||
logger.warning(f"Music stream {name} not found")
|
logger.warning(f"Music stream {name} not found")
|
||||||
|
|
||||||
@@ -414,7 +425,7 @@ class AudioEngine:
|
|||||||
"""Unload a music stream"""
|
"""Unload a music stream"""
|
||||||
if name in self.music_streams:
|
if name in self.music_streams:
|
||||||
music = self.music_streams[name]
|
music = self.music_streams[name]
|
||||||
lib.unload_music_stream(music) # type: ignore
|
self.lib.unload_music_stream(music) # type: ignore
|
||||||
del self.music_streams[name]
|
del self.music_streams[name]
|
||||||
else:
|
else:
|
||||||
logger.warning(f"Music stream {name} not found")
|
logger.warning(f"Music stream {name} not found")
|
||||||
@@ -428,10 +439,76 @@ class AudioEngine:
|
|||||||
"""Seek a music stream to a specific position"""
|
"""Seek a music stream to a specific position"""
|
||||||
if name in self.music_streams:
|
if name in self.music_streams:
|
||||||
music = self.music_streams[name]
|
music = self.music_streams[name]
|
||||||
lib.seek_music_stream(music, position) # type: ignore
|
self.lib.seek_music_stream(music, position) # type: ignore
|
||||||
|
else:
|
||||||
|
logger.warning(f"Music stream {name} not found")
|
||||||
|
|
||||||
|
class AudioEngineLegacy(AudioEngine):
|
||||||
|
def __init__(self, device_type: int, sample_rate: float, buffer_size: int,
|
||||||
|
volume_presets: VolumeConfig, sounds_path: Path | None = None):
|
||||||
|
super().__init__(device_type, sample_rate, buffer_size, volume_presets, sounds_path)
|
||||||
|
self.lib = ray
|
||||||
|
|
||||||
|
def set_log_level(self, level: int):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def list_host_apis(self):
|
||||||
|
"""Prints a list of available host APIs to the console"""
|
||||||
|
pass
|
||||||
|
|
||||||
|
def get_host_api_name(self, api_id: int) -> str:
|
||||||
|
"""Returns the name of the host API with the given ID"""
|
||||||
|
return ''
|
||||||
|
|
||||||
|
def init_audio_device(self) -> bool:
|
||||||
|
"""Initialize the audio device"""
|
||||||
|
try:
|
||||||
|
self.lib.init_audio_device()
|
||||||
|
self.audio_device_ready = self.lib.is_audio_device_ready()
|
||||||
|
file_path_str = str(self.sounds_path / 'don.wav')
|
||||||
|
self.don = self.lib.load_sound(file_path_str)
|
||||||
|
file_path_str = str(self.sounds_path / 'ka.wav')
|
||||||
|
self.kat = self.lib.load_sound(file_path_str)
|
||||||
|
if self.audio_device_ready:
|
||||||
|
logger.info("Audio device initialized successfully")
|
||||||
|
return self.audio_device_ready
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"Failed to initialize audio device: {e}")
|
||||||
|
return False
|
||||||
|
|
||||||
|
def load_sound(self, file_path: Path, name: str) -> str:
|
||||||
|
"""Load a sound file and return sound ID"""
|
||||||
|
try:
|
||||||
|
sound = self.lib.load_sound(str(file_path))
|
||||||
|
if self.lib.is_sound_valid(sound):
|
||||||
|
self.sounds[name] = sound
|
||||||
|
return name
|
||||||
|
else:
|
||||||
|
logger.error(f"Failed to load sound: {file_path}")
|
||||||
|
return ""
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"Error loading sound {file_path}: {e}")
|
||||||
|
return ""
|
||||||
|
|
||||||
|
def load_music_stream(self, file_path: Path, name: str) -> str:
|
||||||
|
"""Load a music stream and return music ID"""
|
||||||
|
music = self.lib.load_music_stream(str(file_path))
|
||||||
|
if self.lib.is_music_valid(music):
|
||||||
|
self.music_streams[name] = music
|
||||||
|
logger.info(f"Loaded music stream from {file_path} as {name}")
|
||||||
|
return name
|
||||||
|
else:
|
||||||
|
logger.error(f"Failed to load music: {file_path}")
|
||||||
|
return ""
|
||||||
|
|
||||||
|
def update_music_stream(self, name: str) -> None:
|
||||||
|
"""Update a music stream (only if buffers need refilling)"""
|
||||||
|
if name in self.music_streams:
|
||||||
|
music = self.music_streams[name]
|
||||||
|
self.lib.update_music_stream(music)
|
||||||
else:
|
else:
|
||||||
logger.warning(f"Music stream {name} not found")
|
logger.warning(f"Music stream {name} not found")
|
||||||
|
|
||||||
# Create the global audio instance
|
# Create the global audio instance
|
||||||
audio = AudioEngine(get_config()["audio"]["device_type"], get_config()["audio"]["sample_rate"], get_config()["audio"]["buffer_size"], get_config()["volume"])
|
audio = AudioEngineLegacy(get_config()["audio"]["device_type"], get_config()["audio"]["sample_rate"], get_config()["audio"]["buffer_size"], get_config()["volume"])
|
||||||
audio.set_master_volume(0.75)
|
audio.set_master_volume(0.75)
|
||||||
|
|||||||
@@ -175,6 +175,7 @@ void pause_music_stream(music music);
|
|||||||
void resume_music_stream(music music);
|
void resume_music_stream(music music);
|
||||||
void stop_music_stream(music music);
|
void stop_music_stream(music music);
|
||||||
void seek_music_stream(music music, float position);
|
void seek_music_stream(music music, float position);
|
||||||
|
bool music_stream_needs_update(music music);
|
||||||
void update_music_stream(music music);
|
void update_music_stream(music music);
|
||||||
bool is_music_stream_playing(music music);
|
bool is_music_stream_playing(music music);
|
||||||
void set_music_volume(music music, float volume);
|
void set_music_volume(music music, float volume);
|
||||||
@@ -1064,6 +1065,17 @@ void seek_music_stream(music music, float position) {
|
|||||||
pthread_mutex_unlock(&AUDIO.System.lock);
|
pthread_mutex_unlock(&AUDIO.System.lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool music_stream_needs_update(music music) {
|
||||||
|
if (music.stream.buffer == NULL || music.ctxData == NULL) return false;
|
||||||
|
|
||||||
|
pthread_mutex_lock(&AUDIO.System.lock);
|
||||||
|
bool needs_update = music.stream.buffer->isSubBufferProcessed[0] ||
|
||||||
|
music.stream.buffer->isSubBufferProcessed[1];
|
||||||
|
pthread_mutex_unlock(&AUDIO.System.lock);
|
||||||
|
|
||||||
|
return needs_update;
|
||||||
|
}
|
||||||
|
|
||||||
void update_music_stream(music music) {
|
void update_music_stream(music music) {
|
||||||
if (music.stream.buffer == NULL || music.ctxData == NULL) return;
|
if (music.stream.buffer == NULL || music.ctxData == NULL) return;
|
||||||
|
|
||||||
@@ -1071,72 +1083,80 @@ void update_music_stream(music music) {
|
|||||||
SNDFILE *sndFile = ctx->snd_file;
|
SNDFILE *sndFile = ctx->snd_file;
|
||||||
if (sndFile == NULL) return;
|
if (sndFile == NULL) return;
|
||||||
|
|
||||||
|
bool needs_refill[2];
|
||||||
|
pthread_mutex_lock(&AUDIO.System.lock);
|
||||||
|
needs_refill[0] = music.stream.buffer->isSubBufferProcessed[0];
|
||||||
|
needs_refill[1] = music.stream.buffer->isSubBufferProcessed[1];
|
||||||
|
pthread_mutex_unlock(&AUDIO.System.lock);
|
||||||
|
|
||||||
|
if (!needs_refill[0] && !needs_refill[1]) return;
|
||||||
|
|
||||||
|
unsigned int subBufferSizeFrames = music.stream.buffer->sizeInFrames / 2;
|
||||||
|
float *buffer_data = (float *)music.stream.buffer->data;
|
||||||
|
bool needs_resampling = (ctx->resampler != NULL);
|
||||||
|
bool needs_mono_to_stereo = (music.stream.channels == 1 && AUDIO_DEVICE_CHANNELS == 2);
|
||||||
|
|
||||||
|
unsigned int frames_to_read = subBufferSizeFrames;
|
||||||
|
if (needs_resampling) {
|
||||||
|
frames_to_read = (unsigned int)(subBufferSizeFrames / ctx->src_ratio) + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t required_size = frames_to_read * music.stream.channels * sizeof(float);
|
||||||
|
if (AUDIO.System.pcmBufferSize < required_size) {
|
||||||
|
FREE(AUDIO.System.pcmBuffer);
|
||||||
|
AUDIO.System.pcmBuffer = calloc(1, required_size);
|
||||||
|
AUDIO.System.pcmBufferSize = required_size;
|
||||||
|
}
|
||||||
|
|
||||||
for (int i = 0; i < 2; i++) {
|
for (int i = 0; i < 2; i++) {
|
||||||
pthread_mutex_lock(&AUDIO.System.lock);
|
if (!needs_refill[i]) continue;
|
||||||
bool needs_refill = music.stream.buffer->isSubBufferProcessed[i];
|
|
||||||
pthread_mutex_unlock(&AUDIO.System.lock);
|
|
||||||
|
|
||||||
if (needs_refill) {
|
sf_count_t frames_read = sf_readf_float(sndFile, (float*)AUDIO.System.pcmBuffer, frames_to_read);
|
||||||
unsigned int subBufferSizeFrames = music.stream.buffer->sizeInFrames / 2;
|
|
||||||
|
|
||||||
unsigned int frames_to_read = subBufferSizeFrames;
|
unsigned int subBufferOffset = i * subBufferSizeFrames * AUDIO_DEVICE_CHANNELS;
|
||||||
if (ctx->resampler) {
|
float *input_ptr = (float *)AUDIO.System.pcmBuffer;
|
||||||
frames_to_read = (unsigned int)(subBufferSizeFrames / ctx->src_ratio) + 1;
|
sf_count_t frames_written = 0;
|
||||||
|
|
||||||
|
if (needs_resampling) {
|
||||||
|
spx_uint32_t in_len = frames_read;
|
||||||
|
spx_uint32_t out_len = subBufferSizeFrames;
|
||||||
|
|
||||||
|
int error = speex_resampler_process_interleaved_float(
|
||||||
|
ctx->resampler,
|
||||||
|
input_ptr,
|
||||||
|
&in_len,
|
||||||
|
buffer_data + subBufferOffset,
|
||||||
|
&out_len
|
||||||
|
);
|
||||||
|
|
||||||
|
if (error != RESAMPLER_ERR_SUCCESS) {
|
||||||
|
TRACELOG(LOG_WARNING, "Resampling failed with error: %d", error);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (AUDIO.System.pcmBufferSize < frames_to_read * music.stream.channels * sizeof(float)) {
|
frames_written = out_len;
|
||||||
FREE(AUDIO.System.pcmBuffer);
|
} else {
|
||||||
AUDIO.System.pcmBuffer = calloc(1, frames_to_read * music.stream.channels * sizeof(float));
|
if (needs_mono_to_stereo) {
|
||||||
AUDIO.System.pcmBufferSize = frames_to_read * music.stream.channels * sizeof(float);
|
for (int j = 0; j < frames_read; j++) {
|
||||||
}
|
buffer_data[subBufferOffset + j*2] = input_ptr[j];
|
||||||
|
buffer_data[subBufferOffset + j*2 + 1] = input_ptr[j];
|
||||||
sf_count_t frames_read = sf_readf_float(sndFile, (float*)AUDIO.System.pcmBuffer, frames_to_read);
|
|
||||||
|
|
||||||
unsigned int subBufferOffset = i * subBufferSizeFrames * AUDIO_DEVICE_CHANNELS;
|
|
||||||
float *buffer_data = (float *)music.stream.buffer->data;
|
|
||||||
float *input_ptr = (float *)AUDIO.System.pcmBuffer;
|
|
||||||
sf_count_t frames_written = 0;
|
|
||||||
|
|
||||||
if (ctx->resampler) {
|
|
||||||
spx_uint32_t in_len = frames_read;
|
|
||||||
spx_uint32_t out_len = subBufferSizeFrames;
|
|
||||||
|
|
||||||
int error = speex_resampler_process_interleaved_float(
|
|
||||||
ctx->resampler,
|
|
||||||
input_ptr,
|
|
||||||
&in_len,
|
|
||||||
buffer_data + subBufferOffset,
|
|
||||||
&out_len
|
|
||||||
);
|
|
||||||
|
|
||||||
if (error != RESAMPLER_ERR_SUCCESS) {
|
|
||||||
TRACELOG(LOG_WARNING, "Resampling failed with error: %d", error);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
frames_written = out_len;
|
|
||||||
} else {
|
} else {
|
||||||
if (music.stream.channels == 1 && AUDIO_DEVICE_CHANNELS == 2) {
|
memcpy(buffer_data + subBufferOffset, input_ptr, frames_read * music.stream.channels * sizeof(float));
|
||||||
for (int j = 0; j < frames_read; j++) {
|
|
||||||
buffer_data[subBufferOffset + j*2] = input_ptr[j];
|
|
||||||
buffer_data[subBufferOffset + j*2 + 1] = input_ptr[j];
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
memcpy(buffer_data + subBufferOffset, input_ptr, frames_read * music.stream.channels * sizeof(float));
|
|
||||||
}
|
|
||||||
frames_written = frames_read;
|
|
||||||
}
|
}
|
||||||
|
frames_written = frames_read;
|
||||||
|
}
|
||||||
|
|
||||||
if (frames_written < subBufferSizeFrames) {
|
if (frames_written < subBufferSizeFrames) {
|
||||||
unsigned int offset = subBufferOffset + (frames_written * AUDIO_DEVICE_CHANNELS);
|
unsigned int offset = subBufferOffset + (frames_written * AUDIO_DEVICE_CHANNELS);
|
||||||
unsigned int size = (subBufferSizeFrames - frames_written) * AUDIO_DEVICE_CHANNELS * sizeof(float);
|
unsigned int size = (subBufferSizeFrames - frames_written) * AUDIO_DEVICE_CHANNELS * sizeof(float);
|
||||||
memset(buffer_data + offset, 0, size);
|
memset(buffer_data + offset, 0, size);
|
||||||
}
|
|
||||||
|
|
||||||
pthread_mutex_lock(&AUDIO.System.lock);
|
|
||||||
music.stream.buffer->isSubBufferProcessed[i] = false;
|
|
||||||
pthread_mutex_unlock(&AUDIO.System.lock);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pthread_mutex_lock(&AUDIO.System.lock);
|
||||||
|
if (needs_refill[0]) music.stream.buffer->isSubBufferProcessed[0] = false;
|
||||||
|
if (needs_refill[1]) music.stream.buffer->isSubBufferProcessed[1] = false;
|
||||||
|
pthread_mutex_unlock(&AUDIO.System.lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool is_music_stream_playing(music music) {
|
bool is_music_stream_playing(music music) {
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ class OsuParser:
|
|||||||
self.metadata.offset = -30/1000
|
self.metadata.offset = -30/1000
|
||||||
self.metadata.title["en"] = self.osu_metadata["Version"]
|
self.metadata.title["en"] = self.osu_metadata["Version"]
|
||||||
self.metadata.subtitle["en"] = self.osu_metadata["Creator"]
|
self.metadata.subtitle["en"] = self.osu_metadata["Creator"]
|
||||||
match = re.search(r'\[Events\][\s\S]*?^[ \t]*(\d+),(\d+),"([^"]+)"', osu_file.read_text(), re.MULTILINE)
|
match = re.search(r'\[Events\][\s\S]*?^[ \t]*(\d+),(\d+),"([^"]+)"', osu_file.read_text(encoding='utf-8'), re.MULTILINE)
|
||||||
if match:
|
if match:
|
||||||
self.metadata.bgmovie = osu_file.parent / Path(match.group(3))
|
self.metadata.bgmovie = osu_file.parent / Path(match.group(3))
|
||||||
self.metadata.course_data[0] = CourseData()
|
self.metadata.course_data[0] = CourseData()
|
||||||
@@ -43,7 +43,7 @@ class OsuParser:
|
|||||||
self.bpm.append(math.floor(1 / points[1] * 1000 * 60))
|
self.bpm.append(math.floor(1 / points[1] * 1000 * 60))
|
||||||
self.osu_NoteList = self.note_data_to_NoteList(self.hit_objects)
|
self.osu_NoteList = self.note_data_to_NoteList(self.hit_objects)
|
||||||
for points in self.timing_points:
|
for points in self.timing_points:
|
||||||
if points[1] > 0:
|
if 0 < points[1] < 60000:
|
||||||
obj = TimelineObject()
|
obj = TimelineObject()
|
||||||
obj.hit_ms = points[0]
|
obj.hit_ms = points[0]
|
||||||
obj.bpm = math.floor(1 / points[1] * 1000 * 60)
|
obj.bpm = math.floor(1 / points[1] * 1000 * 60)
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import copy
|
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
import sys
|
import sys
|
||||||
@@ -128,7 +127,7 @@ class TextureWrapper:
|
|||||||
if index not in self.animations:
|
if index not in self.animations:
|
||||||
raise Exception(f"Unable to find id {index} in loaded animations")
|
raise Exception(f"Unable to find id {index} in loaded animations")
|
||||||
if is_copy:
|
if is_copy:
|
||||||
new_anim = copy.deepcopy(self.animations[index])
|
new_anim = self.animations[index].copy()
|
||||||
if self.animations[index].loop:
|
if self.animations[index].loop:
|
||||||
new_anim.start()
|
new_anim.start()
|
||||||
return new_anim
|
return new_anim
|
||||||
|
|||||||
@@ -40,9 +40,9 @@ def rounded(num: float) -> int:
|
|||||||
result += 1
|
result += 1
|
||||||
return sign * result
|
return sign * result
|
||||||
|
|
||||||
def get_current_ms() -> int:
|
def get_current_ms() -> float:
|
||||||
"""Get the current time in milliseconds"""
|
"""Get the current time in milliseconds"""
|
||||||
return rounded(time.time() * 1000)
|
return time.time() * 1000
|
||||||
|
|
||||||
def strip_comments(code: str) -> str:
|
def strip_comments(code: str) -> str:
|
||||||
"""Strip comments from a string of code"""
|
"""Strip comments from a string of code"""
|
||||||
@@ -175,6 +175,12 @@ class OutlinedText:
|
|||||||
|
|
||||||
self.default_src = ray.Rectangle(0, 0, self.texture.width, self.texture.height)
|
self.default_src = ray.Rectangle(0, 0, self.texture.width, self.texture.height)
|
||||||
|
|
||||||
|
self._last_outline_color = None
|
||||||
|
self._last_color = None
|
||||||
|
self._last_fade = None
|
||||||
|
self._outline_color_alloc = None
|
||||||
|
self._alpha_value = None
|
||||||
|
|
||||||
def _hash_text(self, text: str, font_size: int, color: ray.Color, vertical: bool):
|
def _hash_text(self, text: str, font_size: int, color: ray.Color, vertical: bool):
|
||||||
n = hashlib.sha256()
|
n = hashlib.sha256()
|
||||||
n.update(text.encode('utf-8'))
|
n.update(text.encode('utf-8'))
|
||||||
@@ -406,39 +412,46 @@ class OutlinedText:
|
|||||||
rotation (float): The rotation angle of the text.
|
rotation (float): The rotation angle of the text.
|
||||||
fade (float): The fade factor to apply to the text.
|
fade (float): The fade factor to apply to the text.
|
||||||
"""
|
"""
|
||||||
if isinstance(outline_color, tuple):
|
if self._last_outline_color != outline_color:
|
||||||
outline_color_alloc = ray.ffi.new("float[4]", [
|
if isinstance(outline_color, tuple):
|
||||||
outline_color[0] / 255.0,
|
self._outline_color_alloc = ray.ffi.new("float[4]", [
|
||||||
outline_color[1] / 255.0,
|
outline_color[0] / 255.0,
|
||||||
outline_color[2] / 255.0,
|
outline_color[1] / 255.0,
|
||||||
outline_color[3] / 255.0
|
outline_color[2] / 255.0,
|
||||||
])
|
outline_color[3] / 255.0
|
||||||
else:
|
])
|
||||||
outline_color_alloc = ray.ffi.new("float[4]", [
|
else:
|
||||||
outline_color.r / 255.0,
|
self._outline_color_alloc = ray.ffi.new("float[4]", [
|
||||||
outline_color.g / 255.0,
|
outline_color.r / 255.0,
|
||||||
outline_color.b / 255.0,
|
outline_color.g / 255.0,
|
||||||
outline_color.a / 255.0
|
outline_color.b / 255.0,
|
||||||
])
|
outline_color.a / 255.0
|
||||||
ray.set_shader_value(self.shader, self.outline_color_loc, outline_color_alloc, SHADER_UNIFORM_VEC4)
|
])
|
||||||
if isinstance(color, tuple):
|
ray.set_shader_value(self.shader, self.outline_color_loc, self._outline_color_alloc, SHADER_UNIFORM_VEC4)
|
||||||
alpha_value = ray.ffi.new('float*', min(fade * 255, color[3]) / 255.0)
|
self._last_outline_color = outline_color
|
||||||
else:
|
|
||||||
alpha_value = ray.ffi.new('float*', min(fade * 255, color.a) / 255.0)
|
if self._last_color != color or self._last_fade != fade:
|
||||||
|
if isinstance(color, tuple):
|
||||||
|
self._alpha_value = ray.ffi.new('float*', min(fade * 255, color[3]) / 255.0)
|
||||||
|
else:
|
||||||
|
self._alpha_value = ray.ffi.new('float*', min(fade * 255, color.a) / 255.0)
|
||||||
|
ray.set_shader_value(self.shader, self.alpha_loc, self._alpha_value, SHADER_UNIFORM_FLOAT)
|
||||||
|
self._last_color = color
|
||||||
|
self._last_fade = fade
|
||||||
|
|
||||||
if fade != 1.1:
|
if fade != 1.1:
|
||||||
final_color = ray.fade(color, fade)
|
final_color = ray.fade(color, fade)
|
||||||
else:
|
else:
|
||||||
final_color = color
|
final_color = color
|
||||||
ray.set_shader_value(self.shader, self.alpha_loc, alpha_value, SHADER_UNIFORM_FLOAT)
|
|
||||||
if not self.vertical:
|
if not self.vertical:
|
||||||
offset = (10 * global_tex.screen_scale)-10
|
offset = (10 * global_tex.screen_scale)-10
|
||||||
else:
|
else:
|
||||||
offset = 0
|
offset = 0
|
||||||
dest_rect = ray.Rectangle(x, y+offset, self.texture.width+x2, self.texture.height+y2)
|
dest_rect = ray.Rectangle(x, y+offset, self.texture.width+x2, self.texture.height+y2)
|
||||||
if self.outline_thickness > 0:
|
if self.outline_thickness > 0 and self._last_color != ray.BLANK:
|
||||||
ray.begin_shader_mode(self.shader)
|
ray.begin_shader_mode(self.shader)
|
||||||
ray.draw_texture_pro(self.texture, self.default_src, dest_rect, origin, rotation, final_color)
|
ray.draw_texture_pro(self.texture, self.default_src, dest_rect, origin, rotation, final_color)
|
||||||
if self.outline_thickness > 0:
|
if self.outline_thickness > 0 and self._last_color != ray.BLANK:
|
||||||
ray.end_shader_mode()
|
ray.end_shader_mode()
|
||||||
|
|
||||||
def unload(self):
|
def unload(self):
|
||||||
|
|||||||
@@ -198,10 +198,26 @@ class VideoPlayer:
|
|||||||
def draw(self):
|
def draw(self):
|
||||||
"""Draw video frames to the raylib canvas"""
|
"""Draw video frames to the raylib canvas"""
|
||||||
if self.texture is not None:
|
if self.texture is not None:
|
||||||
|
source = (0, 0, self.texture.width, self.texture.height)
|
||||||
|
texture_aspect = self.texture.width / self.texture.height
|
||||||
|
screen_aspect = tex.screen_width / tex.screen_height
|
||||||
|
if texture_aspect > screen_aspect:
|
||||||
|
dest_width = tex.screen_width
|
||||||
|
dest_height = tex.screen_width / texture_aspect
|
||||||
|
dest_x = 0
|
||||||
|
dest_y = (tex.screen_height - dest_height) / 2
|
||||||
|
else:
|
||||||
|
dest_height = tex.screen_height
|
||||||
|
dest_width = tex.screen_height * texture_aspect
|
||||||
|
dest_x = (tex.screen_width - dest_width) / 2
|
||||||
|
dest_y = 0
|
||||||
|
|
||||||
|
destination = (dest_x, dest_y, dest_width, dest_height)
|
||||||
|
ray.ClearBackground(ray.BLACK)
|
||||||
ray.DrawTexturePro(
|
ray.DrawTexturePro(
|
||||||
self.texture,
|
self.texture,
|
||||||
(0, 0, self.texture.width, self.texture.height),
|
source,
|
||||||
(0, 0, tex.screen_width, tex.screen_height),
|
destination,
|
||||||
(0, 0),
|
(0, 0),
|
||||||
0,
|
0,
|
||||||
ray.WHITE
|
ray.WHITE
|
||||||
|
|||||||
@@ -314,8 +314,10 @@ class GameScreen(Screen):
|
|||||||
|
|
||||||
def draw_overlay(self):
|
def draw_overlay(self):
|
||||||
self.song_info.draw()
|
self.song_info.draw()
|
||||||
self.transition.draw()
|
if not self.transition.is_finished:
|
||||||
self.result_transition.draw()
|
self.transition.draw()
|
||||||
|
if self.result_transition.is_started:
|
||||||
|
self.result_transition.draw()
|
||||||
self.allnet_indicator.draw()
|
self.allnet_indicator.draw()
|
||||||
|
|
||||||
def draw(self):
|
def draw(self):
|
||||||
@@ -534,8 +536,8 @@ class Player:
|
|||||||
self.draw_note_list.extend(branch_section.draw_notes)
|
self.draw_note_list.extend(branch_section.draw_notes)
|
||||||
self.draw_bar_list.extend(branch_section.bars)
|
self.draw_bar_list.extend(branch_section.bars)
|
||||||
self.play_notes = deque(sorted(self.play_notes))
|
self.play_notes = deque(sorted(self.play_notes))
|
||||||
self.draw_note_list = deque(sorted(self.draw_note_list, key=lambda x: x.hit_ms))
|
self.draw_note_list = deque(sorted(self.draw_note_list, key=lambda x: x.load_ms))
|
||||||
self.draw_bar_list = deque(sorted(self.draw_bar_list, key=lambda x: x.hit_ms))
|
self.draw_bar_list = deque(sorted(self.draw_bar_list, key=lambda x: x.load_ms))
|
||||||
total_don = [note for note in self.play_notes if note.type in {NoteType.DON, NoteType.DON_L}]
|
total_don = [note for note in self.play_notes if note.type in {NoteType.DON, NoteType.DON_L}]
|
||||||
total_kat = [note for note in self.play_notes if note.type in {NoteType.KAT, NoteType.KAT_L}]
|
total_kat = [note for note in self.play_notes if note.type in {NoteType.KAT, NoteType.KAT_L}]
|
||||||
total_other = [note for note in self.play_notes if note.type not in {NoteType.DON, NoteType.DON_L, NoteType.KAT, NoteType.KAT_L}]
|
total_other = [note for note in self.play_notes if note.type not in {NoteType.DON, NoteType.DON_L, NoteType.KAT, NoteType.KAT_L}]
|
||||||
@@ -861,7 +863,8 @@ class Player:
|
|||||||
if background is not None:
|
if background is not None:
|
||||||
background.add_renda()
|
background.add_renda()
|
||||||
self.score += 100
|
self.score += 100
|
||||||
self.base_score_list.append(ScoreCounterAnimation(self.player_num, 100, self.is_2p))
|
if len(self.base_score_list) < 5:
|
||||||
|
self.base_score_list.append(ScoreCounterAnimation(self.player_num, 100, self.is_2p))
|
||||||
if not self.current_notes_draw:
|
if not self.current_notes_draw:
|
||||||
return
|
return
|
||||||
if not isinstance(self.current_notes_draw[0], Drumroll):
|
if not isinstance(self.current_notes_draw[0], Drumroll):
|
||||||
@@ -880,7 +883,8 @@ class Player:
|
|||||||
self.curr_balloon_count += 1
|
self.curr_balloon_count += 1
|
||||||
self.total_drumroll += 1
|
self.total_drumroll += 1
|
||||||
self.score += 100
|
self.score += 100
|
||||||
self.base_score_list.append(ScoreCounterAnimation(self.player_num, 100, self.is_2p))
|
if len(self.base_score_list) < 5:
|
||||||
|
self.base_score_list.append(ScoreCounterAnimation(self.player_num, 100, self.is_2p))
|
||||||
if self.curr_balloon_count == note.count:
|
if self.curr_balloon_count == note.count:
|
||||||
self.is_balloon = False
|
self.is_balloon = False
|
||||||
note.popped = True
|
note.popped = True
|
||||||
@@ -954,11 +958,13 @@ class Player:
|
|||||||
|
|
||||||
big = curr_note.type == NoteType.DON_L or curr_note.type == NoteType.KAT_L
|
big = curr_note.type == NoteType.DON_L or curr_note.type == NoteType.KAT_L
|
||||||
if (curr_note.hit_ms - good_window_ms) <= ms_from_start <= (curr_note.hit_ms + good_window_ms):
|
if (curr_note.hit_ms - good_window_ms) <= ms_from_start <= (curr_note.hit_ms + good_window_ms):
|
||||||
self.draw_judge_list.append(Judgment(Judgments.GOOD, big, self.is_2p))
|
if len(self.draw_judge_list) < 7:
|
||||||
self.lane_hit_effect = LaneHitEffect(Judgments.GOOD, self.is_2p)
|
self.draw_judge_list.append(Judgment(Judgments.GOOD, big, self.is_2p))
|
||||||
|
self.lane_hit_effect = LaneHitEffect(drum_type, Judgments.GOOD, self.is_2p)
|
||||||
self.good_count += 1
|
self.good_count += 1
|
||||||
self.score += self.base_score
|
self.score += self.base_score
|
||||||
self.base_score_list.append(ScoreCounterAnimation(self.player_num, self.base_score, self.is_2p))
|
if len(self.base_score_list) < 5:
|
||||||
|
self.base_score_list.append(ScoreCounterAnimation(self.player_num, self.base_score, self.is_2p))
|
||||||
self.input_log[curr_note.index] = 'GOOD'
|
self.input_log[curr_note.index] = 'GOOD'
|
||||||
self.note_correct(curr_note, current_time)
|
self.note_correct(curr_note, current_time)
|
||||||
if self.gauge is not None:
|
if self.gauge is not None:
|
||||||
@@ -973,9 +979,11 @@ class Player:
|
|||||||
|
|
||||||
elif (curr_note.hit_ms - ok_window_ms) <= ms_from_start <= (curr_note.hit_ms + ok_window_ms):
|
elif (curr_note.hit_ms - ok_window_ms) <= ms_from_start <= (curr_note.hit_ms + ok_window_ms):
|
||||||
self.draw_judge_list.append(Judgment(Judgments.OK, big, self.is_2p))
|
self.draw_judge_list.append(Judgment(Judgments.OK, big, self.is_2p))
|
||||||
|
self.lane_hit_effect = LaneHitEffect(drum_type, Judgments.OK, self.is_2p)
|
||||||
self.ok_count += 1
|
self.ok_count += 1
|
||||||
self.score += 10 * math.floor(self.base_score / 2 / 10)
|
self.score += 10 * math.floor(self.base_score / 2 / 10)
|
||||||
self.base_score_list.append(ScoreCounterAnimation(self.player_num, 10 * math.floor(self.base_score / 2 / 10), self.is_2p))
|
if len(self.base_score_list) < 5:
|
||||||
|
self.base_score_list.append(ScoreCounterAnimation(self.player_num, 10 * math.floor(self.base_score / 2 / 10), self.is_2p))
|
||||||
self.input_log[curr_note.index] = 'OK'
|
self.input_log[curr_note.index] = 'OK'
|
||||||
self.note_correct(curr_note, current_time)
|
self.note_correct(curr_note, current_time)
|
||||||
if self.gauge is not None:
|
if self.gauge is not None:
|
||||||
@@ -1036,8 +1044,9 @@ class Player:
|
|||||||
self.kusudama_anim = None
|
self.kusudama_anim = None
|
||||||
|
|
||||||
def spawn_hit_effects(self, drum_type: DrumType, side: Side):
|
def spawn_hit_effects(self, drum_type: DrumType, side: Side):
|
||||||
self.lane_hit_effect = LaneHitEffect(drum_type, self.is_2p)
|
self.lane_hit_effect = LaneHitEffect(drum_type, Judgments.BAD, self.is_2p) # Bad code detected...
|
||||||
self.draw_drum_hit_list.append(DrumHitEffect(drum_type, side, self.is_2p))
|
if len(self.draw_drum_hit_list) < 4:
|
||||||
|
self.draw_drum_hit_list.append(DrumHitEffect(drum_type, side, self.is_2p))
|
||||||
|
|
||||||
def handle_input(self, ms_from_start: float, current_time: float, background: Optional[Background]):
|
def handle_input(self, ms_from_start: float, current_time: float, background: Optional[Background]):
|
||||||
input_checks = [
|
input_checks = [
|
||||||
@@ -1152,7 +1161,7 @@ class Player:
|
|||||||
finished_arcs = []
|
finished_arcs = []
|
||||||
for i, anim in enumerate(self.draw_arc_list):
|
for i, anim in enumerate(self.draw_arc_list):
|
||||||
anim.update(current_time)
|
anim.update(current_time)
|
||||||
if anim.is_finished:
|
if anim.is_finished and len(self.gauge_hit_effect) < 7:
|
||||||
self.gauge_hit_effect.append(GaugeHitEffect(anim.note_type, anim.is_big, self.is_2p))
|
self.gauge_hit_effect.append(GaugeHitEffect(anim.note_type, anim.is_big, self.is_2p))
|
||||||
finished_arcs.append(i)
|
finished_arcs.append(i)
|
||||||
for i in reversed(finished_arcs):
|
for i in reversed(finished_arcs):
|
||||||
@@ -1461,9 +1470,10 @@ class Judgment:
|
|||||||
|
|
||||||
class LaneHitEffect:
|
class LaneHitEffect:
|
||||||
"""Display a gradient overlay when the player hits the drum"""
|
"""Display a gradient overlay when the player hits the drum"""
|
||||||
def __init__(self, type: Judgments | DrumType, is_2p: bool):
|
def __init__(self, type: DrumType, judgment: Judgments, is_2p: bool):
|
||||||
self.is_2p = is_2p
|
self.is_2p = is_2p
|
||||||
self.type = type
|
self.type = type
|
||||||
|
self.judgment = judgment
|
||||||
self.fade = tex.get_animation(0, is_copy=True)
|
self.fade = tex.get_animation(0, is_copy=True)
|
||||||
self.fade.start()
|
self.fade.start()
|
||||||
self.is_finished = False
|
self.is_finished = False
|
||||||
@@ -1474,12 +1484,12 @@ class LaneHitEffect:
|
|||||||
self.is_finished = True
|
self.is_finished = True
|
||||||
|
|
||||||
def draw(self):
|
def draw(self):
|
||||||
if self.type == Judgments.GOOD:
|
if self.type == DrumType.DON:
|
||||||
tex.draw_texture('lane', 'lane_hit_effect', frame=2, index=self.is_2p, fade=self.fade.attribute)
|
|
||||||
elif self.type == DrumType.DON:
|
|
||||||
tex.draw_texture('lane', 'lane_hit_effect', frame=0, index=self.is_2p, fade=self.fade.attribute)
|
tex.draw_texture('lane', 'lane_hit_effect', frame=0, index=self.is_2p, fade=self.fade.attribute)
|
||||||
elif self.type == DrumType.KAT:
|
elif self.type == DrumType.KAT:
|
||||||
tex.draw_texture('lane', 'lane_hit_effect', frame=1, index=self.is_2p, fade=self.fade.attribute)
|
tex.draw_texture('lane', 'lane_hit_effect', frame=1, index=self.is_2p, fade=self.fade.attribute)
|
||||||
|
if self.judgment == Judgments.GOOD or self.judgment == Judgments.OK:
|
||||||
|
tex.draw_texture('lane', 'lane_hit_effect', frame=2, index=self.is_2p, fade=self.fade.attribute)
|
||||||
|
|
||||||
class DrumHitEffect:
|
class DrumHitEffect:
|
||||||
"""Display the side of the drum hit"""
|
"""Display the side of the drum hit"""
|
||||||
@@ -1619,6 +1629,8 @@ class GaugeHitEffect:
|
|||||||
|
|
||||||
class NoteArc:
|
class NoteArc:
|
||||||
"""Note arcing from the player to the gauge"""
|
"""Note arcing from the player to the gauge"""
|
||||||
|
_arc_points_cache = {}
|
||||||
|
|
||||||
def __init__(self, note_type: int, current_ms: float, player_num: PlayerNum, big: bool, is_balloon: bool, start_x: float = 0, start_y: float = 0):
|
def __init__(self, note_type: int, current_ms: float, player_num: PlayerNum, big: bool, is_balloon: bool, start_x: float = 0, start_y: float = 0):
|
||||||
self.note_type = note_type
|
self.note_type = note_type
|
||||||
self.is_big = big
|
self.is_big = big
|
||||||
@@ -1652,13 +1664,20 @@ class NoteArc:
|
|||||||
self.x_i = self.start_x
|
self.x_i = self.start_x
|
||||||
self.y_i = self.start_y
|
self.y_i = self.start_y
|
||||||
self.is_finished = False
|
self.is_finished = False
|
||||||
self.arc_points_cache = []
|
|
||||||
for i in range(self.arc_points + 1):
|
cache_key = (self.start_x, self.start_y, self.end_x, self.end_y, self.control_x, self.control_y, self.arc_points)
|
||||||
t = i / self.arc_points
|
|
||||||
t_inv = 1.0 - t
|
if cache_key not in NoteArc._arc_points_cache:
|
||||||
x = int(t_inv * t_inv * self.start_x + 2 * t_inv * t * self.control_x + t * t * self.end_x)
|
arc_points_list = []
|
||||||
y = int(t_inv * t_inv * self.start_y + 2 * t_inv * t * self.control_y + t * t * self.end_y)
|
for i in range(self.arc_points + 1):
|
||||||
self.arc_points_cache.append((x, y))
|
t = i / self.arc_points
|
||||||
|
t_inv = 1.0 - t
|
||||||
|
x = int(t_inv * t_inv * self.start_x + 2 * t_inv * t * self.control_x + t * t * self.end_x)
|
||||||
|
y = int(t_inv * t_inv * self.start_y + 2 * t_inv * t * self.control_y + t * t * self.end_y)
|
||||||
|
arc_points_list.append((x, y))
|
||||||
|
NoteArc._arc_points_cache[cache_key] = arc_points_list
|
||||||
|
|
||||||
|
self.arc_points_cache = NoteArc._arc_points_cache[cache_key]
|
||||||
|
|
||||||
self.explosion_x, self.explosion_y = self.arc_points_cache[0]
|
self.explosion_x, self.explosion_y = self.arc_points_cache[0]
|
||||||
self.explosion_anim = tex.get_animation(22)
|
self.explosion_anim = tex.get_animation(22)
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ from scenes.game import (
|
|||||||
DrumType,
|
DrumType,
|
||||||
GameScreen,
|
GameScreen,
|
||||||
JudgeCounter,
|
JudgeCounter,
|
||||||
|
Judgments,
|
||||||
LaneHitEffect,
|
LaneHitEffect,
|
||||||
Player,
|
Player,
|
||||||
Side,
|
Side,
|
||||||
@@ -311,7 +312,7 @@ class PracticePlayer(Player):
|
|||||||
self.check_note(ms_from_start, drum_type, current_time, background)
|
self.check_note(ms_from_start, drum_type, current_time, background)
|
||||||
|
|
||||||
def spawn_hit_effects(self, drum_type: DrumType, side: Side):
|
def spawn_hit_effects(self, drum_type: DrumType, side: Side):
|
||||||
self.lane_hit_effect = LaneHitEffect(drum_type, self.is_2p)
|
self.lane_hit_effect = LaneHitEffect(drum_type, Judgments.BAD, self.is_2p)
|
||||||
self.draw_drum_hit_list.append(PracticeDrumHitEffect(drum_type, side, self.is_2p, player_num=self.player_num))
|
self.draw_drum_hit_list.append(PracticeDrumHitEffect(drum_type, side, self.is_2p, player_num=self.player_num))
|
||||||
|
|
||||||
def draw_overlays(self, mask_shader: ray.Shader):
|
def draw_overlays(self, mask_shader: ray.Shader):
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ void main()
|
|||||||
|
|
||||||
float outline = 0.0;
|
float outline = 0.0;
|
||||||
int ringSamples = 16;
|
int ringSamples = 16;
|
||||||
int rings = 2;
|
int rings = 1;
|
||||||
for(int ring = 1; ring <= rings; ring++) {
|
for(int ring = 1; ring <= rings; ring++) {
|
||||||
float ringRadius = float(ring) / float(rings);
|
float ringRadius = float(ring) / float(rings);
|
||||||
for(int i = 0; i < ringSamples; i++) {
|
for(int i = 0; i < ringSamples; i++) {
|
||||||
|
|||||||
@@ -197,33 +197,6 @@ class TestTextureWrapper(unittest.TestCase):
|
|||||||
|
|
||||||
self.assertEqual(result, mock_animation)
|
self.assertEqual(result, mock_animation)
|
||||||
|
|
||||||
@patch('libs.texture.get_config')
|
|
||||||
@patch('libs.texture.Path')
|
|
||||||
@patch('libs.texture.copy.deepcopy')
|
|
||||||
def test_get_animation_copy(self, mock_deepcopy, mock_path_cls, mock_get_config):
|
|
||||||
"""Test getting animation copy."""
|
|
||||||
mock_get_config.return_value = {'paths': {'skin': 'TestSkin'}}
|
|
||||||
|
|
||||||
# Mock the skin_config.json file
|
|
||||||
mock_path_instance = Mock()
|
|
||||||
mock_config_path = Mock()
|
|
||||||
mock_config_path.exists.return_value = True
|
|
||||||
mock_config_path.read_text.return_value = '{"screen": {"width": 1280, "height": 720}}'
|
|
||||||
mock_path_instance.__truediv__ = Mock(return_value=mock_config_path)
|
|
||||||
mock_path_cls.return_value = mock_path_instance
|
|
||||||
|
|
||||||
mock_animation = Mock()
|
|
||||||
mock_copy = Mock()
|
|
||||||
mock_deepcopy.return_value = mock_copy
|
|
||||||
|
|
||||||
wrapper = TextureWrapper()
|
|
||||||
wrapper.animations = {0: mock_animation}
|
|
||||||
|
|
||||||
result = wrapper.get_animation(0, is_copy=True)
|
|
||||||
|
|
||||||
mock_deepcopy.assert_called_once_with(mock_animation)
|
|
||||||
self.assertEqual(result, mock_copy)
|
|
||||||
|
|
||||||
@patch('libs.texture.get_config')
|
@patch('libs.texture.get_config')
|
||||||
@patch('libs.texture.Path')
|
@patch('libs.texture.Path')
|
||||||
@patch('libs.texture.ray')
|
@patch('libs.texture.ray')
|
||||||
|
|||||||
Reference in New Issue
Block a user