mirror of
https://github.com/Yonokid/PyTaiko.git
synced 2026-02-04 11:40:13 +01:00
add automatic tnde score import
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
import configparser
|
||||||
import csv
|
import csv
|
||||||
import json
|
import json
|
||||||
import sqlite3
|
import sqlite3
|
||||||
@@ -22,6 +23,21 @@ class DiffHashesDecoder(json.JSONDecoder):
|
|||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super().__init__(object_hook=diff_hashes_object_hook, *args, **kwargs)
|
super().__init__(object_hook=diff_hashes_object_hook, *args, **kwargs)
|
||||||
|
|
||||||
|
def read_tjap3_score(input_file: Path):
|
||||||
|
score_ini = configparser.ConfigParser()
|
||||||
|
score_ini.read(input_file)
|
||||||
|
scores = [int(score_ini['HiScore.Drums']['HiScore1']),
|
||||||
|
int(score_ini['HiScore.Drums']['HiScore2']),
|
||||||
|
int(score_ini['HiScore.Drums']['HiScore3']),
|
||||||
|
int(score_ini['HiScore.Drums']['HiScore4']),
|
||||||
|
int(score_ini['HiScore.Drums']['HiScore5'])]
|
||||||
|
clears = [int(score_ini['HiScore.Drums']['Clear0']),
|
||||||
|
int(score_ini['HiScore.Drums']['Clear1']),
|
||||||
|
int(score_ini['HiScore.Drums']['Clear2']),
|
||||||
|
int(score_ini['HiScore.Drums']['Clear3']),
|
||||||
|
int(score_ini['HiScore.Drums']['Clear4'])]
|
||||||
|
return scores, clears
|
||||||
|
|
||||||
def build_song_hashes(output_dir=Path("cache")):
|
def build_song_hashes(output_dir=Path("cache")):
|
||||||
if not output_dir.exists():
|
if not output_dir.exists():
|
||||||
output_dir.mkdir()
|
output_dir.mkdir()
|
||||||
@@ -125,6 +141,37 @@ def build_song_hashes(output_dir=Path("cache")):
|
|||||||
en_name = tja.metadata.title.get('en', '') if isinstance(tja.metadata.title, dict) else str(tja.metadata.title)
|
en_name = tja.metadata.title.get('en', '') if isinstance(tja.metadata.title, dict) else str(tja.metadata.title)
|
||||||
jp_name = tja.metadata.title.get('jp', '') if isinstance(tja.metadata.title, dict) else ''
|
jp_name = tja.metadata.title.get('jp', '') if isinstance(tja.metadata.title, dict) else ''
|
||||||
|
|
||||||
|
score_ini_path = tja_path.with_suffix('.tja.score.ini')
|
||||||
|
if score_ini_path.exists():
|
||||||
|
imported_scores, imported_clears = read_tjap3_score(score_ini_path)
|
||||||
|
conn = sqlite3.connect(db_path)
|
||||||
|
cursor = conn.cursor()
|
||||||
|
for i in range(len(imported_scores)):
|
||||||
|
if i not in diff_hashes or imported_scores[i] == 0:
|
||||||
|
continue
|
||||||
|
cursor.execute("SELECT score FROM scores WHERE hash = ?", (diff_hashes[i],))
|
||||||
|
existing_record = cursor.fetchone()
|
||||||
|
if existing_record and existing_record[0] >= imported_scores[i]:
|
||||||
|
continue
|
||||||
|
if imported_clears[i] == 2:
|
||||||
|
bads = 0
|
||||||
|
clear = 1
|
||||||
|
elif imported_clears[i] == 1:
|
||||||
|
bads = None
|
||||||
|
clear = 1
|
||||||
|
else:
|
||||||
|
bads = None
|
||||||
|
clear = 0
|
||||||
|
cursor.execute("""
|
||||||
|
INSERT OR REPLACE INTO scores (hash, en_name, jp_name, diff, score, clear, bad)
|
||||||
|
VALUES (?, ?, ?, ?, ?, ?, ?)
|
||||||
|
""", (diff_hashes[i], en_name, jp_name, i, imported_scores[i], clear, bads))
|
||||||
|
if cursor.rowcount > 0:
|
||||||
|
action = "Added" if not existing_record else "Updated"
|
||||||
|
print(f"{action} entry for {en_name} ({i}) - Score: {imported_scores[i]}")
|
||||||
|
conn.commit()
|
||||||
|
conn.close()
|
||||||
|
|
||||||
for diff, diff_hash in diff_hashes.items():
|
for diff, diff_hash in diff_hashes.items():
|
||||||
db_updates.append((diff_hash, en_name, jp_name, diff))
|
db_updates.append((diff_hash, en_name, jp_name, diff))
|
||||||
|
|
||||||
|
|||||||
@@ -33,12 +33,8 @@ class LoadScreen:
|
|||||||
|
|
||||||
def _load_song_hashes(self):
|
def _load_song_hashes(self):
|
||||||
"""Background thread function to load song hashes"""
|
"""Background thread function to load song hashes"""
|
||||||
try:
|
|
||||||
global_data.song_hashes = build_song_hashes()
|
global_data.song_hashes = build_song_hashes()
|
||||||
self.songs_loaded = True
|
self.songs_loaded = True
|
||||||
except Exception as e:
|
|
||||||
print(f"Error loading song hashes: {e}")
|
|
||||||
self.songs_loaded = True
|
|
||||||
|
|
||||||
def _load_navigator(self):
|
def _load_navigator(self):
|
||||||
"""Background thread function to load navigator"""
|
"""Background thread function to load navigator"""
|
||||||
|
|||||||
@@ -1503,6 +1503,10 @@ class FileSystemItem:
|
|||||||
'段位道場': 13,
|
'段位道場': 13,
|
||||||
'DIFFICULTY': 14
|
'DIFFICULTY': 14
|
||||||
}
|
}
|
||||||
|
GENRE_MAP_2 = {
|
||||||
|
'ボーカロイド': 3,
|
||||||
|
'バラエティ': 5
|
||||||
|
}
|
||||||
"""Base class for files and directories in the navigation system"""
|
"""Base class for files and directories in the navigation system"""
|
||||||
def __init__(self, path: Path, name: str):
|
def __init__(self, path: Path, name: str):
|
||||||
self.path = path
|
self.path = path
|
||||||
@@ -2003,6 +2007,8 @@ class FileNavigator:
|
|||||||
if line.startswith("#GENRE:"):
|
if line.startswith("#GENRE:"):
|
||||||
genre = line.split(":", 1)[1].strip()
|
genre = line.split(":", 1)[1].strip()
|
||||||
texture_index = FileSystemItem.GENRE_MAP.get(genre, 9)
|
texture_index = FileSystemItem.GENRE_MAP.get(genre, 9)
|
||||||
|
if texture_index == 9:
|
||||||
|
texture_index = FileSystemItem.GENRE_MAP_2.get(genre, 9)
|
||||||
elif line.startswith("#TITLE:"):
|
elif line.startswith("#TITLE:"):
|
||||||
name = line.split(":", 1)[1].strip()
|
name = line.split(":", 1)[1].strip()
|
||||||
elif line.startswith("#TITLEJA:"):
|
elif line.startswith("#TITLEJA:"):
|
||||||
|
|||||||
Reference in New Issue
Block a user