mirror of
https://github.com/Zenithsiz/dcb.git
synced 2026-02-09 11:48:16 +00:00
Fixed wrong usage of char in documentation.
Added some derives to `CardTable`. Added documentation for `Deck`.
This commit is contained in:
@@ -7,7 +7,7 @@ The digimon card has a size of `0x138` bytes, and it's layout is the following:
|
||||
|
||||
| Offset | Size | Type | Name | Location | Details |
|
||||
| ------ | ---- | ------------------- | ------------------------ | ---------------------- | ----------------------------------------------------------------------------------- |
|
||||
| 0x0 | 0x15 | `[char; 0x15]` | Name | `name` | Null-terminated |
|
||||
| 0x0 | 0x15 | `[u8; 0x15]` | Name | `name` | Null-terminated |
|
||||
| 0x15 | 0x2 | `u16` | Unknown | `unknown_15` | |
|
||||
| 0x17 | 0x1 | `u8` | Speciality & Level | `speciality level` | The bottom nibble of this byte is the level, while the top nibble is the speciality |
|
||||
| 0x18 | 0x1 | `u8` | DP | `dp_cost` | |
|
||||
@@ -25,4 +25,4 @@ The digimon card has a size of `0x138` bytes, and it's layout is the following:
|
||||
| 0xe1 | 0x1 | [`CrossMoveEffect`] | Cross move effect | `cross_move_effect` | |
|
||||
| 0xe2 | 0x1 | `u8` | Unknown | `unknown_e2` | |
|
||||
| 0xe3 | 0x1 | [`ArrowColor`] | Effect arrow color | `effect_arrow_color` | |
|
||||
| 0xe4 | 0x54 | `[[char; 0x15]; 4]` | Effect description lines | `effect_description` | Each line is` 0x15` bytes, split over 4 lines, each null terminated |
|
||||
| 0xe4 | 0x54 | `[[u8; 0x15]; 4]` | Effect description lines | `effect_description` | Each line is` 0x15` bytes, split over 4 lines, each null terminated |
|
||||
|
||||
@@ -5,8 +5,8 @@ This module contains the [`Digivolve`] struct, which describes a digivolve card.
|
||||
# Layout
|
||||
The digivolve card has a size of `0x6c` bytes, and it's layout is the following:
|
||||
|
||||
| Offset | Size | Type | Name | Location | Details |
|
||||
| ------ | ---- | ------------------- | ------------------------ | -------------------- | ------------------------------------------------------------------- |
|
||||
| 0x0 | 0x15 | `[char; 0x15]` | Name | `name` | Null-terminated |
|
||||
| 0x15 | 0x3 | `[u8; 3]` | Unknown | `unknown_15` | Probably contains the card effect |
|
||||
| 0x8a | 0x54 | `[[char; 0x15]; 4]` | Effect description lines | `effect_description` | Each line is` 0x15` bytes, split over 4 lines, each null terminated |
|
||||
| Offset | Size | Type | Name | Location | Details |
|
||||
| ------ | ---- | ----------------- | ------------------------ | -------------------- | ------------------------------------------------------------------- |
|
||||
| 0x0 | 0x15 | `[u8; 0x15]` | Name | `name` | Null-terminated |
|
||||
| 0x15 | 0x3 | `[u8; 3]` | Unknown | `unknown_15` | Probably contains the card effect |
|
||||
| 0x8a | 0x54 | `[[u8; 0x15]; 4]` | Effect description lines | `effect_description` | Each line is` 0x15` bytes, split over 4 lines, each null terminated |
|
||||
|
||||
@@ -7,7 +7,7 @@ The item card has a size of `0xde` bytes, and it's layout is the following:
|
||||
|
||||
| Offset | Size | Type | Name | Location | Details |
|
||||
| ------ | ---- | ------------------- | ------------------------ | ---------------------- | ------------------------------------------------------------------- |
|
||||
| 0x0 | 0x15 | `[char; 0x15]` | Name | `name` | Null-terminated |
|
||||
| 0x0 | 0x15 | `[u8; 0x15]` | Name | `name` | Null-terminated |
|
||||
| 0x15 | 0x4 | `u32` | Unknown | `unknown_15` | |
|
||||
| 0x19 | 0x20 | [`EffectCondition`] | First condition | `effect_conditions[0]` | |
|
||||
| 0x39 | 0x20 | [`EffectCondition`] | Second condition | `effect_conditions[1]` | |
|
||||
@@ -15,4 +15,4 @@ The item card has a size of `0xde` bytes, and it's layout is the following:
|
||||
| 0x69 | 0x10 | [`Effect`] | Second effect | `effects[1]` | |
|
||||
| 0x79 | 0x10 | [`Effect`] | Third effect | `effects[2]` | |
|
||||
| 0x89 | 0x1 | [`ArrowColor`] | Effect arrow color | `effect_arrow_color` | |
|
||||
| 0x8a | 0x54 | `[[char; 0x15]; 4]` | Effect description lines | `effect_description` | Each line is` 0x15` bytes, split over 4 lines, each null terminated |
|
||||
| 0x8a | 0x54 | `[[u8; 0x15]; 4]` | Effect description lines | `effect_description` | Each line is` 0x15` bytes, split over 4 lines, each null terminated |
|
||||
|
||||
@@ -5,8 +5,8 @@ This module contains the [`Move`] struct, which describes a generic move over th
|
||||
# Layout
|
||||
Each move has a size of `0x1c` bytes, and it's layout is the following:
|
||||
|
||||
| Offset | Size | Type | Name | Location | Details |
|
||||
| ------ | ---- | -------------- | ------- | --------- | --------------------------------- |
|
||||
| 0x0 | 0x2 | `u16` | Power | `power` | |
|
||||
| 0x2 | 0x4 | `u32` | Unknown | `unknown` | Most likely stores animation data |
|
||||
| 0x6 | 0x16 | `[char; 0x16]` | Name | `name` | Null-terminated |
|
||||
| Offset | Size | Type | Name | Location | Details |
|
||||
| ------ | ---- | ------------ | ------- | --------- | --------------------------------- |
|
||||
| 0x0 | 0x2 | `u16` | Power | `power` | |
|
||||
| 0x2 | 0x4 | `u32` | Unknown | `unknown` | Most likely stores animation data |
|
||||
| 0x6 | 0x16 | `[u8; 0x16]` | Name | `name` | Null-terminated |
|
||||
|
||||
@@ -26,7 +26,7 @@ use std::{
|
||||
};
|
||||
|
||||
/// The table storing all cards
|
||||
#[derive(Debug)]
|
||||
#[derive(PartialEq, Eq, Clone, Debug)]
|
||||
#[derive(serde::Serialize, serde::Deserialize)]
|
||||
pub struct Table {
|
||||
/// All digimons in this table
|
||||
|
||||
13
src/game/deck/deck.md
Normal file
13
src/game/deck/deck.md
Normal file
@@ -0,0 +1,13 @@
|
||||
A deck
|
||||
|
||||
This module contains the [`Deck`] struct, which describes a deck.
|
||||
|
||||
# Layout
|
||||
Each deck has a size of `0x6e` bytes, and it's layout is the following:
|
||||
|
||||
| Offset | Size | Type | Name | Location | Details |
|
||||
| ------ | ---- | ------------ | ---------- | ------------ | -------------------- |
|
||||
| 0x0 | 0x3c | `[u16; 30]` | Cards | `cards` | List of all card ids |
|
||||
| 0x3c | 0x13 | `[u8; 0x13]` | Deck name | `name` | Null terminated |
|
||||
| 0x4f | 0x13 | `[u8; 0x13]` | Owner name | `owner` | Null terminated |
|
||||
| 0x62 | 0x13 | `[u8; 0xc]` | Unknown | `unknown_62` | |
|
||||
@@ -10,9 +10,12 @@ use crate::{
|
||||
};
|
||||
use byteorder::{ByteOrder, LittleEndian};
|
||||
|
||||
/// Card id type
|
||||
pub type CardId = u16;
|
||||
|
||||
/// A deck
|
||||
#[derive(Debug)]
|
||||
#[derive(::serde::Serialize, ::serde::Deserialize)]
|
||||
#[derive(PartialEq, Eq, Clone, Debug)]
|
||||
#[derive(serde::Serialize, serde::Deserialize)]
|
||||
pub struct Deck {
|
||||
/// Name of this deck
|
||||
pub name: ascii::AsciiString,
|
||||
@@ -21,10 +24,10 @@ pub struct Deck {
|
||||
pub owner: ascii::AsciiString,
|
||||
|
||||
/// All of the card ids that make up this deck
|
||||
pub cards: [u16; 30],
|
||||
pub cards: [CardId; 30],
|
||||
|
||||
/// Unknown data
|
||||
unknown: [u8; 0xc],
|
||||
/// Unknown data at `0x62`
|
||||
unknown_62: [u8; 0xc],
|
||||
}
|
||||
|
||||
/// Error type for [`Bytes::from_bytes`]
|
||||
@@ -59,38 +62,35 @@ impl Bytes for Deck {
|
||||
fn from_bytes(bytes: &Self::ByteArray) -> Result<Self, Self::FromError> {
|
||||
// Split the bytes
|
||||
let bytes = array_split!(bytes,
|
||||
deck : [0x3c],
|
||||
name : [0x13],
|
||||
owner : [0x13],
|
||||
unknown: [0xc],
|
||||
deck : [0x3c],
|
||||
name : [0x13],
|
||||
owner : [0x13],
|
||||
unknown_62: [0xc],
|
||||
);
|
||||
|
||||
let mut cards = [0; 30];
|
||||
for (card_id, card) in cards.iter_mut().enumerate() {
|
||||
/// Size of [`CardId`]
|
||||
const CARD_ID_SIZE: usize = std::mem::size_of::<CardId>();
|
||||
let offset = card_id * CARD_ID_SIZE;
|
||||
*card = LittleEndian::read_u16(&bytes.deck[offset..offset + CARD_ID_SIZE]);
|
||||
}
|
||||
|
||||
Ok(Self {
|
||||
name: bytes.name.read_string().map_err(FromBytesError::Name)?.to_ascii_string(),
|
||||
|
||||
owner: bytes.owner.read_string().map_err(FromBytesError::Owner)?.to_ascii_string(),
|
||||
|
||||
cards: {
|
||||
let mut cards_buf = [0; 0x1e];
|
||||
|
||||
for (card_id, card) in cards_buf.iter_mut().enumerate() {
|
||||
*card = LittleEndian::read_u16(&bytes.deck[0x0 + card_id * 2..0x2 + card_id * 2]);
|
||||
}
|
||||
|
||||
cards_buf
|
||||
},
|
||||
|
||||
unknown: *bytes.unknown,
|
||||
cards,
|
||||
unknown_62: *bytes.unknown_62,
|
||||
})
|
||||
}
|
||||
|
||||
fn to_bytes(&self, bytes: &mut Self::ByteArray) -> Result<(), Self::ToError> {
|
||||
// Split the bytes
|
||||
let bytes = array_split_mut!(bytes,
|
||||
deck : [0x3c],
|
||||
name : [0x13],
|
||||
owner : [0x13],
|
||||
unknown: [0xc],
|
||||
deck : [0x3c],
|
||||
name : [0x13],
|
||||
owner : [0x13],
|
||||
unknown_62: [0xc],
|
||||
);
|
||||
|
||||
// Name / Owner
|
||||
@@ -99,11 +99,14 @@ impl Bytes for Deck {
|
||||
|
||||
// Deck
|
||||
for (card_id, card) in self.cards.iter().enumerate() {
|
||||
LittleEndian::write_u16(&mut bytes.deck[0x0 + card_id * 2..0x2 + card_id * 2], *card);
|
||||
/// Size of [`CardId`]
|
||||
const CARD_ID_SIZE: usize = std::mem::size_of::<CardId>();
|
||||
let offset = card_id * CARD_ID_SIZE;
|
||||
LittleEndian::write_u16(&mut bytes.deck[offset..offset + CARD_ID_SIZE], *card);
|
||||
}
|
||||
|
||||
// Unknown
|
||||
*bytes.unknown = self.unknown;
|
||||
*bytes.unknown_62 = self.unknown_62;
|
||||
|
||||
// And return Ok
|
||||
Ok(())
|
||||
|
||||
@@ -8,13 +8,8 @@ use crate::{
|
||||
use std::io::{Read, Seek, Write};
|
||||
|
||||
/// The decks table, where all decks are stored
|
||||
///
|
||||
/// # Details
|
||||
/// This type serves as an interface to this table, being able to read
|
||||
/// and write to it, it is the only type able to do so, as each deck
|
||||
/// type may only be converted to and from bytes.
|
||||
#[derive(Debug)]
|
||||
#[derive(::serde::Serialize, ::serde::Deserialize)]
|
||||
#[derive(PartialEq, Eq, Clone, Debug)]
|
||||
#[derive(serde::Serialize, serde::Deserialize)]
|
||||
pub struct Table {
|
||||
/// All decks
|
||||
decks: Vec<Deck>,
|
||||
|
||||
Reference in New Issue
Block a user