32 lines
855 B
Gleam
32 lines
855 B
Gleam
import gleam/dynamic/decode.{type Decoder}
|
|
import models/sector_symbol.{type SectorSymbol}
|
|
import models/system_symbol.{type SystemSymbol}
|
|
import 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:,
|
|
))
|
|
}
|