1use crate::skill::Skill;
2use thousands::Separable;
3
4#[derive(Debug, Copy, Clone, PartialEq)]
5pub struct Hiscore {
6 pub overall: Skill,
7 pub attack: Skill,
8 pub defence: Skill,
9 pub strength: Skill,
10 pub hitpoints: Skill,
11 pub ranged: Skill,
12 pub prayer: Skill,
13 pub magic: Skill,
14 pub cooking: Skill,
15 pub woodcutting: Skill,
16 pub fletching: Skill,
17 pub fishing: Skill,
18 pub firemaking: Skill,
19 pub crafting: Skill,
20 pub smithing: Skill,
21 pub mining: Skill,
22 pub herblore: Skill,
23 pub agility: Skill,
24 pub thieving: Skill,
25 pub slayer: Skill,
26 pub farming: Skill,
27 pub runecraft: Skill,
28 pub hunter: Skill,
29 pub construction: Skill
30}
31
32impl IntoIterator for Hiscore {
33 type Item = Skill;
34
35 type IntoIter = std::vec::IntoIter<Self::Item>;
36
37 fn into_iter(self) -> Self::IntoIter {
38 let mut skills: Vec<Skill> = Vec::new();
39 skills.push(self.overall);
40 skills.push(self.attack);
41 skills.push(self.defence);
42 skills.push(self.strength);
43 skills.push(self.hitpoints);
44 skills.push(self.ranged);
45 skills.push(self.prayer);
46 skills.push(self.magic);
47 skills.push(self.cooking);
48 skills.push(self.woodcutting);
49 skills.push(self.fletching);
50 skills.push(self.fishing);
51 skills.push(self.firemaking);
52 skills.push(self.crafting);
53 skills.push(self.smithing);
54 skills.push(self.mining);
55 skills.push(self.herblore);
56 skills.push(self.agility);
57 skills.push(self.thieving);
58 skills.push(self.slayer);
59 skills.push(self.farming);
60 skills.push(self.runecraft);
61 skills.push(self.hunter);
62 skills.push(self.construction);
63
64 skills.into_iter()
65 }
66}
67
68impl std::fmt::Display for Hiscore {
72 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
73 let mut table = prettytable::Table::new();
74
75 let skill_names = [
76 "Overall",
77 "Attack",
78 "Defence",
79 "Strength",
80 "Hitpoints",
81 "Ranged",
82 "Prayer",
83 "Magic",
84 "Cooking",
85 "Woodcutting",
86 "Fletching",
87 "Fishing",
88 "Firemaking",
89 "Crafting",
90 "Smithing",
91 "Mining",
92 "Herblore",
93 "Agility",
94 "Thieving",
95 "Slayer",
96 "Farming",
97 "Runecraft",
98 "Hunter",
99 "Construction"
100 ];
101
102 table.set_format(*prettytable::format::consts::FORMAT_NO_LINESEP_WITH_TITLE);
103 table.set_titles(row!["Name", "Rank", "Level", "XP"]);
104
105 skill_names.iter().zip(self.into_iter()).skip(1).for_each(|(skill_name, skill)| {
106 let rank = skill.rank.separate_with_commas();
107 let level = skill.level.separate_with_commas();
108 let xp = skill.xp.separate_with_commas();
109 table.add_row(row![skill_name, rank, level, xp]);
110 });
111 let rank = self.overall.rank.separate_with_commas();
112 let level = self.overall.level.separate_with_commas();
113 let xp = self.overall.xp.separate_with_commas();
114 table.add_empty_row();
115 table.add_row(row!["Overall", rank, level, xp]);
116
117 write!(f, "{}", table.to_string())
118 }
119}
120
121impl Default for Hiscore {
122 fn default() -> Self {
123 Hiscore {
124 overall: Skill::default(),
125 attack: Skill::default(),
126 defence: Skill::default(),
127 strength: Skill::default(),
128 hitpoints: Skill::default(),
129 ranged: Skill::default(),
130 prayer: Skill::default(),
131 magic: Skill::default(),
132 cooking: Skill::default(),
133 woodcutting: Skill::default(),
134 fletching: Skill::default(),
135 fishing: Skill::default(),
136 firemaking: Skill::default(),
137 crafting: Skill::default(),
138 smithing: Skill::default(),
139 mining: Skill::default(),
140 herblore: Skill::default(),
141 agility: Skill::default(),
142 thieving: Skill::default(),
143 slayer: Skill::default(),
144 farming: Skill::default(),
145 runecraft: Skill::default(),
146 hunter: Skill::default(),
147 construction: Skill::default()
148 }
149 }
150}