jake
5 years ago
4 changed files with 277 additions and 42 deletions
@ -0,0 +1,132 @@ |
|||||
|
use crate::common::leveltable::CharacterStats;
|
||||
|
use libpso::character::character;
|
||||
|
|
||||
|
|
||||
|
pub struct CharacterBuilder<'a> {
|
||||
|
character: Option<&'a character::Character>,
|
||||
|
stats: Option<&'a CharacterStats>,
|
||||
|
level: Option<u32>,
|
||||
|
}
|
||||
|
|
||||
|
|
||||
|
impl<'a> CharacterBuilder<'a> {
|
||||
|
pub fn new() -> CharacterBuilder<'a> {
|
||||
|
CharacterBuilder {
|
||||
|
character: None,
|
||||
|
stats: None,
|
||||
|
level: None,
|
||||
|
}
|
||||
|
}
|
||||
|
|
||||
|
pub fn character(self, character: &'a character::Character) -> CharacterBuilder<'a> {
|
||||
|
CharacterBuilder {
|
||||
|
character: Some(character),
|
||||
|
..self
|
||||
|
}
|
||||
|
}
|
||||
|
|
||||
|
pub fn stats(self, stats: &'a CharacterStats) -> CharacterBuilder<'a> {
|
||||
|
CharacterBuilder {
|
||||
|
stats: Some(stats),
|
||||
|
..self
|
||||
|
}
|
||||
|
}
|
||||
|
|
||||
|
pub fn level(self, level: u32) -> CharacterBuilder<'a> {
|
||||
|
CharacterBuilder {
|
||||
|
level: Some(level),
|
||||
|
..self
|
||||
|
}
|
||||
|
}
|
||||
|
|
||||
|
pub fn build(self) -> character::Character {
|
||||
|
let character = self.character.unwrap();
|
||||
|
let stats = self.stats.unwrap();
|
||||
|
let level = self.level.unwrap();
|
||||
|
character::Character {
|
||||
|
hp: stats.hp,
|
||||
|
atp: stats.atp,
|
||||
|
mst: stats.mst,
|
||||
|
evp: stats.evp,
|
||||
|
dfp: stats.dfp,
|
||||
|
ata: stats.ata,
|
||||
|
lck: stats.lck,
|
||||
|
level: level,
|
||||
|
..*character
|
||||
|
}
|
||||
|
}
|
||||
|
}
|
||||
|
|
||||
|
|
||||
|
pub struct FullCharacterBuilder<'a> {
|
||||
|
character: Option<&'a character::Character>,
|
||||
|
inventory: Option<&'a [character::InventoryItem; 30]>,
|
||||
|
inventory_len: Option<usize>,
|
||||
|
key_config: Option<&'a [u8; 0x16C]>,
|
||||
|
joystick_config: Option<&'a [u8; 0x38]>,
|
||||
|
}
|
||||
|
|
||||
|
|
||||
|
impl<'a> FullCharacterBuilder<'a> {
|
||||
|
pub fn new() -> FullCharacterBuilder<'a> {
|
||||
|
FullCharacterBuilder {
|
||||
|
character: None,
|
||||
|
inventory: None,
|
||||
|
inventory_len: None,
|
||||
|
key_config: None,
|
||||
|
joystick_config: None,
|
||||
|
}
|
||||
|
}
|
||||
|
|
||||
|
pub fn character(self, character: &'a character::Character) -> FullCharacterBuilder<'a> {
|
||||
|
FullCharacterBuilder {
|
||||
|
character: Some(character),
|
||||
|
..self
|
||||
|
}
|
||||
|
}
|
||||
|
|
||||
|
pub fn inventory(self, inventory: &'a [character::InventoryItem; 30], len: usize) -> FullCharacterBuilder<'a> {
|
||||
|
FullCharacterBuilder {
|
||||
|
inventory: Some(inventory),
|
||||
|
inventory_len: Some(len),
|
||||
|
..self
|
||||
|
}
|
||||
|
}
|
||||
|
|
||||
|
pub fn key_config(self, key_config: &'a [u8; 0x16C]) -> FullCharacterBuilder<'a> {
|
||||
|
FullCharacterBuilder {
|
||||
|
key_config: Some(key_config),
|
||||
|
..self
|
||||
|
}
|
||||
|
}
|
||||
|
|
||||
|
pub fn joystick_config(self, joystick_config: &'a [u8; 0x38]) -> FullCharacterBuilder<'a> {
|
||||
|
FullCharacterBuilder {
|
||||
|
joystick_config: Some(joystick_config),
|
||||
|
..self
|
||||
|
}
|
||||
|
}
|
||||
|
|
||||
|
pub fn build(self) -> character::FullCharacter {
|
||||
|
let character = self.character.unwrap();
|
||||
|
let inventory = self.inventory.unwrap();
|
||||
|
let inventory_len = self.inventory_len.unwrap();
|
||||
|
let key_config = self.key_config.unwrap();
|
||||
|
let joystick_config = self.joystick_config.unwrap();
|
||||
|
|
||||
|
character::FullCharacter {
|
||||
|
character: *character,
|
||||
|
inventory: character::Inventory {
|
||||
|
item_count: inventory_len as u8,
|
||||
|
items: *inventory,
|
||||
|
..character::Inventory::default()
|
||||
|
},
|
||||
|
key_team_config: character::KeyTeamConfig {
|
||||
|
key_config: *key_config,
|
||||
|
joystick_config: *joystick_config,
|
||||
|
..character::KeyTeamConfig::default()
|
||||
|
},
|
||||
|
..character::FullCharacter::default()
|
||||
|
}
|
||||
|
}
|
||||
|
}
|
@ -1,2 +1,3 @@ |
|||||
pub mod ship;
|
pub mod ship;
|
||||
pub mod location;
|
pub mod location;
|
||||
|
pub mod character;
|
Write
Preview
Loading…
Cancel
Save
Reference in new issue