e4dc0ce029
Wires pkg/calc/ship.go into the WASM Core boundary as seven thin
wrappers (DriveEffective, EmptyMass, WeaponsBlockMass, FullMass,
Speed, CargoCapacity, CarryingMass). The ship-class designer reads
Core through a new CORE_CONTEXT_KEY populated by the in-game layout
and renders a five-row preview pane (mass, full-load mass, max
speed, range at full load, cargo capacity) that updates reactively
on every form edit and on the player's localPlayer{Drive,Weapons,
Shields,Cargo} tech levels — three of which are now decoded from
the report's Player block alongside the existing localPlayerDrive.
CarryingMass is the seventh wrapper added to the original six-function
list so that "full-load mass" composes through pkg/calc/ functions
without putting math in TypeScript.
58 lines
2.3 KiB
Go
58 lines
2.3 KiB
Go
// Package calc is the WASM-side bridge over `galaxy/calc`'s ship math.
|
|
// Each function is a one-line passthrough: signatures match the
|
|
// underlying `pkg/calc/ship.go` exactly so the bridge contains zero
|
|
// math beyond the call. Wrapping `pkg/calc` here keeps the JS/Go
|
|
// surface in one file and lets the canonical math live in a single
|
|
// upstream package shared with the engine.
|
|
package calc
|
|
|
|
import "galaxy/calc"
|
|
|
|
// DriveEffective wraps `calc.DriveEffective` (`pkg/calc/ship.go`):
|
|
// effective drive power equals the ship's drive block multiplied by
|
|
// the player's drive tech level.
|
|
func DriveEffective(drive, driveTech float64) float64 {
|
|
return calc.DriveEffective(drive, driveTech)
|
|
}
|
|
|
|
// EmptyMass wraps `calc.EmptyMass` (`pkg/calc/ship.go`): mass of the
|
|
// ship without cargo. Returns ok == false when the weapons/armament
|
|
// pair is invalid (one zero, the other non-zero).
|
|
func EmptyMass(drive, weapons float64, armament uint, shields, cargo float64) (float64, bool) {
|
|
return calc.EmptyMass(drive, weapons, armament, shields, cargo)
|
|
}
|
|
|
|
// WeaponsBlockMass wraps `calc.WeaponsBlockMass` (`pkg/calc/ship.go`):
|
|
// mass of the weapons sub-block. Returns ok == false on the same
|
|
// invalid pairing as EmptyMass.
|
|
func WeaponsBlockMass(weapons float64, armament uint) (float64, bool) {
|
|
return calc.WeaponsBlockMass(weapons, armament)
|
|
}
|
|
|
|
// FullMass wraps `calc.FullMass` (`pkg/calc/ship.go`): empty mass plus
|
|
// the mass of the carried cargo.
|
|
func FullMass(emptyMass, carryingMass float64) float64 {
|
|
return calc.FullMass(emptyMass, carryingMass)
|
|
}
|
|
|
|
// Speed wraps `calc.Speed` (`pkg/calc/ship.go`): light-years per turn,
|
|
// equal to effective drive times 20 divided by the ship's full mass.
|
|
// Zero when fullMass is non-positive.
|
|
func Speed(driveEffective, fullMass float64) float64 {
|
|
return calc.Speed(driveEffective, fullMass)
|
|
}
|
|
|
|
// CargoCapacity wraps `calc.CargoCapacity` (`pkg/calc/ship.go`):
|
|
// hold capacity of one ship in cargo units, scaled by the player's
|
|
// cargo tech.
|
|
func CargoCapacity(cargo, cargoTech float64) float64 {
|
|
return calc.CargoCapacity(cargo, cargoTech)
|
|
}
|
|
|
|
// CarryingMass wraps `calc.CarryingMass` (`pkg/calc/ship.go`): mass of
|
|
// a payload of `load` cargo units at the player's cargo tech. Used by
|
|
// the designer preview to derive full-load mass from CargoCapacity.
|
|
func CarryingMass(load, cargoTech float64) float64 {
|
|
return calc.CarryingMass(load, cargoTech)
|
|
}
|