mirror of
https://github.com/Yonokid/PyTaiko.git
synced 2026-02-04 03:30:13 +01:00
Compare commits
10 Commits
0fa765e58b
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c5a3f1e9e5 | ||
|
|
46ddce2443 | ||
|
|
ae2702b3dd | ||
|
|
034be723c9 | ||
|
|
81d67a7ab3 | ||
|
|
1ba25d6ce6 | ||
|
|
0c9645bda7 | ||
|
|
f62201dbb5 | ||
|
|
027ef5408a | ||
|
|
29d3fdd289 |
19
PyTaiko.py
19
PyTaiko.py
@@ -47,6 +47,7 @@ from scenes.two_player.result import TwoPlayerResultScreen
|
||||
from scenes.two_player.song_select import TwoPlayerSongSelectScreen
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
'''
|
||||
DISCORD_APP_ID = '1451423960401973353'
|
||||
try:
|
||||
RPC = Presence(DISCORD_APP_ID)
|
||||
@@ -55,6 +56,7 @@ try:
|
||||
except Exception as e:
|
||||
discord_connected = False
|
||||
logger.warning(f"Could not connect to Discord: {e}")
|
||||
'''
|
||||
|
||||
class Screens:
|
||||
TITLE = "TITLE"
|
||||
@@ -279,13 +281,14 @@ def check_discord_heartbeat(current_screen):
|
||||
details = f"Playing Song: {global_data.session_data[global_data.player_num].song_title}"
|
||||
else:
|
||||
details = "Idling"
|
||||
'''
|
||||
RPC.update(
|
||||
state=f"In Screen {current_screen}",
|
||||
details=details,
|
||||
large_text="PyTaiko",
|
||||
start=get_current_ms()/1000,
|
||||
buttons=[{"label": "Play Now", "url": "https://github.com/Yonokid/PyTaiko"}]
|
||||
)
|
||||
)'''
|
||||
|
||||
def draw_fps(last_fps: int):
|
||||
curr_fps = ray.GetFPS()
|
||||
@@ -297,7 +300,7 @@ def draw_fps(last_fps: int):
|
||||
elif last_fps < 60:
|
||||
pyray.draw_text_ex(global_data.font, f'{last_fps} FPS', (pos, pos), pos, 1, pyray.YELLOW)
|
||||
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):
|
||||
pyray.draw_rectangle(-screen_width, 0, screen_width, screen_height, last_color)
|
||||
@@ -400,9 +403,9 @@ def main():
|
||||
|
||||
while not ray.WindowShouldClose():
|
||||
current_time = get_current_ms()
|
||||
if discord_connected and current_time > last_discord_check + 1000:
|
||||
check_discord_heartbeat(current_screen)
|
||||
last_discord_check = current_time
|
||||
#if discord_connected and current_time > last_discord_check + 1000:
|
||||
#check_discord_heartbeat(current_screen)
|
||||
#last_discord_check = current_time
|
||||
|
||||
if ray.IsKeyPressed(global_data.config["keys"]["fullscreen_key"]):
|
||||
ray.ToggleFullscreen()
|
||||
@@ -444,8 +447,10 @@ def main():
|
||||
|
||||
ray.CloseWindow()
|
||||
audio.close_audio_device()
|
||||
if discord_connected:
|
||||
RPC.close()
|
||||
#if discord_connected:
|
||||
#RPC.close()
|
||||
global_tex.unload_textures()
|
||||
screen_mapping[current_screen].on_screen_end("LOADING")
|
||||
logger.info("Window closed and audio device shut down")
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Submodule Skins/PyTaikoGreen updated: 8cac9f3e0b...ff7f52ef4f
@@ -64,7 +64,7 @@ device_type = 0
|
||||
sample_rate = 44100
|
||||
# buffer_size: Size in samples per audio buffer
|
||||
# - 0 = let driver choose (may result in very small buffers with ASIO, typically 64)
|
||||
buffer_size = 32
|
||||
buffer_size = 128
|
||||
|
||||
[volume]
|
||||
sound = 1.0
|
||||
|
||||
@@ -3,17 +3,8 @@ from typing import Any, Optional
|
||||
|
||||
from libs.global_data import global_data
|
||||
|
||||
|
||||
def rounded(num: float) -> int:
|
||||
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)
|
||||
def get_current_ms() -> float:
|
||||
return time.time() * 1000
|
||||
|
||||
|
||||
class BaseAnimation():
|
||||
@@ -84,6 +75,22 @@ class BaseAnimation():
|
||||
self.restart()
|
||||
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:
|
||||
if ease_type == "quadratic":
|
||||
return progress * progress
|
||||
@@ -133,6 +140,20 @@ class FadeAnimation(BaseAnimation):
|
||||
self.final_opacity = self.final_opacity_saved
|
||||
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:
|
||||
if not self.is_started:
|
||||
return
|
||||
@@ -181,6 +202,20 @@ class MoveAnimation(BaseAnimation):
|
||||
self.start_position = self.start_position_saved
|
||||
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:
|
||||
if not self.is_started:
|
||||
return
|
||||
@@ -217,6 +252,13 @@ class TextureChangeAnimation(BaseAnimation):
|
||||
super().reset()
|
||||
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:
|
||||
if not self.is_started:
|
||||
return
|
||||
@@ -234,6 +276,10 @@ class TextureChangeAnimation(BaseAnimation):
|
||||
self.is_finished = True
|
||||
|
||||
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:
|
||||
if not self.is_started:
|
||||
return
|
||||
@@ -275,6 +321,20 @@ class TextureResizeAnimation(BaseAnimation):
|
||||
self.initial_size = self.initial_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:
|
||||
if not self.is_started:
|
||||
|
||||
@@ -92,6 +92,7 @@ ffi.cdef("""
|
||||
void resume_music_stream(music music);
|
||||
void stop_music_stream(music music);
|
||||
void seek_music_stream(music music, float position);
|
||||
bool music_stream_needs_update(music music);
|
||||
void update_music_stream(music music);
|
||||
bool is_music_stream_playing(music music);
|
||||
void set_music_volume(music music, float volume);
|
||||
@@ -359,11 +360,19 @@ class AudioEngine:
|
||||
else:
|
||||
logger.warning(f"Music stream {name} not found")
|
||||
|
||||
def update_music_stream(self, name: str) -> None:
|
||||
"""Update a music stream"""
|
||||
def music_stream_needs_update(self, name: str) -> bool:
|
||||
"""Check if a music stream needs updating (buffers need refilling)"""
|
||||
if name in self.music_streams:
|
||||
music = self.music_streams[name]
|
||||
lib.update_music_stream(music) # type: ignore
|
||||
return 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 lib.music_stream_needs_update(music): # type: ignore
|
||||
lib.update_music_stream(music) # type: ignore
|
||||
else:
|
||||
logger.warning(f"Music stream {name} not found")
|
||||
|
||||
|
||||
@@ -175,6 +175,7 @@ void pause_music_stream(music music);
|
||||
void resume_music_stream(music music);
|
||||
void stop_music_stream(music music);
|
||||
void seek_music_stream(music music, float position);
|
||||
bool music_stream_needs_update(music music);
|
||||
void update_music_stream(music music);
|
||||
bool is_music_stream_playing(music music);
|
||||
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);
|
||||
}
|
||||
|
||||
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) {
|
||||
if (music.stream.buffer == NULL || music.ctxData == NULL) return;
|
||||
|
||||
@@ -1071,72 +1083,80 @@ void update_music_stream(music music) {
|
||||
SNDFILE *sndFile = ctx->snd_file;
|
||||
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++) {
|
||||
pthread_mutex_lock(&AUDIO.System.lock);
|
||||
bool needs_refill = music.stream.buffer->isSubBufferProcessed[i];
|
||||
pthread_mutex_unlock(&AUDIO.System.lock);
|
||||
if (!needs_refill[i]) continue;
|
||||
|
||||
if (needs_refill) {
|
||||
unsigned int subBufferSizeFrames = music.stream.buffer->sizeInFrames / 2;
|
||||
sf_count_t frames_read = sf_readf_float(sndFile, (float*)AUDIO.System.pcmBuffer, frames_to_read);
|
||||
|
||||
unsigned int frames_to_read = subBufferSizeFrames;
|
||||
if (ctx->resampler) {
|
||||
frames_to_read = (unsigned int)(subBufferSizeFrames / ctx->src_ratio) + 1;
|
||||
unsigned int subBufferOffset = i * subBufferSizeFrames * AUDIO_DEVICE_CHANNELS;
|
||||
float *input_ptr = (float *)AUDIO.System.pcmBuffer;
|
||||
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)) {
|
||||
FREE(AUDIO.System.pcmBuffer);
|
||||
AUDIO.System.pcmBuffer = calloc(1, frames_to_read * music.stream.channels * sizeof(float));
|
||||
AUDIO.System.pcmBufferSize = frames_to_read * music.stream.channels * sizeof(float);
|
||||
}
|
||||
|
||||
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 {
|
||||
if (needs_mono_to_stereo) {
|
||||
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];
|
||||
}
|
||||
|
||||
frames_written = out_len;
|
||||
} else {
|
||||
if (music.stream.channels == 1 && AUDIO_DEVICE_CHANNELS == 2) {
|
||||
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;
|
||||
memcpy(buffer_data + subBufferOffset, input_ptr, frames_read * music.stream.channels * sizeof(float));
|
||||
}
|
||||
frames_written = frames_read;
|
||||
}
|
||||
|
||||
if (frames_written < subBufferSizeFrames) {
|
||||
unsigned int offset = subBufferOffset + (frames_written * AUDIO_DEVICE_CHANNELS);
|
||||
unsigned int size = (subBufferSizeFrames - frames_written) * AUDIO_DEVICE_CHANNELS * sizeof(float);
|
||||
memset(buffer_data + offset, 0, size);
|
||||
}
|
||||
|
||||
pthread_mutex_lock(&AUDIO.System.lock);
|
||||
music.stream.buffer->isSubBufferProcessed[i] = false;
|
||||
pthread_mutex_unlock(&AUDIO.System.lock);
|
||||
if (frames_written < subBufferSizeFrames) {
|
||||
unsigned int offset = subBufferOffset + (frames_written * AUDIO_DEVICE_CHANNELS);
|
||||
unsigned int size = (subBufferSizeFrames - frames_written) * AUDIO_DEVICE_CHANNELS * sizeof(float);
|
||||
memset(buffer_data + offset, 0, size);
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
|
||||
@@ -26,6 +26,7 @@ class Background:
|
||||
"IMAS_CG": (libs.bg_collabs.imas.Background, 'background/collab/imas_cg', 3),
|
||||
"IMAS_ML": (libs.bg_collabs.imas.Background, 'background/collab/imas_ml', 3),
|
||||
"IMAS_SIDEM": (libs.bg_collabs.imas_sidem.Background, 'background/collab/imas_sidem', 3),
|
||||
"FUNASSYI": (libs.bg_collabs.funassyi.Background, 'background/collab/funassyi', 5),
|
||||
"DAN": (libs.bg_collabs.dan.Background, 'background/collab/dan', 1),
|
||||
"PRACTICE": (libs.bg_collabs.practice.Background, 'background/collab/practice', 1)
|
||||
}
|
||||
|
||||
@@ -6,3 +6,4 @@ from . import imas
|
||||
from . import dan
|
||||
from . import imas_sidem
|
||||
from . import practice
|
||||
from . import funassyi
|
||||
|
||||
66
libs/bg_collabs/funassyi.py
Normal file
66
libs/bg_collabs/funassyi.py
Normal file
@@ -0,0 +1,66 @@
|
||||
from libs.bg_objects.bg_fever import BGFeverBase
|
||||
from libs.bg_objects.bg_normal import BGNormalBase
|
||||
from libs.bg_objects.chibi import ChibiController
|
||||
from libs.bg_objects.dancer import BaseDancer, BaseDancerGroup
|
||||
from libs.bg_objects.don_bg import DonBG4
|
||||
from libs.bg_objects.renda import RendaController
|
||||
from libs.bg_objects.fever import Fever0
|
||||
from libs.bg_objects.footer import Footer
|
||||
from libs.global_data import PlayerNum
|
||||
from libs.texture import TextureWrapper
|
||||
|
||||
|
||||
class Background:
|
||||
def __init__(self, tex: TextureWrapper, player_num: PlayerNum, bpm: float, path: str, max_dancers: int):
|
||||
self.tex_wrapper = tex
|
||||
self.max_dancers = max_dancers
|
||||
self.don_bg = DonBG4(tex, 0, player_num, path)
|
||||
self.bg_normal = BGNormalBase(self.tex_wrapper, 0, path)
|
||||
self.bg_fever = BGFever(self.tex_wrapper, 0, path)
|
||||
self.footer = Footer(self.tex_wrapper, 2)
|
||||
self.fever = Fever0(self.tex_wrapper, 0, bpm)
|
||||
self.dancer = DancerGroup(self.tex_wrapper, 0, bpm, max_dancers, path)
|
||||
self.renda = RendaController(self.tex_wrapper, 0)
|
||||
self.chibi = ChibiController(self.tex_wrapper, 0, bpm, path)
|
||||
|
||||
class DancerGroup(BaseDancerGroup):
|
||||
def __init__(self, tex: TextureWrapper, index: int, bpm: float, max_dancers: int, path: str):
|
||||
self.name = 'dancer_' + str(index)
|
||||
self.active_count = 0
|
||||
tex.load_zip(path, f'dancer/{self.name}')
|
||||
self.spawn_positions = [2, 1, 3, 0, 4]
|
||||
self.active_dancers = [None] * max_dancers
|
||||
self.dancers = [BaseDancer(self.name, 0, bpm, tex),
|
||||
BaseDancer(self.name, 1, bpm, tex),
|
||||
BaseDancer(self.name, 2, bpm, tex),
|
||||
BaseDancer(self.name, 3, bpm, tex),
|
||||
BaseDancer(self.name, 4, bpm, tex)]
|
||||
self.add_dancer()
|
||||
|
||||
|
||||
class BGFever(BGFeverBase):
|
||||
def __init__(self, tex: TextureWrapper, index: int, path: str):
|
||||
super().__init__(tex, index, path)
|
||||
self.horizontal_move = tex.get_animation(16)
|
||||
self.bg_texture_move_down = tex.get_animation(17)
|
||||
self.bg_texture_move_up = tex.get_animation(18)
|
||||
|
||||
def start(self):
|
||||
self.bg_texture_move_down.start()
|
||||
self.bg_texture_move_up.start()
|
||||
|
||||
def update(self, current_time_ms: float):
|
||||
self.bg_texture_move_down.update(current_time_ms)
|
||||
|
||||
self.bg_texture_move_up.update(current_time_ms)
|
||||
if self.bg_texture_move_up.is_finished and not self.transitioned:
|
||||
self.transitioned = True
|
||||
self.horizontal_move.restart()
|
||||
|
||||
if self.transitioned:
|
||||
self.horizontal_move.update(current_time_ms)
|
||||
def draw(self, tex: TextureWrapper):
|
||||
y = self.bg_texture_move_down.attribute - self.bg_texture_move_up.attribute
|
||||
tex.draw_texture(self.name, 'background', y=y)
|
||||
tex.draw_texture(self.name, 'overlay', x=-self.horizontal_move.attribute, y=y)
|
||||
tex.draw_texture(self.name, 'overlay', x=tex.textures[self.name]['overlay'].width - self.horizontal_move.attribute, y=y)
|
||||
@@ -1,3 +1,4 @@
|
||||
from libs.animation import Animation
|
||||
from libs.global_data import PlayerNum
|
||||
from libs.texture import TextureWrapper
|
||||
|
||||
@@ -14,7 +15,8 @@ class DonBGBase:
|
||||
def __init__(self, tex: TextureWrapper, index: int, player_num: PlayerNum, path: str):
|
||||
self.name = f'{index}_{player_num}'
|
||||
tex.load_zip(path, f'donbg/{self.name}')
|
||||
self.move = tex.get_animation(0)
|
||||
self.move = Animation.create_move(3000, total_distance=-tex.textures[self.name]['background'].width, loop=True)
|
||||
self.move.start()
|
||||
self.is_clear = False
|
||||
self.clear_fade = tex.get_animation(1)
|
||||
|
||||
@@ -97,7 +99,7 @@ class DonBG4(DonBGBase):
|
||||
self.overlay_move.update(current_time_ms)
|
||||
|
||||
def _draw_textures(self, tex: TextureWrapper, fade: float, y: float):
|
||||
for i in range(int(5 * tex.screen_scale)):
|
||||
for i in range(5):
|
||||
tex.draw_texture(self.name, 'background', frame=self.is_clear, fade=fade, x=(i*tex.textures[self.name]['background'].width)+self.move.attribute, y=y)
|
||||
tex.draw_texture(self.name, 'overlay', frame=self.is_clear, fade=fade, x=(i*tex.textures[self.name]['overlay'].width)+self.move.attribute, y=self.overlay_move.attribute+y)
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ class OsuParser:
|
||||
self.bpm.append(math.floor(1 / points[1] * 1000 * 60))
|
||||
self.osu_NoteList = self.note_data_to_NoteList(self.hit_objects)
|
||||
for points in self.timing_points:
|
||||
if points[1] > 0:
|
||||
if 0 < points[1] < 60000:
|
||||
obj = TimelineObject()
|
||||
obj.hit_ms = points[0]
|
||||
obj.bpm = math.floor(1 / points[1] * 1000 * 60)
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import copy
|
||||
import json
|
||||
import logging
|
||||
import sys
|
||||
@@ -128,7 +127,7 @@ class TextureWrapper:
|
||||
if index not in self.animations:
|
||||
raise Exception(f"Unable to find id {index} in loaded animations")
|
||||
if is_copy:
|
||||
new_anim = copy.deepcopy(self.animations[index])
|
||||
new_anim = self.animations[index].copy()
|
||||
if self.animations[index].loop:
|
||||
new_anim.start()
|
||||
return new_anim
|
||||
|
||||
@@ -40,9 +40,9 @@ def rounded(num: float) -> int:
|
||||
result += 1
|
||||
return sign * result
|
||||
|
||||
def get_current_ms() -> int:
|
||||
def get_current_ms() -> float:
|
||||
"""Get the current time in milliseconds"""
|
||||
return rounded(time.time() * 1000)
|
||||
return time.time() * 1000
|
||||
|
||||
def strip_comments(code: str) -> str:
|
||||
"""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._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):
|
||||
n = hashlib.sha256()
|
||||
n.update(text.encode('utf-8'))
|
||||
@@ -406,39 +412,46 @@ class OutlinedText:
|
||||
rotation (float): The rotation angle of the text.
|
||||
fade (float): The fade factor to apply to the text.
|
||||
"""
|
||||
if isinstance(outline_color, tuple):
|
||||
outline_color_alloc = ray.ffi.new("float[4]", [
|
||||
outline_color[0] / 255.0,
|
||||
outline_color[1] / 255.0,
|
||||
outline_color[2] / 255.0,
|
||||
outline_color[3] / 255.0
|
||||
])
|
||||
else:
|
||||
outline_color_alloc = ray.ffi.new("float[4]", [
|
||||
outline_color.r / 255.0,
|
||||
outline_color.g / 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):
|
||||
alpha_value = ray.ffi.new('float*', min(fade * 255, color[3]) / 255.0)
|
||||
else:
|
||||
alpha_value = ray.ffi.new('float*', min(fade * 255, color.a) / 255.0)
|
||||
if self._last_outline_color != outline_color:
|
||||
if isinstance(outline_color, tuple):
|
||||
self._outline_color_alloc = ray.ffi.new("float[4]", [
|
||||
outline_color[0] / 255.0,
|
||||
outline_color[1] / 255.0,
|
||||
outline_color[2] / 255.0,
|
||||
outline_color[3] / 255.0
|
||||
])
|
||||
else:
|
||||
self._outline_color_alloc = ray.ffi.new("float[4]", [
|
||||
outline_color.r / 255.0,
|
||||
outline_color.g / 255.0,
|
||||
outline_color.b / 255.0,
|
||||
outline_color.a / 255.0
|
||||
])
|
||||
ray.set_shader_value(self.shader, self.outline_color_loc, self._outline_color_alloc, SHADER_UNIFORM_VEC4)
|
||||
self._last_outline_color = outline_color
|
||||
|
||||
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:
|
||||
final_color = ray.fade(color, fade)
|
||||
else:
|
||||
final_color = color
|
||||
ray.set_shader_value(self.shader, self.alpha_loc, alpha_value, SHADER_UNIFORM_FLOAT)
|
||||
if not self.vertical:
|
||||
offset = (10 * global_tex.screen_scale)-10
|
||||
else:
|
||||
offset = 0
|
||||
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.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()
|
||||
|
||||
def unload(self):
|
||||
|
||||
@@ -198,10 +198,26 @@ class VideoPlayer:
|
||||
def draw(self):
|
||||
"""Draw video frames to the raylib canvas"""
|
||||
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(
|
||||
self.texture,
|
||||
(0, 0, self.texture.width, self.texture.height),
|
||||
(0, 0, tex.screen_width, tex.screen_height),
|
||||
source,
|
||||
destination,
|
||||
(0, 0),
|
||||
0,
|
||||
ray.WHITE
|
||||
|
||||
@@ -314,8 +314,10 @@ class GameScreen(Screen):
|
||||
|
||||
def draw_overlay(self):
|
||||
self.song_info.draw()
|
||||
self.transition.draw()
|
||||
self.result_transition.draw()
|
||||
if not self.transition.is_finished:
|
||||
self.transition.draw()
|
||||
if self.result_transition.is_started:
|
||||
self.result_transition.draw()
|
||||
self.allnet_indicator.draw()
|
||||
|
||||
def draw(self):
|
||||
@@ -534,8 +536,8 @@ class Player:
|
||||
self.draw_note_list.extend(branch_section.draw_notes)
|
||||
self.draw_bar_list.extend(branch_section.bars)
|
||||
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_bar_list = deque(sorted(self.draw_bar_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.load_ms))
|
||||
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_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:
|
||||
background.add_renda()
|
||||
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:
|
||||
return
|
||||
if not isinstance(self.current_notes_draw[0], Drumroll):
|
||||
@@ -880,7 +883,8 @@ class Player:
|
||||
self.curr_balloon_count += 1
|
||||
self.total_drumroll += 1
|
||||
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:
|
||||
self.is_balloon = False
|
||||
note.popped = True
|
||||
@@ -954,11 +958,13 @@ class Player:
|
||||
|
||||
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):
|
||||
self.draw_judge_list.append(Judgment(Judgments.GOOD, big, self.is_2p))
|
||||
if len(self.draw_judge_list) < 7:
|
||||
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.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.note_correct(curr_note, current_time)
|
||||
if self.gauge is not None:
|
||||
@@ -976,7 +982,8 @@ class Player:
|
||||
self.lane_hit_effect = LaneHitEffect(drum_type, Judgments.OK, self.is_2p)
|
||||
self.ok_count += 1
|
||||
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.note_correct(curr_note, current_time)
|
||||
if self.gauge is not None:
|
||||
@@ -1038,7 +1045,8 @@ class Player:
|
||||
|
||||
def spawn_hit_effects(self, drum_type: DrumType, side: Side):
|
||||
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]):
|
||||
input_checks = [
|
||||
@@ -1153,7 +1161,7 @@ class Player:
|
||||
finished_arcs = []
|
||||
for i, anim in enumerate(self.draw_arc_list):
|
||||
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))
|
||||
finished_arcs.append(i)
|
||||
for i in reversed(finished_arcs):
|
||||
@@ -1621,6 +1629,8 @@ class GaugeHitEffect:
|
||||
|
||||
class NoteArc:
|
||||
"""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):
|
||||
self.note_type = note_type
|
||||
self.is_big = big
|
||||
@@ -1654,13 +1664,20 @@ class NoteArc:
|
||||
self.x_i = self.start_x
|
||||
self.y_i = self.start_y
|
||||
self.is_finished = False
|
||||
self.arc_points_cache = []
|
||||
for i in range(self.arc_points + 1):
|
||||
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)
|
||||
self.arc_points_cache.append((x, y))
|
||||
|
||||
cache_key = (self.start_x, self.start_y, self.end_x, self.end_y, self.control_x, self.control_y, self.arc_points)
|
||||
|
||||
if cache_key not in NoteArc._arc_points_cache:
|
||||
arc_points_list = []
|
||||
for i in range(self.arc_points + 1):
|
||||
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_anim = tex.get_animation(22)
|
||||
|
||||
@@ -32,6 +32,7 @@ from scenes.game import (
|
||||
DrumType,
|
||||
GameScreen,
|
||||
JudgeCounter,
|
||||
Judgments,
|
||||
LaneHitEffect,
|
||||
Player,
|
||||
Side,
|
||||
@@ -311,7 +312,7 @@ class PracticePlayer(Player):
|
||||
self.check_note(ms_from_start, drum_type, current_time, background)
|
||||
|
||||
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))
|
||||
|
||||
def draw_overlays(self, mask_shader: ray.Shader):
|
||||
|
||||
@@ -17,7 +17,7 @@ void main()
|
||||
|
||||
float outline = 0.0;
|
||||
int ringSamples = 16;
|
||||
int rings = 2;
|
||||
int rings = 1;
|
||||
for(int ring = 1; ring <= rings; ring++) {
|
||||
float ringRadius = float(ring) / float(rings);
|
||||
for(int i = 0; i < ringSamples; i++) {
|
||||
|
||||
@@ -197,33 +197,6 @@ class TestTextureWrapper(unittest.TestCase):
|
||||
|
||||
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.Path')
|
||||
@patch('libs.texture.ray')
|
||||
|
||||
Reference in New Issue
Block a user