More .sm framework

This commit is contained in:
Luke Hubmayer-Werner 2020-03-30 23:21:20 +10:30
parent 703edb9656
commit c1aac96a6e
3 changed files with 47 additions and 14 deletions

View File

@ -6,7 +6,7 @@ var userroot := "user://" if OS.get_name() != "Android" else "/storage/emulated/
# "/storage/emulated/0/Android/data/au.ufeff.rhythmgame/" # "/storage/emulated/0/Android/data/au.ufeff.rhythmgame/"
# "/sdcard/Android/data/au.ufeff.rhythmgame/" # "/sdcard/Android/data/au.ufeff.rhythmgame/"
func directory_list(directory: String, hidden: bool) -> Dictionary: func directory_list(directory: String, hidden: bool, sort:=true) -> Dictionary:
# Sadly there's no filelist sugar so we make our own # Sadly there's no filelist sugar so we make our own
var output = {folders=[], files=[], err=OK} var output = {folders=[], files=[], err=OK}
var dir = Directory.new() var dir = Directory.new()
@ -27,6 +27,22 @@ func directory_list(directory: String, hidden: bool) -> Dictionary:
output['files'].append(item) output['files'].append(item)
item = dir.get_next() item = dir.get_next()
dir.list_dir_end() dir.list_dir_end()
if sort:
output.folders.sort()
output.files.sort()
# Maybe convert the Arrays to PoolStringArrays?
return output
func find_by_extensions(array, extensions) -> Dictionary:
# Both args can be Array or PoolStringArray
var output = {}
for ext in extensions:
output[ext] = []
for string in array:
for ext in extensions:
if string.ends_with(ext):
output[ext].append(string)
return output return output
func scan_library(): func scan_library():
@ -49,6 +65,7 @@ func scan_library():
dir.open(rootdir) dir.open(rootdir)
for key in songslist.folders: for key in songslist.folders:
if dir.file_exists(key + "/song.json"): if dir.file_exists(key + "/song.json"):
# Our format
song_defs[key] = FileLoader.load_folder("%s/%s" % [rootdir, key]) song_defs[key] = FileLoader.load_folder("%s/%s" % [rootdir, key])
print("Loaded song directory: %s" % key) print("Loaded song directory: %s" % key)
song_images[key] = FileLoader.load_image("%s/%s/%s" % [rootdir, key, song_defs[key]["tile_filename"]]) song_images[key] = FileLoader.load_image("%s/%s/%s" % [rootdir, key, song_defs[key]["tile_filename"]])
@ -57,7 +74,15 @@ func scan_library():
else: else:
genres[song_defs[key]["genre"]] = [key] genres[song_defs[key]["genre"]] = [key]
else: else:
print("Found non-song directory: " + key) var step_files = find_by_extensions(directory_list(rootdir + '/' + key, false).files, ['.sm'])
if len(step_files['.sm']) > 0:
var sm_filename = step_files['.sm'][0]
print(sm_filename)
var thing = SM.load_file(rootdir + '/' + key + '/' + sm_filename)
print(thing)
pass
else:
print("Found non-song directory: " + key)
for file in songslist.files: for file in songslist.files:
print("Found file: " + file) print("Found file: " + file)
@ -166,17 +191,17 @@ class SM:
'#CREDIT': 'chart_author', '#CREDIT': 'chart_author',
'#BANNER': 'image_banner', '#BANNER': 'image_banner',
'#BACKGROUND': 'image_background', '#BACKGROUND': 'image_background',
'#LYRICSPATH': '', # '#LYRICSPATH': '',
'#CDTITLE': 'image_cd_title', '#CDTITLE': 'image_cd_title',
'#MUSIC': 'audio_filelist', '#MUSIC': 'audio_filelist',
'#OFFSET': 'audio_offsets', '#OFFSET': 'audio_offsets',
'#SAMPLESTART': 'audio_preview_times', '#SAMPLESTART': 'audio_preview_times',
'#SAMPLELENGTH': 'audio_preview_times', '#SAMPLELENGTH': 'audio_preview_times',
'#SELECTABLE': '', # '#SELECTABLE': '',
'#BPMS': 'bpm_values', '#BPMS': 'bpm_values',
'#STOPS': '', # '#STOPS': '',
'#BGCHANGES': '', # '#BGCHANGES': '',
'#KEYSOUNDS': '', # '#KEYSOUNDS': '',
} }
static func load_chart(lines): static func load_chart(lines):
@ -235,17 +260,21 @@ class SM:
notes.append(Note.make_tap(time, col)) notes.append(Note.make_tap(time, col))
'2': # Hold '2': # Hold
ongoing_holds[col] = len(notes) ongoing_holds[col] = len(notes)
notes.append(Note.make_tap(time, col)) notes.append(Note.make_hold(time, 0.0, col))
num_holds += 1
'4': # Roll '4': # Roll
ongoing_holds[col] = len(notes) ongoing_holds[col] = len(notes)
notes.append(Note.make_tap(time, col)) notes.append(Note.make_roll(time, 0.0, col))
num_rolls += 1
'3': # End Hold/Roll '3': # End Hold/Roll
assert(ongoing_holds.has(col)) assert(ongoing_holds.has(col))
notes[ongoing_holds[col]].set_time_release(time) notes[ongoing_holds[col]].set_time_release(time)
ongoing_holds.erase(col)
'M': # Mine 'M': # Mine
num_mines += 1 num_mines += 1
pass pass
metadata['num_notes'] = num_notes metadata['num_notes'] = num_notes
metadata['num_taps'] = num_notes - num_jumps
metadata['num_jumps'] = num_jumps metadata['num_jumps'] = num_jumps
metadata['num_hands'] = num_hands metadata['num_hands'] = num_hands
metadata['num_holds'] = num_holds metadata['num_holds'] = num_holds
@ -264,7 +293,7 @@ class SM:
var length = file.get_len() var length = file.get_len()
var lines = [[]] # First list will be header, then every subsequent one is a chart var lines = [[]] # First list will be header, then every subsequent one is a chart
while (file.get_position() < (length-1)): # Could probably replace this with file.eof_reached() while (file.get_position() < (length-1)): # Could probably replace this with file.eof_reached()
var line : String = file.read_line() var line : String = file.get_line()
if line.begins_with('#NOTES'): # Split to a new list for each chart definition if line.begins_with('#NOTES'): # Split to a new list for each chart definition
lines.append([]) lines.append([])
lines[-1].append(line) lines[-1].append(line)
@ -275,12 +304,14 @@ class SM:
var tokens = line.rstrip(';').split(':') var tokens = line.rstrip(';').split(':')
if TAG_TRANSLATIONS.has(tokens[0]): if TAG_TRANSLATIONS.has(tokens[0]):
metadata[TAG_TRANSLATIONS[tokens[0]]] = tokens[1] metadata[TAG_TRANSLATIONS[tokens[0]]] = tokens[1]
elif len(tokens) >= 2:
metadata[tokens[0]] = tokens[1]
var charts = [] var charts = []
for i in range(1, len(lines)): for i in range(1, len(lines)):
charts.append(load_chart(lines[i])) charts.append(load_chart(lines[i]))
return charts return [metadata, charts]
class Test: class Test:

