Skip to content

Commit

Permalink
维护
Browse files Browse the repository at this point in the history
  • Loading branch information
SK-la committed Nov 2, 2024
1 parent abd8c4a commit 58abdf0
Show file tree
Hide file tree
Showing 11 changed files with 113 additions and 98 deletions.
18 changes: 5 additions & 13 deletions Dispatch_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from SV import get_sv
from Samples import get_samples
from osu import generate_osu_file
import json
import os
import logging
import json
Expand All @@ -16,7 +15,7 @@

def dispatch(data, settings):
config = get_config()
info = get_info(data, config, settings)
info = get_info(data, config)
samples, main_audio, offset, song_lg = get_samples(data, info, settings)
notes_obj, cs = bms(data, info, offset)
#print("bms 函数返回的 notes_obj 内容:", notes_obj)
Expand All @@ -30,7 +29,7 @@ def dispatch(data, settings):

sv = get_sv(data, offset, info, settings) if settings.convert_sv else ''
#print("c e c 返回的 notes_obj 类型:", type(notes_obj))
osu_content = generate_osu_file(config, info, sv, offset, samples, song_lg, notes_obj, new_cs, settings)
osu_content = generate_osu_file(config, info, sv, offset, samples, song_lg, notes_obj, new_cs)



Expand All @@ -48,7 +47,7 @@ def dispatch(data, settings):
# print(f"Difficulty: {info.diff}")
#print(f"Song: {info.song}")
# print(f"CS: {info.CS}")
# print(f"Mode Hint: {info.EZmode}")
# print(f"Mode Hint: {info.ez_mode}")

print(f"New Folder Name: {info.new_folder}")
print(f"Sub Folder Name: {info.sub_folder}")
Expand Down Expand Up @@ -86,19 +85,12 @@ def setup_logging(log_file_path):

logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
format='%(pastime)s - %(name)s - %(levelness)s - %(message)s',
handlers=[
logging.FileHandler(log_file_path),
logging.StreamHandler()
]
)

# 配置日志记录
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s')

# 检查数据用
def check_lines(lines):
for line in lines:
if not line.endswith('.wav'):
print(line)

logging.basicConfig(level=logging.DEBUG, format='%(pastime)s - %(levelness)s - %(message)s')
4 changes: 2 additions & 2 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def _check_and_create_config(self):
'noP': 'N',
'Packset': 'N'
}
with open(self.config_file, 'w') as configfile:
with open(self.config_file, 'w', encoding='utf-8') as configfile:
self.config.write(configfile)

def _load_config(self):
Expand All @@ -46,7 +46,7 @@ def save_config(self, settings):
'noP': settings['noP'],
'Packset': settings['packset']
}
with open(self.config_file, 'w') as configfile:
with open(self.config_file, 'w', encoding='utf-8') as configfile:
self.config.write(configfile)

# 单例模式实现
Expand Down
14 changes: 7 additions & 7 deletions conv_bmson.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# converter_bmson.py
# conv_bmson.py

def bms(data, info, offset):
cs = info.CS
def cal_notex(cs, set_x):
set_x = int((set_x - 1) * 512 / cs) + int(256 / cs)
def cal_notex(base_cs, set_x):
set_x = int((set_x - 1) * 512 / base_cs) + int(256 / base_cs)
return set_x

def calculate_pulse_time(note_y):
Expand All @@ -13,16 +13,16 @@ def calculate_pulse_time(note_y):
hit_sound = 0
normal_set = 0
addition_set = 0
ksindex = 0
ks_index = 0
volume = 100
note_x = 8
notes_obj = []
valid_notes = []

for channel in data['sound_channels']:
notes = channel['notes']
ksfilename = channel['name'].replace("sound\\", f"{info.sub_folder}/")
hit_sample = f"{normal_set}:{addition_set}:{ksindex}:{volume}:{ksfilename}"
ks_filename = channel['name'].replace("sound\\", f"{info.sub_folder}/")
hit_sample = f"{normal_set}:{addition_set}:{ks_index}:{volume}:{ks_filename}"

