jagua_rs/entities/instances/
instance_generic.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
use crate::entities::item::Item;
use crate::fsize;

/// Trait for shared functionality of all instance variants.
pub trait InstanceGeneric {
    fn items(&self) -> &[(Item, usize)];
    fn item_qty(&self, id: usize) -> usize {
        self.items()[id].1
    }
    fn item(&self, id: usize) -> &Item {
        &self.items()[id].0
    }
    fn total_item_qty(&self) -> usize {
        self.items().iter().map(|(_, qty)| qty).sum()
    }
    fn item_area(&self) -> fsize;
}