2024-08-27 21:11:45 +00:00
|
|
|
extends Node
|
|
|
|
class_name BaseTrack
|
|
|
|
|
|
|
|
var _default = null
|
|
|
|
var _tracks = null
|
2024-08-27 22:35:42 +00:00
|
|
|
var _autoload = null
|
2024-08-27 21:11:45 +00:00
|
|
|
|
|
|
|
func get_tracks():
|
2024-08-27 22:35:42 +00:00
|
|
|
if not _tracks and not _autoload:
|
2024-08-27 21:11:45 +00:00
|
|
|
return []
|
|
|
|
|
2024-08-27 22:35:42 +00:00
|
|
|
var tracks = []
|
2024-08-27 21:11:45 +00:00
|
|
|
|
2024-08-27 22:35:42 +00:00
|
|
|
if _autoload:
|
|
|
|
var dir = DirAccess.open(_autoload.path)
|
|
|
|
|
|
|
|
if dir:
|
|
|
|
dir.list_dir_begin()
|
|
|
|
var file_name = dir.get_next()
|
|
|
|
|
|
|
|
while file_name != "":
|
|
|
|
if not dir.current_is_dir() and not file_name.ends_with(".import"):
|
2024-08-27 22:55:22 +00:00
|
|
|
var track_name = file_name.rsplit(".", true, 1)[0]
|
2024-08-27 22:35:42 +00:00
|
|
|
var regex = RegEx.new()
|
|
|
|
regex.compile(_autoload.pattern)
|
2024-08-27 22:55:22 +00:00
|
|
|
var result = regex.search(track_name)
|
2024-08-27 22:35:42 +00:00
|
|
|
if result:
|
|
|
|
track_name = result.get_string()
|
|
|
|
|
|
|
|
tracks.push_back({
|
|
|
|
"name": track_name,
|
|
|
|
"track": "%s/%s" % [_autoload.path, file_name]
|
|
|
|
})
|
|
|
|
|
|
|
|
file_name = dir.get_next()
|
|
|
|
|
|
|
|
if _tracks:
|
|
|
|
for track in _tracks:
|
|
|
|
var filter = tracks.filter(func(a): return a.track == track.track)
|
|
|
|
|
|
|
|
if filter.size() == 0:
|
|
|
|
# Does not exist as an autoload
|
|
|
|
tracks.push_back(track)
|
|
|
|
else:
|
|
|
|
# Exists as an overload, override all keys
|
|
|
|
var found_track = filter[0]
|
|
|
|
|
|
|
|
for key in found_track:
|
|
|
|
track[key] = found_track[key]
|
2024-08-27 21:11:45 +00:00
|
|
|
|
|
|
|
for track in tracks:
|
|
|
|
for key in _default:
|
|
|
|
if not track.has(key):
|
|
|
|
track[key] = _default[key]
|
|
|
|
|
|
|
|
return tracks
|