1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
use serde::Deserialize;
use stdweb::Value;
use crate::{
local::{Position, RoomName},
objects::StructurePortal,
traits::TryInto,
};
#[derive(Deserialize, Debug)]
pub struct InterShardPortalDestination {
shard: String,
room: RoomName,
}
js_deserializable!(InterShardPortalDestination);
pub enum PortalDestination {
InterRoom(Position),
InterShard(InterShardPortalDestination),
}
impl StructurePortal {
pub fn destination(&self) -> PortalDestination {
let v = js! {
let destination = @{self.as_ref()}.destination;
if (destination instanceof Position) {
return destination.__packedPos;
} else {
return destination;
}
};
match v {
Value::Number(_) => PortalDestination::InterRoom(
v.try_into()
.expect("expected Position::try_from(pos.__packedPos) to succeed"),
),
_ => PortalDestination::InterShard(
v.try_into()
.expect("Value couldn't be converted into an InterShardPortalDestination"),
),
}
}
}