43 lines
1.1 KiB
Gleam
43 lines
1.1 KiB
Gleam
import gleam/dynamic/decode.{type Decoder}
|
|
import gleam/json.{type Json}
|
|
|
|
pub type WaypointModifierSymbol {
|
|
Stripped
|
|
Unstable
|
|
RadiationLeak
|
|
CriticalLimit
|
|
CivilUnrest
|
|
}
|
|
|
|
pub fn parse(value: String) -> Result(WaypointModifierSymbol, Nil) {
|
|
case value {
|
|
"STRIPPED" -> Ok(Stripped)
|
|
"UNSTABLE" -> Ok(Unstable)
|
|
"RADIATION_LEAK" -> Ok(RadiationLeak)
|
|
"CRITICAL_LIMIT" -> Ok(CriticalLimit)
|
|
"CIVIL_UNREST" -> Ok(CivilUnrest)
|
|
_ -> Error(Nil)
|
|
}
|
|
}
|
|
|
|
pub fn decoder() -> Decoder(WaypointModifierSymbol) {
|
|
use value <- decode.then(decode.string)
|
|
case parse(value) {
|
|
Ok(waypoint_modifier_symbol) -> decode.success(waypoint_modifier_symbol)
|
|
Error(Nil) -> decode.failure(Stripped, "WaypointModifierSymbol")
|
|
}
|
|
}
|
|
|
|
pub fn to_string(waypoint_modifier_symbol: WaypointModifierSymbol) -> String {
|
|
case waypoint_modifier_symbol {
|
|
Stripped -> "STRIPPED"
|
|
Unstable -> "UNSTABLE"
|
|
RadiationLeak -> "RADIATION_LEAK"
|
|
CriticalLimit -> "CRITICAL_LIMIT"
|
|
CivilUnrest -> "CIVIL_UNREST"
|
|
}
|
|
}
|
|
|
|
pub fn encode(waypoint_modifier_symbol: WaypointModifierSymbol) -> Json {
|
|
json.string(to_string(waypoint_modifier_symbol))
|
|
}
|