1use crate::trade::SiteId;
2use common_i18n::Content;
3use serde::{Deserialize, Serialize};
4use std::{any::Any, hash::Hash};
5use vek::*;
6
7bitflags::bitflags! {
8 #[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq)]
9 pub struct MarkerFlags: u8 {
10 const IS_QUEST = 0b0000_0001;
11 }
12}
13
14#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
15pub struct Marker {
16 id: Option<u64>, pub site: Option<SiteId>,
19 pub kind: MarkerKind,
20 pub wpos: Vec2<f32>,
21 pub label: Option<Content>,
22 pub flags: MarkerFlags,
23}
24
25impl Marker {
26 pub fn at(wpos: Vec2<f32>) -> Self {
27 Self {
28 id: None,
29 site: None,
30 kind: MarkerKind::Unknown,
31 wpos,
32 label: None,
33 flags: MarkerFlags::empty(),
34 }
35 }
36
37 pub fn with_id<T: Any + Hash>(mut self, id: T) -> Self {
42 self.id = Some(ahash::RandomState::with_seed(0).hash_one((id.type_id(), id)));
43 self
44 }
45
46 pub fn with_kind(mut self, kind: MarkerKind) -> Self {
47 self.kind = kind;
48 self
49 }
50
51 pub fn with_label(mut self, label: impl Into<Option<Content>>) -> Self {
52 self.label = label.into();
53 self
54 }
55
56 pub fn with_site_id(mut self, site: impl Into<Option<SiteId>>) -> Self {
57 self.site = site.into();
58 self
59 }
60
61 pub fn with_quest_flag(mut self, is: bool) -> Self {
62 self.flags.set(MarkerFlags::IS_QUEST, is);
63 self
64 }
65
66 pub fn is_same(&self, other: &Self) -> bool { self.id.is_some_and(|id| Some(id) == other.id) }
67}
68
69#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
70#[repr(u8)]
71pub enum MarkerKind {
72 Town,
73 Castle,
74 Cave,
75 Tree,
76 Gnarling,
77 GliderCourse,
78 ChapelSite,
79 Terracotta,
80 Bridge,
81 Adlet,
82 Haniwa,
83 DwarvenMine,
84 Cultist,
85 Sahagin,
86 VampireCastle,
87 Myrmidon,
88 Character,
89 Unknown,
90}