simfile-scripts/docs/remove-all-but-one-chart.py

25 lines
978 B
Python
Raw Normal View History

2022-08-20 18:02:25 -07:00
from typing import Optional, Sequence
from simfile.types import Chart, Charts, Simfile
# When you have multiple parameters of the same type (str in this case),
# it's good practice to use a * pseudo-argument to require them to be named
def find_chart(
charts: Sequence[Chart], *, stepstype: str, difficulty: str
) -> Optional[Chart]:
for chart in charts:
if chart.stepstype == stepstype and chart.difficulty == difficulty:
return chart
def remove_other_charts(
sf: Simfile, *, stepstype="dance-single", difficulty="Challenge"
):
the_chart = find_chart(sf.charts, stepstype=stepstype, difficulty=difficulty)
if the_chart:
# Replace the simfile's charts with a list of one
sf.charts = [the_chart] # type: ignore
else:
# You could alternatively raise an exception, pick a different chart,
# set sf.charts to an empty list, etc.
print(f"No {stepstype} {difficulty} chart found for {repr(sf)}")