fix(ui): calculator polish — smart input steps, unified tech/MAT lock idiom, tech floor, speed-lock ceiling fix
- pkg/calc: DriveForSpeed treats restMass==0 as a valid ceiling-only case (every positive drive solves it), so locking the displayed speed of a D=1, W=A=S=C=0 ship is no longer a phantom "infeasible". - ship-design-area: drive/weapons/shields/cargo inputs use a JS-driven smart step on ArrowUp/ArrowDown (0↔1 jump, otherwise ±0.1) and hide the native spinner so it cannot produce invalid (0, 1) values; armament keeps its native step 1. - Tech and planet MAT cells follow the same lock idiom as goal-seek locks: open padlock (🔓) over the inherited value → click to open an input with a closed padlock (🔒). The padlock slot is always reserved, so the column width is stable. - Tech overrides (design area and modernization target) are floored at the player's current tech on this turn — a lower value is flagged as invalid.
This commit is contained in:
+19
-1
@@ -24,12 +24,30 @@ func TestDriveForSpeed(t *testing.T) {
|
||||
if !ok || math.Abs(got-drive) > 1e-9 {
|
||||
t.Errorf("DriveForSpeed round-trip = %v (ok=%v), want %v", got, ok, drive)
|
||||
}
|
||||
// Speed can never reach the stripped-hull ceiling 20*driveTech.
|
||||
// With a positive restMass speed can never reach 20*driveTech.
|
||||
if _, ok := calc.DriveForSpeed(20*driveTech, driveTech, restMass); ok {
|
||||
t.Error("DriveForSpeed at the speed ceiling should be infeasible")
|
||||
}
|
||||
}
|
||||
|
||||
func TestDriveForSpeedZeroRest(t *testing.T) {
|
||||
// With restMass==0 the only achievable speed is the stripped-hull
|
||||
// ceiling 20*driveTech; any positive drive reaches it. Off-ceiling
|
||||
// targets are infeasible.
|
||||
const driveTech = 1.5
|
||||
ceiling := 20 * driveTech
|
||||
got, ok := calc.DriveForSpeed(ceiling, driveTech, 0)
|
||||
if !ok || got <= 0 {
|
||||
t.Errorf("DriveForSpeed(ceiling, _, 0) = %v (ok=%v), want positive", got, ok)
|
||||
}
|
||||
if _, ok := calc.DriveForSpeed(ceiling/2, driveTech, 0); ok {
|
||||
t.Error("DriveForSpeed(below ceiling, _, 0) should be infeasible")
|
||||
}
|
||||
if _, ok := calc.DriveForSpeed(ceiling+1, driveTech, 0); ok {
|
||||
t.Error("DriveForSpeed(above ceiling, _, 0) should be infeasible")
|
||||
}
|
||||
}
|
||||
|
||||
func TestShieldsForDefence(t *testing.T) {
|
||||
const shields, shieldsTech, restMass = 5.75, 1.0, 40.0
|
||||
defence := calc.EffectiveDefence(shields, shieldsTech, shields+restMass)
|
||||
|
||||
Reference in New Issue
Block a user