Gondwana Game Engine Development (master) - 2.6.1
Gondwana is a cross-platform 2.5D game and rendering engine written in C#/.NET 8. It provides fine-grained control over rendering, timing, and scene composition, with built-in support for parallax, z-ordering, pixel overhang, collision detection, and particle effects. Gondwana targets desktop and web platforms using SkiaSharp for graphics and pluggable audio backends for desktop and browser targets.
Loading...
Searching...
No Matches
EngineConfigurationFile.cs
1using Microsoft.Extensions.Configuration;
2using Newtonsoft.Json;
3
5
11[JsonObject(IsReference = true)]
12public partial class EngineConfigurationFile : IEngineConfigurationStore
13{
14 private const string _defaultConfigFileName = "gondwana.json";
15 private string _fileName = _defaultConfigFileName;
16
17 private EngineConfigurationFile()
18 { }
19
26 public static EngineConfigurationFile CreateNew(string? configFileName = null, bool? autoSave = null)
27 {
28 var config = new EngineConfigurationFile
29 {
30 FileName = configFileName ?? _defaultConfigFileName,
31 AutoSave = autoSave ?? false,
33 };
34
35 return config;
36 }
37
46 public static EngineConfigurationFile Load(string? configFileName = null, bool? autoSave = null)
47 {
48 var configFile = configFileName ?? _defaultConfigFileName;
49
50 var configRoot = new ConfigurationBuilder()
51 .AddJsonFile(configFile, optional: true, reloadOnChange: true)
52 .Build();
53
54 var settings = configRoot.GetSection(nameof(EngineConfig)).Get<EngineConfiguration>();
55 return new EngineConfigurationFile
56 {
57 FileName = configFile,
58 AutoSave = autoSave ?? false,
59 EngineConfig = settings ?? new EngineConfiguration()
60 };
61 }
62
66 [JsonIgnore]
67 public string FileName
68 {
69 get => Path.GetFileName(_fileName);
70 private set => _fileName = Path.GetFullPath(value);
71 }
72
76 [JsonIgnore]
77 public string FilePath => Path.GetFullPath(_fileName);
78
83 [JsonIgnore]
84 public bool AutoSave { get; set; } = false;
85
89 public EngineConfiguration EngineConfig { get; private set; } = new();
90
94 [JsonIgnore]
96
101 public void Save()
102 {
103 Save(FilePath);
104 }
105
112 public void Save(string jsonPath)
113 {
114 var json = JsonConvert.SerializeObject(this, Formatting.Indented);
115 File.WriteAllText(jsonPath, json);
116 FileName = jsonPath;
117 }
118
123 public void Dispose()
124 {
125 if (AutoSave)
126 Save();
127
128 GC.SuppressFinalize(this);
129 }
130}
string FilePath
Gets the full path to the configuration file.
bool AutoSave
Gets or sets a value indicating whether the configuration should be automatically saved when the inst...
EngineConfiguration Configuration
Gets the engine configuration represented by this file-backed store.
static EngineConfigurationFile Load(string? configFileName=null, bool? autoSave=null)
Loads an engine configuration file from disk.
void Dispose()
Releases all resources used by the EngineConfigurationFile.
EngineConfiguration EngineConfig
Gets the engine configuration settings.
void Save(string jsonPath)
Saves the configuration to the specified file path.
void Save()
Saves the configuration to the file specified by FilePath.
static EngineConfigurationFile CreateNew(string? configFileName=null, bool? autoSave=null)
Creates a new engine configuration file with default settings.
string FileName
Gets the name of the configuration file without the directory path.
Settings used by the engine when cycling.
Provides a persistence boundary for EngineConfiguration.