75 lines
2.2 KiB
Gleam
75 lines
2.2 KiB
Gleam
import gleam/dynamic/decode.{type Decoder}
|
|
import gleam/option.{type Option}
|
|
import spacetraders_models/chart.{type Chart}
|
|
import spacetraders_models/system_symbol.{type SystemSymbol}
|
|
import spacetraders_models/waypoint_faction.{type WaypointFaction}
|
|
import spacetraders_models/waypoint_modifier.{type WaypointModifier}
|
|
import spacetraders_models/waypoint_orbital.{type WaypointOrbital}
|
|
import spacetraders_models/waypoint_symbol.{type WaypointSymbol}
|
|
import spacetraders_models/waypoint_trait.{type WaypointTrait}
|
|
import spacetraders_models/waypoint_type.{type WaypointType}
|
|
|
|
pub type Waypoint {
|
|
Waypoint(
|
|
symbol: WaypointSymbol,
|
|
type_: WaypointType,
|
|
system_symbol: SystemSymbol,
|
|
x: Int,
|
|
y: Int,
|
|
orbitals: List(WaypointOrbital),
|
|
orbits: Option(WaypointSymbol),
|
|
faction: Option(WaypointFaction),
|
|
traits: List(WaypointTrait),
|
|
modifiers: Option(List(WaypointModifier)),
|
|
chart: Option(Chart),
|
|
is_under_construction: Bool,
|
|
)
|
|
}
|
|
|
|
pub fn decoder() -> Decoder(Waypoint) {
|
|
use symbol <- decode.field("symbol", waypoint_symbol.decoder())
|
|
use type_ <- decode.field("type", waypoint_type.decoder())
|
|
use system_symbol <- decode.field("systemSymbol", system_symbol.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()),
|
|
)
|
|
use chart <- decode.optional_field(
|
|
"chart",
|
|
option.None,
|
|
decode.optional(chart.decoder()),
|
|
)
|
|
use faction <- decode.optional_field(
|
|
"faction",
|
|
option.None,
|
|
decode.optional(waypoint_faction.decoder()),
|
|
)
|
|
use traits <- decode.field("traits", decode.list(waypoint_trait.decoder()))
|
|
use modifiers <- decode.optional_field(
|
|
"modifiers",
|
|
option.None,
|
|
decode.optional(decode.list(waypoint_modifier.decoder())),
|
|
)
|
|
use is_under_construction <- decode.field("isUnderConstruction", decode.bool)
|
|
decode.success(Waypoint(
|
|
symbol:,
|
|
type_:,
|
|
system_symbol:,
|
|
x:,
|
|
y:,
|
|
orbitals:,
|
|
orbits:,
|
|
faction:,
|
|
traits:,
|
|
modifiers:,
|
|
chart:,
|
|
is_under_construction:,
|
|
))
|
|
}
|