Update list/dict/tuple typing for 3.8
This commit is contained in:
parent
35090449a3
commit
2042c8177e
@ -5,7 +5,7 @@ Dataclasses used to represent song courses, branches, measures, and notes.
|
||||
import csv
|
||||
import os
|
||||
import struct
|
||||
from typing import Any
|
||||
from typing import Any, List, Dict, Tuple
|
||||
|
||||
from dataclasses import dataclass, field, fields
|
||||
|
||||
@ -23,9 +23,9 @@ class TJAData:
|
||||
@dataclass()
|
||||
class TJAMeasure:
|
||||
"""Contains all the data in a single TJA measure (denoted by ',')."""
|
||||
notes: list[str] = field(default_factory=list)
|
||||
events: list[TJAData] = field(default_factory=list)
|
||||
combined: list[TJAData] = field(default_factory=list)
|
||||
notes: List[str] = field(default_factory=list)
|
||||
events: List[TJAData] = field(default_factory=list)
|
||||
combined: List[TJAData] = field(default_factory=list)
|
||||
|
||||
|
||||
@dataclass()
|
||||
@ -35,11 +35,11 @@ class TJACourse:
|
||||
offset: float
|
||||
course: str
|
||||
level: int = 0
|
||||
balloon: list[int] = field(default_factory=list)
|
||||
balloon: List[int] = field(default_factory=list)
|
||||
score_init: int = 0
|
||||
score_diff: int = 0
|
||||
data: list[str] = field(default_factory=list)
|
||||
branches: dict[str, list[TJAMeasure]] = field(default_factory=dict)
|
||||
data: List[str] = field(default_factory=list)
|
||||
branches: Dict[str, List[TJAMeasure]] = field(default_factory=dict)
|
||||
|
||||
|
||||
@dataclass()
|
||||
@ -47,7 +47,7 @@ class TJASong:
|
||||
"""Contains all the data in a single TJA (`.tja`) chart file."""
|
||||
bpm: float
|
||||
offset: float
|
||||
courses: dict[str, TJACourse]
|
||||
courses: Dict[str, TJACourse]
|
||||
|
||||
|
||||
@dataclass()
|
||||
@ -65,7 +65,7 @@ class TJAMeasureProcessed:
|
||||
scroll: float
|
||||
gogo: bool
|
||||
barline: bool
|
||||
time_sig: list[int]
|
||||
time_sig: List[int]
|
||||
subdivisions: int
|
||||
pos_start: int = 0
|
||||
pos_end: int = 0
|
||||
@ -73,8 +73,8 @@ class TJAMeasureProcessed:
|
||||
section: bool = False
|
||||
levelhold: bool = False
|
||||
branch_type: str = ''
|
||||
branch_cond: tuple[float, float] = (0.0, 0.0)
|
||||
notes: list[TJAData] = field(default_factory=list)
|
||||
branch_cond: Tuple[float, float] = (0.0, 0.0)
|
||||
notes: List[TJAData] = field(default_factory=list)
|
||||
|
||||
|
||||
@dataclass()
|
||||
@ -99,7 +99,7 @@ class FumenBranch:
|
||||
length: int = 0
|
||||
speed: float = 0.0
|
||||
padding: int = 0
|
||||
notes: list[FumenNote] = field(default_factory=list)
|
||||
notes: List[FumenNote] = field(default_factory=list)
|
||||
|
||||
|
||||
@dataclass()
|
||||
@ -111,15 +111,15 @@ class FumenMeasure:
|
||||
duration: float = 0.0
|
||||
gogo: bool = False
|
||||
barline: bool = True
|
||||
branch_info: list[int] = field(default_factory=lambda: [-1] * 6)
|
||||
branches: dict[str, FumenBranch] = field(
|
||||
branch_info: List[int] = field(default_factory=lambda: [-1] * 6)
|
||||
branches: Dict[str, FumenBranch] = field(
|
||||
default_factory=lambda: {b: FumenBranch() for b in BRANCH_NAMES}
|
||||
)
|
||||
padding1: int = 0
|
||||
padding2: int = 0
|
||||
|
||||
def set_duration(self,
|
||||
time_sig: list[int],
|
||||
time_sig: List[int],
|
||||
measure_length: int,
|
||||
subdivisions: int) -> None:
|
||||
"""Compute the millisecond duration of the measure."""
|
||||
@ -165,7 +165,7 @@ class FumenMeasure:
|
||||
|
||||
def set_branch_info(self,
|
||||
branch_type: str,
|
||||
branch_cond: tuple[float, float],
|
||||
branch_cond: Tuple[float, float],
|
||||
branch_points_total: int,
|
||||
current_branch: str,
|
||||
has_levelhold: bool) -> None:
|
||||
@ -222,7 +222,7 @@ class FumenMeasure:
|
||||
class FumenHeader:
|
||||
"""Contains all the byte values for a Fumen chart file's header."""
|
||||
order: str = "<"
|
||||
b000_b431_timing_windows: tuple[float, ...] = (25.025, 75.075, 108.422)*36
|
||||
b000_b431_timing_windows: Tuple[float, ...] = (25.025, 75.075, 108.422)*36
|
||||
b432_b435_has_branches: int = 0
|
||||
b436_b439_hp_max: int = 10000
|
||||
b440_b443_hp_clear: int = 8000
|
||||
@ -347,6 +347,6 @@ class FumenHeader:
|
||||
class FumenCourse:
|
||||
"""Contains all the data in a single Fumen (`.bin`) chart file."""
|
||||
header: FumenHeader
|
||||
measures: list[FumenMeasure] = field(default_factory=list)
|
||||
measures: List[FumenMeasure] = field(default_factory=list)
|
||||
score_init: int = 0
|
||||
score_diff: int = 0
|
||||
|
@ -3,14 +3,15 @@ Functions for converting TJA song data to Fumen song data.
|
||||
"""
|
||||
|
||||
import re
|
||||
from typing import List, Dict, Tuple, Union
|
||||
|
||||
from tja2fumen.classes import (TJACourse, TJAMeasure, TJAMeasureProcessed,
|
||||
FumenCourse, FumenHeader, FumenMeasure,
|
||||
FumenNote)
|
||||
|
||||
|
||||
def process_commands(tja_branches: dict[str, list[TJAMeasure]], bpm: float) \
|
||||
-> dict[str, list[TJAMeasureProcessed]]:
|
||||
def process_commands(tja_branches: Dict[str, List[TJAMeasure]], bpm: float) \
|
||||
-> Dict[str, List[TJAMeasureProcessed]]:
|
||||
"""
|
||||
Process all commands in each measure.
|
||||
|
||||
@ -27,7 +28,7 @@ def process_commands(tja_branches: dict[str, list[TJAMeasure]], bpm: float) \
|
||||
After this function is finished, all the #COMMANDS will be gone, and each
|
||||
measure will have attributes (e.g. measure.bpm, measure.scroll) instead.
|
||||
"""
|
||||
tja_branches_processed: dict[str, list[TJAMeasureProcessed]] = {
|
||||
tja_branches_processed: Dict[str, List[TJAMeasureProcessed]] = {
|
||||
branch_name: [] for branch_name in tja_branches.keys()
|
||||
}
|
||||
for branch_name, branch_measures_tja in tja_branches.items():
|
||||
@ -89,7 +90,7 @@ def process_commands(tja_branches: dict[str, list[TJAMeasure]], bpm: float) \
|
||||
# measure in those cases.)
|
||||
elif data.name in ['bpm', 'scroll', 'gogo']:
|
||||
# Parse the values
|
||||
new_val: bool | float
|
||||
new_val: Union[bool, float]
|
||||
if data.name == 'bpm':
|
||||
new_val = current_bpm = float(data.value)
|
||||
elif data.name == 'scroll':
|
||||
@ -199,8 +200,8 @@ def convert_tja_to_fumen(tja: TJACourse) -> FumenCourse:
|
||||
branch_points_measure = 0
|
||||
current_drumroll = FumenNote()
|
||||
current_levelhold = False
|
||||
branch_types: list[str] = []
|
||||
branch_conditions: list[tuple[float, float]] = []
|
||||
branch_types: List[str] = []
|
||||
branch_conditions: List[Tuple[float, float]] = []
|
||||
course_balloons = tja.balloon.copy()
|
||||
|
||||
# Iterate over pairs of TJA and Fumen measures
|
||||
|
@ -6,7 +6,7 @@ import os
|
||||
import re
|
||||
import struct
|
||||
from copy import deepcopy
|
||||
from typing import BinaryIO, Any
|
||||
from typing import BinaryIO, Any, List, Dict, Tuple
|
||||
|
||||
from tja2fumen.classes import (TJASong, TJACourse, TJAMeasure, TJAData,
|
||||
FumenCourse, FumenMeasure, FumenBranch,
|
||||
@ -37,7 +37,7 @@ def parse_tja(fname_tja: str) -> TJASong:
|
||||
return tja
|
||||
|
||||
|
||||
def split_tja_lines_into_courses(lines: list[str]) -> TJASong:
|
||||
def split_tja_lines_into_courses(lines: List[str]) -> TJASong:
|
||||
"""
|
||||
Parse TJA metadata in order to split TJA lines into separate courses.
|
||||
|
||||
@ -159,7 +159,7 @@ def split_tja_lines_into_courses(lines: list[str]) -> TJASong:
|
||||
return parsed_tja
|
||||
|
||||
|
||||
def parse_tja_course_data(data: list[str]) -> dict[str, list[TJAMeasure]]:
|
||||
def parse_tja_course_data(data: List[str]) -> Dict[str, List[TJAMeasure]]:
|
||||
"""
|
||||
Parse course data (notes, commands) into a nested song structure.
|
||||
|
||||
@ -475,7 +475,7 @@ def parse_fumen(fumen_file: str,
|
||||
|
||||
def read_struct(file: BinaryIO,
|
||||
order: str,
|
||||
format_string: str) -> tuple[Any, ...]:
|
||||
format_string: str) -> Tuple[Any, ...]:
|
||||
"""
|
||||
Interpret bytes as packed binary data.
|
||||
|
||||
|
@ -3,7 +3,7 @@ Functions for writing song data to fumen files (.bin)
|
||||
"""
|
||||
|
||||
import struct
|
||||
from typing import BinaryIO, Any
|
||||
from typing import BinaryIO, Any, List
|
||||
|
||||
from tja2fumen.classes import FumenCourse
|
||||
from tja2fumen.constants import BRANCH_NAMES, FUMEN_TYPE_NOTES
|
||||
@ -55,7 +55,7 @@ def write_fumen(path_out: str, song: FumenCourse) -> None:
|
||||
def write_struct(file: BinaryIO,
|
||||
order: str,
|
||||
format_string: str,
|
||||
value_list: list[Any]) -> None:
|
||||
value_list: List[Any]) -> None:
|
||||
"""Pack (int, float, etc.) values into a string of bytes, then write."""
|
||||
packed_bytes = struct.pack(order + format_string, *value_list)
|
||||
file.write(packed_bytes)
|
||||
|
Loading…
Reference in New Issue
Block a user