mirror of
https://github.com/doukutsu-rs/doukutsu-rs
synced 2024-11-22 13:42:47 +00:00
Save, load, and display item counts
This commit is contained in:
parent
e53d4c7f43
commit
0369b37d10
|
@ -362,6 +362,23 @@ impl GameEntity<(&mut Context, &mut Player, &mut Inventory)> for InventoryUI {
|
|||
|
||||
batch.draw(ctx)?;
|
||||
|
||||
for (idx, (item_id, amount)) in self.item_data.iter().enumerate() {
|
||||
if *item_id == 0 || *amount == 0 {
|
||||
break;
|
||||
}
|
||||
|
||||
if *amount > 1 {
|
||||
draw_number(
|
||||
x + 12.0 + (idx % count_x) as f32 * 32.0 + 32.0,
|
||||
y + 68.0 + (idx / count_x) as f32 * 16.0,
|
||||
*amount as usize,
|
||||
Alignment::Right,
|
||||
state,
|
||||
ctx,
|
||||
)?;
|
||||
}
|
||||
}
|
||||
|
||||
for (idx, weapon) in self.weapon_data.iter().enumerate() {
|
||||
if weapon.wtype == WeaponType::None {
|
||||
break;
|
||||
|
|
|
@ -43,6 +43,14 @@ impl Inventory {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn add_item_amount(&mut self, item_id: u16, amount: u16) {
|
||||
if !self.has_item(item_id) {
|
||||
self.items.push(Item(item_id, amount));
|
||||
} else if let Some(item) = self.get_item(item_id) {
|
||||
item.1 += amount;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn consume_item(&mut self, item_id: u16) {
|
||||
if let Some(item) = self.get_item(item_id) {
|
||||
if item.1 > 1 {
|
||||
|
|
|
@ -78,11 +78,13 @@ impl GameProfile {
|
|||
}
|
||||
|
||||
for item in self.items.iter().copied() {
|
||||
if item == 0 {
|
||||
let item_id = item as u16;
|
||||
let amount = (item >> 16) as u16;
|
||||
if item_id == 0 {
|
||||
break;
|
||||
}
|
||||
|
||||
game_scene.inventory_player1.add_item(item as u16);
|
||||
game_scene.inventory_player1.add_item_amount(item_id, amount + 1);
|
||||
}
|
||||
|
||||
for slot in &self.teleporter_slots {
|
||||
|
@ -190,7 +192,7 @@ impl GameProfile {
|
|||
|
||||
for (idx, item) in items.iter_mut().enumerate() {
|
||||
if let Some(sitem) = game_scene.inventory_player1.get_item_idx(idx) {
|
||||
*item = sitem.0 as u32;
|
||||
*item = sitem.0 as u32 + (((sitem.1 - 1) as u32) << 16);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue