Gondwana Game Engine Development (master) - 2.7.0
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 }
20
27 public static EngineConfigurationFile CreateNew(string? configFileName = null, bool? autoSave = null)
28 {
29 var config = new EngineConfigurationFile
30 {
31 FileName = configFileName ?? _defaultConfigFileName,
32 AutoSave = autoSave ?? false,
34 };
35
36 return config;
37 }
38
47 public static EngineConfigurationFile Load(string? configFileName = null, bool? autoSave = null)
48 {
49 var configFile = configFileName ?? _defaultConfigFileName;
50
51 var configRoot = new ConfigurationBuilder()
52 .AddJsonFile(configFile, optional: true, reloadOnChange: true)
53 .Build();
54
55 var settings = configRoot.GetSection(nameof(EngineConfig)).Get<EngineConfiguration>();
56
57 return new EngineConfigurationFile
58 {
59 FileName = configFile,
60 AutoSave = autoSave ?? false,
61 EngineConfig = settings ?? new EngineConfiguration()
62 };
63 }
64
68 [JsonIgnore]
69 public string FileName
70 {
71 get => Path.GetFileName(_fileName);
72 private set => _fileName = Path.GetFullPath(value);
73 }
74
78 [JsonIgnore]
79 public string FilePath => Path.GetFullPath(_fileName);
80
85 [JsonIgnore]
86 public bool AutoSave { get; set; } = false;
87
91 public EngineConfiguration EngineConfig { get; private set; } = new();
92
96 [JsonIgnore]
98
103 public void Save()
104 {
105 Save(FilePath);
106 }
107
114 public void Save(string jsonPath)
115 {
116 var json = JsonConvert.SerializeObject(this, Formatting.Indented);
117 File.WriteAllText(jsonPath, json);
118 FileName = jsonPath;
119 }
120
125 public void Dispose()
126 {
127 if (AutoSave)
128 Save();
129
130 GC.SuppressFinalize(this);
131 }
132}
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.