mirror of
https://github.com/Yonokid/PyTaiko.git
synced 2026-02-04 03:30:13 +01:00
update paths to pathlib for linux/mac support
This commit is contained in:
12
libs/tja.py
12
libs/tja.py
@@ -1,5 +1,6 @@
|
||||
import math
|
||||
from collections import deque
|
||||
from pathlib import Path
|
||||
|
||||
from libs.utils import get_pixels_per_frame, strip_comments
|
||||
|
||||
@@ -28,9 +29,9 @@ def calculate_base_score(play_note_list: deque[dict]) -> int:
|
||||
class TJAParser:
|
||||
def __init__(self, path: str):
|
||||
#Defined on startup
|
||||
self.folder_path = path
|
||||
self.folder_name = self.folder_path.split('\\')[-1]
|
||||
self.file_path = f'{self.folder_path}\\{self.folder_name}.tja'
|
||||
self.folder_path = Path(path)
|
||||
self.folder_name = self.folder_path.name
|
||||
self.file_path = self.folder_path / f"{self.folder_name}.tja"
|
||||
|
||||
#Defined on file_to_data()
|
||||
self.data = []
|
||||
@@ -40,7 +41,7 @@ class TJAParser:
|
||||
self.title_ja = ''
|
||||
self.subtitle = ''
|
||||
self.subtitle_ja = ''
|
||||
self.wave = f'{self.folder_path}\\'
|
||||
self.wave = self.folder_path / ""
|
||||
self.offset = 0
|
||||
self.demo_start = 0
|
||||
self.course_data = dict()
|
||||
@@ -81,7 +82,8 @@ class TJAParser:
|
||||
elif 'BPM' in item:
|
||||
self.bpm = float(item.split(':')[1])
|
||||
elif 'WAVE' in item:
|
||||
self.wave += str(item.split(':')[1])
|
||||
filename = item.split(':')[1].strip()
|
||||
self.wave = self.folder_path / filename
|
||||
elif 'OFFSET' in item:
|
||||
self.offset = float(item.split(':')[1])
|
||||
elif 'DEMOSTART' in item:
|
||||
|
||||
@@ -3,6 +3,7 @@ import tempfile
|
||||
import time
|
||||
import zipfile
|
||||
from dataclasses import dataclass
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
import pyray as ray
|
||||
@@ -12,14 +13,16 @@ import tomllib
|
||||
|
||||
def get_zip_filenames(zip_path: str) -> list[str]:
|
||||
result = []
|
||||
with zipfile.ZipFile(zip_path, 'r') as zip_ref:
|
||||
new_path = Path(zip_path)
|
||||
with zipfile.ZipFile(new_path, 'r') as zip_ref:
|
||||
file_list = zip_ref.namelist()
|
||||
for file_name in file_list:
|
||||
result.append(file_name)
|
||||
return result
|
||||
|
||||
def load_image_from_zip(zip_path: str, filename: str) -> ray.Image:
|
||||
with zipfile.ZipFile(zip_path, 'r') as zip_ref:
|
||||
new_path = Path(zip_path)
|
||||
with zipfile.ZipFile(new_path, 'r') as zip_ref:
|
||||
with zip_ref.open(filename) as image_file:
|
||||
with tempfile.NamedTemporaryFile(delete=False, suffix='.png') as temp_file:
|
||||
temp_file.write(image_file.read())
|
||||
@@ -29,7 +32,8 @@ def load_image_from_zip(zip_path: str, filename: str) -> ray.Image:
|
||||
return image
|
||||
|
||||
def load_texture_from_zip(zip_path: str, filename: str) -> ray.Texture:
|
||||
with zipfile.ZipFile(zip_path, 'r') as zip_ref:
|
||||
new_path = Path(zip_path)
|
||||
with zipfile.ZipFile(new_path, 'r') as zip_ref:
|
||||
with zip_ref.open(filename) as image_file:
|
||||
with tempfile.NamedTemporaryFile(delete=False, suffix='.png') as temp_file:
|
||||
temp_file.write(image_file.read())
|
||||
@@ -40,7 +44,8 @@ def load_texture_from_zip(zip_path: str, filename: str) -> ray.Texture:
|
||||
|
||||
def load_all_textures_from_zip(zip_path: str) -> dict[str, list[ray.Texture]]:
|
||||
result_dict = dict()
|
||||
with zipfile.ZipFile(zip_path, 'r') as zip_ref:
|
||||
new_path = Path(zip_path)
|
||||
with zipfile.ZipFile(new_path, 'r') as zip_ref:
|
||||
files = zip_ref.namelist()
|
||||
for file in files:
|
||||
with zip_ref.open(file) as image_file:
|
||||
|
||||
Reference in New Issue
Block a user