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

33 lines
894 B
Gleam
Raw Permalink Normal View History

2025-06-16 11:43:06 -04:00
import gleam/dynamic/decode.{type Decoder}
2025-06-18 05:44:38 -04:00
import spacetraders_models/sector_symbol.{type SectorSymbol}
import spacetraders_models/system_symbol.{type SystemSymbol}
import spacetraders_models/system_type.{type SystemType}
2025-06-16 11:43:06 -04:00
pub type ScannedSystem {
ScannedSystem(
symbol: SystemSymbol,
2025-06-17 05:04:29 -04:00
sector_symbol: SectorSymbol,
2025-06-16 11:43:06 -04:00
type_: SystemType,
x: Int,
y: Int,
distance: Int,
)
}
pub fn decoder() -> Decoder(ScannedSystem) {
2025-06-17 05:04:29 -04:00
use symbol <- decode.field("symbol", system_symbol.decoder())
use sector_symbol <- decode.field("sectorSymbol", sector_symbol.decoder())
2025-06-16 11:43:06 -04:00
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:,
))
}