37 lines
1.1 KiB
Gleam
37 lines
1.1 KiB
Gleam
import gleam/dynamic/decode.{type Decoder}
|
|
import gleam/option.{type Option}
|
|
import spacetraders_models/faction_symbol.{type FactionSymbol}
|
|
import spacetraders_models/faction_trait.{type FactionTrait}
|
|
import spacetraders_models/waypoint_symbol.{type WaypointSymbol}
|
|
|
|
pub type Faction {
|
|
Faction(
|
|
symbol: FactionSymbol,
|
|
name: String,
|
|
description: String,
|
|
headquarters: Option(WaypointSymbol),
|
|
traits: List(FactionTrait),
|
|
is_recruiting: Bool,
|
|
)
|
|
}
|
|
|
|
pub fn decoder() -> Decoder(Faction) {
|
|
use symbol <- decode.field("symbol", faction_symbol.decoder())
|
|
use name <- decode.field("name", decode.string)
|
|
use description <- decode.field("description", decode.string)
|
|
use headquarters <- decode.optional_field(
|
|
"headquarters",
|
|
option.None,
|
|
decode.optional(waypoint_symbol.decoder()),
|
|
)
|
|
use traits <- decode.field("traits", decode.list(faction_trait.decoder()))
|
|
use is_recruiting <- decode.field("isRecruiting", decode.bool)
|
|
decode.success(Faction(
|
|
symbol:,
|
|
name:,
|
|
description:,
|
|
headquarters:,
|
|
traits:,
|
|
is_recruiting:,
|
|
))
|
|
}
|