gleam-spacetraders-sdk/src/models/system_waypoint.gleam
Lily Rose 64f3729d0c
Some checks are pending
test / test (push) Waiting to run
Refactoring and general tidying up
2025-06-17 19:04:29 +10:00

33 lines
987 B
Gleam

import gleam/dynamic/decode.{type Decoder}
import gleam/option.{type Option}
import models/waypoint_orbital.{type WaypointOrbital}
import models/waypoint_symbol.{type WaypointSymbol}
import models/waypoint_type.{type WaypointType}
pub type SystemWaypoint {
SystemWaypoint(
symbol: WaypointSymbol,
type_: WaypointType,
x: Int,
y: Int,
orbitals: List(WaypointOrbital),
orbits: Option(WaypointSymbol),
)
}
pub fn decoder() -> Decoder(SystemWaypoint) {
use symbol <- decode.field("symbol", waypoint_symbol.decoder())
use type_ <- decode.field("type", waypoint_type.decoder())
use x <- decode.field("x", decode.int)
use y <- decode.field("y", decode.int)
use orbitals <- decode.field(
"orbitals",
decode.list(waypoint_orbital.decoder()),
)
use orbits <- decode.optional_field(
"orbits",
option.None,
decode.optional(waypoint_symbol.decoder()),
)
decode.success(SystemWaypoint(symbol:, type_:, x:, y:, orbitals:, orbits:))
}