mod txt;
pub use txt::TxtData;
use crate::error::Result;
use crate::{ItemCode, StatId};
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub struct StatInfo {
pub csv_bits: u8,
pub csv_param: u8,
pub csv_signed: bool,
pub save_bits: i32,
pub save_param_bits: i32,
pub save_add: i32,
pub val_shift: u8,
}
impl StatInfo {
pub fn max_semantic_value(&self) -> i32 {
1i32.wrapping_shl(self.save_bits as u32).wrapping_sub(1).wrapping_sub(self.save_add)
}
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub struct ItemTypeInfo {
pub compact_save: bool,
pub has_variable_gfx: bool,
pub is_armor: bool,
pub is_weapon: bool,
pub is_gold: bool,
pub is_stackable: bool,
pub is_charm: bool,
pub is_body_part: bool,
pub is_player_body_part: bool,
pub is_scroll_or_book: bool,
pub is_quest: bool,
pub quest_diff_check: bool,
}
pub trait ExternalData {
fn stat_info(&self, stat: StatId, save_version: u32) -> Result<StatInfo>;
fn item_info(&self, code: ItemCode, save_version: u32) -> Result<ItemTypeInfo>;
fn quantity_bits(&self, save_version: u32) -> u32 {
if save_version > 80 {
9
} else {
8
}
}
fn magic_prefix_offset(&self, save_version: u32) -> i32 {
match save_version {
0x48 | 0x49 | 0x50..=0x52 => -661,
0x53 | 0x54 => -674,
0x55..=0x57 => -675,
0x58 => -729,
_ => 0,
}
}
fn auto_magic_offset(&self, save_version: u32) -> i32 {
match save_version {
0x48 | 0x49 | 0x50..=0x52 => -1262,
0x53 | 0x54 => -1265,
0x55..=0x57 => -1266,
0x58 => -1440,
_ => 0,
}
}
}
impl<T: ExternalData + ?Sized> ExternalData for &T {
fn stat_info(&self, stat: StatId, save_version: u32) -> Result<StatInfo> {
(**self).stat_info(stat, save_version)
}
fn item_info(&self, code: ItemCode, save_version: u32) -> Result<ItemTypeInfo> {
(**self).item_info(code, save_version)
}
fn quantity_bits(&self, save_version: u32) -> u32 {
(**self).quantity_bits(save_version)
}
fn magic_prefix_offset(&self, save_version: u32) -> i32 {
(**self).magic_prefix_offset(save_version)
}
fn auto_magic_offset(&self, save_version: u32) -> i32 {
(**self).auto_magic_offset(save_version)
}
}
#[cfg(feature = "embedded-data")]
pub fn default_data() -> &'static TxtData {
TxtData::embedded()
}