2026-08-10 14:57:50 +01:00
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using UnityEngine;
|
2026-09-14 17:39:12 +02:00
|
|
|
using CultMath;
|
Convert engine types through CultMath.UnityBridge
CultMath has no implicit conversions to or from Vector*, Quaternion or
Color, so Assembly-CSharp converts explicitly with ToCultMath/ToUnity at
each engine boundary: FieldDriver, GuidedProjectile(Manager),
EntityInstance, ActionGameManager, HullCollider, GridObject, ShipInstance,
ShieldManager, ItemPickup, FieldTester, PlaceUIElementWorldspace,
MapMenuInput, MapRenderer, SectorRenderer and ZoneRenderer. CultMath math
calls that were handed Unity vectors now take converted values;
Vector3.Scale in FieldDriver becomes a float3 product, and ItemPickup's
Vector3.Dot on float3s becomes dot. packages-lock.json records the
cultmath git package at f0605367 and demotes com.unity.mathematics to a
transitive dependency.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-14 17:47:33 +02:00
|
|
|
using CultMath.UnityBridge;
|
2026-09-14 17:39:12 +02:00
|
|
|
using static CultMath.math;
|
2026-08-10 14:57:50 +01:00
|
|
|
using Random = UnityEngine.Random;
|
|
|
|
|
|
2026-09-17 14:36:54 +02:00
|
|
|
// Drives the field ONLY by publishing capability events into a CapabilityEvents source that
|
|
|
|
|
// CapabilityPresentationBinder (a component alongside FieldDriver) feeds to it. This scene stands in
|
|
|
|
|
// for the capability owner the simulation does not have yet (docs/headless-playground-cut.md fork L:
|
|
|
|
|
// "Simulation emits capability events; presentations subscribe and decide nothing"). FieldTester
|
|
|
|
|
// itself decides nothing about how those events render -- that stays FieldDriver's job as a presenter.
|
2026-08-10 14:57:50 +01:00
|
|
|
public class FieldTester : MonoBehaviour
|
|
|
|
|
{
|
|
|
|
|
public int PickupCount;
|
|
|
|
|
public ItemPickup[] PickupPrefabs;
|
|
|
|
|
public float PickupTravelDistance;
|
|
|
|
|
public float PickupTravelTimeMin;
|
|
|
|
|
public float PickupTravelTimeMax;
|
|
|
|
|
public float PickupSizeMin;
|
|
|
|
|
public float PickupSizeMax;
|
|
|
|
|
public float ScaleExponent;
|
|
|
|
|
public float PickupSpawnDistanceMin;
|
|
|
|
|
public float PickupSpawnDistanceMax;
|
|
|
|
|
public Camera Camera;
|
|
|
|
|
public FieldDriver TestField;
|
|
|
|
|
public PropertiesPanel Properties;
|
2026-09-17 14:36:54 +02:00
|
|
|
|
2026-08-10 14:57:50 +01:00
|
|
|
private AetheriaInput _input;
|
|
|
|
|
private bool _forceThrust;
|
|
|
|
|
private float _throttleDecay = 2;
|
|
|
|
|
private bool _directionalPush;
|
2026-09-17 14:36:54 +02:00
|
|
|
|
|
|
|
|
// Damped thrust state: previously lived on TestField.Push/FrontTwist/RearTwist and was written
|
|
|
|
|
// there directly every frame. Now that FieldTester only ever publishes a ThrustEvent, the damped
|
|
|
|
|
// state itself has to live here instead -- FieldDriver's own Push/FrontTwist/RearTwist fields are
|
|
|
|
|
// set from the event by FieldDriver.Thrust() and read only for the shader and the properties panel.
|
|
|
|
|
private float2 _push;
|
|
|
|
|
private float _frontTwist;
|
|
|
|
|
private float _rearTwist;
|
|
|
|
|
|
|
|
|
|
private CapabilityEvents _capabilityEvents;
|
|
|
|
|
|
|
|
|
|
// Cycles through every DamageType on each absorbed hit so the operator can see how a presenter
|
|
|
|
|
// that varies by type would behave; the field shield presentation itself ignores it today.
|
|
|
|
|
private static readonly DamageType[] DamageTypeCycle = (DamageType[])Enum.GetValues(typeof(DamageType));
|
|
|
|
|
private int _nextDamageTypeIndex;
|
2026-08-10 14:57:50 +01:00
|
|
|
|
|
|
|
|
private List<(float lerp, float time, Transform transform)> _pickups = new List<(float lerp, float time, Transform transform)>();
|
|
|
|
|
|
|
|
|
|
private void Start()
|
|
|
|
|
{
|
|
|
|
|
_input = new AetheriaInput();
|
|
|
|
|
_input.Player.Enable();
|
2026-09-17 14:36:54 +02:00
|
|
|
|
|
|
|
|
_capabilityEvents = new CapabilityEvents();
|
|
|
|
|
var binder = TestField.GetComponent<CapabilityPresentationBinder>();
|
|
|
|
|
if (binder == null)
|
|
|
|
|
Debug.LogError("FieldTester expects a CapabilityPresentationBinder on TestField's GameObject; no capability events will reach the field.");
|
|
|
|
|
else
|
|
|
|
|
binder.Bind(_capabilityEvents,
|
|
|
|
|
grabTargetResolver: handle => handle >= 0 && handle < _pickups.Count ? _pickups[handle].transform : null,
|
|
|
|
|
grabInitialVelocityResolver: handle => Vector3.forward *
|
|
|
|
|
(PickupTravelDistance / lerp(PickupTravelTimeMin, PickupTravelTimeMax, _pickups[handle].lerp)));
|
|
|
|
|
|
|
|
|
|
// Impact absorption (fork L): what used to be FieldDriver's own click handler is now this
|
|
|
|
|
// scene's stand-in for whatever will eventually detect a hit and publish AbsorbEvent.
|
|
|
|
|
var clickableCollider = TestField.GetComponent<ClickableCollider>();
|
|
|
|
|
if (clickableCollider != null)
|
|
|
|
|
{
|
|
|
|
|
clickableCollider.OnClick += (_, _, ray, hit) =>
|
|
|
|
|
{
|
|
|
|
|
var damageType = DamageTypeCycle[_nextDamageTypeIndex];
|
|
|
|
|
_nextDamageTypeIndex = (_nextDamageTypeIndex + 1) % DamageTypeCycle.Length;
|
|
|
|
|
_capabilityEvents.PublishAbsorb(new AbsorbEvent(hit.point.ToCultMath(), ray.direction.ToCultMath(), TestField.TestMagnitude, damageType));
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-10 14:57:50 +01:00
|
|
|
Properties.AddField("Time Scale", () => Time.timeScale, f => Time.timeScale = f, 0, 2);
|
|
|
|
|
Properties.AddField("FOV", () => Camera.fieldOfView, f => Camera.fieldOfView = f, 15, 45);
|
2026-09-17 14:36:54 +02:00
|
|
|
Properties.AddButton("Melee", () => _capabilityEvents.PublishMelee(
|
|
|
|
|
new MeleeEvent(float3(0, 0, 1), TestField.MeleeRange, TestField.MeleeAngle, TestField.MeleeDuration)));
|
2026-08-10 14:57:50 +01:00
|
|
|
Properties.AddField("Force Thrust", () => _forceThrust, b => _forceThrust = b);
|
|
|
|
|
Properties.AddField("Directional Push", () => _directionalPush, b => _directionalPush = b);
|
|
|
|
|
Properties.AddField("Throttle Decay", () => _throttleDecay, f => _throttleDecay = f);
|
|
|
|
|
Properties.Inspect(TestField, true, true);
|
|
|
|
|
Properties.AddProperty("Current Hits", () => TestField.HitCount.ToString());
|
|
|
|
|
Properties.AddProperty("Push X", () => $"{(int)(TestField.Push.x * 100)}%");
|
|
|
|
|
Properties.AddProperty("Push Y", () => $"{(int)(TestField.Push.y * 100)}%");
|
|
|
|
|
Properties.AddProperty("Front Twist", () => $"{(int)(TestField.FrontTwist * 100)}%");
|
|
|
|
|
Properties.AddProperty("Rear Twist", () => $"{(int)(TestField.RearTwist * 100)}%");
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < PickupCount; i++)
|
|
|
|
|
{
|
|
|
|
|
var l = (float)i / PickupCount;
|
|
|
|
|
var pickup = Instantiate(PickupPrefabs[(int)(l * PickupPrefabs.Length)], transform);
|
|
|
|
|
var i1 = i;
|
|
|
|
|
var click = pickup.GetComponent<ClickableCollider>();
|
|
|
|
|
click.OnClick += (collider, data, ray, hit) =>
|
|
|
|
|
{
|
|
|
|
|
if (!TestField.CanGrab) return;
|
|
|
|
|
click.Clear();
|
|
|
|
|
var p = _pickups[i1];
|
2026-09-17 14:36:54 +02:00
|
|
|
_capabilityEvents.PublishGrab(new GrabEvent(i1, GrabPhase.Started, p.transform.position.ToCultMath(), 0));
|
2026-08-10 14:57:50 +01:00
|
|
|
p.transform = null;
|
|
|
|
|
_pickups[i1] = p;
|
|
|
|
|
};
|
2026-09-17 14:36:54 +02:00
|
|
|
|
2026-08-10 14:57:50 +01:00
|
|
|
pickup.ScanLabelContainer.gameObject.SetActive(false);
|
|
|
|
|
pickup.enabled = false;
|
|
|
|
|
var pickupTransform = pickup.transform;
|
|
|
|
|
var time = Random.value;
|
|
|
|
|
var circle = Random.insideUnitCircle.normalized * Random.Range(PickupSpawnDistanceMin,PickupSpawnDistanceMax);
|
|
|
|
|
pickupTransform.position = new Vector3(circle.x,circle.y, (time-.5f)*PickupTravelDistance);
|
|
|
|
|
_pickups.Add((l, time, pickupTransform));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Update()
|
|
|
|
|
{
|
Convert engine types through CultMath.UnityBridge
CultMath has no implicit conversions to or from Vector*, Quaternion or
Color, so Assembly-CSharp converts explicitly with ToCultMath/ToUnity at
each engine boundary: FieldDriver, GuidedProjectile(Manager),
EntityInstance, ActionGameManager, HullCollider, GridObject, ShipInstance,
ShieldManager, ItemPickup, FieldTester, PlaceUIElementWorldspace,
MapMenuInput, MapRenderer, SectorRenderer and ZoneRenderer. CultMath math
calls that were handed Unity vectors now take converted values;
Vector3.Scale in FieldDriver becomes a float3 product, and ItemPickup's
Vector3.Dot on float3s becomes dot. packages-lock.json records the
cultmath git package at f0605367 and demotes com.unity.mathematics to a
transitive dependency.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-14 17:47:33 +02:00
|
|
|
var move = _forceThrust ? float2(0,1) : _input.Player.Move.ReadValue<Vector2>().ToCultMath();
|
2026-08-10 14:57:50 +01:00
|
|
|
var turn = _input.Player.Turn.ReadValue<float>();
|
2026-09-17 14:36:54 +02:00
|
|
|
|
|
|
|
|
float2 targetPush;
|
|
|
|
|
float targetFrontTwist;
|
|
|
|
|
float targetRearTwist;
|
2026-08-10 14:57:50 +01:00
|
|
|
if (_directionalPush)
|
|
|
|
|
{
|
2026-09-17 14:36:54 +02:00
|
|
|
targetPush = move;
|
|
|
|
|
targetFrontTwist = turn;
|
|
|
|
|
targetRearTwist = turn;
|
2026-08-10 14:57:50 +01:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2026-09-17 14:36:54 +02:00
|
|
|
targetPush = float2(0, move.y);
|
|
|
|
|
targetFrontTwist = clamp(turn + move.x, -1, 1) * (1 + min(move.y, 0));
|
|
|
|
|
targetRearTwist = clamp(turn - move.x, -1, 1) * (1 + min(-move.y, 0));
|
2026-08-10 14:57:50 +01:00
|
|
|
}
|
|
|
|
|
|
2026-09-17 14:36:54 +02:00
|
|
|
_push = damp(_push, targetPush, _throttleDecay, Time.deltaTime);
|
|
|
|
|
_frontTwist = damp(_frontTwist, targetFrontTwist, _throttleDecay, Time.deltaTime);
|
|
|
|
|
_rearTwist = damp(_rearTwist, targetRearTwist, _throttleDecay, Time.deltaTime);
|
|
|
|
|
|
|
|
|
|
_capabilityEvents.PublishThrust(new ThrustEvent(_push, min(length(_push), 1), float2(_frontTwist, _rearTwist)));
|
|
|
|
|
|
2026-08-10 14:57:50 +01:00
|
|
|
for (var i = 0; i < _pickups.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
var (l, time, t) = _pickups[i];
|
|
|
|
|
if (t == null) continue;
|
|
|
|
|
time = frac(time + Time.deltaTime / lerp(PickupTravelTimeMin, PickupTravelTimeMax, l));
|
|
|
|
|
t.localScale = Vector3.one * lerp(PickupSizeMin, PickupSizeMax, l) * Zone.PowerPulse(time - .5f, ScaleExponent);
|
|
|
|
|
t.position = new Vector3(t.position.x, t.position.y, (time - .5f) * PickupTravelDistance);
|
|
|
|
|
_pickups[i] = (l, time, t);
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-09-17 14:36:54 +02:00
|
|
|
}
|