清理代码

master
lightyears 2 years ago
parent f8294dff94
commit f8f281f2f7
Signed by: lightyears
GPG Key ID: 98D80DDF26D4F2F9

@ -1,7 +1,6 @@
using CMSGame.Models;
using Newtonsoft.Json;
namespace CMSGame.Autoloads
namespace CMSGame
{
/// <summary>
/// 游戏设置持久化节点
@ -27,6 +26,7 @@ namespace CMSGame.Autoloads
RegisterAllSettings();
MakeDirectories();
LoadAllSettings();
ApplyVideoSettings();
}
protected void RegisterAllSettings()
@ -62,12 +62,12 @@ namespace CMSGame.Autoloads
}
}
private static void MakeDirectories()
protected static void MakeDirectories()
{
DirAccess.MakeDirRecursiveAbsolute("user://Settings/");
}
private void LoadSettings(Type settingsType)
protected void LoadSettings(Type settingsType)
{
string settingsText = ReadFileAsString(SettingsPaths[settingsType]);
var settings = JsonConvert.DeserializeObject(settingsText, settingsType);
@ -83,7 +83,7 @@ namespace CMSGame.Autoloads
return (TSettings)CurrentSettings[typeof(TSettings)];
}
private static string ReadFileAsString(string path)
protected static string ReadFileAsString(string path)
{
if (FileAccess.FileExists(path))
{
@ -93,11 +93,16 @@ namespace CMSGame.Autoloads
return "null";
}
private void SaveSettings(Type settingsType)
protected void SaveSettings(Type settingsType)
{
string settingsText = JsonConvert.SerializeObject(CurrentSettings[settingsType]);
using var file = FileAccess.Open(SettingsPaths[settingsType], FileAccess.ModeFlags.Write);
file.StoreString(settingsText);
}
protected void ApplyVideoSettings()
{
DisplayServerHelper.ApplyResolutionSettings(VideoSettings.UseFullScreen);
}
}
}

@ -6,7 +6,7 @@ namespace CMSGame
{
}
public void On_OpenUserDataDirButton_Pressed()
public static void On_OpenUserDataDirButton_Pressed()
{
OS.ShellOpen(new GodotPath("user://"));
}

@ -1,5 +1,3 @@
using CMSGame.Autoloads;
namespace CMSGame
{
public partial class SettingsMenu : TabContainer

@ -1,5 +1,3 @@
using CMSGame.Models;
namespace CMSGame
{
public partial class VideoSettingsMenu : Control
@ -16,20 +14,13 @@ namespace CMSGame
FullScreenCheckButton!.Toggled += FullScreenCheckButton_Toggled;
FullScreenCheckButton.ButtonPressed = Settings.UseFullScreen;
FullScreenCheckButton.SetPressedNoSignal(Settings.UseFullScreen);
}
private void FullScreenCheckButton_Toggled(bool buttonPressed)
{
Settings!.UseFullScreen = buttonPressed;
if (buttonPressed)
{
DisplayServer.WindowSetMode(DisplayServer.WindowMode.Fullscreen);
}
else
{
DisplayServer.WindowSetMode(DisplayServer.WindowMode.Windowed);
}
DisplayServerHelper.ApplyResolutionSettings(buttonPressed);
}
}
}

@ -1,5 +1,4 @@
global using System;
global using System.Collections;
global using System.Collections.Generic;
global using System.Linq;
global using Godot;

@ -1,8 +1,8 @@
namespace CMSGame.Helpers
namespace CMSGame
{
internal static class DisplayServerHelper
{
public static void ApplyAndPersistResolutionSettings(bool useFullScreen)
public static void ApplyResolutionSettings(bool useFullScreen)
{
if (useFullScreen)
{

@ -1,6 +1,6 @@
using System.Text;
namespace CMSGame.Models
namespace CMSGame
{
internal record class Changelog
{

@ -1,4 +1,4 @@
namespace CMSGame.Models
namespace CMSGame
{
public record class GameSettings
{

@ -1,4 +1,3 @@
using CMSGame.Models;
using System.Text;
namespace CMSGame

Loading…
Cancel
Save