40250 classic: increment 50 (W4) — map BGM selection + background volume save/restore

§9.1 map BGM selection (bgm_director.gd):
- server bgm_changed(name, volume): non-empty name plays it as field music;
  empty name falls back to musicInfo.fieldMusic (METIN2THEMA = "M2BG.mp3")
- volume < 0 (server unspecified, GC_MAIN_CHARACTER3_BGM) -> default
  1/5*0.1 = 0.02; otherwise server volume; volume applied before play_bgm()
  fade-in (matches game.py:190 SetMusicVolume/SetSoundVolume then FadeInMusic)
- connect M2Client.world_reset -> re-run selection on map change
- new musicinfo.gd: METIN2THEMA/loginMusic/createMusic/selectMusic/fieldMusic
  constants + save/load_last_play_field_music -> user://BGM/lastplay.inf

§9.2 background/foreground volume save-restore:
- audio.gd: save_volume()/restore_volume() (backup fields echo reference
  m_fBackupMusicVolume / m_fBackupSoundVolume) + set_music_volume()
- app_lifecycle.gd: _enter_background() uses save_volume() + mute instead of
  stop_bgm(); _exit_background() calls restore_volume(); _bgm_name never cleared

§9.3 lifecycle ownership: DOC ONLY — design confirmed, deferred to Phase 2 / W0
(AppFlow sole lifecycle owner; M2Client drops NOTIFICATION_* keeps suspend/resume).
game_scene.gd / app_flow.gd / m2_client.* left untouched per workflow constraints.

Tests: bgm_test.gd (new) PASS; gamescene_test / netplay_test / p9_test green.
Docs: CLIENT-GAP.md increment 50 bullet + W4 progress row; CLIENT-GAP-FIX.md
§9.1 §9.2 状态/改动/测试/验收, §9.3 deferred note, C.5 batch record.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014yvAPqPivoY7vmBbzgqK4W
This commit is contained in:
shenlei
2026-09-02 15:31:58 +09:00
co-authored by Claude Sonnet 5
parent f32064c74a
commit 9732f2799e
10 changed files with 393 additions and 11 deletions
+47
View File
@@ -0,0 +1,47 @@
# 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()