Improve chart difficulty selection resilience

This commit is contained in:
Luke Hubmayer-Werner 2020-12-27 17:51:40 +10:30
parent 82280ca49d
commit d1e3150061
4 changed files with 26 additions and 10 deletions

View File

@ -590,7 +590,7 @@ func load_folder(folder, filename='song'):
func load_filelist(filelist: Array, directory=''):
var charts = {}
var key := 1
var key := 0
for name in filelist:
var extension: String = name.rsplit('.', true, 1)[-1]
name = directory.rstrip('/') + '/' + name
@ -600,8 +600,8 @@ func load_filelist(filelist: Array, directory=''):
'rgtm': # multiple charts
var res = RGT.load_file(filename)
for k in res:
charts[k] = res[k]
'rgts', 'rgtx': # single chart
charts[Library.difficulty_translations.get(k, k)] = res[k]
'rgts', 'rgtx': # single chart - The keys for this should be translated afterwards
charts[key] = RGT.load_file(filename)
key += 1
'srt': # maimai, single chart

View File

@ -1,5 +1,7 @@
extends Node
const difficulty_translations = {'01': 'Z', '02': 'B', '03': 'A', '04': 'E', '05': 'M', '06': 'R', '10': ''} # A bit redundant now but might be useful later for other hacks
class MultilangStr:
# Automatically propogate higher langs to lower ones if lower ones are missing.
# e.g. if we don't have a proper english title, return the transliterated one instead
@ -48,7 +50,7 @@ class Song:
var video_offsets: Array
var audio_preview_times: Array
var video_dimensions: Array
var chart_difficulties: Dictionary
var chart_difficulties := {}
const default_difficulty_keys = ['Z', 'B', 'A', 'E', 'M', 'R', '']
const difficulty_key_ids = {'Z':0, 'B':1, 'A':2, 'E':3, 'M':4, 'R':5, '':6}
@ -83,12 +85,10 @@ class Song:
TYPE_DICTIONARY:
chart_difficulties = diffs
TYPE_ARRAY:
chart_difficulties = {}
for i in min(len(diffs), len(default_difficulty_keys)):
chart_difficulties[default_difficulty_keys[i]] = diffs[i]
_:
print_debug('Invalid chart_difficulties!', title.en)
chart_difficulties = {}
func get_BPM(realtime:=0.0):
if not dynamic_bpm:
@ -128,7 +128,23 @@ func get_song_charts(song_key):
if song_key in charts_cache:
return charts_cache[song_key]
elif song_key in all_songs:
charts_cache[song_key] = FileLoader.load_filelist(all_songs[song_key].chart_filelist, 'songs/'+all_songs[song_key].filepath)
var charts = FileLoader.load_filelist(all_songs[song_key].chart_filelist, 'songs/'+all_songs[song_key].filepath)
# Need to fix keys on this to match the song
var diffs = all_songs[song_key].chart_difficulties
var missing_diffs = []
var unid_charts = []
for k in diffs:
if not (k in charts):
missing_diffs.push_back(k)
for k in charts:
if not (k in diffs):
unid_charts.push_back(k)
for i in len(missing_diffs):
if i < len(unid_charts):
charts[missing_diffs[i]] = charts[unid_charts[i]]
charts.erase(unid_charts[i])
charts_cache[song_key] = charts
return charts_cache[song_key]
else:
print_debug('Invalid song_key: ', song_key)

View File

@ -92,7 +92,7 @@ func _process(delta):
if (menu_mode == MenuMode.GAMEPLAY) and (menu_mode_prev_fade_timer <= 0.0) and not NoteHandler.running:
var songslist = genres[genres.keys()[selected_genre]]
var song_key = songslist[selected_song % len(songslist)]
NoteHandler.load_track(song_key, selected_difficulty)
NoteHandler.load_track(song_key, Library.Song.default_difficulty_keys[selected_difficulty])
NoteHandler.running = true
func draw_string_centered(font, position, string, color := Color.white):

View File

@ -512,14 +512,14 @@ func _ready():
InputHandler.connect('button_released', self, 'button_released')
InputHandler.connect('touchbutton_released', self, 'touchbutton_released')
func load_track(song_key: String, difficulty_idx: int):
func load_track(song_key: String, difficulty_key: String):
self.song_key = song_key
set_time(-3.0)
active_notes = []
next_note_to_load = 0
all_notes = []
var data = Library.all_songs[song_key]
var chart = Library.get_song_charts(song_key).values()[difficulty_idx]
var chart = Library.get_song_charts(song_key)[difficulty_key]
for note in chart[1]:
all_notes.append(Note.copy_note(note))
bpm = data.BPM