Terachor/tracks/base.gd

56 lines
1.2 KiB
GDScript

extends Node
class_name BaseTrack
var _default = null
var _tracks = null
var _autoload = null
func get_tracks():
if not _tracks and not _autoload:
return []
var tracks = []
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"):
var track_name = file_name.rsplit(".", true, 1)[0]
var regex = RegEx.new()
regex.compile(_autoload.pattern)
var result = regex.search(track_name)
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]
for track in tracks:
for key in _default:
if not track.has(key):
track[key] = _default[key]
return tracks