Change To OpenGL

This commit is contained in:
Mueller Wayan
2025-08-15 10:44:29 +02:00
parent 1862530728
commit a36789dd7e
101 changed files with 2981 additions and 1027 deletions
+118 -118
View File
@@ -1,144 +1,144 @@
using Firebird2D.Logger;
using Microsoft.Extensions.Configuration;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Schema;
using SFML.Window;
using System.Text;
//using Firebird2D.Logger;
//using Microsoft.Extensions.Configuration;
//using Newtonsoft.Json.Linq;
//using Newtonsoft.Json.Schema;
//using SFML.Window;
//using System.Text;
namespace Firebird2D.Configuration
{
public class GameConfig
{
public VideoMode VideoMode { get { return _videoMode; } set { _videoMode = value; updateConfig(); } }
//namespace Firebird2D.Configuration
//{
// public class GameConfig
// {
// public VideoMode VideoMode { get { return _videoMode; } set { _videoMode = value; updateConfig(); } }
public bool FullScreen { get { return _fullScreen; } set { _fullScreen = value; updateConfig(); } }
// public bool FullScreen { get { return _fullScreen; } set { _fullScreen = value; updateConfig(); } }
public bool LogActive { get { return _logActive; } set { _logActive = value; GameLogger.LogActive = value; updateConfig(); } }
// public bool LogActive { get { return _logActive; } set { _logActive = value; GameLogger.LogActive = value; updateConfig(); } }
private static readonly string ConfigSchema = "Configuration/ConfigurationSchema/ConfigSchema.json";
// private static readonly string ConfigSchema = "Configuration/ConfigurationSchema/ConfigSchema.json";
private static readonly string ConfigPath = "Configuration/GameConfig.json";
// private static readonly string ConfigPath = "Configuration/GameConfig.json";
private IConfigurationBuilder _configurationBuilder;
// private IConfigurationBuilder _configurationBuilder;
private IConfigurationSection _configurationSection;
// private IConfigurationSection _configurationSection;
private VideoMode _videoMode;
// private VideoMode _videoMode;
private bool _fullScreen;
// private bool _fullScreen;
private bool _logActive;
// private bool _logActive;
public GameConfig() {
CheckFile();
LoadConfig();
}
// public GameConfig() {
// CheckFile();
// LoadConfig();
// }
private void updateConfig()
{
if (_configurationBuilder != null)
{
_configurationSection["ScreenResolution:x"] = _videoMode.Width.ToString();
_configurationSection["ScreenResolution:y"] = _videoMode.Height.ToString();
_configurationSection["Fullscreen"] = _fullScreen.ToString();
_configurationSection["Log"] = _logActive.ToString();
}
}
// private void updateConfig()
// {
// if (_configurationBuilder != null)
// {
// _configurationSection["ScreenResolution:x"] = _videoMode.Width.ToString();
// _configurationSection["ScreenResolution:y"] = _videoMode.Height.ToString();
// _configurationSection["Fullscreen"] = _fullScreen.ToString();
// _configurationSection["Log"] = _logActive.ToString();
// }
// }
private void LoadConfig()
{
_configurationBuilder = new ConfigurationBuilder().AddJsonFile(ConfigPath, false, true);
_configurationSection = _configurationBuilder.Build().GetSection("AppSettings");
// private void LoadConfig()
// {
// _configurationBuilder = new ConfigurationBuilder().AddJsonFile(ConfigPath, false, true);
// _configurationSection = _configurationBuilder.Build().GetSection("AppSettings");
_videoMode = new VideoMode();
// _videoMode = new VideoMode();
if (_configurationSection != null)
{
try
{
_videoMode.Width = uint.Parse(_configurationSection["ScreenResolution:x"]);
_videoMode.Height = uint.Parse(_configurationSection["ScreenResolution:y"]);
_fullScreen = bool.Parse(_configurationSection["Fullscreen"]);
_logActive = bool.Parse(_configurationSection["Log"]);
GameLogger.LogActive = _logActive;
}
catch(Exception ex)
{
GameLogger.Log("GameConfig", LogType.Error, ex.Message);
File.Delete(ConfigPath);
MakeConfigFile();
LoadConfig();
}
}
else
{
GameLogger.Log("GameConfig", LogType.Error, "The Config File Was Corrupted");
File.Delete(ConfigPath);
MakeConfigFile();
LoadConfig();
}
// if (_configurationSection != null)
// {
// try
// {
// _videoMode.Width = uint.Parse(_configurationSection["ScreenResolution:x"]);
// _videoMode.Height = uint.Parse(_configurationSection["ScreenResolution:y"]);
// _fullScreen = bool.Parse(_configurationSection["Fullscreen"]);
// _logActive = bool.Parse(_configurationSection["Log"]);
// GameLogger.LogActive = _logActive;
// }
// catch(Exception ex)
// {
// GameLogger.Log("GameConfig", LogType.Error, ex.Message);
// File.Delete(ConfigPath);
// MakeConfigFile();
// LoadConfig();
// }
// }
// else
// {
// GameLogger.Log("GameConfig", LogType.Error, "The Config File Was Corrupted");
// File.Delete(ConfigPath);
// MakeConfigFile();
// LoadConfig();
// }
}
// }
private void CheckFile()
{
if (File.Exists(ConfigPath))
{
string schemaJson = File.ReadAllText(ConfigSchema);
JSchema schema = JSchema.Parse(schemaJson);
string ConfigData = File.ReadAllText(ConfigPath);
JObject json = JObject.Parse(ConfigData);
// private void CheckFile()
// {
// if (File.Exists(ConfigPath))
// {
// string schemaJson = File.ReadAllText(ConfigSchema);
// JSchema schema = JSchema.Parse(schemaJson);
// string ConfigData = File.ReadAllText(ConfigPath);
// JObject json = JObject.Parse(ConfigData);
IList<string> validationErrors = [];
// IList<string> validationErrors = [];
if (schema != null)
{
if (!json.IsValid(schema,out validationErrors)){
// if (schema != null)
// {
// if (!json.IsValid(schema,out validationErrors)){
File.Delete(ConfigPath);
MakeConfigFile();
GameLogger.Log("GameConfig", LogType.Error, "The Config File Was Corrupted");
foreach (string error in validationErrors)
{
GameLogger.Log("GameConfig", LogType.Error, error);
}
}
// File.Delete(ConfigPath);
// MakeConfigFile();
// GameLogger.Log("GameConfig", LogType.Error, "The Config File Was Corrupted");
// foreach (string error in validationErrors)
// {
// GameLogger.Log("GameConfig", LogType.Error, error);
// }
// }
}
// }
}
else
{
MakeConfigFile();
}
}
// }
// else
// {
// MakeConfigFile();
// }
// }
private void MakeConfigFile()
{
VideoMode desktopMode = VideoMode.DesktopMode;
// private void MakeConfigFile()
// {
// VideoMode desktopMode = VideoMode.DesktopMode;
using (FileStream stream = File.Create(ConfigPath))
{
AddText(stream, "{" +
" \"AppSettings\":{" +
" \"ScreenResolution\": {" +
string.Format(" \"x\": {0},", desktopMode.Width) +
string.Format(" \"y\": {0}", desktopMode.Height) +
" }," +
" \"Fullscreen\": false," +
" \"Log\": true," +
" }" +
"}"
);
stream.Close();
}
}
// using (FileStream stream = File.Create(ConfigPath))
// {
// AddText(stream, "{" +
// " \"AppSettings\":{" +
// " \"ScreenResolution\": {" +
// string.Format(" \"x\": {0},", desktopMode.Width) +
// string.Format(" \"y\": {0}", desktopMode.Height) +
// " }," +
// " \"Fullscreen\": false," +
// " \"Log\": true," +
// " }" +
// "}"
// );
// stream.Close();
// }
// }
private static void AddText(FileStream fs, string value)
{
byte[] info = new UTF8Encoding(true).GetBytes(value);
fs.Write(info, 0, info.Length);
}
}
}
// private static void AddText(FileStream fs, string value)
// {
// byte[] info = new UTF8Encoding(true).GetBytes(value);
// fs.Write(info, 0, info.Length);
// }
// }
//}