1use super::Item;
2use crate::Prefix;
3use std::num::TryFromIntError;
4use terra_types::{PositiveI16, PositiveI32};
5
6#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
7pub struct ItemSlot {
8 pub item: Item,
9 pub prefix: Option<Prefix>,
10 pub count: PositiveI32,
11}
12
13impl From<SingleItemSlot> for ItemSlot {
14 fn from(value: SingleItemSlot) -> Self {
15 ItemSlot {
16 item: value.item,
17 prefix: value.prefix,
18 count: PositiveI32::new(1).expect("In bounds"),
19 }
20 }
21}
22
23impl From<WorldItemSlot> for ItemSlot {
24 fn from(value: WorldItemSlot) -> Self {
25 ItemSlot {
26 item: value.item,
27 prefix: value.prefix,
28 count: PositiveI32::new(value.count.get() as i32).expect("In bounds"),
29 }
30 }
31}
32
33impl ItemSlot {
34 pub fn new(item: Item) -> Self {
35 Self::from(item)
36 }
37
38 pub fn prefix(mut self, prefix: Prefix) -> Self {
39 self.prefix = Some(prefix);
40 self
41 }
42
43 pub fn count(mut self, count: PositiveI32) -> Self {
44 self.count = count;
45 self
46 }
47}
48
49impl From<Item> for ItemSlot {
50 fn from(value: Item) -> Self {
51 Self {
52 item: value,
53 prefix: None,
54 count: PositiveI32::MIN,
55 }
56 }
57}
58
59#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
60pub struct SingleItemSlot {
61 pub item: Item,
62 pub prefix: Option<Prefix>,
63}
64
65impl SingleItemSlot {
66 pub fn new(item: Item) -> Self {
67 Self::from(item)
68 }
69
70 pub fn prefix(mut self, prefix: Prefix) -> Self {
71 self.prefix = Some(prefix);
72 self
73 }
74}
75
76impl From<Item> for SingleItemSlot {
77 fn from(value: Item) -> Self {
78 Self {
79 item: value,
80 prefix: None,
81 }
82 }
83}
84
85impl From<ItemSlot> for SingleItemSlot {
86 fn from(item_slot: ItemSlot) -> Self {
87 SingleItemSlot {
88 item: item_slot.item,
89 prefix: item_slot.prefix,
90 }
91 }
92}
93
94impl From<WorldItemSlot> for SingleItemSlot {
95 fn from(item_slot: WorldItemSlot) -> Self {
96 SingleItemSlot {
97 item: item_slot.item,
98 prefix: item_slot.prefix,
99 }
100 }
101}
102
103#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
104pub struct WorldItemSlot {
105 pub item: Item,
106 pub prefix: Option<Prefix>,
107 pub count: PositiveI16,
108}
109
110impl WorldItemSlot {
111 pub fn new(item: Item) -> Self {
112 Self::from(item)
113 }
114
115 pub fn prefix(mut self, prefix: Prefix) -> Self {
116 self.prefix = Some(prefix);
117 self
118 }
119
120 pub fn count(mut self, count: PositiveI16) -> Self {
121 self.count = count;
122 self
123 }
124}
125
126impl From<Item> for WorldItemSlot {
127 fn from(value: Item) -> Self {
128 Self {
129 item: value,
130 prefix: None,
131 count: PositiveI16::MIN,
132 }
133 }
134}
135
136impl TryFrom<ItemSlot> for WorldItemSlot {
137 type Error = TryFromIntError;
138 fn try_from(value: ItemSlot) -> Result<Self, Self::Error> {
139 Ok(WorldItemSlot {
140 item: value.item,
141 prefix: value.prefix,
142 count: PositiveI16::new(i16::try_from(value.count.get())?).expect("In bounds"),
143 })
144 }
145}
146
147impl From<SingleItemSlot> for WorldItemSlot {
148 fn from(value: SingleItemSlot) -> Self {
149 WorldItemSlot {
150 item: value.item,
151 prefix: value.prefix,
152 count: PositiveI16::MIN,
153 }
154 }
155}