make some enums

This commit is contained in:
Anthony Samms
2025-11-14 07:54:22 -05:00
parent d0cdb7b866
commit d06e5276b6
12 changed files with 138 additions and 105 deletions

View File

@@ -245,7 +245,7 @@ class AudioEngine:
"""Load sounds for a given screen"""
path = self.sounds_path / screen_name
if not path.exists():
logger.warning(f"Sounds for {screen_name} not found")
logger.warning(f"Sounds for screen {screen_name} not found")
return
for sound in path.iterdir():
if sound.is_dir():

View File

@@ -10,6 +10,7 @@ from libs.bg_objects.don_bg import DonBG
from libs.bg_objects.fever import Fever
from libs.bg_objects.footer import Footer
from libs.bg_objects.renda import RendaController
from libs.global_data import Difficulty
from libs.texture import TextureWrapper
logger = logging.getLogger(__name__)
@@ -124,7 +125,7 @@ class Background:
gauge_2p (Gauge): The gauge object for player 2.
"""
if self.dancer is not None and gauge_1p is not None:
clear_threshold = gauge_1p.clear_start[min(gauge_1p.difficulty, 3)]
clear_threshold = gauge_1p.clear_start[min(gauge_1p.difficulty, Difficulty.ONI)]
if gauge_1p.gauge_length < clear_threshold:
current_milestone = min(self.max_dancers - 1, int(gauge_1p.gauge_length / (clear_threshold / self.max_dancers)))
else:

View File

@@ -6,6 +6,7 @@ import random
from typing import Optional, Union
from libs.audio import audio
from libs.animation import Animation, MoveAnimation
from libs.global_data import Crown, Difficulty
from libs.tja import TJAParser, test_encodings
from libs.texture import tex
from libs.utils import OutlinedText, get_current_ms, global_data
@@ -55,7 +56,7 @@ class SongBox:
self.is_open = False
self.is_back = self.texture_index == SongBox.BACK_INDEX
if self.is_back:
for i in range(1, 16):
for i in range(1, SongBox.BACK_INDEX-1):
if audio.is_sound_playing(f'genre_voice_{i}'):
audio.stop_sound(f'genre_voice_{i}')
self.name = None
@@ -209,20 +210,20 @@ class SongBox:
if valid_scores:
highest_key = max(valid_scores.keys())
score = self.scores[highest_key]
if score and ((score[5] == 2 and score[2] == 0) or (score[2] == 0 and score[3] == 0)):
tex.draw_texture('yellow_box', 'crown_dfc', x=x, y=y, frame=min(4, highest_key))
elif score and ((score[5] == 2) or (score[3] == 0)):
tex.draw_texture('yellow_box', 'crown_fc', x=x, y=y, frame=min(4, highest_key))
elif score and score[5] >= 1:
tex.draw_texture('yellow_box', 'crown_clear', x=x, y=y, frame=min(4, highest_key))
if score and score[5] == Crown.DFC:
tex.draw_texture('yellow_box', 'crown_dfc', x=x, y=y, frame=min(Difficulty.URA, highest_key))
elif score and score[5] == Crown.FC:
tex.draw_texture('yellow_box', 'crown_fc', x=x, y=y, frame=min(Difficulty.URA, highest_key))
elif score and score[5] >= Crown.CLEAR:
tex.draw_texture('yellow_box', 'crown_clear', x=x, y=y, frame=min(Difficulty.URA, highest_key))
if self.crown: #Folder lamp
highest_crown = max(self.crown)
if self.crown[highest_crown] == 'DFC':
tex.draw_texture('yellow_box', 'crown_dfc', x=x, y=y, frame=min(4, highest_crown))
tex.draw_texture('yellow_box', 'crown_dfc', x=x, y=y, frame=min(Difficulty.URA, highest_crown))
elif self.crown[highest_crown] == 'FC':
tex.draw_texture('yellow_box', 'crown_fc', x=x, y=y, frame=min(4, highest_crown))
tex.draw_texture('yellow_box', 'crown_fc', x=x, y=y, frame=min(Difficulty.URA, highest_crown))
else:
tex.draw_texture('yellow_box', 'crown_clear', x=x, y=y, frame=min(4, highest_crown))
tex.draw_texture('yellow_box', 'crown_clear', x=x, y=y, frame=min(Difficulty.URA, highest_crown))
def _draw_open(self, x: int, y: int, fade_override: Optional[float]):
color = ray.WHITE
@@ -371,13 +372,13 @@ class YellowBox:
if self.tja is None:
return
for diff in self.tja.metadata.course_data:
if diff >= 4:
if diff >= Difficulty.URA:
continue
elif diff in song_box.scores and song_box.scores[diff] is not None and ((song_box.scores[diff][4] == 2 and song_box.scores[diff][2] == 0) or (song_box.scores[diff][2] == 0 and song_box.scores[diff][3] == 0)):
elif diff in song_box.scores and song_box.scores[diff] is not None and song_box.scores[diff][4] == Crown.DFC:
tex.draw_texture('yellow_box', 's_crown_dfc', x=(diff*60), color=color)
elif diff in song_box.scores and song_box.scores[diff] is not None and ((song_box.scores[diff][4] == 2) or (song_box.scores[diff][3] == 0)):
elif diff in song_box.scores and song_box.scores[diff] is not None and song_box.scores[diff][4] == Crown.FC:
tex.draw_texture('yellow_box', 's_crown_fc', x=(diff*60), color=color)
elif diff in song_box.scores and song_box.scores[diff] is not None and song_box.scores[diff][4] >= 1:
elif diff in song_box.scores and song_box.scores[diff] is not None and song_box.scores[diff][4] >= Crown.CLEAR:
tex.draw_texture('yellow_box', 's_crown_clear', x=(diff*60), color=color)
tex.draw_texture('yellow_box', 's_crown_outline', x=(diff*60), fade=min(fade, 0.25))
@@ -398,7 +399,7 @@ class YellowBox:
tex.draw_texture('yellow_box', 'difficulty_bar_shadow', frame=i, x=(i*60), fade=min(fade, 0.25))
for diff in self.tja.metadata.course_data:
if diff >= 4:
if diff >= Difficulty.URA:
continue
for j in range(self.tja.metadata.course_data[diff].level):
tex.draw_texture('yellow_box', 'star', x=(diff*60), y=(j*-17), color=color)
@@ -415,7 +416,7 @@ class YellowBox:
for diff in self.tja.metadata.course_data:
if song_box is None:
continue
if diff >= 4:
if diff >= Difficulty.URA:
continue
elif diff in song_box.scores and song_box.scores[diff] is not None and ((song_box.scores[diff][4] == 2 and song_box.scores[diff][2] == 0) or (song_box.scores[diff][2] == 0 and song_box.scores[diff][3] == 0)):
tex.draw_texture('yellow_box', 's_crown_dfc', x=(diff*115)+8, y=-120, fade=self.fade_in.attribute)
@@ -426,7 +427,7 @@ class YellowBox:
tex.draw_texture('yellow_box', 's_crown_outline', x=(diff*115)+8, y=-120, fade=min(self.fade_in.attribute, 0.25))
for i in range(4):
if i == 3 and is_ura:
if i == Difficulty.ONI and is_ura:
tex.draw_texture('diff_select', 'diff_tower', frame=4, x=(i*115), fade=self.fade_in.attribute)
tex.draw_texture('diff_select', 'ura_oni_plate', fade=self.fade_in.attribute)
else:
@@ -435,16 +436,16 @@ class YellowBox:
tex.draw_texture('diff_select', 'diff_tower_shadow', frame=i, x=(i*115), fade=min(self.fade_in.attribute, 0.25))
for course in self.tja.metadata.course_data:
if (course == 4 and not is_ura) or (course == 3 and is_ura):
if (course == Difficulty.URA and not is_ura) or (course == Difficulty.ONI and is_ura):
continue
for j in range(self.tja.metadata.course_data[course].level):
tex.draw_texture('yellow_box', 'star_ura', x=min(course, 3)*115, y=(j*-20), fade=self.fade_in.attribute)
tex.draw_texture('yellow_box', 'star_ura', x=min(course, Difficulty.ONI)*115, y=(j*-20), fade=self.fade_in.attribute)
if self.tja.metadata.course_data[course].is_branching and (get_current_ms() // 1000) % 2 == 0:
if course == 4:
if course == Difficulty.URA:
name = 'branch_indicator_ura'
else:
name = 'branch_indicator_diff'
tex.draw_texture('yellow_box', name, x=min(course, 3)*115, fade=self.fade_in.attribute)
tex.draw_texture('yellow_box', name, x=min(course, Difficulty.ONI)*115, fade=self.fade_in.attribute)
def _draw_text(self, song_box):
if not isinstance(self.right_out, MoveAnimation):
@@ -726,7 +727,7 @@ class ScoreHistory:
def draw_long(self):
tex.draw_texture('leaderboard','background_2')
tex.draw_texture('leaderboard','title', index=self.long)
if self.curr_difficulty == 4:
if self.curr_difficulty == Difficulty.URA:
tex.draw_texture('leaderboard', 'shinuchi_ura', index=self.long)
else:
tex.draw_texture('leaderboard', 'shinuchi', index=self.long)
@@ -743,7 +744,7 @@ class ScoreHistory:
tex.draw_texture('leaderboard', 'judge_drumroll')
for j, counter in enumerate(self.scores[self.curr_difficulty]):
if j == 5:
if j == Difficulty.TOWER:
continue
counter = str(counter)
margin = 24
@@ -760,7 +761,7 @@ class ScoreHistory:
tex.draw_texture('leaderboard','background')
tex.draw_texture('leaderboard','title')
if self.curr_difficulty == 4:
if self.curr_difficulty == Difficulty.URA:
tex.draw_texture('leaderboard', 'normal_ura')
tex.draw_texture('leaderboard', 'shinuchi_ura')
else:
@@ -768,7 +769,7 @@ class ScoreHistory:
tex.draw_texture('leaderboard', 'shinuchi')
color = ray.BLACK
if self.curr_difficulty == 4:
if self.curr_difficulty == Difficulty.URA:
color = ray.WHITE
tex.draw_texture('leaderboard','ura')
@@ -944,7 +945,7 @@ class FileNavigator:
self.favorite_folder: Optional[Directory] = None
self.recent_folder: Optional[Directory] = None
self.selected_index = 0
self.diff_sort_diff = 4
self.diff_sort_diff = Difficulty.URA
self.diff_sort_level = 10
self.diff_sort_statistics = dict()
self.history = []
@@ -1105,8 +1106,8 @@ class FileNavigator:
scores = song_obj.box.scores.get(course)
if scores is not None:
is_cleared = scores[4] >= 1
is_full_combo = (scores[4] == 2) or (scores[3] == 0)
is_cleared = scores[4] >= Crown.CLEAR
is_full_combo = scores[4] == Crown.FC
else:
is_cleared = False
is_full_combo = False
@@ -1281,7 +1282,7 @@ class FileNavigator:
if selected_item.collection == Directory.COLLECTIONS[3]:
diff_sort = self.diff_sort_level
diffs = ['かんたん', 'ふつう', 'むずかしい', 'おに']
hori_name = OutlinedText(diffs[min(3, self.diff_sort_diff)], 40, ray.WHITE, outline_thickness=5)
hori_name = OutlinedText(diffs[min(Difficulty.ONI, self.diff_sort_diff)], 40, ray.WHITE, outline_thickness=5)
self.genre_bg = GenreBG(start_box, end_box, hori_name, diff_sort)
def select_current_item(self):
@@ -1367,11 +1368,11 @@ class FileNavigator:
all_scores[diff].append(song_obj.box.scores[diff])
for diff in all_scores:
if all(score is not None and ((score[5] == 2 and score[2] == 0) or (score[2] == 0 and score[3] == 0)) for score in all_scores[diff]):
if all(score is not None and score[5] == Crown.DFC for score in all_scores[diff]):
crowns[diff] = 'DFC'
elif all(score is not None and ((score[5] == 2) or (score[3] == 0)) for score in all_scores[diff]):
elif all(score is not None and score[5] == Crown.FC for score in all_scores[diff]):
crowns[diff] = 'FC'
elif all(score is not None and score[5] >= 1 for score in all_scores[diff]):
elif all(score is not None and score[5] >= Crown.CLEAR for score in all_scores[diff]):
crowns[diff] = 'CLEAR'
self.directory_crowns[dir_key] = crowns

View File

@@ -1,7 +1,23 @@
from dataclasses import dataclass, field
from enum import IntEnum
from pathlib import Path
from typing import Any, TypedDict
class Difficulty(IntEnum):
EASY = 0
NORMAL = 1
HARD = 2
ONI = 3
URA = 4
TOWER = 5
DAN = 6
class Crown(IntEnum):
NONE = 0
CLEAR = 1
FC = 2
DFC = 3
class GeneralConfig(TypedDict):
fps_counter: bool
audio_offset: int

View File

@@ -7,6 +7,7 @@ import sys
import time
from pathlib import Path
from libs.global_data import Crown
from libs.tja import NoteList, TJAParser, test_encodings
from libs.utils import get_config, global_data
@@ -179,13 +180,13 @@ def build_song_hashes(output_dir=Path("cache")):
continue
if imported_clears[i] == 2:
bads = 0
clear = 2
clear = Crown.FC
elif imported_clears[i] == 1:
bads = None
clear = 1
clear = Crown.CLEAR
else:
bads = None
clear = 0
clear = Crown.NONE
cursor.execute("""
INSERT OR REPLACE INTO scores (hash, en_name, jp_name, diff, score, clear, bad)
VALUES (?, ?, ?, ?, ?, ?, ?)

View File

@@ -166,7 +166,7 @@ class TextureWrapper:
"""Load textures for a screen."""
screen_path = self.graphics_path / screen_name
if not screen_path.exists():
logger.warning(f"Screen {screen_name} does not exist")
logger.warning(f"Textures for Screen {screen_name} do not exist")
return
if (screen_path / 'animation.json').exists():
with open(screen_path / 'animation.json') as json_file:

View File

@@ -1,4 +1,5 @@
import bisect
from enum import IntEnum
import hashlib
import math
import logging
@@ -26,6 +27,18 @@ def get_pixels_per_ms(pixels_per_frame: float):
"""Calculate the number of pixels per millisecond."""
return pixels_per_frame / (1000 / 60)
class NoteType(IntEnum):
NONE = 0
DON = 1
KAT = 2
DON_L = 3
KAT_L = 4
ROLL_HEAD = 5
ROLL_HEAD_L = 6
BALLOON_HEAD = 7
TAIL = 8
KUSUDAMA = 9
@dataclass()
class Note:
"""A note in a TJA file.