gleam-spacetraders-sdk/src/spacetraders_models/scanned_system.gleam

32 lines
894 B
Gleam

import gleam/dynamic/decode.{type Decoder}
import spacetraders_models/sector_symbol.{type SectorSymbol}
import spacetraders_models/system_symbol.{type SystemSymbol}
import spacetraders_models/system_type.{type SystemType}
pub type ScannedSystem {
ScannedSystem(
symbol: SystemSymbol,
sector_symbol: SectorSymbol,
type_: SystemType,
x: Int,
y: Int,
distance: Int,
)
}
pub fn decoder() -> Decoder(ScannedSystem) {
use symbol <- decode.field("symbol", system_symbol.decoder())
use sector_symbol <- decode.field("sectorSymbol", sector_symbol.decoder())
use type_ <- decode.field("type", system_type.decoder())
use x <- decode.field("x", decode.int)
use y <- decode.field("y", decode.int)
use distance <- decode.field("distance", decode.int)
decode.success(ScannedSystem(
symbol:,
sector_symbol:,
type_:,
x:,
y:,
distance:,
))
}