using System.Collections.Generic; using ProjectM.Simulation; using Unity.Entities; using Unity.NetCode; using UnityEngine; namespace ProjectM.Client { /// /// Client-side class-pick sender: a static enqueue (the Staging class-select HUD buttons) drained into /// RPCs (the MetaSpendSendSystem idiom). Carries only the class id; the server /// re-validates the phase + applies the full swap. Statics reset on play-enter (the stale-bridge hazard). /// [WorldSystemFilter(WorldSystemFilterFlags.ClientSimulation)] public partial class ClassSelectSendSystem : SystemBase { static readonly Queue s_Queue = new(); [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)] static void ResetStatics() => s_Queue.Clear(); /// Queue a class pick (0=Warrior, 1=Ranger). The Staging class buttons drive this. public static void RequestClass(byte classId) => s_Queue.Enqueue(classId); protected override void OnCreate() => RequireForUpdate(); protected override void OnUpdate() { while (s_Queue.Count > 0) { var req = EntityManager.CreateEntity(typeof(ClassSelectRequest), typeof(SendRpcCommandRequest)); EntityManager.SetComponentData(req, new ClassSelectRequest { ClassId = s_Queue.Dequeue() }); } } } }