forked from Shardstone/trail-into-darkness
feat: add channel enable/disable, prefab docs, and UI updates
Add per-channel enable/disable toggle to the in-game logging system with Enable()/Disable() on InGameLogger and EnableChannel/DisableChannel on IGameLogStore. Update README with prefab setup guide and enable/disable documentation. Update character creation and log container prefabs. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -135,6 +135,32 @@ var tradeLogger = new InGameLogger(logStore, MyLogChannels.Trading);
|
||||
tradeLogger.Log("Sold Iron Sword for 50 gold.");
|
||||
```
|
||||
|
||||
## Enable / Disable Channels
|
||||
|
||||
Each logger can be toggled on or off. When disabled, calls to `Log` are silently dropped (no allocation, no entry added). All channels are enabled by default.
|
||||
|
||||
```csharp
|
||||
var combatLog = new InGameLogger(logStore, LogChannel.Combat);
|
||||
|
||||
combatLog.Disable();
|
||||
combatLog.Log("This message is silently dropped.");
|
||||
|
||||
combatLog.Enable();
|
||||
combatLog.Log("Back online.");
|
||||
|
||||
if(combatLog.IsEnabled) {
|
||||
// check state
|
||||
}
|
||||
```
|
||||
|
||||
The state lives in the `IGameLogStore`, so disabling a channel from one `InGameLogger` instance disables it for all instances using the same store and channel. You can also call the store directly:
|
||||
|
||||
```csharp
|
||||
logStore.DisableChannel(LogChannel.World);
|
||||
logStore.EnableChannel(LogChannel.World);
|
||||
bool enabled = logStore.IsChannelEnabled(LogChannel.World);
|
||||
```
|
||||
|
||||
## Rich Text
|
||||
|
||||
Log messages support TextMeshPro rich text tags. The `InGameLogger.Log(message, hexColor)` overload wraps the message in a `<color>` tag automatically:
|
||||
@@ -194,13 +220,19 @@ logStore.RestoreFromSaveData(saveData);
|
||||
- `InGameLogger(IGameLogStore store, LogChannel channel)` -- constructor
|
||||
- `void Log(string message)` -- add an entry to the store
|
||||
- `void Log(string message, string hexColor)` -- add a color-wrapped entry
|
||||
- `void Enable()` -- enable this logger's channel
|
||||
- `void Disable()` -- disable this logger's channel (Log calls are silently dropped)
|
||||
- `bool IsEnabled` -- whether this logger's channel is currently enabled
|
||||
|
||||
### IGameLogStore / GameLogStore
|
||||
|
||||
- `GameLogStore(int capacity = 500)` -- constructor with ring buffer size
|
||||
- `int Count` -- current number of entries
|
||||
- `int Capacity` -- maximum entries before oldest are overwritten
|
||||
- `void Add(LogChannel channel, string message)` -- add an entry
|
||||
- `void Add(LogChannel channel, string message)` -- add an entry (silently dropped if channel is disabled)
|
||||
- `void EnableChannel(LogChannel channel)` -- enable a channel
|
||||
- `void DisableChannel(LogChannel channel)` -- disable a channel
|
||||
- `bool IsChannelEnabled(LogChannel channel)` -- check if a channel is enabled
|
||||
- `void Clear()` -- remove all entries
|
||||
- `void Clear(LogChannel channel)` -- remove entries for a specific channel
|
||||
- `ReadOnlySpan<LogEntry> GetEntries()` -- all entries in chronological order
|
||||
|
||||
Reference in New Issue
Block a user