mirror of
https://github.com/Zenithsiz/dcb.git
synced 2026-02-09 03:40:23 +00:00
Removed valicdation interface as-is.
Fixed missing documentation accross the whole project.
This commit is contained in:
@@ -30,7 +30,4 @@ where
|
||||
|
||||
/// Writes this structure to `bytes`
|
||||
fn to_bytes(&self, bytes: &mut Self::ByteArray) -> Result<(), Self::ToError>;
|
||||
|
||||
/// Validates this structure to be written to bytes.
|
||||
fn validate(&self) -> Validation;
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@ use byteorder::{ByteOrder, LittleEndian};
|
||||
|
||||
// Crate
|
||||
use crate::game::{
|
||||
bytes::Validation,
|
||||
card::property::{self, ArrowColor, CrossMoveEffect, Effect, EffectCondition, Level, Move, Speciality},
|
||||
util, Bytes,
|
||||
};
|
||||
@@ -75,9 +74,13 @@ pub struct Digimon {
|
||||
#[serde(default)]
|
||||
pub effects: [Option<Effect>; 3],
|
||||
|
||||
// Unknown fields
|
||||
/// Unknown field at `0x1a`
|
||||
pub unknown_1a: u8,
|
||||
|
||||
/// Unknown field at `0x15`
|
||||
pub unknown_15: u16,
|
||||
|
||||
/// Unknown field at `0xe2`
|
||||
pub unknown_e2: u8,
|
||||
}
|
||||
|
||||
@@ -372,8 +375,4 @@ impl Bytes for Digimon {
|
||||
// Return Ok
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn validate(&self) -> Validation {
|
||||
Validation::new()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#![doc(include = "digivolve.md")]
|
||||
|
||||
// Crate
|
||||
use crate::game::{bytes::Validation, util, Bytes};
|
||||
use crate::game::{util, Bytes};
|
||||
|
||||
/// A digivolve card
|
||||
///
|
||||
@@ -20,7 +20,7 @@ pub struct Digivolve {
|
||||
/// being an ascii string with 20 characters at most.
|
||||
pub effect_description: [ascii::AsciiString; 4],
|
||||
|
||||
// Unknown
|
||||
/// Unknown field at `0x15`
|
||||
pub unknown_15: [u8; 3],
|
||||
}
|
||||
|
||||
@@ -143,8 +143,4 @@ impl Bytes for Digivolve {
|
||||
// Return Ok
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn validate(&self) -> Validation {
|
||||
Validation::new()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@ use byteorder::{ByteOrder, LittleEndian};
|
||||
|
||||
// Crate
|
||||
use crate::game::{
|
||||
bytes::Validation,
|
||||
card::property::{self, ArrowColor, Effect, EffectCondition},
|
||||
util, Bytes,
|
||||
};
|
||||
@@ -39,7 +38,7 @@ pub struct Item {
|
||||
#[serde(default)]
|
||||
pub effects: [Option<Effect>; 3],
|
||||
|
||||
// Unknown fields
|
||||
/// Unknown field at `0x15`
|
||||
pub unknown_15: u32,
|
||||
}
|
||||
|
||||
@@ -232,8 +231,4 @@ impl Bytes for Item {
|
||||
// Return Ok
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn validate(&self) -> Validation {
|
||||
Validation::new()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,10 +119,6 @@ macro_rules! generate_enum_property_mod
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn validate(&self) -> $crate::game::bytes::Validation {
|
||||
$crate::game::bytes::Validation::new()
|
||||
}
|
||||
}
|
||||
|
||||
// Extra definitions
|
||||
@@ -164,10 +160,6 @@ macro generate_enum_property_option {
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn validate(&self) -> $crate::game::bytes::Validation {
|
||||
$crate::game::bytes::Validation::new()
|
||||
}
|
||||
}
|
||||
)*
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@ use byteorder::{ByteOrder, LittleEndian};
|
||||
|
||||
// Crate
|
||||
use crate::game::{
|
||||
bytes::Validation,
|
||||
card::property::{self, AttackType, DigimonProperty, EffectOperation, PlayerType, Slot},
|
||||
util, Bytes,
|
||||
};
|
||||
@@ -39,6 +38,7 @@ pub enum Effect {
|
||||
///
|
||||
/// `<property> = ( <A> + <Y> ) + ( <C> <op> ( <B> + <X> ) )`
|
||||
#[serde(rename = "Change property")]
|
||||
#[allow(clippy::missing_docs_in_private_items)] // Explained the formula
|
||||
ChangeProperty {
|
||||
property: DigimonProperty,
|
||||
|
||||
@@ -54,7 +54,13 @@ pub enum Effect {
|
||||
|
||||
/// A player uses an attack type
|
||||
#[serde(rename = "Use attack")]
|
||||
UseAttack { player: PlayerType, attack: AttackType },
|
||||
UseAttack {
|
||||
/// Player being forced to use `attack`
|
||||
player: PlayerType,
|
||||
|
||||
/// Attack being forced to be used
|
||||
attack: AttackType,
|
||||
},
|
||||
|
||||
/// Set the temp slot
|
||||
///
|
||||
@@ -64,6 +70,7 @@ pub enum Effect {
|
||||
///
|
||||
/// `<temp slot> = <A> + (<B> <op> <C>)`
|
||||
#[serde(rename = "Set temp slot")]
|
||||
#[allow(clippy::missing_docs_in_private_items)] // Explained the formula
|
||||
SetTempSlot {
|
||||
a: Option<DigimonProperty>,
|
||||
b: Option<DigimonProperty>,
|
||||
@@ -82,15 +89,25 @@ pub enum Effect {
|
||||
/// - `Dp` -> `Offline`
|
||||
#[serde(rename = "Move cards")]
|
||||
MoveCards {
|
||||
player: PlayerType,
|
||||
source: Slot,
|
||||
/// Which player has their cards moved
|
||||
player: PlayerType,
|
||||
|
||||
/// Source slot
|
||||
source: Slot,
|
||||
|
||||
/// Destination slot
|
||||
destination: Slot,
|
||||
count: u16,
|
||||
|
||||
/// Number of cards
|
||||
count: u16,
|
||||
},
|
||||
|
||||
/// Shuffles a player's online deck
|
||||
#[serde(rename = "Shuffle online deck")]
|
||||
ShuffleOnlineDeck { player: PlayerType },
|
||||
ShuffleOnlineDeck {
|
||||
/// Player to shuffle the deck of
|
||||
player: PlayerType,
|
||||
},
|
||||
|
||||
/// Voids the opponent's support effect
|
||||
#[serde(rename = "Void opponent support effect")]
|
||||
@@ -116,11 +133,20 @@ pub enum Effect {
|
||||
|
||||
/// If the digimon is Ko'd it revives with health
|
||||
#[serde(rename = "Ko'd digimon revives")]
|
||||
KoDigimonRevives { health: u16 },
|
||||
KoDigimonRevives {
|
||||
/// Health to revive with
|
||||
health: u16,
|
||||
},
|
||||
|
||||
/// A player draws cards
|
||||
#[serde(rename = "Draw cards")]
|
||||
DrawCards { player: PlayerType, count: u16 },
|
||||
DrawCards {
|
||||
/// Player drawing the cards
|
||||
player: PlayerType,
|
||||
|
||||
/// How many cards to draw
|
||||
count: u16,
|
||||
},
|
||||
|
||||
/// Own attack becomes Eat Up HP
|
||||
#[serde(rename = "Own attack becomes Eat Up HP")]
|
||||
@@ -128,7 +154,10 @@ pub enum Effect {
|
||||
|
||||
/// A player attacks first
|
||||
#[serde(rename = "Attack first")]
|
||||
AttackFirst { player: PlayerType },
|
||||
AttackFirst {
|
||||
/// Player attacking first
|
||||
player: PlayerType,
|
||||
},
|
||||
}
|
||||
|
||||
/// Error type for [`Bytes::from_bytes`]
|
||||
@@ -156,7 +185,10 @@ pub enum FromBytesError {
|
||||
|
||||
/// Unknown effect type
|
||||
#[error("Unknown byte for an effect type: {}", byte)]
|
||||
EffectType { byte: u8 },
|
||||
EffectType {
|
||||
/// Unknown byte
|
||||
byte: u8,
|
||||
},
|
||||
}
|
||||
|
||||
/// Error type for [`Bytes::from_bytes`]
|
||||
@@ -164,7 +196,13 @@ pub enum FromBytesError {
|
||||
pub enum ToBytesError {
|
||||
/// Invalid move [`Effect::MoveCards`] effect
|
||||
#[error("Invalid move cards effect ({} => {})", from, to)]
|
||||
InvalidMoveCards { from: Slot, to: Slot },
|
||||
InvalidMoveCards {
|
||||
/// Slot we tried to move from
|
||||
from: Slot,
|
||||
|
||||
/// Slot we tried to move to
|
||||
to: Slot,
|
||||
},
|
||||
}
|
||||
|
||||
impl Bytes for Effect {
|
||||
@@ -419,10 +457,6 @@ impl Bytes for Effect {
|
||||
// And return Ok
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn validate(&self) -> Validation {
|
||||
Validation::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl Bytes for Option<Effect> {
|
||||
@@ -466,8 +500,4 @@ impl Bytes for Option<Effect> {
|
||||
// An return Ok
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn validate(&self) -> Validation {
|
||||
Validation::new()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@ use byteorder::{ByteOrder, LittleEndian};
|
||||
|
||||
// Crate
|
||||
use crate::game::{
|
||||
bytes::Validation,
|
||||
card::property::{self, DigimonProperty, EffectConditionOperation},
|
||||
util, Bytes,
|
||||
};
|
||||
@@ -29,11 +28,19 @@ pub struct EffectCondition {
|
||||
/// The operation
|
||||
operation: EffectConditionOperation,
|
||||
|
||||
// Unknown
|
||||
unknown_1: u8,
|
||||
unknown_3: [u8; 0x5],
|
||||
unknown_9: [u8; 0xb],
|
||||
/// Unknown field at `0x1`
|
||||
unknown_1: u8,
|
||||
|
||||
/// Unknown field at `0x3`
|
||||
unknown_3: [u8; 0x5],
|
||||
|
||||
/// Unknown field at `0x9`
|
||||
unknown_9: [u8; 0xb],
|
||||
|
||||
/// Unknown field at `0x16`
|
||||
unknown_16: [u8; 0x4],
|
||||
|
||||
/// Unknown field at `0x1b`
|
||||
unknown_1b: [u8; 0x5],
|
||||
}
|
||||
|
||||
@@ -125,10 +132,6 @@ impl Bytes for EffectCondition {
|
||||
// And return OK
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn validate(&self) -> Validation {
|
||||
Validation::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl Bytes for Option<EffectCondition> {
|
||||
@@ -157,8 +160,4 @@ impl Bytes for Option<EffectCondition> {
|
||||
// And return Ok
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn validate(&self) -> Validation {
|
||||
Validation::new()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ mod test;
|
||||
use byteorder::{ByteOrder, LittleEndian};
|
||||
|
||||
// Crate
|
||||
use crate::game::{bytes::Validation, util, Bytes};
|
||||
use crate::game::{util, Bytes};
|
||||
|
||||
/// A digimon's move
|
||||
#[derive(PartialEq, Eq, Clone, Hash, Debug)]
|
||||
@@ -81,6 +81,7 @@ impl Bytes for Move {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/*
|
||||
fn validate(&self) -> Validation {
|
||||
// Create the initial validation
|
||||
let mut validation = Validation::new();
|
||||
@@ -100,4 +101,5 @@ impl Bytes for Move {
|
||||
// And return the validation
|
||||
validation
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
@@ -34,9 +34,11 @@ fn bytes() {
|
||||
assert_eq!(&Move::from_bytes(move_bytes).expect("Unable to convert move from bytes"), mov);
|
||||
|
||||
// Make sure the validation succeeds
|
||||
/*
|
||||
let validation = mov.validate();
|
||||
assert!(validation.successful());
|
||||
assert!(validation.warnings().is_empty());
|
||||
*/
|
||||
|
||||
// Then serialize it to bytes and make sure it's equal
|
||||
let mut bytes = <Move as Bytes>::ByteArray::default();
|
||||
|
||||
@@ -68,7 +68,10 @@ pub enum DeserializeError {
|
||||
|
||||
/// The magic of the table was wrong
|
||||
#[error("Found wrong table header magic (expected {:x}, found {:x})", Table::HEADER_MAGIC, magic)]
|
||||
HeaderMagic { magic: u32 },
|
||||
HeaderMagic {
|
||||
/// Magic we found
|
||||
magic: u32,
|
||||
},
|
||||
|
||||
/// There were too many cards
|
||||
#[error(
|
||||
@@ -82,15 +85,23 @@ pub enum DeserializeError {
|
||||
Table::MAX_BYTE_SIZE
|
||||
)]
|
||||
TooManyCards {
|
||||
digimon_cards: usize,
|
||||
item_cards: usize,
|
||||
/// Number of digimon cards
|
||||
digimon_cards: usize,
|
||||
|
||||
/// Number of item cards
|
||||
item_cards: usize,
|
||||
|
||||
/// Number of digivolve cards
|
||||
digivolve_cards: usize,
|
||||
},
|
||||
|
||||
/// Unable to read card header
|
||||
#[error("Unable to read card header for card id {}", id)]
|
||||
ReadCardHeader {
|
||||
id: usize,
|
||||
/// Id of card
|
||||
id: usize,
|
||||
|
||||
/// Underlying error
|
||||
#[source]
|
||||
err: std::io::Error,
|
||||
},
|
||||
@@ -98,7 +109,10 @@ pub enum DeserializeError {
|
||||
/// An unknown card type was found
|
||||
#[error("Unknown card type for card id {}", id)]
|
||||
UnknownCardType {
|
||||
id: usize,
|
||||
/// Id of card
|
||||
id: usize,
|
||||
|
||||
/// Underlying error
|
||||
#[source]
|
||||
err: property::card_type::FromBytesError,
|
||||
},
|
||||
@@ -106,9 +120,13 @@ pub enum DeserializeError {
|
||||
/// Unable to read a card
|
||||
#[error("Unable to read {} with id {}", card_type, id)]
|
||||
ReadCard {
|
||||
id: usize,
|
||||
/// Id of card
|
||||
id: usize,
|
||||
|
||||
/// Card type
|
||||
card_type: CardType,
|
||||
|
||||
/// Underlying error
|
||||
#[source]
|
||||
err: std::io::Error,
|
||||
},
|
||||
@@ -116,7 +134,10 @@ pub enum DeserializeError {
|
||||
/// Unable to deserialize a digimon card
|
||||
#[error("Unable to deserialize digimon card with id {}", id)]
|
||||
DigimonCard {
|
||||
id: usize,
|
||||
/// Id of card
|
||||
id: usize,
|
||||
|
||||
/// Underlying error
|
||||
#[source]
|
||||
err: card::digimon::FromBytesError,
|
||||
},
|
||||
@@ -124,7 +145,10 @@ pub enum DeserializeError {
|
||||
/// Unable to deserialize an item card
|
||||
#[error("Unable to deserialize item card with id {}", id)]
|
||||
ItemCard {
|
||||
id: usize,
|
||||
/// Id of card
|
||||
id: usize,
|
||||
|
||||
/// Underlying error
|
||||
#[source]
|
||||
err: card::item::FromBytesError,
|
||||
},
|
||||
@@ -132,7 +156,10 @@ pub enum DeserializeError {
|
||||
/// Unable to deserialize a digivolve card
|
||||
#[error("Unable to deserialize digivolve card with id {}", id)]
|
||||
DigivolveCard {
|
||||
id: usize,
|
||||
/// Id of card
|
||||
id: usize,
|
||||
|
||||
/// Underlying error
|
||||
#[source]
|
||||
err: card::digivolve::FromBytesError,
|
||||
},
|
||||
@@ -140,7 +167,10 @@ pub enum DeserializeError {
|
||||
/// Unable to read card footer
|
||||
#[error("Unable to read card footer for card id {}", id)]
|
||||
ReadCardFooter {
|
||||
id: usize,
|
||||
/// Id of card
|
||||
id: usize,
|
||||
|
||||
/// Underlying error
|
||||
#[source]
|
||||
err: std::io::Error,
|
||||
},
|
||||
@@ -169,15 +199,23 @@ pub enum SerializeError {
|
||||
Table::MAX_BYTE_SIZE
|
||||
)]
|
||||
TooManyCards {
|
||||
digimon_cards: usize,
|
||||
item_cards: usize,
|
||||
/// Number of digimon cards
|
||||
digimon_cards: usize,
|
||||
|
||||
/// Number of item cards
|
||||
item_cards: usize,
|
||||
|
||||
/// Number of digivolve cards
|
||||
digivolve_cards: usize,
|
||||
},
|
||||
|
||||
/// Unable to write a digimon card
|
||||
#[error("Unable to write digimon card with id {}", id)]
|
||||
WriteDigimonCard {
|
||||
id: usize,
|
||||
/// Id of card
|
||||
id: usize,
|
||||
|
||||
/// Underlying error
|
||||
#[source]
|
||||
err: std::io::Error,
|
||||
},
|
||||
@@ -185,7 +223,10 @@ pub enum SerializeError {
|
||||
/// Unable to write an item card
|
||||
#[error("Unable to write item card with id {}", id)]
|
||||
WriteItemCard {
|
||||
id: usize,
|
||||
/// Id of card
|
||||
id: usize,
|
||||
|
||||
/// Underlying error
|
||||
#[source]
|
||||
err: std::io::Error,
|
||||
},
|
||||
@@ -193,7 +234,10 @@ pub enum SerializeError {
|
||||
/// Unable to write a digivolve card
|
||||
#[error("Unable to write digivolve card with id {}", id)]
|
||||
WriteDigivolveCard {
|
||||
id: usize,
|
||||
/// Id of card
|
||||
id: usize,
|
||||
|
||||
/// Underlying error
|
||||
#[source]
|
||||
err: std::io::Error,
|
||||
},
|
||||
@@ -201,7 +245,10 @@ pub enum SerializeError {
|
||||
/// Unable to parse a digimon card
|
||||
#[error("Unable to parse digimon card with id {}", id)]
|
||||
ParseDigimonCard {
|
||||
id: usize,
|
||||
/// Id of card
|
||||
id: usize,
|
||||
|
||||
/// Underlying error
|
||||
#[source]
|
||||
err: card::digimon::ToBytesError,
|
||||
},
|
||||
@@ -209,7 +256,10 @@ pub enum SerializeError {
|
||||
/// Unable to parse an item card
|
||||
#[error("Unable to parse item card with id {}", id)]
|
||||
ParseItemCard {
|
||||
id: usize,
|
||||
/// Id of card
|
||||
id: usize,
|
||||
|
||||
/// Underlying error
|
||||
#[source]
|
||||
err: card::item::ToBytesError,
|
||||
},
|
||||
@@ -217,7 +267,10 @@ pub enum SerializeError {
|
||||
/// Unable to parse a digivolve card
|
||||
#[error("Unable to parse digivolve card with id {}", id)]
|
||||
ParseDigivolveCard {
|
||||
id: usize,
|
||||
/// Id of card
|
||||
id: usize,
|
||||
|
||||
/// Underlying error
|
||||
#[source]
|
||||
err: card::digivolve::ToBytesError,
|
||||
},
|
||||
@@ -324,6 +377,7 @@ impl Table {
|
||||
Ok(Self { digimons, items, digivolves })
|
||||
}
|
||||
|
||||
/// Serializes this card table to `file`.
|
||||
pub fn serialize<R: Read + Write + Seek>(&self, file: &mut GameFile<R>) -> Result<(), SerializeError> {
|
||||
// Get the final table size
|
||||
let table_size = self.digimons.len() * (0x3 + CardType::Digimon.byte_size() + 0x1) +
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
use byteorder::{ByteOrder, LittleEndian};
|
||||
|
||||
// Crate
|
||||
use crate::game::{bytes::Validation, util, Bytes};
|
||||
use crate::game::{util, Bytes};
|
||||
|
||||
/// A deck
|
||||
#[derive(Debug)]
|
||||
@@ -19,7 +19,7 @@ pub struct Deck {
|
||||
/// All of the card ids that make up this deck
|
||||
pub cards: [u16; 30],
|
||||
|
||||
// Unknown
|
||||
/// Unknown data
|
||||
unknown: [u8; 0xc],
|
||||
}
|
||||
|
||||
@@ -108,8 +108,4 @@ impl Bytes for Deck {
|
||||
// And return Ok
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn validate(&self) -> Validation {
|
||||
Validation::new()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ use crate::{
|
||||
#[derive(Debug)]
|
||||
#[derive(::serde::Serialize, ::serde::Deserialize)]
|
||||
pub struct Table {
|
||||
/// All decks
|
||||
decks: Vec<Deck>,
|
||||
}
|
||||
|
||||
@@ -41,7 +42,10 @@ pub enum DeserializeError {
|
||||
/// Could not read a deck entry
|
||||
#[error("Unable to read deck entry with id {}", id)]
|
||||
ReadDeck {
|
||||
id: usize,
|
||||
/// Id of card
|
||||
id: usize,
|
||||
|
||||
/// Underlying error
|
||||
#[source]
|
||||
err: std::io::Error,
|
||||
},
|
||||
@@ -49,7 +53,10 @@ pub enum DeserializeError {
|
||||
/// Could not deserialize a deck entry
|
||||
#[error("Unable to serialize deck entry with id {}", id)]
|
||||
DeserializeDeck {
|
||||
id: usize,
|
||||
/// Id of card
|
||||
id: usize,
|
||||
|
||||
/// Underlying error
|
||||
#[source]
|
||||
err: deck::FromBytesError,
|
||||
},
|
||||
@@ -69,7 +76,10 @@ pub enum SerializeError {
|
||||
/// Could not deserialize a deck entry
|
||||
#[error("Unable to deserialize deck entry with id {}", id)]
|
||||
SerializeDeck {
|
||||
id: usize,
|
||||
/// Id of card
|
||||
id: usize,
|
||||
|
||||
/// Underlying error
|
||||
#[source]
|
||||
err: deck::ToBytesError,
|
||||
},
|
||||
@@ -77,14 +87,18 @@ pub enum SerializeError {
|
||||
/// Could not write a deck entry
|
||||
#[error("Unable to read deck entry with id {}", id)]
|
||||
WriteDeck {
|
||||
id: usize,
|
||||
/// Id of card
|
||||
id: usize,
|
||||
|
||||
/// Underlying error
|
||||
#[source]
|
||||
err: std::io::Error,
|
||||
},
|
||||
}
|
||||
|
||||
impl Table {
|
||||
pub fn deserialize<R>(game_file: &mut GameFile<R>) -> Result<Self, DeserializeError>
|
||||
/// Deserializes the deck table from `file`.
|
||||
pub fn deserialize<R>(file: &mut GameFile<R>) -> Result<Self, DeserializeError>
|
||||
where
|
||||
R: Read + Write + Seek,
|
||||
{
|
||||
@@ -92,15 +106,14 @@ impl Table {
|
||||
let mut decks = vec![];
|
||||
|
||||
// Seek to the beginning of the deck table
|
||||
game_file
|
||||
.seek(std::io::SeekFrom::Start(u64::from(Self::DECK_TABLE_START_ADDRESS)))
|
||||
file.seek(std::io::SeekFrom::Start(u64::from(Self::DECK_TABLE_START_ADDRESS)))
|
||||
.map_err(DeserializeError::Seek)?;
|
||||
|
||||
// Then get each deck
|
||||
for id in 0..159 {
|
||||
// Read all bytes of the deck
|
||||
let mut bytes = [0; 0x6e];
|
||||
game_file.read_exact(&mut bytes).map_err(|err| DeserializeError::ReadDeck { id, err })?;
|
||||
file.read_exact(&mut bytes).map_err(|err| DeserializeError::ReadDeck { id, err })?;
|
||||
|
||||
// And try to serialize the deck
|
||||
let deck = Deck::from_bytes(&bytes).map_err(|err| DeserializeError::DeserializeDeck { id, err })?;
|
||||
@@ -113,13 +126,13 @@ impl Table {
|
||||
Ok(Self { decks })
|
||||
}
|
||||
|
||||
pub fn serialize<R>(&self, game_file: &mut GameFile<R>) -> Result<(), SerializeError>
|
||||
/// Serializes the deck table to `file`
|
||||
pub fn serialize<R>(&self, file: &mut GameFile<R>) -> Result<(), SerializeError>
|
||||
where
|
||||
R: Read + Write + Seek,
|
||||
{
|
||||
// Seek to the beginning of the deck table
|
||||
game_file
|
||||
.seek(std::io::SeekFrom::Start(u64::from(Self::DECK_TABLE_START_ADDRESS)))
|
||||
file.seek(std::io::SeekFrom::Start(u64::from(Self::DECK_TABLE_START_ADDRESS)))
|
||||
.map_err(SerializeError::Seek)?;
|
||||
|
||||
// Then get each deck
|
||||
@@ -129,7 +142,7 @@ impl Table {
|
||||
deck.to_bytes(&mut bytes).map_err(|err| SerializeError::SerializeDeck { id, err })?;
|
||||
|
||||
// And write them to file
|
||||
game_file.write(&bytes).map_err(|err| SerializeError::WriteDeck { id, err })?;
|
||||
file.write(&bytes).map_err(|err| SerializeError::WriteDeck { id, err })?;
|
||||
}
|
||||
|
||||
// And return Ok
|
||||
|
||||
@@ -187,7 +187,13 @@ pub fn write_null_ascii_string<'a>(input: &ascii::AsciiStr, buf: &'a mut [u8]) -
|
||||
pub enum WriteMaybeNullAsciiStringError {
|
||||
/// The input string was too large
|
||||
#[error("Input string was too large for buffer. ({} / {})", input_len, buffer_len)]
|
||||
TooLarge { input_len: usize, buffer_len: usize },
|
||||
TooLarge {
|
||||
/// Length of input string
|
||||
input_len: usize,
|
||||
|
||||
/// Length of buffer
|
||||
buffer_len: usize,
|
||||
},
|
||||
}
|
||||
|
||||
/// Writes a possibly null-terminated ascii string to a buffer and returns it
|
||||
|
||||
Reference in New Issue
Block a user