Files
sbox-public/engine/Sandbox.Engine/Systems/Project/ProjectSettings/ConfigData.cs
Tony Ferguson 06f7a33e73 Platform chat system (#4857)
* 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.
2026-05-20 10:53:10 +00:00

61 lines
1.4 KiB
C#

using System.Text.Json.Nodes;
using System.Text.Json.Serialization;
namespace Sandbox;
/// <summary>
/// Project configuration data is derived from this class
/// </summary>
public abstract class ConfigData
{
[JsonPropertyName( "__guid" ), Hide]
public Guid Guid { get; set; } = Guid.NewGuid();
/// <summary>
/// Whether this config was loaded from a file on disk, or created with code defaults.
/// </summary>
[JsonIgnore, Hide]
public bool LoadedFromDisk { get; internal set; }
[JsonIgnore, Hide]
public virtual int Version => 1;
public JsonObject Serialize()
{
OnValidate();
var obj = Json.SerializeAsObject( this );
obj["__schema"] = "configdata";
obj["__type"] = GetType().Name;
obj["__version"] = Version;
return obj;
}
public void Deserialize( string json )
{
var jso = Json.ParseToJsonObject( json );
if ( jso is null ) return;
// read schema, version etc, upgrade if needed
var serializedVersion = (int)(jso["__version"] ?? 1);
if ( serializedVersion < Version )
{
// Log.Warning( $"{this} needs an API update, running upgraders (from version {serializedVersion} to {Version})" );
JsonUpgrader.Upgrade( serializedVersion, jso, GetType() );
}
Json.DeserializeToObject( this, jso );
OnValidate();
}
/// <summary>
/// Called after deserialization, and before serialization. A place to error check and make sure everything is fine.
/// </summary>
protected virtual void OnValidate()
{
// nothing
}
}