Loads of cleanup
Some checks reported errors
continuous-integration/drone/push Build was killed

This commit is contained in:
2022-11-27 17:29:29 +01:00
parent aa3ceaed3e
commit efd1acdfa5
45 changed files with 259 additions and 162 deletions

View File

@@ -1,6 +1,8 @@
use hashbrown::HashSet;
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
use std::any::Any;
use std::fmt::Debug;
use crate::{StringKey, ValueIdentifiable, ValueIdentifier};
@@ -44,10 +46,26 @@ pub enum BattleItemCategory {
MiscBattleItem,
}
/// An item is an object which the player can pick up, keep in their Bag, and use in some manner
pub trait Item: ValueIdentifiable + Debug + Any {
/// The name of the item.
fn name(&self) -> &StringKey;
/// Which bag slot items are stored in.
fn category(&self) -> ItemCategory;
/// How the item is categorized when in battle.
fn battle_category(&self) -> BattleItemCategory;
/// The buying value of the item.
fn price(&self) -> i32;
/// A set of arbitrary flags that can be set on the item.
fn flags(&self) -> &HashSet<StringKey>;
/// Checks whether the item has a specific flag.
fn has_flag(&self, key: &StringKey) -> bool;
}
/// An item is an object which the player can pick up, keep in their Bag, and use in some manner
#[derive(Debug)]
#[cfg_attr(feature = "wasm", derive(unique_type_id_derive::UniqueTypeId))]
pub struct Item {
pub struct ItemImpl {
/// A unique identifier so we know what value this is.
identifier: ValueIdentifier,
/// The name of the item.
@@ -62,7 +80,7 @@ pub struct Item {
flags: HashSet<StringKey>,
}
impl Item {
impl ItemImpl {
/// Instantiates an item.
pub fn new(
name: &StringKey,
@@ -70,8 +88,8 @@ impl Item {
battle_category: BattleItemCategory,
price: i32,
flags: HashSet<StringKey>,
) -> Item {
Item {
) -> ItemImpl {
ItemImpl {
identifier: Default::default(),
name: name.clone(),
category,
@@ -80,35 +98,37 @@ impl Item {
flags,
}
}
}
impl Item for ItemImpl {
/// The name of the item.
pub fn name(&self) -> &StringKey {
fn name(&self) -> &StringKey {
&self.name
}
/// Which bag slot items are stored in.
pub fn category(&self) -> ItemCategory {
fn category(&self) -> ItemCategory {
self.category
}
/// How the item is categorized when in battle.
pub fn battle_category(&self) -> BattleItemCategory {
fn battle_category(&self) -> BattleItemCategory {
self.battle_category
}
/// The buying value of the item.
pub fn price(&self) -> i32 {
fn price(&self) -> i32 {
self.price
}
/// A set of arbitrary flags that can be set on the item.
pub fn flags(&self) -> &HashSet<StringKey> {
fn flags(&self) -> &HashSet<StringKey> {
&self.flags
}
/// Checks whether the item has a specific flag.
pub fn has_flag(&self, key: &StringKey) -> bool {
fn has_flag(&self, key: &StringKey) -> bool {
self.flags.contains(key)
}
}
impl ValueIdentifiable for Item {
impl ValueIdentifiable for ItemImpl {
fn value_identifier(&self) -> ValueIdentifier {
self.identifier
}