mirror of
https://github.com/Facepunch/sbox-public.git
synced 2026-08-01 08:18:20 -04:00
* Added a platform level chatbox that games can use * Published games do not have this * Newly published projects have it enabled by default, if the game is networked * Check out the Platform page in Project Settings to turn it off * Party chat uses this, you can also switch between party / game chat if eligible using TAB You can use `Sandbox.Platform.Chat.AddText( ... )` to add system text for notifications or other things. This has blocking behaviour built-in, and you can disable the chat in your settings menu. You can listen to chat messages using `IChatEvent.OnChatMessage`, so if you want to filter for stuff like team chat, add commands to your game, you can do that. We have potential plans for first-party commands / chat channels in the future.
80 lines
2.5 KiB
C#
80 lines
2.5 KiB
C#
using Sandbox.Audio;
|
|
|
|
namespace Sandbox;
|
|
|
|
public class ProjectSettings
|
|
{
|
|
/// <summary>
|
|
/// Get the <see cref="CollisionRules"/> from the active project settings.
|
|
/// </summary>
|
|
public static CollisionRules Collision => Get<CollisionRules>( "Collision.config" );
|
|
|
|
/// <summary>
|
|
/// Get the <see cref="Input"/> from the active project settings.
|
|
/// </summary>
|
|
public static InputSettings Input => Get<InputSettings>( "Input.config" );
|
|
|
|
/// <summary>
|
|
/// Get the <see cref="NetworkingSettings"/> from the active project settings.
|
|
/// </summary>
|
|
public static NetworkingSettings Networking => Get<NetworkingSettings>( "Networking.config" );
|
|
|
|
/// <summary>
|
|
/// Get the <see cref="MixerSettings"/> from the active project settings.
|
|
/// </summary>
|
|
internal static MixerSettings Mixer => Get<MixerSettings>( "Mixer.config" );
|
|
|
|
/// <summary>
|
|
/// Get the <see cref="CursorSettings"/> from the active project settings.
|
|
/// </summary>
|
|
internal static CursorSettings Cursor => Get<CursorSettings>( "Cursors.config" );
|
|
|
|
/// <summary>
|
|
/// Get the <see cref="PhysicsSettings"/> from the active project settings.
|
|
/// </summary>
|
|
public static PhysicsSettings Physics => Get<PhysicsSettings>( "Physics.config" );
|
|
|
|
/// <summary>
|
|
/// Get the <see cref="SystemsConfig"/> from the active project settings.
|
|
/// </summary>
|
|
public static SystemsConfig Systems => Get<SystemsConfig>( "Systems.config" );
|
|
|
|
/// <summary>
|
|
/// Get the <see cref="PlatformSettings"/> from the active project settings.
|
|
/// </summary>
|
|
public static PlatformSettings Platform => Get<PlatformSettings>( "Platform.config" );
|
|
|
|
/// <summary>
|
|
/// Reset any stored references to Project Settings.
|
|
/// </summary>
|
|
internal static void ClearCache()
|
|
{
|
|
_cache.Clear();
|
|
}
|
|
|
|
static Dictionary<string, ConfigData> _cache = new();
|
|
|
|
/// <summary>
|
|
/// 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.
|
|
/// </summary>
|
|
public static T Get<T>( 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 );
|
|
config.LoadedFromDisk = true;
|
|
}
|
|
|
|
return config;
|
|
}
|
|
}
|