using Sandbox.Audio; namespace Sandbox; public class ProjectSettings { /// /// Get the from the active project settings. /// public static CollisionRules Collision => Get( "Collision.config" ); /// /// Get the from the active project settings. /// public static InputSettings Input => Get( "Input.config" ); /// /// Get the from the active project settings. /// public static NetworkingSettings Networking => Get( "Networking.config" ); /// /// Get the from the active project settings. /// internal static MixerSettings Mixer => Get( "Mixer.config" ); /// /// Get the from the active project settings. /// internal static CursorSettings Cursor => Get( "Cursors.config" ); /// /// Get the from the active project settings. /// public static PhysicsSettings Physics => Get( "Physics.config" ); /// /// Reset any stored references to Project Settings. /// internal static void ClearCache() { _cache.Clear(); } static Dictionary _cache = new(); /// /// Gets or creates a default version of this config data. You can safely call this multiple times /// and it will return the same object. The cache is cleared automatically when the project changes, /// or when it's hotloaded. /// public static T Get( string filename ) where T : ConfigData, new() { if ( _cache.TryGetValue( filename, out var result ) && result is T t ) return t; var txt = EngineFileSystem.ProjectSettings?.ReadAllText( BaseFileSystem.NormalizeFilename( filename ) ); var config = new T(); _cache[filename] = config; if ( !string.IsNullOrEmpty( txt ) ) { config.Deserialize( txt ); } return config; } }