From 8a4a581c2c21b1988d499015e2e293efcc55e9be Mon Sep 17 00:00:00 2001 From: soul Date: Fri, 27 Nov 2026 02:54:05 +0100 Subject: [PATCH] Hands-off input through one route: ActionGameManager subscribes and reads every Player and Global action via Bind/TryRead/Held/ActiveControl, which consult TacticalInput; tractor is press/release and releases on entry and ship change; scan test pins the route [ruling tactical-input-hands-off] Co-Authored-By: Claude Sonnet 5.5 --- Assets/Scripts/Gameplay/ActionGameManager.cs | 102 +++++++++++------- .../ServerShared/EconomyBalance.cs.meta | 2 + .../LiberationSans SDF - Fallback.asset | 4 +- .../TacticalInputTests.cs | 18 ++++ 4 files changed, 88 insertions(+), 38 deletions(-) create mode 100644 Assets/Scripts/ServerShared/EconomyBalance.cs.meta diff --git a/Assets/Scripts/Gameplay/ActionGameManager.cs b/Assets/Scripts/Gameplay/ActionGameManager.cs index 1b3b120a7..ab6c43176 100644 --- a/Assets/Scripts/Gameplay/ActionGameManager.cs +++ b/Assets/Scripts/Gameplay/ActionGameManager.cs @@ -332,7 +332,7 @@ public class ActionGameManager : MonoBehaviour Input.Global.Enable(); // The latch is the game's own, so it can disagree with the keyboard's Caps Lock light: show it. - Input.Player.ToggleFaceAim.performed += context => _helm.Toggle(); + Bind(Input.Player.ToggleFaceAim, context => _helm.Toggle()); var markParent = GameplayUI != null ? GameplayUI.transform : UiRoot.transform; var markObject = new GameObject("Face Aim Mark", typeof(RectTransform)); markObject.transform.SetParent(markParent, false); @@ -346,11 +346,11 @@ public class ActionGameManager : MonoBehaviour _faceAimMark.enabled = false; _zoomLevelIndex = Settings.DefaultMinimapZoom; - Input.Player.MinimapZoom.performed += context => + Bind(Input.Player.MinimapZoom, context => { _zoomLevelIndex = (_zoomLevelIndex + 1) % Settings.MinimapZoomLevels.Length; ZoneRenderer.MinimapDistance = Settings.MinimapZoomLevels[_zoomLevelIndex]; - }; + }); // The tactical view is a distinct camera over the grid (ruling tactical-view-distinct-mode): the wheel is one axis // from the chase view through a detent into it, and TacticalView the one owner of where on that axis the camera is. @@ -379,26 +379,26 @@ public class ActionGameManager : MonoBehaviour _schematicCamera.depth = ZoneRenderer.MainCamera.depth + 1; _schematicCamera.cullingMask = 1 << LayerMask.NameToLayer("Minimap"); _schematicCamera.enabled = false; - Input.Player.Zoom.performed += context => + Bind(Input.Player.Zoom, context => { var scroll = context.ReadValue(); if (scroll == 0 || !Flying) return; var was = _tactical.Tactical; _tactical.Scroll(-Mathf.Sign(scroll)); if (_tactical.Tactical != was) EnablePlayerInput(); - }; + }); - Input.Global.ZoneMap.performed += context => + Bind(Input.Global.ZoneMap, context => { ToggleMenuTab(MenuTab.Map); MenuMap.Position = DrawAhead.Position(CurrentEntity, Clock.Lead).xz; - }; + }); - Input.Global.Inventory.performed += context => ToggleMenuTab(MenuTab.Inventory); + Bind(Input.Global.Inventory, context => ToggleMenuTab(MenuTab.Inventory)); - Input.Global.GalaxyMap.performed += context => ToggleMenuTab(MenuTab.Galaxy); + Bind(Input.Global.GalaxyMap, context => ToggleMenuTab(MenuTab.Galaxy)); - Input.Global.Interact.performed += context => + Bind(Input.Global.Interact, context => { if (EventSystem.current.currentSelectedGameObject != null && EventSystem.current.currentSelectedGameObject.GetComponent() != null) return; if (MainMenu.gameObject.activeSelf) return; @@ -441,53 +441,57 @@ public class ActionGameManager : MonoBehaviour Dock(); } else Undock(); - }; + }); - Input.Global.MainMenu.performed += context => + Bind(Input.Global.MainMenu, context => { if(Menu.gameObject.activeSelf) ToggleMenuTab(Menu.CurrentTab); else ToggleFullscreenMenu(MainMenu.gameObject); - }; + }); - Input.Global.InputScreen.performed += context => ToggleFullscreenMenu(HelpScreen); + Bind(Input.Global.InputScreen, context => ToggleFullscreenMenu(HelpScreen)); - Input.Player.HideUI.performed += context => + Bind(Input.Player.HideUI, context => { _uiHidden = !_uiHidden; GameplayUI.alpha = _uiHidden ? 0 : 1; ActionBar.gameObject.SetActive(!_uiHidden); - }; + }); // The switches and the ping are presses on the entity's command, flipped at the next step. - Input.Player.OverrideShutdown.performed += context => CurrentEntity.Command.ToggleOverrideShutdown(); - Input.Player.Ping.performed += context => CurrentEntity.Command.Ping(); + Bind(Input.Player.OverrideShutdown, context => CurrentEntity.Command.ToggleOverrideShutdown()); + Bind(Input.Player.Ping, context => CurrentEntity.Command.Ping()); // TODO: SFX: Success/Fail - Input.Player.ToggleHeatsinks.performed += context => CurrentEntity.Command.ToggleHeatsinks(); + Bind(Input.Player.ToggleHeatsinks, context => CurrentEntity.Command.ToggleHeatsinks()); // TODO: SFX: Success/Fail - Input.Player.ToggleShield.performed += context => CurrentEntity.Command.ToggleShield(); + Bind(Input.Player.ToggleShield, context => CurrentEntity.Command.ToggleShield()); // Flips the player's own stance on the current target between hostile and neutral. Going // neutral mid-fight safes weapons (Weapon.StanceAllowsFire); an unmarked/undetected target // reads as non-hostile, so the first press declares hostile. The flip reads the target and its stance when applied, // after the step's target presses, so two presses in a step cancel. - Input.Player.ToggleStance.performed += context => CurrentEntity.Command.ToggleStance(); + Bind(Input.Player.ToggleStance, context => CurrentEntity.Command.ToggleStance()); #region Targeting // The reticle, nearest, next and previous presses each command a verb; the applier chooses through Entity at the // next step (mining target-queries cut): the rule lives with the entity, so the player, the test agent and any // director pick alike. - Input.Player.TargetReticle.performed += context => CurrentEntity.Command.Verb(TargetVerb.UnderReticle); - Input.Player.TargetNearest.performed += context => CurrentEntity.Command.Verb(TargetVerb.NearestEnemy); - Input.Player.TargetNext.performed += context => CurrentEntity.Command.Verb(TargetVerb.Next); - Input.Player.TargetPrevious.performed += context => CurrentEntity.Command.Verb(TargetVerb.Previous); + Bind(Input.Player.TargetReticle, context => CurrentEntity.Command.Verb(TargetVerb.UnderReticle)); + Bind(Input.Player.TargetNearest, context => CurrentEntity.Command.Verb(TargetVerb.NearestEnemy)); + Bind(Input.Player.TargetNext, context => CurrentEntity.Command.Verb(TargetVerb.Next)); + Bind(Input.Player.TargetPrevious, context => CurrentEntity.Command.Verb(TargetVerb.Previous)); // Cut 2 (docs/fire-control-cut.md): steps the aim through the target's schematic rows -- every mount this ship // has located, empty or not, minus the ones it saw destroyed. Decides nothing: the entity owns the cycle, applied at // the next step. - Input.Player.CycleTargetItem.performed += context => CurrentEntity.Command.CycleAim(); + Bind(Input.Player.CycleTargetItem, context => CurrentEntity.Command.CycleAim()); + + // The tractor is held while its key is: a press and a release each set it. It is not polled, so a key already down when the + // flight view returns does nothing until it is pressed again, as with fire; Update releases it while the view is tactical. + Bind(Input.Player.TractorBeam, context => CurrentEntity.Command.Tractor = context.ReadValue(), context => CurrentEntity.Command.Tractor = 0); #endregion @@ -773,6 +777,29 @@ public class ActionGameManager : MonoBehaviour return success ?? false; } + // Ruling tactical-input-hands-off: the one route every Player and Global action is subscribed and read through. TacticalInput + // decides per action whether it is live (an unclassified action is not); a press, a release or a read that is not live is + // dropped, never queued, so the ship holds its last commands. A test scans this file and fails if an action is touched anywhere else. + private bool Live(InputAction action) => TacticalInput.Live(_tactical, action.actionMap.name, action.name); + + private void Bind(InputAction action, Action performed, Action canceled = null) + { + action.performed += context => { if (Live(action)) performed(context); }; + if (canceled != null) action.canceled += context => { if (Live(action)) canceled(context); }; + } + + private bool TryRead(InputAction action, out T value) where T : struct + { + value = default; + if (!Live(action)) return false; + value = action.ReadValue(); + return true; + } + + private bool Held(InputAction action) => Live(action) && action.IsPressed(); + + private InputControl ActiveControl(InputAction action) => Live(action) ? action.activeControl : null; + // The one writer of the cursor lock and the action bar while playing: the tactical view frees the cursor and gives the // mouse buttons to Pan, so the bar is off there. It is re-applied whenever Tactical changes. public void EnablePlayerInput() @@ -1155,6 +1182,8 @@ public class ActionGameManager : MonoBehaviour private void BindToEntity(Entity entity) { + // A tractor held through a ship change would stay on for the ship we leave: its release is a press we will no longer see. + if (CurrentEntity != null) CurrentEntity.Command.Tractor = 0; if (!ZoneRenderer.EntityInstances.ContainsKey(entity)) { Debug.LogError($"Attempted to bind to entity {entity.Name}, but SectorRenderer has no such instance!"); @@ -1348,13 +1377,14 @@ public class ActionGameManager : MonoBehaviour // Drag: the grid point under the cursor when the button went down stays under it. private void PanTarget() { - if (!Input.Player.Pan.IsPressed()) + if (!Held(Input.Player.Pan)) { _grab = null; return; } var height = DrawAhead.Height(CurrentEntity.Zone, _tactical.Target, Clock.Lead); - var ray = ZoneRenderer.MainCamera.ScreenPointToRay(Input.Player.Point.ReadValue()); + TryRead(Input.Player.Point, out Vector2 pointer); + var ray = ZoneRenderer.MainCamera.ScreenPointToRay(pointer); if (!new Plane(Vector3.up, new Vector3(0, height, 0)).Raycast(ray, out var hit)) return; var point = ray.GetPoint(hit); var ground = float2(point.x, point.z); @@ -1554,9 +1584,8 @@ public class ActionGameManager : MonoBehaviour PlaceFill(indicator.Value, indicator.Key); } // The tactical view does not steer: the aim and the chase yaw hold while the mouse pans the view. - if (!_tactical.Tactical) + if (TryRead(Input.Player.Look, out Vector2 look)) { - var look = Input.Player.Look.ReadValue(); var sensitivity = PlayerSettings.InputSettings.Sensitivity; _entityYawPitch = float2(_entityYawPitch.x + look.x * sensitivity.x, clamp(_entityYawPitch.y + look.y * sensitivity.y, -.45f * PI, .45f * PI)); _viewDirection = mul(float3(0, 0, 1), CultMath.float3x3.Euler(float3(_entityYawPitch.yx, 0), RotationOrder.YXZ)); @@ -1569,13 +1598,14 @@ public class ActionGameManager : MonoBehaviour max(Settings.HeatstrokePhasingFloor, sin(Time.time * Settings.HeatstrokePhasingFrequency)); _faceAimMark.enabled = _helm.Latched; - if(CurrentEntity is Ship ship) + if (CurrentEntity is Ship ship && TryRead(Input.Player.Move, out Vector2 move)) { - ship.Command.Movement = Input.Player.Move.ReadValue().ToCultMath(); - _helm.Held = Input.Player.FaceAim.IsPressed(); - if (Input.Player.Turn.activeControl is { } turnControl) + ship.Command.Movement = move.ToCultMath(); + _helm.Held = Held(Input.Player.FaceAim); + if (ActiveControl(Input.Player.Turn) is { } turnControl) _turnDigital = turnControl.device is UnityEngine.InputSystem.Keyboard; - var turnAxis = _helm.TurnAxis(Input.Player.Turn.ReadValue(), _turnDigital, Time.deltaTime, KeyboardTurnRampTime); + TryRead(Input.Player.Turn, out float turn); + var turnAxis = _helm.TurnAxis(turn, _turnDigital, Time.deltaTime, KeyboardTurnRampTime); ship.Command.Turn = _helm.Demand(_viewDirection.xz, ship.BandedTurn(turnAxis)); } @@ -1591,7 +1621,7 @@ public class ActionGameManager : MonoBehaviour TargetShieldsFill.fillAmount = target.Shield == null ? 0 : lerp(.25f, .75f, target.Shield.Progress); } - CurrentEntity.Command.Tractor = Input.Player.TractorBeam.ReadValue(); + if (!Live(Input.Player.TractorBeam)) CurrentEntity.Command.Tractor = 0; } } // One clock steps the zone, paused or not: a paused frame feeds it no real time. diff --git a/Assets/Scripts/ServerShared/EconomyBalance.cs.meta b/Assets/Scripts/ServerShared/EconomyBalance.cs.meta new file mode 100644 index 000000000..ed13be587 --- /dev/null +++ b/Assets/Scripts/ServerShared/EconomyBalance.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: af6be4282775ce448a9a06b22e39d518 \ No newline at end of file diff --git a/Assets/TextMesh Pro/Resources/Fonts & Materials/LiberationSans SDF - Fallback.asset b/Assets/TextMesh Pro/Resources/Fonts & Materials/LiberationSans SDF - Fallback.asset index 4d9191d4c..4787be7c3 100644 --- a/Assets/TextMesh Pro/Resources/Fonts & Materials/LiberationSans SDF - Fallback.asset +++ b/Assets/TextMesh Pro/Resources/Fonts & Materials/LiberationSans SDF - Fallback.asset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:f1eead45000fe0fe0a6fce50b4d21ab2ff1ea25f5b390452116e0b04f28540a7 -size 536050 +oid sha256:f53586850a70c4f308e7e71b99b63881a49f38de4bd40f4edb7fe7ae6ecf8a52 +size 9748 diff --git a/tests/Aetheria.Shared.Tests/TacticalInputTests.cs b/tests/Aetheria.Shared.Tests/TacticalInputTests.cs index e61de2f37..fbd7f40f6 100644 --- a/tests/Aetheria.Shared.Tests/TacticalInputTests.cs +++ b/tests/Aetheria.Shared.Tests/TacticalInputTests.cs @@ -6,6 +6,7 @@ using System; using System.Collections.Generic; using System.IO; using System.Linq; +using System.Text.RegularExpressions; using System.Text.Json; using CultMath; using Xunit; @@ -42,6 +43,23 @@ public sealed class TacticalInputTests .ToList(); } + // The one route: every Player and Global action ActionGameManager touches is an argument of Bind, TryRead, Held, ActiveControl or + // Live, and only Bind subscribes. A callback or a read outside them would skip TacticalInput. + [Fact] + public void ActionGameManagerTouchesEveryShipInputActionThroughTheOneHelper() + { + var dir = new DirectoryInfo(AppContext.BaseDirectory); + while (dir != null && !File.Exists(Path.Combine(dir.FullName, "Assets", "Scripts", "Gameplay", "ActionGameManager.cs"))) + dir = dir.Parent; + Assert.NotNull(dir); + var source = File.ReadAllText(Path.Combine(dir.FullName, "Assets", "Scripts", "Gameplay", "ActionGameManager.cs")); + var uses = Regex.Matches(source, @"\bInput\.(Player|Global)\.(?!Enable\b|Disable\b)\w+").Count; + var routed = Regex.Matches(source, @"\b(Bind|TryRead|Held|ActiveControl|Live)(<[^>(]*>)?\(\s*Input\.(Player|Global)\.\w+").Count; + Assert.True(uses > 20); + Assert.Equal(uses, routed); + Assert.Equal(1, Regex.Matches(source, @"\.performed\s*\+=").Count); + } + [Fact] public void EveryPlayerAndGlobalActionIsClassifiedAsShipOrViewInput() {