makes keyhandling debug msgs optional
This commit is contained in:
parent
bc4f960d88
commit
a92f60bb15
1 changed files with 45 additions and 23 deletions
|
|
@ -20,7 +20,7 @@ use crate::invkeys::*;
|
||||||
|
|
||||||
pub struct KeyHandling {}
|
pub struct KeyHandling {}
|
||||||
|
|
||||||
const DEBUG_KEYHANDLING: bool = true;
|
const DEBUG_KEYHANDLING: bool = false;
|
||||||
|
|
||||||
impl<'a> System<'a> for KeyHandling {
|
impl<'a> System<'a> for KeyHandling {
|
||||||
#[allow(clippy::type_complexity)]
|
#[allow(clippy::type_complexity)]
|
||||||
|
|
@ -75,28 +75,40 @@ impl<'a> System<'a> for KeyHandling {
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
if stacks {
|
if stacks {
|
||||||
console::log(&format!("KEYHANDLING: Item is stackable."));
|
if DEBUG_KEYHANDLING {
|
||||||
|
console::log(&format!("KEYHANDLING: Item is stackable."));
|
||||||
|
}
|
||||||
let maybe_key = item_exists(&unique);
|
let maybe_key = item_exists(&unique);
|
||||||
if maybe_key.is_some() {
|
if maybe_key.is_some() {
|
||||||
console::log(&format!("KEYHANDLING: Existing stack found for this item."));
|
if DEBUG_KEYHANDLING {
|
||||||
|
console::log(&format!("KEYHANDLING: Existing stack found for this item."));
|
||||||
|
}
|
||||||
let key = maybe_key.unwrap();
|
let key = maybe_key.unwrap();
|
||||||
keys.insert(e, Key { idx: key }).expect("Unable to insert Key.");
|
keys.insert(e, Key { idx: key }).expect("Unable to insert Key.");
|
||||||
console::log(&format!("KEYHANDLING: Assigned key idx {} to item.", key));
|
if DEBUG_KEYHANDLING {
|
||||||
|
console::log(&format!("KEYHANDLING: Assigned key idx {} to item.", key));
|
||||||
|
}
|
||||||
handled = true;
|
handled = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !handled {
|
if !handled {
|
||||||
console::log(
|
if DEBUG_KEYHANDLING {
|
||||||
&format!("KEYHANDLING: Item is not stackable, or no existing stack found.")
|
|
||||||
);
|
|
||||||
if let Some(idx) = assign_next_available() {
|
|
||||||
console::log(
|
console::log(
|
||||||
&format!("KEYHANDLING: Assigned next available index {} to item.", idx)
|
&format!("KEYHANDLING: Item is not stackable, or no existing stack found.")
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
if let Some(idx) = assign_next_available() {
|
||||||
|
if DEBUG_KEYHANDLING {
|
||||||
|
console::log(
|
||||||
|
&format!("KEYHANDLING: Assigned next available index {} to item.", idx)
|
||||||
|
);
|
||||||
|
}
|
||||||
keys.insert(e, Key { idx }).expect("Unable to insert Key.");
|
keys.insert(e, Key { idx }).expect("Unable to insert Key.");
|
||||||
register_stackable(stacks, unique, idx);
|
register_stackable(stacks, unique, idx);
|
||||||
} else {
|
} else {
|
||||||
console::log(&format!("KEYHANDLING: No more keys available."));
|
if DEBUG_KEYHANDLING {
|
||||||
|
console::log(&format!("KEYHANDLING: No more keys available."));
|
||||||
|
}
|
||||||
gamelog::Logger
|
gamelog::Logger
|
||||||
::new()
|
::new()
|
||||||
.append(messages::NO_MORE_KEYS)
|
.append(messages::NO_MORE_KEYS)
|
||||||
|
|
@ -113,37 +125,47 @@ impl<'a> System<'a> for KeyHandling {
|
||||||
}
|
}
|
||||||
// If the item is *not* stackable, then we can just remove the key and clear the index.
|
// If the item is *not* stackable, then we can just remove the key and clear the index.
|
||||||
if let None = stackable.get(e) {
|
if let None = stackable.get(e) {
|
||||||
console::log(
|
if DEBUG_KEYHANDLING {
|
||||||
&format!("KEYHANDLING: Item is not stackable, clearing index {}.", idx)
|
console::log(
|
||||||
);
|
&format!("KEYHANDLING: Item is not stackable, clearing index {}.", idx)
|
||||||
|
);
|
||||||
|
}
|
||||||
clear_idx(idx);
|
clear_idx(idx);
|
||||||
keys.remove(e);
|
keys.remove(e);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// If the item *is* stackable, then we need to check if there are any other items that
|
// If the item *is* stackable, then we need to check if there are any other items that
|
||||||
// share this key assignment, before clearing the index.
|
// share this key assignment, before clearing the index.
|
||||||
console::log(
|
if DEBUG_KEYHANDLING {
|
||||||
&format!(
|
console::log(
|
||||||
"KEYHANDLING: Item is stackable, checking if any other items share this key."
|
&format!(
|
||||||
)
|
"KEYHANDLING: Item is stackable, checking if any other items share this key."
|
||||||
);
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
let mut sole_item_with_key = true;
|
let mut sole_item_with_key = true;
|
||||||
for (entity, key) in (&entities, &keys).join() {
|
for (entity, key) in (&entities, &keys).join() {
|
||||||
if entity != e && key.idx == idx {
|
if entity != e && key.idx == idx {
|
||||||
console::log(&format!("KEYHANDLING: Another item shares index {}", idx));
|
if DEBUG_KEYHANDLING {
|
||||||
|
console::log(&format!("KEYHANDLING: Another item shares index {}", idx));
|
||||||
|
}
|
||||||
sole_item_with_key = false;
|
sole_item_with_key = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// If no other items shared this key, free up the index.
|
// If no other items shared this key, free up the index.
|
||||||
if sole_item_with_key {
|
if sole_item_with_key {
|
||||||
console::log(
|
if DEBUG_KEYHANDLING {
|
||||||
&format!("KEYHANDLING: No other items found, clearing index {}.", idx)
|
console::log(
|
||||||
);
|
&format!("KEYHANDLING: No other items found, clearing index {}.", idx)
|
||||||
|
);
|
||||||
|
}
|
||||||
clear_idx(idx);
|
clear_idx(idx);
|
||||||
}
|
}
|
||||||
// Either way, remove the key component from this item, because we're dropping it.
|
// Either way, remove the key component from this item, because we're dropping it.
|
||||||
console::log(&format!("KEYHANDLING: Removing key component from item."));
|
if DEBUG_KEYHANDLING {
|
||||||
|
console::log(&format!("KEYHANDLING: Removing key component from item."));
|
||||||
|
}
|
||||||
keys.remove(e);
|
keys.remove(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue