#[cfg(feature = "cos")]
pub mod cos_options {
use crate::location;
pub struct Options {
pub location: location::Local,
pub level: Level,
pub page: i32,
}
impl std::fmt::Display for Options {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"Options {{ location: {}, level: {}, page: {} }}",
self.location, self.level, self.page
)
}
}
pub struct OptionsBuilder {
pub options: Options,
}
impl Options {
pub fn new(location: location::Local, level: Level, page: i32) -> Self {
Options { location, level, page: page.clamp(0, 100000) }
}
pub fn builder() -> OptionsBuilder {
OptionsBuilder {
options: Options {
location: location::Local::default(),
level: Level::default(),
page: 0,
},
}
}
pub(crate) fn build_for_clan(self) -> Vec<(String, String)> {
match self.location {
location::Local::None => vec![
("location".to_string(), "global".to_string()),
("page".to_string(), self.page.to_string()),
],
_ => vec![
("location".to_string(), (self.location as i32).to_string()),
("page".to_string(), self.page.to_string()),
],
}
}
pub(crate) fn build_for_player(self) -> Vec<(String, String)> {
match self.location {
location::Local::None => vec![
("location".to_string(), "global".to_string()),
("level".to_string(), (self.level as i32).to_string()),
("page".to_string(), self.page.to_string()),
],
_ => vec![
("location".to_string(), (self.location as i32).to_string()),
("level".to_string(), (self.level as i32).to_string()),
("page".to_string(), self.page.to_string()),
],
}
}
pub(crate) fn build_for_legends(self) -> Vec<(String, String)> {
vec![("page".to_string(), self.page.to_string())]
}
pub(crate) fn build_for_builder(self) -> Vec<(String, String)> {
match self.location {
location::Local::None => vec![
("location".to_string(), "global".to_string()),
("level".to_string(), (self.level as i32).min(9).to_string()),
("page".to_string(), self.page.to_string()),
],
_ => vec![
("location".to_string(), (self.location as i32).to_string()),
("level".to_string(), (self.level as i32).min(9).to_string()),
("page".to_string(), self.page.to_string()),
],
}
}
}
impl OptionsBuilder {
pub fn location(mut self, location: location::Local) -> Self {
self.options.location = location;
self
}
pub fn level(mut self, level: i32) -> Self {
self.options.level = match level {
1 => Level::One,
2 => Level::Two,
3 => Level::Three,
4 => Level::Four,
5 => Level::Five,
6 => Level::Six,
7 => Level::Seven,
8 => Level::Eight,
9 => Level::Nine,
10 => Level::Ten,
11 => Level::Eleven,
12 => Level::Twelve,
13 => Level::Thirteen,
14 => Level::Fourteen,
15 => Level::Fifteen,
_ => Level::default(),
};
self
}
pub fn page(mut self, mut page: i32) -> Self {
if page <= 0 {
page = 1;
}
self.options.page = (page - 1).clamp(0, 100000);
self
}
pub fn build(self) -> Options {
self.options
}
}
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub enum Level {
#[default]
None = 0,
One = 1,
Two = 2,
Three = 3,
Four = 4,
Five = 5,
Six = 6,
Seven = 7,
Eight = 8,
Nine = 9,
Ten = 10,
Eleven = 11,
Twelve = 12,
Thirteen = 13,
Fourteen = 14,
Fifteen = 15,
}
impl std::fmt::Display for Level {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
std::fmt::Debug::fmt(self, f)
}
}
}