# MusicInfo —— 对标 POC/assets/root/musicinfo.py:默认曲目常量 + 上次战场曲目持久化。 # # 参考(musicinfo.py): # METIN2THEMA = "M2BG.mp3" # loginMusic = "login_window.mp3" # createMusic = "characterselect.mp3" # selectMusic = "characterselect.mp3" # fieldMusic = METIN2THEMA # SaveLastPlayFieldMusic() / LoadLastPlayFieldMusic() → 文件 "BGM/lastplay.inf" # # 用法: # const MusicInfo = preload("res://musicinfo.gd") # MusicInfo.fieldMusic # -> "M2BG.mp3" # MusicInfo.save_last_play_field_music("x.mp3") # MusicInfo.load_last_play_field_music() # -> "x.mp3" 或 "" extends RefCounted const METIN2THEMA := "M2BG.mp3" const loginMusic := "login_window.mp3" const createMusic := "characterselect.mp3" const selectMusic := "characterselect.mp3" # 选人页 const fieldMusic := METIN2THEMA # 参考写死 "BGM/lastplay.inf"(相对客户端目录);Godot 侧落到用户可写目录。 const LAST_PLAY_DIR := "user://BGM" const LAST_PLAY_PATH := "user://BGM/lastplay.inf" # musicInfo.SaveLastPlayFieldMusic(name) static func save_last_play_field_music(name: String) -> void: if name == "": return DirAccess.make_dir_recursive_absolute(LAST_PLAY_DIR) var f := FileAccess.open(LAST_PLAY_PATH, FileAccess.WRITE) if f: f.store_string(name) f.close() # musicInfo.LoadLastPlayFieldMusic() -> 曲目名(无记录时空串) static func load_last_play_field_music() -> String: if not FileAccess.file_exists(LAST_PLAY_PATH): return "" var f := FileAccess.open(LAST_PLAY_PATH, FileAccess.READ) if f == null: return "" var s := f.get_as_text() f.close() return s.strip_edges()