View File

@ -648,9 +648,10 @@ func _process(delta):
if note.time_death < t: if note.time_death < t:
match note.type: match note.type:
Note.NOTE_HOLD: Note.NOTE_HOLD:
scores[-Note.NOTE_HOLD][3] += 1 if note.is_held: # Held too long
active_judgement_texts.append({col=note.column, judgement=3, time=t}) scores[-Note.NOTE_HOLD][3] += 1
SFXPlayer.play(SFXPlayer.Type.NON_POSITIONAL, self, snd_judgement[3], db_judgement[3]) active_judgement_texts.append({col=note.column, judgement=3, time=t})
SFXPlayer.play(SFXPlayer.Type.NON_POSITIONAL, self, snd_judgement[3], db_judgement[3])
Note.NOTE_SLIDE: Note.NOTE_SLIDE:
SlideTrailHandler.remove_child(slide_trail_mesh_instances[note.slide_id]) SlideTrailHandler.remove_child(slide_trail_mesh_instances[note.slide_id])
slide_trail_mesh_instances.erase(note.slide_id) slide_trail_mesh_instances.erase(note.slide_id)

View File

@ -219,6 +219,7 @@ margin_left = 4.0
margin_top = 90.0 margin_top = 90.0
margin_right = 121.0 margin_right = 121.0
margin_bottom = 130.0 margin_bottom = 130.0
pressed = true
text = "Vsync" text = "Vsync"
__meta__ = { __meta__ = {
"_edit_use_anchors_": false "_edit_use_anchors_": false