use std::ops::{Add, Sub};
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Clone, Copy)]
#[cfg_attr(target_family = "wasm", derive(tsify_next::Tsify))]
#[cfg_attr(
target_family = "wasm",
tsify(into_wasm_abi, from_wasm_abi, large_number_types_as_bigints)
)]
pub struct Level {
pub born: i16,
pub growth: i16,
pub bonus: i16,
}
impl Add<i16> for Level {
type Output = i16;
fn add(self, rhs: i16) -> Self::Output {
self.curr() + rhs
}
}
impl Sub<i16> for Level {
type Output = i16;
fn sub(self, rhs: i16) -> Self::Output {
self.curr() - rhs
}
}
impl Add for Level {
type Output = i16;
fn add(self, rhs: Self) -> Self::Output {
self.curr() + rhs.curr()
}
}
impl Sub for Level {
type Output = i16;
fn sub(self, rhs: Self) -> Self::Output {
self.curr() - rhs.curr()
}
}
impl Level {
pub fn new(born: i16) -> Self {
Self {
born,
growth: 0,
bonus: 0,
}
}
pub fn base(&self) -> i16 {
self.born + self.growth
}
pub fn curr(&self) -> i16 {
self.base() + self.bonus
}
}