Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 37 additions & 19 deletions scenes/actors/music/music.gd
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func is_tween_active() -> bool:


##### CUSTOM MUSIC
func get_custom_file_path() -> String:
func get_custom_file_path(file_type: String) -> String:
# i think accessing leveldata singleton is safe for now since
# this only is called inside levels, i hope i dont regret that decision
var level_id: String = Singleton.CurrentLevelData.level_id
Expand All @@ -64,10 +64,11 @@ func get_custom_file_path() -> String:
return level_list_util.get_level_music_path(
level_id,
area,
working_folder)
working_folder,
file_type)

func reset_custom_song() -> void:
var file_path: String = get_custom_file_path()
func reset_custom_song(file_type: String) -> void:
var file_path: String = get_custom_file_path(file_type)
if level_list_util.file_exists(file_path):
level_list_util.delete_file(file_path)

Expand All @@ -80,30 +81,32 @@ func handle_custom_song(url: String) -> void:

stop()

var file_path: String = get_custom_file_path()
var file_type: String = url.substr(url.find_last("."))
var file_path: String = get_custom_file_path(file_type)
if not level_list_util.file_exists(file_path):
print("OGG file not found, downloading from url...")
print("Music file not found, downloading from url...")

var level_id: String = Singleton.CurrentLevelData.level_id
var area: int = Singleton.CurrentLevelData.area
var working_folder: String = Singleton.CurrentLevelData.working_folder
save_ogg(url, level_id, area, working_folder)
save_music(url, level_id, area, working_folder, file_type)
else:
print("OGG file found, loading...")
print("Music file found, loading...")

var ogg_file := File.new()
var _open = ogg_file.open(file_path, File.READ)
var bytes: PoolByteArray = ogg_file.get_buffer(ogg_file.get_len())
ogg_file.close()

load_ogg(bytes)
load_music(bytes,file_type)


func save_ogg(url: String, level_id: String, area: int, working_folder: String) -> void:
func save_music(url: String, level_id: String, area: int, working_folder: String, file_type: String) -> void:
var file_path: String = level_list_util.get_level_music_path(
level_id,
area,
working_folder)
working_folder,
file_type)

#http_request.download_file = file_path
http_request.request(url)
Expand All @@ -122,22 +125,37 @@ func request_completed(result: int, response_code: int, headers: PoolStringArray
ogg_file.store_buffer(body)
ogg_file.close()

load_ogg(body)


func load_ogg(bytes: PoolByteArray) -> void:
var stream := AudioStreamOGGVorbis.new()
var file_type: String = file_path.substr(file_path.find_last("."))
load_music(body,file_type)


func load_music(bytes: PoolByteArray,file_type: String) -> void:
var stream: AudioStream
match (file_type):
".ogg":
stream = AudioStreamOGGVorbis.new()
stream.loop = true
stream.loop_offset = loop
".mp3":
stream = AudioStreamMP3.new()
stream.loop = true
stream.loop_offset = loop
# ".wav": Doesn't work currently and I don't know how to fix it
# stream = AudioStreamSample.new()
# stream.loop_mode = AudioStreamSample.LOOP_FORWARD
# stream.loop_begin = loop
_:
stream = AudioStream.new()
stream.data = bytes
stream.loop = true
stream.loop_offset = loop

if stream.data == null:
return

if get_tree().get_current_scene().mode != 2:
self.stream = stream
play()

print("OGG file loaded.")
print("Music file loaded.")
#######


Expand Down
2 changes: 1 addition & 1 deletion scenes/actors/objects/buoyant_platform/buoyant_platform.gd
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ var spawn_pos

func _ready():
if palette != 0:
$Sprite.texture = palette_textures[palette]
sprite.texture = palette_textures[palette]

if override_part_width != 0:
part_width = override_part_width
Expand Down
12 changes: 10 additions & 2 deletions scenes/editor/music_changer.gd
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,25 @@ func text_entered(text):
var re = RegEx.new()

re.compile("(^https:\\/\\/[^\\/]*)(.*)")
var file_type: String = music_title.text.substr(music_title.text.find_last("."))

if not re.search_all(music_title.text) or !music_title.text.ends_with(".ogg"):
if not re.search_all(music_title.text) or !is_music_file(file_type):
music_title.text = "Invalid URL"
else:

re.compile("(\\d+(?:\\.\\d+)?)")
if not re.search(music_note.text):
music_note.text = "0.00"
Singleton.CurrentLevelData.level_data.areas[Singleton.CurrentLevelData.area].settings.music = "LP" + music_note.text + "=" + music_title.text
Singleton.Music.reset_custom_song()
Singleton.Music.reset_custom_song(file_type)
update_display()

func is_music_file(file_type: String) -> bool:

var valid_types: PoolStringArray = [".ogg",".mp3"]#,".wav"]

return (file_type in valid_types)

func _ready():
var _connect = button_left.connect("pressed", self, "button_press")
var _connect2 = button_right.connect("pressed", self, "button_press")
Expand Down
5 changes: 3 additions & 2 deletions util/new/levels_list/level_list_util.gd
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,9 @@ static func get_image_from_path(file_path: String) -> ImageTexture:


## MUSIC
static func get_level_music_path(level_id: String, area_id: int, working_folder: String) -> String:
return get_level_music_folder(working_folder) + level_id + "-" + str(area_id) + ".ogg"
static func get_level_music_path(level_id: String, area_id: int, working_folder: String,
file_type: String) -> String:
return get_level_music_folder(working_folder) + level_id + "-" + str(area_id) + file_type

static func get_level_music_folder(working_folder: String) -> String:
return working_folder + "/music/"
Expand Down