basic developer console

This commit is contained in:
Ian Woods 2026-07-21 20:37:57 -07:00
parent 4375350901
commit 04d7b42e60
4 changed files with 184 additions and 8 deletions

View file

@ -0,0 +1,78 @@
// Assets/_Project/Scripts/Dev/DebugCommandRelay.cs
using System.Collections.Generic;
using Unity.Netcode;
using UnityEngine;
using TD.Gameplay.Draft;
namespace TD.Dev
{
/// <summary>
/// Debug-only network relay: exposes one RPC that force-applies a <see cref="DraftOption"/>
/// by its <see cref="DraftPool"/> index, bypassing <c>PlayerDraft</c>'s "must currently be
/// offered" check.
/// </summary>
/// <remarks>
/// Lives entirely separate from PlayerDraft/DraftOption/DraftPool — none of those files
/// know this component exists. Removing this component (and TD.Dev.DebugConsole, which
/// calls it) leaves the shipping draft system completely untouched.
///
/// Added to the Player prefab alongside PlayerDraft/PlayerGoldManager/etc. so it spawns
/// with a per-player OwnerClientId. Static per-client registry mirrors PlayerDraft's
/// GetForClient/Local pattern.
/// </remarks>
public class DebugCommandRelay : NetworkBehaviour
{
private static readonly Dictionary<ulong, DebugCommandRelay> s_byClientId
= new Dictionary<ulong, DebugCommandRelay>();
public static DebugCommandRelay GetForClient(ulong clientId)
{
s_byClientId.TryGetValue(clientId, out var relay);
return relay;
}
public static DebugCommandRelay Local
{
get
{
var nm = NetworkManager.Singleton;
if (nm == null || !nm.IsClient) return null;
return GetForClient(nm.LocalClientId);
}
}
public override void OnNetworkSpawn()
{
s_byClientId[OwnerClientId] = this;
}
public override void OnNetworkDespawn()
{
if (s_byClientId.TryGetValue(OwnerClientId, out var registered) && registered == this)
s_byClientId.Remove(OwnerClientId);
}
/// <summary>
/// Owning client: force-apply the DraftOption at <paramref name="optionId"/> (its
/// DraftPool index) immediately, skipping the normal "must be currently offered" gate.
/// Debug/testing only — any connected client can grant themselves anything via this
/// RPC, same tradeoff DevWaveControls already accepts for its hotkeys.
/// </summary>
[Rpc(SendTo.Server, InvokePermission = RpcInvokePermission.Owner)]
public void DebugGrantDraftOptionRpc(int optionId)
{
var option = DraftPool.Instance != null ? DraftPool.Instance.Get(optionId) : null;
if (option == null)
{
Debug.LogWarning($"[DebugCommandRelay] Grant requested for unknown option id {optionId}.");
return;
}
if (option.ServerApply(OwnerClientId))
Debug.Log($"[DebugCommandRelay] Granted '{option.DisplayName}' to client {OwnerClientId}.");
else
Debug.LogWarning($"[DebugCommandRelay] '{option.DisplayName}' could not be applied " +
$"to client {OwnerClientId}.");
}
}
}