mirror of
https://github.com/GeWuYou/GFramework.git
synced 2026-03-22 10:34:30 +08:00
refactor(setting): 重构设置模块结构并添加版本控制功能
- 将AudioSettings和GraphicsSettings移至data子目录 - 为AudioSettings和GraphicsSettings实现IVersioned接口 - 新增LocalizationSettings类管理本地化配置 - 重命名AudioBusMapSettings为AudioBusMap并移至data目录 - 新增LocalizationMap类定义语言映射关系 - 更新GodotAudioSettings依赖注入参数名称 - 修复GodotAudioSettings重置方法逻辑 - 新增GodotLocalizationSettings类应用本地化配置到Godot引擎 - 添加必要的using语句和版权注释
This commit is contained in:
parent
4cfc5d3505
commit
9531cd0883
@ -1,9 +1,11 @@
|
||||
using GFramework.Core.Abstractions.versioning;
|
||||
|
||||
namespace GFramework.Game.Abstractions.setting;
|
||||
|
||||
/// <summary>
|
||||
/// 音频设置类,用于管理游戏中的音频配置
|
||||
/// </summary>
|
||||
public class AudioSettings : ISettingsData
|
||||
public class AudioSettings : ISettingsData, IVersioned
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取或设置主音量,控制所有音频的总体音量
|
||||
@ -25,8 +27,11 @@ public class AudioSettings : ISettingsData
|
||||
/// </summary>
|
||||
public void Reset()
|
||||
{
|
||||
// 重置所有音量设置为默认值
|
||||
MasterVolume = 1.0f;
|
||||
BgmVolume = 0.8f;
|
||||
SfxVolume = 0.8f;
|
||||
}
|
||||
|
||||
public int Version { get; set; } = 1;
|
||||
}
|
||||
@ -1,9 +1,11 @@
|
||||
using GFramework.Core.Abstractions.versioning;
|
||||
|
||||
namespace GFramework.Game.Abstractions.setting;
|
||||
|
||||
/// <summary>
|
||||
/// 图形设置类,用于管理游戏的图形相关配置
|
||||
/// </summary>
|
||||
public class GraphicsSettings : ISettingsData
|
||||
public class GraphicsSettings : ISettingsData, IVersioned
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取或设置是否启用全屏模式
|
||||
@ -29,4 +31,6 @@ public class GraphicsSettings : ISettingsData
|
||||
ResolutionWidth = 1920;
|
||||
ResolutionHeight = 1080;
|
||||
}
|
||||
|
||||
public int Version { get; set; } = 1;
|
||||
}
|
||||
@ -0,0 +1,44 @@
|
||||
// Copyright (c) 2026 GeWuYou
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
using GFramework.Core.Abstractions.versioning;
|
||||
|
||||
namespace GFramework.Game.Abstractions.setting.data;
|
||||
|
||||
/// <summary>
|
||||
/// 本地化设置类,用于管理游戏的语言本地化配置
|
||||
/// 实现了ISettingsData接口提供设置数据功能,实现IVersioned接口提供版本控制功能
|
||||
/// </summary>
|
||||
public class LocalizationSettings : ISettingsData, IVersioned
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取或设置当前使用的语言
|
||||
/// </summary>
|
||||
/// <value>默认值为"简体中文"</value>
|
||||
public string Language { get; set; } = "简体中文";
|
||||
|
||||
/// <summary>
|
||||
/// 重置本地化设置到默认状态
|
||||
/// 将Language属性恢复为默认的"简体中文"值
|
||||
/// </summary>
|
||||
public void Reset()
|
||||
{
|
||||
Language = "简体中文";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置设置数据的版本号
|
||||
/// </summary>
|
||||
/// <value>默认版本号为1</value>
|
||||
public int Version { get; set; } = 1;
|
||||
}
|
||||
@ -7,8 +7,8 @@ namespace GFramework.Godot.setting;
|
||||
/// Godot音频设置实现类,用于应用音频配置到Godot音频系统
|
||||
/// </summary>
|
||||
/// <param name="settings">音频设置对象,包含主音量、背景音乐音量和音效音量</param>
|
||||
/// <param name="audioBusMapSettings">音频总线映射对象,定义了不同音频类型的总线名称</param>
|
||||
public class GodotAudioSettings(AudioSettings settings, AudioBusMapSettings audioBusMapSettings)
|
||||
/// <param name="audioBusMap">音频总线映射对象,定义了不同音频类型的总线名称</param>
|
||||
public class GodotAudioSettings(AudioSettings settings, AudioBusMap audioBusMap)
|
||||
: IPersistentApplyAbleSettings
|
||||
{
|
||||
/// <summary>
|
||||
@ -17,15 +17,15 @@ public class GodotAudioSettings(AudioSettings settings, AudioBusMapSettings audi
|
||||
/// <returns>表示异步操作的任务</returns>
|
||||
public Task Apply()
|
||||
{
|
||||
SetBus(audioBusMapSettings.Master, settings.MasterVolume);
|
||||
SetBus(audioBusMapSettings.Bgm, settings.BgmVolume);
|
||||
SetBus(audioBusMapSettings.Sfx, settings.SfxVolume);
|
||||
SetBus(audioBusMap.Master, settings.MasterVolume);
|
||||
SetBus(audioBusMap.Bgm, settings.BgmVolume);
|
||||
SetBus(audioBusMap.Sfx, settings.SfxVolume);
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
audioBusMapSettings.Reset();
|
||||
settings.Reset();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
46
GFramework.Godot/setting/GodotLocalizationSettings.cs
Normal file
46
GFramework.Godot/setting/GodotLocalizationSettings.cs
Normal file
@ -0,0 +1,46 @@
|
||||
// Copyright (c) 2026 GeWuYou
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
using GFramework.Game.Abstractions.setting;
|
||||
using GFramework.Game.Abstractions.setting.data;
|
||||
using GFramework.Godot.setting.data;
|
||||
using Godot;
|
||||
|
||||
namespace GFramework.Godot.setting;
|
||||
|
||||
/// <summary>
|
||||
/// Godot本地化设置类,负责应用本地化配置到Godot引擎
|
||||
/// </summary>
|
||||
/// <param name="settings">本地化设置对象</param>
|
||||
/// <param name="localizationMap">本地化映射表</param>
|
||||
public class GodotLocalizationSettings(LocalizationSettings settings, LocalizationMap localizationMap)
|
||||
: IPersistentApplyAbleSettings
|
||||
{
|
||||
/// <summary>
|
||||
/// 应用本地化设置到Godot引擎
|
||||
/// </summary>
|
||||
/// <returns>完成的任务</returns>
|
||||
public Task Apply()
|
||||
{
|
||||
// 尝试从映射表获取 Godot locale
|
||||
var locale = localizationMap.LanguageMap.GetValueOrDefault(settings.Language, "en");
|
||||
// 默认值
|
||||
TranslationServer.SetLocale(locale);
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 重置本地化设置
|
||||
/// </summary>
|
||||
public void Reset() => settings.Reset();
|
||||
}
|
||||
@ -1,12 +1,10 @@
|
||||
using GFramework.Game.Abstractions.setting;
|
||||
|
||||
namespace GFramework.Godot.setting;
|
||||
|
||||
/// <summary>
|
||||
/// 音频总线映射设置
|
||||
/// 定义了游戏中不同音频类型的总线名称配置
|
||||
/// </summary>
|
||||
public class AudioBusMapSettings : ISettingsData
|
||||
public class AudioBusMap
|
||||
{
|
||||
/// <summary>
|
||||
/// 主音频总线名称
|
||||
29
GFramework.Godot/setting/data/LocalizationMap.cs
Normal file
29
GFramework.Godot/setting/data/LocalizationMap.cs
Normal file
@ -0,0 +1,29 @@
|
||||
// Copyright (c) 2026 GeWuYou
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
namespace GFramework.Godot.setting.data;
|
||||
|
||||
/// <summary>
|
||||
/// 本地化映射设置
|
||||
/// </summary>
|
||||
public class LocalizationMap
|
||||
{
|
||||
/// <summary>
|
||||
/// 用户语言 -> Godot locale 映射表
|
||||
/// </summary>
|
||||
public Dictionary<string, string> LanguageMap { get; set; } = new()
|
||||
{
|
||||
{ "简体中文", "zh_CN" },
|
||||
{ "English", "en" }
|
||||
};
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user