for note in notes:
x = note['x']
Expand All @@ -33,7 +33,7 @@ def calculate_pulse_time(note_y):
if 1 <= x <= 16:
valid_notes.append((x, y, l, hit_sample))
# 按 y 值排序,重新计算
valid_notes.sort(key=lambda notes: notes[1])
valid_notes.sort(key=lambda notey: notey[1])
# 重置y值从0开始
min_y = valid_notes[0][1] if valid_notes else 0
valid_notes = [(x, y - min_y, L, hitSample) for x, y, L, hitSample in valid_notes]
Expand Down
11 changes: 4 additions & 7 deletions get_info.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import os
from config import get_config

config = get_config()

class Info:
def __init__(self, title, artist, osumode, bpm, bpms, image, resolution, m_p_b, lv, ver, diff, song, tags, cs, ez_mode, img, vdo, new_folder, sub_folder, osu_filename, img_filename):
Expand All @@ -18,7 +15,7 @@ def __init__(self, title, artist, osumode, bpm, bpms, image, resolution, m_p_b,
self.song = song
self.tags = tags
self.CS = cs
self.EZmode = ez_mode
self.ez_mode = ez_mode
self.img = img
self.vdo = vdo
self.new_folder = new_folder
Expand All @@ -27,7 +24,7 @@ def __init__(self, title, artist, osumode, bpm, bpms, image, resolution, m_p_b,
self.img_filename = img_filename
self.osumode = osumode

def get_info(data, config, settings):
def get_info(data, config):
mode_hint = data['info'].get('mode_hint', '').split('-')[-1]
cs = {'5k': 7, '7k': 8, '9k': 9, '10k': 12, '14k': 16}.get(mode_hint, 18)

Expand All @@ -52,9 +49,9 @@ def get_info(data, config, settings):
image_diff = image_ext

artist = f"{config.creator}'s PACK" if config.packset == 'Y' else data['info'].get('artist', '')
title = settings.source if config.packset == 'Y' else data['info'].get('title', '')
title = config.source if config.packset == 'Y' else data['info'].get('title', '')

tags = f"{config.creator} {settings.source} {mode} {ez_mode} {artist} {title}"
tags = f"{config.creator} {config.source} {mode} {ez_mode} {artist} {title}"


bga_name = data.get('bga', {}).get('bga_header', [{}])[0].get('name', '')
Expand Down
4 changes: 2 additions & 2 deletions osu.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# osu.py

def generate_osu_file(config, info, sv, offset, samples, song_lg, notes_obj, new_cs, settings):
def generate_osu_file(config, info, sv, offset, samples, song_lg, notes_obj, new_cs):
vdo= '' if info.vdo == '' else f'\nVideo,0,"{info.vdo}"'

osu_content = f"""osu file format v14
Expand Down Expand Up @@ -32,7 +32,7 @@ def generate_osu_file(config, info, sv, offset, samples, song_lg, notes_obj, new
ArtistUnicode:{info.artist}
Creator:{config.creator}
Version:{info.ver}
Source:{settings.source}
Source:{config.source}
Tags:{info.tags}{config.tags}
BeatmapID:0
BeatmapSetID:-1
Expand Down
73 changes: 38 additions & 35 deletions ui/MainWindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import concurrent.futures
from PyQt5 import QtWidgets, QtCore
from PyQt5.QtWidgets import QMainWindow, QMessageBox, QStatusBar
from PyQt5.QtGui import QCursor
from config import get_config
from Dispatch_file import process_file
from ui.styling import set_window_icon, set_background_image
Expand All @@ -20,10 +19,12 @@ def __init__(self):
self.config = get_config()
system_language = get_system_language()
self.translations = load_translations(system_language)
self.status_bar = QStatusBar()

self.initUI()
self.update_language() # 更新界面语言
self.load_settings() # 加载设置
self.move_to_cursor()
self.restore_window_position()

def initUI(self):

Check notice on line 29 in ui/MainWindow.py

View workflow job for this annotation

GitHub Actions / Qodana for Python

PEP 8 naming convention violation

Function name should be lowercase
self.setWindowTitle('LAs EZ2OSU')
Expand All @@ -37,25 +38,18 @@ def initUI(self):

self.auto_create_output_folder.stateChanged.connect(self.handle_auto_create_output_folder)

# 添加状态栏
self.status_bar = QStatusBar()
self.setStatusBar(self.status_bar)
self.setStatusBar(self.status_bar) # 添加状态栏

def show_notification(self, message):
self.status_bar.showMessage(message, 3000) # 显示消息3秒

def update_language(self):
# 更新界面语言的逻辑
self.setWindowTitle(self.translations.get('window_title', 'LAs EZ2OSU'))
self.start_button.setText(self.translations.get('start_conversion', '开始转换'))
self.input_path.setPlaceholderText(self.translations.get('input_folder_path', '输入文件夹路径'))
self.output_path.setPlaceholderText(self.translations.get('output_folder_path', '输出文件夹路径'))
# 更新其他需要翻译的控件文本

def move_to_cursor(self):
cursor_pos = QCursor.pos()
self.move(cursor_pos.x(), cursor_pos.y())

def select_input(self):
path = QtWidgets.QFileDialog.getExistingDirectory(self, "选择输入文件夹")
if path:
Expand All @@ -69,7 +63,7 @@ def select_output(self):
self.home_tab.output_tree.populate_tree(pathlib.Path(path))

def handle_auto_create_output_folder(self, state):
if state == QtCore.Qt.Checked:
if state == QtCore.Qt.CheckState.Checked:
osu_songs_path = self.settings.value("osu_songs_path", None)
if not osu_songs_path:
osu_songs_path = get_osu_songs_path(self)
Expand All @@ -79,7 +73,8 @@ def handle_auto_create_output_folder(self, state):
QMessageBox.warning(self, "错误", "未选择 osu! 安装路径,请手动设置输出文件夹。")
self.auto_create_output_folder.setChecked(False)

def process_folder(self, folder_path, output_path, settings):
@staticmethod
def process_folder(folder_path, output_path, settings):
for bmson_file in folder_path.glob("**/*.bmson"):
process_file(bmson_file, output_path, settings)

Expand All @@ -97,18 +92,17 @@ def start_conversion(self):
convert_sv=self.convert_sv.isChecked(),
convert_sample_bg=self.convert_sample_bg.isChecked(),
auto_create_output_folder=self.auto_create_output_folder.isChecked(),
source=self.config.source,
)
# 自动创建输出文件夹
if self.auto_create_output_folder.isChecked():
osu_songs_path = pathlib.Path(self.settings.value("osu_songs_path"))
set_output_folder = osu_songs_path / settings.source
set_output_folder = osu_songs_path / self.config.source
set_output_folder.mkdir(parents=True, exist_ok=True)
output_path = set_output_folder
self.output_path.setText(str(output_path))
self.home_tab.output_tree.populate_tree(output_path)
else:
# 使用用户选择的输出路径
set_output_folder = output_path / settings.source
set_output_folder = output_path / self.config.source
set_output_folder.mkdir(parents=True, exist_ok=True)

# 使用多线程处理文件夹
Expand All @@ -128,43 +122,52 @@ def start_conversion(self):
self.home_tab.input_tree.populate_tree(input_path)
self.home_tab.output_tree.populate_tree(output_path)

def restore_window_position(self):
pos = self.settings.value("window_position", None)
if pos:
self.move(pos)
def closeEvent(self, event):

Check notice on line 129 in ui/MainWindow.py

View workflow job for this annotation

GitHub Actions / Qodana for Python

PEP 8 naming convention violation

Function name should be lowercase
self.save_window_position()
self.save_settings()
event.accept()
def save_window_position(self):
self.settings.setValue("window_position", self.pos())

def save_settings(self):
self.settings.setValue("input_path", self.input_path.text())
self.settings.setValue("output_path", self.output_path.text())
self.settings.setValue("include_audio", self.include_audio.isChecked())
self.settings.setValue("include_images", self.include_images.isChecked())
self.settings.setValue("remove_empty_columns", self.remove_empty_columns.isChecked())
self.settings.setValue("lock_cs_set", self.lock_cs_set.isChecked())
self.settings.setValue("lock_cs_num", self.lock_cs_num_combobox.currentText())
self.settings.setValue("convert_sv", self.convert_sv.isChecked())
self.settings.setValue("convert_sample_bg", self.convert_sample_bg.isChecked())
self.settings.setValue("auto_create_output_folder", self.auto_create_output_folder.isChecked())
self.settings.setValue("source", self.config.source)
settings = ConversionSettings(
include_audio=self.include_audio.isChecked(),
include_images=self.include_images.isChecked(),
remove_empty_columns=self.remove_empty_columns.isChecked(),
lock_cs_set=self.lock_cs_set.isChecked(),
lock_cs_num=self.lock_cs_num_combobox.currentText(),
convert_sv=self.convert_sv.isChecked(),
convert_sample_bg=self.convert_sample_bg.isChecked(),
auto_create_output_folder=self.auto_create_output_folder.isChecked(),
)
settings.save_settings(self.settings)
self.show_notification("Settings saved successfully!")

def load_settings(self):
self.input_path.setText(self.settings.value("input_path", ""))
self.output_path.setText(self.settings.value("output_path", ""))
self.include_audio.setChecked(self.settings.value("include_audio", True, type=bool))
self.include_images.setChecked(self.settings.value("include_images", True, type=bool))
self.remove_empty_columns.setChecked(self.settings.value("remove_empty_columns", True, type=bool))
self.lock_cs_set.setChecked(self.settings.value("lock_cs_set", True, type=bool))
self.lock_cs_num_combobox.setCurrentText(self.settings.value("lock_cs_num", "14"))
self.convert_sv.setChecked(self.settings.value("convert_sv", True, type=bool))
self.convert_sample_bg.setChecked(self.settings.value("convert_sample_bg", True, type=bool))
self.auto_create_output_folder.setChecked(self.settings.value("auto_create_output_folder", False, type=bool))
self.config.source = self.settings.value("source", "")
settings = ConversionSettings.load_settings(self.settings)
self.include_audio.setChecked(settings.include_audio)
self.include_images.setChecked(settings.include_images)
self.remove_empty_columns.setChecked(settings.remove_empty_columns)
self.lock_cs_set.setChecked(settings.lock_cs_set)
self.lock_cs_num_combobox.setCurrentText(settings.lock_cs_num)
self.convert_sv.setChecked(settings.convert_sv)
self.convert_sample_bg.setChecked(settings.convert_sample_bg)
self.auto_create_output_folder.setChecked(settings.auto_create_output_folder)

# 加载文件树
input_path = pathlib.Path(self.input_path.text())
output_path = pathlib.Path(self.output_path.text())
if input_path.exists():
self.home_tab.input_tree.populate_tree(input_path)
if output_path.exists():
self.home_tab.output_tree.populate_tree(output_path)


self.home_tab.output_tree.populate_tree(output_path)
3 changes: 2 additions & 1 deletion ui/clm_tab.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def update_bottom_layout(self):
if button.isChecked():
k = int(button.text())
self.bottom_layout = self.create_editable_layout(k, self.bottom_layout)

Check notice on line 63 in ui/clm_tab.py

View workflow job for this annotation

GitHub Actions / Qodana for Python

An instance attribute is defined outside `__init__`

Instance attribute bottom_layout defined outside __init__

@staticmethod
def create_fixed_layout(self, k, layout):

Check notice on line 65 in ui/clm_tab.py

View workflow job for this annotation

GitHub Actions / Qodana for Python

Unused local symbols

Parameter 'self' value is not used
# 清空当前布局
for i in reversed(range(layout.count())):
Expand All @@ -76,6 +76,7 @@ def create_fixed_layout(self, k, layout):

return layout

@staticmethod
def create_editable_layout(self, k, layout):

Check notice on line 80 in ui/clm_tab.py

View workflow job for this annotation

GitHub Actions / Qodana for Python

Unused local symbols

Parameter 'self' value is not used
# 清空当前布局
for i in reversed(range(layout.count())):
Expand Down
Loading

0 comments on commit 58abdf0

Please sign in to comment.