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
+32
View File
@@ -19,6 +19,12 @@ var master_bgm := 0.6
var master_sfx := 0.9
var _queued_bgm := ""
# §9.2 前后台音量存/恢复,字段名对齐参考 CSoundManager 的
# m_fBackupMusicVolume / m_fBackupSoundVolumeREF/MilesLib/SoundManager.h:31)。
var _backup_music_volume := -1.0
var _backup_sound_volume := -1.0
var _volume_saved := false
func _ready() -> void:
if _queued_bgm != "":
var n := _queued_bgm
@@ -127,6 +133,32 @@ func _fade(pl: AudioStreamPlayer, to_db: float, dur: float, stop_after := false)
if stop_after:
tw.tween_callback(pl.stop)
# 立即把 master_bgm 应用到当前正在播放的 BGM 声道(无淡入)。
# 对标 CSoundManager::SetMusicVolume:改的是「当前音乐实例」的音量。
func set_music_volume(v: float) -> void:
master_bgm = clampf(v, 0.0, 1.0)
var pl: AudioStreamPlayer = _bgm[_bgm_cur]
if pl and pl.playing:
pl.volume_db = linear_to_db(master_bgm) if master_bgm > 0.0 else -80.0
# §9.2:进入后台前保存音量(CSoundManager::SaveVolume)。
func save_volume() -> void:
_backup_music_volume = master_bgm
_backup_sound_volume = master_sfx
_volume_saved = true
# §9.2:回到前台后恢复音量(CSoundManager::RestoreVolume)。
# 不碰 _bgm_name / _bgm[],同一首继续播,只把音量拉回来。
func restore_volume() -> void:
if not _volume_saved:
return
master_bgm = _backup_music_volume
master_sfx = _backup_sound_volume
_volume_saved = false
var pl: AudioStreamPlayer = _bgm[_bgm_cur]
if pl and pl.playing:
pl.volume_db = linear_to_db(master_bgm) if master_bgm > 0.0 else -80.0
# --- SFX -------------------------------------------------------------------
func play_ui(name: String) -> void: