Browse Source

lint src/entity/gateway/*

pull/42/head
jake 4 years ago
parent
commit
10c2b1ec89
  1. 2
      src/bin/main.rs
  2. 49
      src/entity/gateway/inmemory.rs
  3. 1
      src/entity/gateway/postgres/mod.rs
  4. 258
      src/entity/gateway/postgres/models.rs
  5. 8
      src/entity/gateway/postgres/postgres.rs
  6. 2
      src/login/character.rs
  7. 52
      tests/test_bank.rs
  8. 2
      tests/test_character.rs
  9. 8
      tests/test_exp_gain.rs
  10. 6
      tests/test_item_actions.rs
  11. 20
      tests/test_item_pickup.rs
  12. 10
      tests/test_item_use.rs
  13. 6
      tests/test_mags.rs
  14. 2
      tests/test_rooms.rs
  15. 26
      tests/test_shops.rs

2
src/bin/main.rs

@ -48,7 +48,7 @@ fn main() {
setup_logger(); setup_logger();
async_std::task::block_on(async move { async_std::task::block_on(async move {
//let mut entity_gateway = PostgresGateway::new("localhost", "elsewhere", "elsewhere", ""); //let mut entity_gateway = PostgresGateway::new("localhost", "elsewhere", "elsewhere", "");
let mut entity_gateway = InMemoryGateway::new();
let mut entity_gateway = InMemoryGateway::default();
for i in 0..5 { for i in 0..5 {
let fake_user = NewUserAccountEntity { let fake_user = NewUserAccountEntity {

49
src/entity/gateway/inmemory.rs

@ -21,8 +21,8 @@ pub struct InMemoryGateway {
weapon_modifiers: Arc<Mutex<BTreeMap<ItemEntityId, Vec<weapon::WeaponModifier>>>>, weapon_modifiers: Arc<Mutex<BTreeMap<ItemEntityId, Vec<weapon::WeaponModifier>>>>,
} }
impl InMemoryGateway {
pub fn new() -> InMemoryGateway {
impl Default for InMemoryGateway {
fn default() -> InMemoryGateway {
InMemoryGateway { InMemoryGateway {
users: Arc::new(Mutex::new(BTreeMap::new())), users: Arc::new(Mutex::new(BTreeMap::new())),
user_settings: Arc::new(Mutex::new(BTreeMap::new())), user_settings: Arc::new(Mutex::new(BTreeMap::new())),
@ -47,7 +47,7 @@ impl InMemoryGateway {
ItemDetail::Weapon(mut weapon) => { ItemDetail::Weapon(mut weapon) => {
if let Some(weapon_modifiers) = self.weapon_modifiers.lock().unwrap().get(&item.id) { if let Some(weapon_modifiers) = self.weapon_modifiers.lock().unwrap().get(&item.id) {
for weapon_modifier in weapon_modifiers.iter() { for weapon_modifier in weapon_modifiers.iter() {
weapon.apply_modifier(&weapon_modifier);
weapon.apply_modifier(weapon_modifier);
} }
} }
ItemDetail::Weapon(weapon) ItemDetail::Weapon(weapon)
@ -58,23 +58,21 @@ impl InMemoryGateway {
for mag_modifier in mag_modifiers.iter() { for mag_modifier in mag_modifiers.iter() {
match mag_modifier { match mag_modifier {
mag::MagModifier::FeedMag {food} => { mag::MagModifier::FeedMag {food} => {
items.get(&food).map(|mag_feed| {
match mag_feed.item {
ItemDetail::Tool(mag_feed) => mag.feed(mag_feed.tool),
_ => {}
if let Some(mag_feed) = items.get(food) {
if let ItemDetail::Tool(mag_feed) = mag_feed.item {
mag.feed(mag_feed.tool)
} }
});
}
}, },
mag::MagModifier::OwnerChange(class, section_id) => { mag::MagModifier::OwnerChange(class, section_id) => {
mag.change_owner(*class, *section_id) mag.change_owner(*class, *section_id)
}, },
mag::MagModifier::MagCell(mag_cell_id) => { mag::MagModifier::MagCell(mag_cell_id) => {
items.get(&mag_cell_id).map(|mag_cell| {
match mag_cell.item {
ItemDetail::Tool(mag_cell) => mag.apply_mag_cell(mag_cell.tool.try_into().unwrap()),
_ => {}
if let Some(mag_cell) = items.get(mag_cell_id) {
if let ItemDetail::Tool(mag_cell) = mag_cell.item {
mag.apply_mag_cell(mag_cell.tool.try_into().unwrap())
} }
});
}
}, },
_ => {} _ => {}
} }
@ -124,7 +122,7 @@ impl EntityGateway for InMemoryGateway {
async fn get_user_by_id(&self, id: UserAccountId) -> Result<UserAccountEntity, GatewayError> { async fn get_user_by_id(&self, id: UserAccountId) -> Result<UserAccountEntity, GatewayError> {
let users = self.users.lock().unwrap(); let users = self.users.lock().unwrap();
users.get(&id).map(|k| k.clone()).ok_or(GatewayError::Error)
users.get(&id).cloned().ok_or(GatewayError::Error)
} }
async fn get_user_by_name(&self, username: String) -> Result<UserAccountEntity, GatewayError> { async fn get_user_by_name(&self, username: String) -> Result<UserAccountEntity, GatewayError> {
@ -233,17 +231,16 @@ impl EntityGateway for InMemoryGateway {
} }
async fn change_item_location(&mut self, item_id: &ItemEntityId, item_location: ItemLocation) -> Result<(), GatewayError> { async fn change_item_location(&mut self, item_id: &ItemEntityId, item_location: ItemLocation) -> Result<(), GatewayError> {
self.items.lock().unwrap().get_mut(&item_id)
.map(|item_entity| {
item_entity.location = item_location
});
if let Some(item_entity) = self.items.lock().unwrap().get_mut(item_id) {
item_entity.location = item_location
}
Ok(()) Ok(())
} }
async fn feed_mag(&mut self, mag_item_id: &ItemEntityId, tool_item_id: &ItemEntityId) -> Result<(), GatewayError> { async fn feed_mag(&mut self, mag_item_id: &ItemEntityId, tool_item_id: &ItemEntityId) -> Result<(), GatewayError> {
self.mag_modifiers.lock().unwrap() self.mag_modifiers.lock().unwrap()
.entry(*mag_item_id) .entry(*mag_item_id)
.or_insert(Vec::new())
.or_insert_with(Vec::new)
.push(mag::MagModifier::FeedMag { .push(mag::MagModifier::FeedMag {
food: *tool_item_id food: *tool_item_id
}); });
@ -253,7 +250,7 @@ impl EntityGateway for InMemoryGateway {
async fn change_mag_owner(&mut self, mag_item_id: &ItemEntityId, character: &CharacterEntity) -> Result<(), GatewayError> { async fn change_mag_owner(&mut self, mag_item_id: &ItemEntityId, character: &CharacterEntity) -> Result<(), GatewayError> {
self.mag_modifiers.lock().unwrap() self.mag_modifiers.lock().unwrap()
.entry(*mag_item_id) .entry(*mag_item_id)
.or_insert(Vec::new())
.or_insert_with(Vec::new)
.push(mag::MagModifier::OwnerChange(character.char_class, character.section_id)); .push(mag::MagModifier::OwnerChange(character.char_class, character.section_id));
Ok(()) Ok(())
} }
@ -261,15 +258,15 @@ impl EntityGateway for InMemoryGateway {
async fn use_mag_cell(&mut self, mag_item_id: &ItemEntityId, mag_cell_id: &ItemEntityId) -> Result<(), GatewayError> { async fn use_mag_cell(&mut self, mag_item_id: &ItemEntityId, mag_cell_id: &ItemEntityId) -> Result<(), GatewayError> {
self.mag_modifiers.lock().unwrap() self.mag_modifiers.lock().unwrap()
.entry(*mag_item_id) .entry(*mag_item_id)
.or_insert(Vec::new())
.push(mag::MagModifier::MagCell(mag_cell_id.clone()));
.or_insert_with(Vec::new)
.push(mag::MagModifier::MagCell(*mag_cell_id));
Ok(()) Ok(())
} }
async fn add_weapon_modifier(&mut self, item_id: &ItemEntityId, modifier: weapon::WeaponModifier) -> Result<(), GatewayError> { async fn add_weapon_modifier(&mut self, item_id: &ItemEntityId, modifier: weapon::WeaponModifier) -> Result<(), GatewayError> {
self.weapon_modifiers.lock().unwrap() self.weapon_modifiers.lock().unwrap()
.entry(*item_id) .entry(*item_id)
.or_insert(Vec::new())
.or_insert_with(Vec::new)
.push(modifier); .push(modifier);
Ok(()) Ok(())
} }
@ -282,7 +279,7 @@ impl EntityGateway for InMemoryGateway {
.find(|(id, _)| **id == *char_id) .find(|(id, _)| **id == *char_id)
.map(|(_, inv)| inv.clone()) .map(|(_, inv)| inv.clone())
.map(|inv| self.apply_modifiers(inv)) .map(|inv| self.apply_modifiers(inv))
.unwrap_or(InventoryEntity::default()))
.unwrap_or_default())
} }
async fn get_character_bank(&mut self, char_id: &CharacterEntityId, _bank_name: BankName) -> Result<BankEntity, GatewayError> { async fn get_character_bank(&mut self, char_id: &CharacterEntityId, _bank_name: BankName) -> Result<BankEntity, GatewayError> {
@ -291,7 +288,7 @@ impl EntityGateway for InMemoryGateway {
.iter() .iter()
.find(|(id, _)| **id == *char_id) .find(|(id, _)| **id == *char_id)
.map(|(_, b)| b.clone()) .map(|(_, b)| b.clone())
.unwrap_or(BankEntity::default()))
.unwrap_or_default())
} }
async fn set_character_inventory(&mut self, char_id: &CharacterEntityId, inventory: &InventoryEntity) -> Result<(), GatewayError> { async fn set_character_inventory(&mut self, char_id: &CharacterEntityId, inventory: &InventoryEntity) -> Result<(), GatewayError> {
@ -313,7 +310,7 @@ impl EntityGateway for InMemoryGateway {
.iter() .iter()
.find(|(id, _)| **id == *char_id) .find(|(id, _)| **id == *char_id)
.map(|(_, inv)| inv.clone()) .map(|(_, inv)| inv.clone())
.unwrap_or(EquippedEntity::default()))
.unwrap_or_default())
} }
async fn set_character_equips(&mut self, char_id: &CharacterEntityId, equipped: &EquippedEntity) -> Result<(), GatewayError> { async fn set_character_equips(&mut self, char_id: &CharacterEntityId, equipped: &EquippedEntity) -> Result<(), GatewayError> {

1
src/entity/gateway/postgres/mod.rs

@ -1,3 +1,4 @@
#[allow(clippy::module_inception)]
pub mod postgres; pub mod postgres;
pub mod migrations; pub mod migrations;
pub mod models; pub mod models;

258
src/entity/gateway/postgres/models.rs

@ -23,22 +23,22 @@ pub struct PgUserAccount {
at_ship: bool, at_ship: bool,
} }
impl Into<UserAccountEntity> for PgUserAccount {
fn into(self) -> UserAccountEntity {
impl From<PgUserAccount> for UserAccountEntity {
fn from(other: PgUserAccount) -> UserAccountEntity {
UserAccountEntity { UserAccountEntity {
id: UserAccountId(self.id as u32),
username: self.username,
password: self.password,
banned_until: self.banned,
muted_until: self.muted,
created_at: self.created_at,
flags: self.flags as u32,
guildcard: self.id as u32 + 1,
id: UserAccountId(other.id as u32),
username: other.username,
password: other.password,
banned_until: other.banned,
muted_until: other.muted,
created_at: other.created_at,
flags: other.flags as u32,
guildcard: other.id as u32 + 1,
team_id: None, team_id: None,
activated: self.activated,
at_login: self.at_login,
at_character: self.at_character,
at_ship: self.at_ship,
activated: other.activated,
at_login: other.at_login,
at_character: other.at_character,
at_ship: other.at_ship,
} }
} }
} }
@ -56,19 +56,19 @@ pub struct PgUserSettings {
team_name: Vec<u8>, //[u16; 0x10], team_name: Vec<u8>, //[u16; 0x10],
} }
impl Into<UserSettingsEntity> for PgUserSettings {
fn into(self) -> UserSettingsEntity {
impl From<PgUserSettings> for UserSettingsEntity {
fn from(other: PgUserSettings) -> UserSettingsEntity {
UserSettingsEntity { UserSettingsEntity {
id: UserSettingsId(self.id as u32),
user_id: UserAccountId(self.user_account as u32),
id: UserSettingsId(other.id as u32),
user_id: UserAccountId(other.user_account as u32),
settings: settings::UserSettings { settings: settings::UserSettings {
blocked_users: vec_to_array(self.blocked_users.chunks(4).map(|b| u32::from_le_bytes([b[0], b[1], b[2], b[3]])).collect()),
key_config: vec_to_array(self.key_config),
joystick_config: vec_to_array(self.joystick_config),
option_flags: self.option_flags as u32,
shortcuts: vec_to_array(self.shortcuts),
symbol_chats: vec_to_array(self.symbol_chats),
team_name: vec_to_array(self.team_name.chunks(2).map(|b| u16::from_le_bytes([b[0], b[1]])).collect()),
blocked_users: vec_to_array(other.blocked_users.chunks(4).map(|b| u32::from_le_bytes([b[0], b[1], b[2], b[3]])).collect()),
key_config: vec_to_array(other.key_config),
joystick_config: vec_to_array(other.joystick_config),
option_flags: other.option_flags as u32,
shortcuts: vec_to_array(other.shortcuts),
symbol_chats: vec_to_array(other.symbol_chats),
team_name: vec_to_array(other.team_name.chunks(2).map(|b| u16::from_le_bytes([b[0], b[1]])).collect()),
} }
} }
} }
@ -91,9 +91,9 @@ pub enum PgCharacterClass {
FOnewearl, FOnewearl,
} }
impl Into<CharacterClass> for PgCharacterClass {
fn into(self) -> CharacterClass {
match self {
impl From<PgCharacterClass> for CharacterClass {
fn from(other: PgCharacterClass) -> CharacterClass {
match other{
PgCharacterClass::HUmar => CharacterClass::HUmar, PgCharacterClass::HUmar => CharacterClass::HUmar,
PgCharacterClass::HUnewearl => CharacterClass::HUnewearl, PgCharacterClass::HUnewearl => CharacterClass::HUnewearl,
PgCharacterClass::HUcast => CharacterClass::HUcast, PgCharacterClass::HUcast => CharacterClass::HUcast,
@ -144,9 +144,9 @@ pub enum PgSectionId {
Whitill, Whitill,
} }
impl Into<SectionID> for PgSectionId {
fn into(self) -> SectionID {
match self {
impl From<PgSectionId> for SectionID {
fn from(other: PgSectionId) -> SectionID {
match other {
PgSectionId::Viridia => SectionID::Viridia, PgSectionId::Viridia => SectionID::Viridia,
PgSectionId::Greenill => SectionID::Greenill, PgSectionId::Greenill => SectionID::Greenill,
PgSectionId::Skyly => SectionID::Skyly, PgSectionId::Skyly => SectionID::Skyly,
@ -220,55 +220,55 @@ pub struct PgCharacter {
bank_meseta: i32, bank_meseta: i32,
} }
impl Into<CharacterEntity> for PgCharacter {
fn into(self) -> CharacterEntity {
impl From<PgCharacter> for CharacterEntity {
fn from(other: PgCharacter) -> CharacterEntity {
CharacterEntity { CharacterEntity {
id: CharacterEntityId(self.id as u32),
user_id: UserAccountId(self.user_account as u32),
slot: self.slot as u32,
name: self.name,
exp: self.exp as u32,
char_class: self.class.parse().unwrap(),
section_id: self.section_id.parse().unwrap(),
id: CharacterEntityId(other.id as u32),
user_id: UserAccountId(other.user_account as u32),
slot: other.slot as u32,
name: other.name,
exp: other.exp as u32,
char_class: other.class.parse().unwrap(),
section_id: other.section_id.parse().unwrap(),
appearance: CharacterAppearance { appearance: CharacterAppearance {
costume: self.costume as u16,
skin: self.skin as u16,
face: self.face as u16,
head: self.head as u16,
hair: self.hair as u16,
hair_r: self.hair_r as u16,
hair_g: self.hair_g as u16,
hair_b: self.hair_b as u16,
prop_x: self.prop_x,
prop_y: self.prop_y,
costume: other.costume as u16,
skin: other.skin as u16,
face: other.face as u16,
head: other.head as u16,
hair: other.hair as u16,
hair_r: other.hair_r as u16,
hair_g: other.hair_g as u16,
hair_b: other.hair_b as u16,
prop_x: other.prop_x,
prop_y: other.prop_y,
}, },
techs: CharacterTechniques { techs: CharacterTechniques {
techs: self.techs.iter().enumerate().take(19).filter(|(_, t)| **t != 0xFF).map(|(i, t)| (tech::Technique::from_value(i as u8), TechLevel(*t)) ).collect()
techs: other.techs.iter().enumerate().take(19).filter(|(_, t)| **t != 0xFF).map(|(i, t)| (tech::Technique::from_value(i as u8), TechLevel(*t)) ).collect()
}, },
config: CharacterConfig { config: CharacterConfig {
raw_data: vec_to_array(self.config)
raw_data: vec_to_array(other.config)
}, },
info_board: CharacterInfoboard { info_board: CharacterInfoboard {
board: libpso::utf8_to_utf16_array!(self.infoboard, 172),
board: libpso::utf8_to_utf16_array!(other.infoboard, 172),
}, },
guildcard: CharacterGuildCard { guildcard: CharacterGuildCard {
description: self.guildcard,
description: other.guildcard,
}, },
option_flags: self.option_flags as u32,
option_flags: other.option_flags as u32,
materials: CharacterMaterials { materials: CharacterMaterials {
power: self.power as u32,
mind: self.mind as u32,
def: self.def as u32,
evade: self.evade as u32,
luck: self.luck as u32,
hp: self.hp as u32,
tp: self.tp as u32,
power: other.power as u32,
mind: other.mind as u32,
def: other.def as u32,
evade: other.evade as u32,
luck: other.luck as u32,
hp: other.hp as u32,
tp: other.tp as u32,
}, },
tech_menu: CharacterTechMenu { tech_menu: CharacterTechMenu {
tech_menu: vec_to_array(self.tech_menu)
tech_menu: vec_to_array(other.tech_menu)
}, },
meseta: self.meseta as u32,
bank_meseta: self.bank_meseta as u32,
meseta: other.meseta as u32,
bank_meseta: other.bank_meseta as u32,
} }
} }
} }
@ -300,10 +300,10 @@ impl From<weapon::Weapon> for PgWeapon {
} }
} }
impl Into<weapon::Weapon> for PgWeapon {
fn into(self) -> weapon::Weapon {
impl From<PgWeapon> for weapon::Weapon {
fn from(other: PgWeapon) -> weapon::Weapon {
let mut attrs: [Option<weapon::WeaponAttribute>; 3] = [None; 3]; let mut attrs: [Option<weapon::WeaponAttribute>; 3] = [None; 3];
for (attr, (atype, value)) in attrs.iter_mut().zip(self.attrs.iter()) {
for (attr, (atype, value)) in attrs.iter_mut().zip(other.attrs.iter()) {
*attr = Some(weapon::WeaponAttribute { *attr = Some(weapon::WeaponAttribute {
attr: *atype, attr: *atype,
value: *value value: *value
@ -311,11 +311,11 @@ impl Into<weapon::Weapon> for PgWeapon {
} }
weapon::Weapon { weapon::Weapon {
weapon: self.weapon,
special: self.special,
grind: self.grind,
weapon: other.weapon,
special: other.special,
grind: other.grind,
attrs: attrs, attrs: attrs,
tekked: self.tekked,
tekked: other.tekked,
} }
} }
} }
@ -345,13 +345,13 @@ impl From<armor::Armor> for PgArmor {
} }
} }
impl Into<armor::Armor> for PgArmor {
fn into(self) -> armor::Armor {
impl From<PgArmor> for armor::Armor {
fn from(other: PgArmor) -> armor::Armor {
armor::Armor { armor::Armor {
armor: self.armor,
dfp: self.dfp,
evp: self.evp,
slots: self.slots,
armor: other.armor,
dfp: other.dfp,
evp: other.evp,
slots: other.slots,
} }
} }
} }
@ -373,12 +373,12 @@ impl From<shield::Shield> for PgShield {
} }
} }
impl Into<shield::Shield> for PgShield {
fn into(self) -> shield::Shield {
impl From<PgShield> for shield::Shield {
fn from(other: PgShield) -> shield::Shield {
shield::Shield { shield::Shield {
shield: self.shield,
dfp: self.dfp,
evp: self.evp,
shield: other.shield,
dfp: other.dfp,
evp: other.evp,
} }
} }
} }
@ -398,11 +398,11 @@ impl From<unit::Unit> for PgUnit {
} }
} }
impl Into<unit::Unit> for PgUnit {
fn into(self) -> unit::Unit {
impl From<PgUnit> for unit::Unit {
fn from(other: PgUnit) -> unit::Unit {
unit::Unit { unit::Unit {
unit: self.unit,
modifier: self.modifier,
unit: other.unit,
modifier: other.modifier,
} }
} }
} }
@ -420,10 +420,10 @@ impl From<tool::Tool> for PgTool {
} }
} }
impl Into<tool::Tool> for PgTool {
fn into(self) -> tool::Tool {
impl From<PgTool> for tool::Tool {
fn from(other: PgTool) -> tool::Tool {
tool::Tool { tool::Tool {
tool: self.tool,
tool: other.tool,
} }
} }
} }
@ -443,11 +443,11 @@ impl From<tech::TechniqueDisk> for PgTechDisk {
} }
} }
impl Into<tech::TechniqueDisk> for PgTechDisk {
fn into(self) -> tech::TechniqueDisk {
impl From<PgTechDisk> for tech::TechniqueDisk {
fn from(other: PgTechDisk) -> tech::TechniqueDisk {
tech::TechniqueDisk { tech::TechniqueDisk {
tech: self.tech,
level: self.level
tech: other.tech,
level: other.level
} }
} }
} }
@ -469,8 +469,8 @@ impl From<mag::Mag> for PgMag {
} }
} }
impl Into<mag::Mag> for PgMag {
fn into(self) -> mag::Mag {
impl From<PgMag> for mag::Mag {
fn from(other: PgMag) -> mag::Mag {
/*mag::Mag { /*mag::Mag {
mag: self.mag, mag: self.mag,
synchro: self.synchro, synchro: self.synchro,
@ -484,9 +484,9 @@ impl Into<mag::Mag> for PgMag {
class: CharacterClass::HUmar, class: CharacterClass::HUmar,
id: SectionID::Viridia, id: SectionID::Viridia,
}*/ }*/
let mut mag = mag::Mag::baby_mag(self.color as u16);
mag.mag = self.mag;
mag.synchro = self.synchro;
let mut mag = mag::Mag::baby_mag(other.color as u16);
mag.mag = other.mag;
mag.synchro = other.synchro;
mag mag
} }
} }
@ -510,13 +510,13 @@ impl From<esweapon::ESWeapon> for PgESWeapon {
} }
} }
impl Into<esweapon::ESWeapon> for PgESWeapon {
fn into(self) -> esweapon::ESWeapon {
impl From<PgESWeapon> for esweapon::ESWeapon {
fn from(other: PgESWeapon) -> esweapon::ESWeapon {
esweapon::ESWeapon { esweapon::ESWeapon {
esweapon: self.esweapon,
special: self.special,
name: self.name,
grind: self.grind,
esweapon: other.esweapon,
special: other.special,
name: other.name,
grind: other.grind,
} }
} }
} }
@ -548,9 +548,9 @@ impl From<ItemDetail> for PgItemDetail {
} }
} }
impl Into<ItemDetail> for PgItemDetail {
fn into(self) -> ItemDetail {
match self {
impl From<PgItemDetail> for ItemDetail {
fn from(other: PgItemDetail) -> ItemDetail {
match other {
PgItemDetail::Weapon(weapon) => ItemDetail::Weapon(weapon.into()), PgItemDetail::Weapon(weapon) => ItemDetail::Weapon(weapon.into()),
PgItemDetail::Armor(armor) => ItemDetail::Armor(armor.into()), PgItemDetail::Armor(armor) => ItemDetail::Armor(armor.into()),
PgItemDetail::Shield(shield) => ItemDetail::Shield(shield.into()), PgItemDetail::Shield(shield) => ItemDetail::Shield(shield.into()),
@ -613,9 +613,9 @@ impl From<ItemLocation> for PgItemLocationDetail {
} }
} }
impl Into<ItemLocation> for PgItemLocationDetail {
fn into(self) -> ItemLocation {
match self {
impl From<PgItemLocationDetail> for ItemLocation {
fn from(other: PgItemLocationDetail) -> ItemLocation {
match other{
PgItemLocationDetail::Inventory{character_id} => ItemLocation::Inventory{character_id: CharacterEntityId(character_id)}, PgItemLocationDetail::Inventory{character_id} => ItemLocation::Inventory{character_id: CharacterEntityId(character_id)},
PgItemLocationDetail::Bank{character_id, name} => ItemLocation::Bank{character_id: CharacterEntityId(character_id), name: BankName(name)}, PgItemLocationDetail::Bank{character_id, name} => ItemLocation::Bank{character_id: CharacterEntityId(character_id), name: BankName(name)},
PgItemLocationDetail::LocalFloor{character_id, map_area, x,y,z} => ItemLocation::LocalFloor{character_id: CharacterEntityId(character_id), map_area, x,y,z}, PgItemLocationDetail::LocalFloor{character_id, map_area, x,y,z} => ItemLocation::LocalFloor{character_id: CharacterEntityId(character_id), map_area, x,y,z},
@ -655,9 +655,9 @@ impl From<mag::MagModifier> for PgMagModifierDetail {
} }
} }
impl Into<mag::MagModifier> for PgMagModifierDetail {
fn into(self) -> mag::MagModifier {
match self {
impl From<PgMagModifierDetail> for mag::MagModifier {
fn from(other: PgMagModifierDetail) -> mag::MagModifier {
match other {
PgMagModifierDetail::FeedMag(food) => mag::MagModifier::FeedMag{food: ItemEntityId(food as u32)}, PgMagModifierDetail::FeedMag(food) => mag::MagModifier::FeedMag{food: ItemEntityId(food as u32)},
PgMagModifierDetail::BankMag => mag::MagModifier::BankMag, PgMagModifierDetail::BankMag => mag::MagModifier::BankMag,
PgMagModifierDetail::MagCell(cell) => mag::MagModifier::MagCell(ItemEntityId(cell as u32)), PgMagModifierDetail::MagCell(cell) => mag::MagModifier::MagCell(ItemEntityId(cell as u32)),
@ -687,12 +687,12 @@ pub struct PgItemWithLocation {
pub location: sqlx::types::Json<PgItemLocationDetail>, pub location: sqlx::types::Json<PgItemLocationDetail>,
} }
impl Into<ItemEntity> for PgItemWithLocation {
fn into(self) -> ItemEntity {
impl From<PgItemWithLocation> for ItemEntity {
fn from(other: PgItemWithLocation) -> ItemEntity {
ItemEntity { ItemEntity {
id: ItemEntityId(self.id as u32),
item: self.item.0.into(),
location: self.location.0.into(),
id: ItemEntityId(other.id as u32),
item: other.item.0.into(),
location: other.location.0.into(),
} }
} }
} }
@ -740,18 +740,18 @@ pub struct PgEquipped {
mag: Option<i32>, mag: Option<i32>,
} }
impl Into<EquippedEntity> for PgEquipped {
fn into(self) -> EquippedEntity {
impl From<PgEquipped> for EquippedEntity{
fn from(other: PgEquipped) -> EquippedEntity {
EquippedEntity { EquippedEntity {
weapon: self.weapon.map(|i| ItemEntityId(i as u32)),
armor: self.armor.map(|i| ItemEntityId(i as u32)),
shield: self.shield.map(|i| ItemEntityId(i as u32)),
unit: [self.unit0.map(|i| ItemEntityId(i as u32)),
self.unit1.map(|i| ItemEntityId(i as u32)),
self.unit2.map(|i| ItemEntityId(i as u32)),
self.unit3.map(|i| ItemEntityId(i as u32)),
weapon: other.weapon.map(|i| ItemEntityId(i as u32)),
armor: other.armor.map(|i| ItemEntityId(i as u32)),
shield: other.shield.map(|i| ItemEntityId(i as u32)),
unit: [other.unit0.map(|i| ItemEntityId(i as u32)),
other.unit1.map(|i| ItemEntityId(i as u32)),
other.unit2.map(|i| ItemEntityId(i as u32)),
other.unit3.map(|i| ItemEntityId(i as u32)),
], ],
mag: self.mag.map(|i| ItemEntityId(i as u32)),
mag: other.mag.map(|i| ItemEntityId(i as u32)),
} }
} }
} }

8
src/entity/gateway/postgres/postgres.rs

@ -25,10 +25,10 @@ pub struct PostgresGateway {
impl PostgresGateway { impl PostgresGateway {
pub fn new(host: &str, dbname: &str, username: &str, password: &str) -> PostgresGateway { pub fn new(host: &str, dbname: &str, username: &str, password: &str) -> PostgresGateway {
let mut conn = refinery::config::Config::new(refinery::config::ConfigDbType::Postgres) let mut conn = refinery::config::Config::new(refinery::config::ConfigDbType::Postgres)
.set_db_host(&host)
.set_db_user(&username)
.set_db_pass(&password)
.set_db_name(&dbname);
.set_db_host(host)
.set_db_user(username)
.set_db_pass(password)
.set_db_name(dbname);
embedded::migrations::runner().run(&mut conn).unwrap(); embedded::migrations::runner().run(&mut conn).unwrap();
let pool = async_std::task::block_on(async move { let pool = async_std::task::block_on(async move {

2
src/login/character.rs

@ -858,7 +858,7 @@ mod test {
#[async_std::test] #[async_std::test]
async fn test_character_create() { async fn test_character_create() {
let test_data = InMemoryGateway::new();
let test_data = InMemoryGateway::default();
let mut fake_user = ClientState::new(); let mut fake_user = ClientState::new();
fake_user.user = Some(UserAccountEntity { fake_user.user = Some(UserAccountEntity {
id: UserAccountId(3), id: UserAccountId(3),

52
tests/test_bank.rs

@ -13,7 +13,7 @@ use common::*;
#[async_std::test] #[async_std::test]
async fn test_bank_items_sent_in_character_login() { async fn test_bank_items_sent_in_character_login() {
let mut entity_gateway = InMemoryGateway::new();
let mut entity_gateway = InMemoryGateway::default();
let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "a").await; let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "a").await;
@ -52,7 +52,7 @@ async fn test_bank_items_sent_in_character_login() {
#[async_std::test] #[async_std::test]
async fn test_request_bank_items() { async fn test_request_bank_items() {
let mut entity_gateway = InMemoryGateway::new();
let mut entity_gateway = InMemoryGateway::default();
let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "a").await; let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "a").await;
@ -104,7 +104,7 @@ async fn test_request_bank_items() {
#[async_std::test] #[async_std::test]
async fn test_request_stacked_bank_items() { async fn test_request_stacked_bank_items() {
let mut entity_gateway = InMemoryGateway::new();
let mut entity_gateway = InMemoryGateway::default();
let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "a").await; let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "a").await;
@ -151,7 +151,7 @@ async fn test_request_stacked_bank_items() {
#[async_std::test] #[async_std::test]
async fn test_request_bank_items_sorted() { async fn test_request_bank_items_sorted() {
let mut entity_gateway = InMemoryGateway::new();
let mut entity_gateway = InMemoryGateway::default();
let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "a").await; let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "a").await;
@ -229,7 +229,7 @@ async fn test_request_bank_items_sorted() {
#[async_std::test] #[async_std::test]
async fn test_deposit_individual_item() { async fn test_deposit_individual_item() {
let mut entity_gateway = InMemoryGateway::new();
let mut entity_gateway = InMemoryGateway::default();
let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "a").await; let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "a").await;
@ -308,7 +308,7 @@ async fn test_deposit_individual_item() {
#[async_std::test] #[async_std::test]
async fn test_deposit_stacked_item() { async fn test_deposit_stacked_item() {
let mut entity_gateway = InMemoryGateway::new();
let mut entity_gateway = InMemoryGateway::default();
let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "a").await; let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "a").await;
@ -372,7 +372,7 @@ async fn test_deposit_stacked_item() {
#[async_std::test] #[async_std::test]
async fn test_deposit_partial_stacked_item() { async fn test_deposit_partial_stacked_item() {
let mut entity_gateway = InMemoryGateway::new();
let mut entity_gateway = InMemoryGateway::default();
let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "a").await; let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "a").await;
@ -445,7 +445,7 @@ async fn test_deposit_partial_stacked_item() {
#[async_std::test] #[async_std::test]
async fn test_deposit_stacked_item_with_stack_already_in_bank() { async fn test_deposit_stacked_item_with_stack_already_in_bank() {
let mut entity_gateway = InMemoryGateway::new();
let mut entity_gateway = InMemoryGateway::default();
let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "a").await; let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "a").await;
@ -524,7 +524,7 @@ async fn test_deposit_stacked_item_with_stack_already_in_bank() {
#[async_std::test] #[async_std::test]
async fn test_deposit_stacked_item_with_full_stack_in_bank() { async fn test_deposit_stacked_item_with_full_stack_in_bank() {
let mut entity_gateway = InMemoryGateway::new();
let mut entity_gateway = InMemoryGateway::default();
let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
@ -603,7 +603,7 @@ async fn test_deposit_stacked_item_with_full_stack_in_bank() {
#[async_std::test] #[async_std::test]
async fn test_deposit_individual_item_in_full_bank() { async fn test_deposit_individual_item_in_full_bank() {
let mut entity_gateway = InMemoryGateway::new();
let mut entity_gateway = InMemoryGateway::default();
let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
@ -684,7 +684,7 @@ async fn test_deposit_individual_item_in_full_bank() {
#[async_std::test] #[async_std::test]
async fn test_deposit_stacked_item_in_full_bank() { async fn test_deposit_stacked_item_in_full_bank() {
let mut entity_gateway = InMemoryGateway::new();
let mut entity_gateway = InMemoryGateway::default();
let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
@ -764,7 +764,7 @@ async fn test_deposit_stacked_item_in_full_bank() {
#[async_std::test] #[async_std::test]
async fn test_deposit_stacked_item_in_full_bank_with_partial_stack() { async fn test_deposit_stacked_item_in_full_bank_with_partial_stack() {
let mut entity_gateway = InMemoryGateway::new();
let mut entity_gateway = InMemoryGateway::default();
let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
@ -858,7 +858,7 @@ async fn test_deposit_stacked_item_in_full_bank_with_partial_stack() {
#[async_std::test] #[async_std::test]
async fn test_deposit_meseta() { async fn test_deposit_meseta() {
let mut entity_gateway = InMemoryGateway::new();
let mut entity_gateway = InMemoryGateway::default();
let (user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a").await; let (user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
char1.meseta = 300; char1.meseta = 300;
@ -895,7 +895,7 @@ async fn test_deposit_meseta() {
#[async_std::test] #[async_std::test]
async fn test_deposit_too_much_meseta() { async fn test_deposit_too_much_meseta() {
let mut entity_gateway = InMemoryGateway::new();
let mut entity_gateway = InMemoryGateway::default();
let (user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a").await; let (user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
char1.meseta = 300; char1.meseta = 300;
@ -934,7 +934,7 @@ async fn test_deposit_too_much_meseta() {
#[async_std::test] #[async_std::test]
async fn test_deposit_meseta_when_bank_is_maxed() { async fn test_deposit_meseta_when_bank_is_maxed() {
let mut entity_gateway = InMemoryGateway::new();
let mut entity_gateway = InMemoryGateway::default();
let (user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a").await; let (user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
char1.meseta = 300; char1.meseta = 300;
@ -973,7 +973,7 @@ async fn test_deposit_meseta_when_bank_is_maxed() {
#[async_std::test] #[async_std::test]
async fn test_withdraw_individual_item() { async fn test_withdraw_individual_item() {
let mut entity_gateway = InMemoryGateway::new();
let mut entity_gateway = InMemoryGateway::default();
let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "a").await; let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "a").await;
@ -1039,7 +1039,7 @@ async fn test_withdraw_individual_item() {
#[async_std::test] #[async_std::test]
async fn test_withdraw_stacked_item() { async fn test_withdraw_stacked_item() {
let mut entity_gateway = InMemoryGateway::new();
let mut entity_gateway = InMemoryGateway::default();
let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "a").await; let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "a").await;
@ -1103,7 +1103,7 @@ async fn test_withdraw_stacked_item() {
#[async_std::test] #[async_std::test]
async fn test_withdraw_partial_stacked_item() { async fn test_withdraw_partial_stacked_item() {
let mut entity_gateway = InMemoryGateway::new();
let mut entity_gateway = InMemoryGateway::default();
let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "a").await; let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "a").await;
@ -1173,7 +1173,7 @@ async fn test_withdraw_partial_stacked_item() {
#[async_std::test] #[async_std::test]
async fn test_withdraw_stacked_item_with_stack_already_in_inventory() { async fn test_withdraw_stacked_item_with_stack_already_in_inventory() {
let mut entity_gateway = InMemoryGateway::new();
let mut entity_gateway = InMemoryGateway::default();
let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "a").await; let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "a").await;
@ -1254,7 +1254,7 @@ async fn test_withdraw_stacked_item_with_stack_already_in_inventory() {
#[async_std::test] #[async_std::test]
async fn test_withdraw_stacked_item_with_full_stack_in_inventory() { async fn test_withdraw_stacked_item_with_full_stack_in_inventory() {
let mut entity_gateway = InMemoryGateway::new();
let mut entity_gateway = InMemoryGateway::default();
let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
@ -1333,7 +1333,7 @@ async fn test_withdraw_stacked_item_with_full_stack_in_inventory() {
#[async_std::test] #[async_std::test]
async fn test_withdraw_individual_item_in_full_inventory() { async fn test_withdraw_individual_item_in_full_inventory() {
let mut entity_gateway = InMemoryGateway::new();
let mut entity_gateway = InMemoryGateway::default();
let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
@ -1410,7 +1410,7 @@ async fn test_withdraw_individual_item_in_full_inventory() {
#[async_std::test] #[async_std::test]
async fn test_withdraw_stacked_item_in_full_inventory() { async fn test_withdraw_stacked_item_in_full_inventory() {
let mut entity_gateway = InMemoryGateway::new();
let mut entity_gateway = InMemoryGateway::default();
let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
@ -1491,7 +1491,7 @@ async fn test_withdraw_stacked_item_in_full_inventory() {
#[async_std::test] #[async_std::test]
async fn test_withdraw_stacked_item_in_full_inventory_with_partial_stack() { async fn test_withdraw_stacked_item_in_full_inventory_with_partial_stack() {
let mut entity_gateway = InMemoryGateway::new();
let mut entity_gateway = InMemoryGateway::default();
let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
@ -1587,7 +1587,7 @@ async fn test_withdraw_stacked_item_in_full_inventory_with_partial_stack() {
#[async_std::test] #[async_std::test]
async fn test_withdraw_meseta() { async fn test_withdraw_meseta() {
let mut entity_gateway = InMemoryGateway::new();
let mut entity_gateway = InMemoryGateway::default();
let (user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a").await; let (user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
char1.bank_meseta = 300; char1.bank_meseta = 300;
@ -1624,7 +1624,7 @@ async fn test_withdraw_meseta() {
#[async_std::test] #[async_std::test]
async fn test_withdraw_too_much_meseta() { async fn test_withdraw_too_much_meseta() {
let mut entity_gateway = InMemoryGateway::new();
let mut entity_gateway = InMemoryGateway::default();
let (user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a").await; let (user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
char1.meseta = 999980; char1.meseta = 999980;
@ -1662,7 +1662,7 @@ async fn test_withdraw_too_much_meseta() {
#[async_std::test] #[async_std::test]
async fn test_withdraw_meseta_inventory_is_maxed() { async fn test_withdraw_meseta_inventory_is_maxed() {
let mut entity_gateway = InMemoryGateway::new();
let mut entity_gateway = InMemoryGateway::default();
let (user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a").await; let (user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
char1.meseta = 999999; char1.meseta = 999999;

2
tests/test_character.rs

@ -10,7 +10,7 @@ use common::*;
#[async_std::test] #[async_std::test]
async fn test_save_options() { async fn test_save_options() {
let mut entity_gateway = InMemoryGateway::new();
let mut entity_gateway = InMemoryGateway::default();
let (user1, _char1) = new_user_character(&mut entity_gateway, "a1", "a").await; let (user1, _char1) = new_user_character(&mut entity_gateway, "a1", "a").await;

8
tests/test_exp_gain.rs

@ -13,7 +13,7 @@ use common::*;
#[async_std::test] #[async_std::test]
async fn test_character_gains_exp() { async fn test_character_gains_exp() {
let mut entity_gateway = InMemoryGateway::new();
let mut entity_gateway = InMemoryGateway::default();
let (_user1, _char1) = new_user_character(&mut entity_gateway, "a1", "a").await; let (_user1, _char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
@ -50,7 +50,7 @@ async fn test_character_gains_exp() {
#[async_std::test] #[async_std::test]
async fn test_character_levels_up() { async fn test_character_levels_up() {
let mut entity_gateway = InMemoryGateway::new();
let mut entity_gateway = InMemoryGateway::default();
let (_user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a").await; let (_user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
char1.exp = 49; char1.exp = 49;
@ -90,7 +90,7 @@ async fn test_character_levels_up() {
#[async_std::test] #[async_std::test]
async fn test_character_levels_up_multiple_times() { async fn test_character_levels_up_multiple_times() {
let mut entity_gateway = InMemoryGateway::new();
let mut entity_gateway = InMemoryGateway::default();
let (_user1, _char1) = new_user_character(&mut entity_gateway, "a1", "a").await; let (_user1, _char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
@ -134,7 +134,7 @@ async fn test_character_levels_up_multiple_times() {
#[async_std::test] #[async_std::test]
async fn test_one_character_gets_full_exp_and_other_attacker_gets_partial() { async fn test_one_character_gets_full_exp_and_other_attacker_gets_partial() {
let mut entity_gateway = InMemoryGateway::new();
let mut entity_gateway = InMemoryGateway::default();
let (_user1, _char1) = new_user_character(&mut entity_gateway, "a1", "a").await; let (_user1, _char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "a").await; let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "a").await;

6
tests/test_item_actions.rs

@ -12,7 +12,7 @@ use common::*;
#[async_std::test] #[async_std::test]
async fn test_equip_unit_from_equip_menu() { async fn test_equip_unit_from_equip_menu() {
let mut entity_gateway = InMemoryGateway::new();
let mut entity_gateway = InMemoryGateway::default();
let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
@ -98,7 +98,7 @@ async fn test_equip_unit_from_equip_menu() {
#[async_std::test] #[async_std::test]
async fn test_unequip_armor_with_units() { async fn test_unequip_armor_with_units() {
let mut entity_gateway = InMemoryGateway::new();
let mut entity_gateway = InMemoryGateway::default();
let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
@ -175,7 +175,7 @@ async fn test_unequip_armor_with_units() {
#[async_std::test] #[async_std::test]
async fn test_sort_items() { async fn test_sort_items() {
let mut entity_gateway = InMemoryGateway::new();
let mut entity_gateway = InMemoryGateway::default();
let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;

20
tests/test_item_pickup.rs

@ -12,7 +12,7 @@ use common::*;
#[async_std::test] #[async_std::test]
async fn test_pick_up_item_stack_of_items_already_in_inventory() { async fn test_pick_up_item_stack_of_items_already_in_inventory() {
let mut entity_gateway = InMemoryGateway::new();
let mut entity_gateway = InMemoryGateway::default();
let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a").await; let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a").await;
@ -94,7 +94,7 @@ async fn test_pick_up_item_stack_of_items_already_in_inventory() {
#[async_std::test] #[async_std::test]
async fn test_pick_up_item_stack_of_items_not_already_held() { async fn test_pick_up_item_stack_of_items_not_already_held() {
let mut entity_gateway = InMemoryGateway::new();
let mut entity_gateway = InMemoryGateway::default();
let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a").await; let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a").await;
@ -156,7 +156,7 @@ async fn test_pick_up_item_stack_of_items_not_already_held() {
#[async_std::test] #[async_std::test]
async fn test_pick_up_meseta_when_inventory_full() { async fn test_pick_up_meseta_when_inventory_full() {
let mut entity_gateway = InMemoryGateway::new();
let mut entity_gateway = InMemoryGateway::default();
let (user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; let (user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
let (user2, mut char2) = new_user_character(&mut entity_gateway, "a2", "a").await; let (user2, mut char2) = new_user_character(&mut entity_gateway, "a2", "a").await;
@ -235,7 +235,7 @@ async fn test_pick_up_meseta_when_inventory_full() {
#[async_std::test] #[async_std::test]
async fn test_pick_up_partial_stacked_item_when_inventory_is_otherwise_full() { async fn test_pick_up_partial_stacked_item_when_inventory_is_otherwise_full() {
let mut entity_gateway = InMemoryGateway::new();
let mut entity_gateway = InMemoryGateway::default();
let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a").await; let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a").await;
@ -327,7 +327,7 @@ async fn test_pick_up_partial_stacked_item_when_inventory_is_otherwise_full() {
#[async_std::test] #[async_std::test]
async fn test_can_not_pick_up_item_when_inventory_full() { async fn test_can_not_pick_up_item_when_inventory_full() {
let mut entity_gateway = InMemoryGateway::new();
let mut entity_gateway = InMemoryGateway::default();
let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a").await; let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a").await;
@ -423,7 +423,7 @@ async fn test_can_not_pick_up_item_when_inventory_full() {
#[async_std::test] #[async_std::test]
async fn test_can_not_drop_more_meseta_than_is_held() { async fn test_can_not_drop_more_meseta_than_is_held() {
let mut entity_gateway = InMemoryGateway::new();
let mut entity_gateway = InMemoryGateway::default();
let (user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a").await; let (user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
@ -464,7 +464,7 @@ async fn test_can_not_drop_more_meseta_than_is_held() {
#[async_std::test] #[async_std::test]
async fn test_pick_up_stack_that_would_exceed_stack_limit() { async fn test_pick_up_stack_that_would_exceed_stack_limit() {
let mut entity_gateway = InMemoryGateway::new();
let mut entity_gateway = InMemoryGateway::default();
let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a").await; let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a").await;
@ -544,7 +544,7 @@ async fn test_pick_up_stack_that_would_exceed_stack_limit() {
#[async_std::test] #[async_std::test]
async fn test_can_not_pick_up_meseta_when_full() { async fn test_can_not_pick_up_meseta_when_full() {
let mut entity_gateway = InMemoryGateway::new();
let mut entity_gateway = InMemoryGateway::default();
let (user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a").await; let (user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
let (user2, mut char2) = new_user_character(&mut entity_gateway, "a2", "a").await; let (user2, mut char2) = new_user_character(&mut entity_gateway, "a2", "a").await;
@ -602,7 +602,7 @@ async fn test_can_not_pick_up_meseta_when_full() {
#[async_std::test] #[async_std::test]
async fn test_meseta_caps_at_999999_when_trying_to_pick_up_more() { async fn test_meseta_caps_at_999999_when_trying_to_pick_up_more() {
let mut entity_gateway = InMemoryGateway::new();
let mut entity_gateway = InMemoryGateway::default();
let (user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a").await; let (user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
let (user2, mut char2) = new_user_character(&mut entity_gateway, "a2", "a").await; let (user2, mut char2) = new_user_character(&mut entity_gateway, "a2", "a").await;
@ -659,7 +659,7 @@ async fn test_meseta_caps_at_999999_when_trying_to_pick_up_more() {
#[async_std::test] #[async_std::test]
async fn test_player_drops_partial_stack_and_other_player_picks_it_up() { async fn test_player_drops_partial_stack_and_other_player_picks_it_up() {
let mut entity_gateway = InMemoryGateway::new();
let mut entity_gateway = InMemoryGateway::default();
let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a").await; let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a").await;

10
tests/test_item_use.rs

@ -14,7 +14,7 @@ use common::*;
#[async_std::test] #[async_std::test]
async fn test_use_monomate() { async fn test_use_monomate() {
let mut entity_gateway = InMemoryGateway::new();
let mut entity_gateway = InMemoryGateway::default();
let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
@ -64,7 +64,7 @@ async fn test_use_monomate() {
#[async_std::test] #[async_std::test]
async fn test_use_monomate_twice() { async fn test_use_monomate_twice() {
let mut entity_gateway = InMemoryGateway::new();
let mut entity_gateway = InMemoryGateway::default();
let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
@ -119,7 +119,7 @@ async fn test_use_monomate_twice() {
#[async_std::test] #[async_std::test]
async fn test_use_last_monomate() { async fn test_use_last_monomate() {
let mut entity_gateway = InMemoryGateway::new();
let mut entity_gateway = InMemoryGateway::default();
let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
@ -164,7 +164,7 @@ async fn test_use_last_monomate() {
#[async_std::test] #[async_std::test]
async fn test_use_nonstackable_tool() { async fn test_use_nonstackable_tool() {
let mut entity_gateway = InMemoryGateway::new();
let mut entity_gateway = InMemoryGateway::default();
let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
@ -202,7 +202,7 @@ async fn test_use_nonstackable_tool() {
#[async_std::test] #[async_std::test]
async fn test_use_materials() { async fn test_use_materials() {
let mut entity_gateway = InMemoryGateway::new();
let mut entity_gateway = InMemoryGateway::default();
let (user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; let (user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;

6
tests/test_mags.rs

@ -13,7 +13,7 @@ use common::*;
#[async_std::test] #[async_std::test]
async fn test_mag_feed() { async fn test_mag_feed() {
let mut entity_gateway = InMemoryGateway::new();
let mut entity_gateway = InMemoryGateway::default();
let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
@ -92,7 +92,7 @@ async fn test_mag_feed() {
#[async_std::test] #[async_std::test]
async fn test_mag_change_owner() { async fn test_mag_change_owner() {
let mut entity_gateway = InMemoryGateway::new();
let mut entity_gateway = InMemoryGateway::default();
let (_user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a").await; let (_user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
let (_user2, mut char2) = new_user_character(&mut entity_gateway, "a2", "a").await; let (_user2, mut char2) = new_user_character(&mut entity_gateway, "a2", "a").await;
@ -160,7 +160,7 @@ async fn test_mag_change_owner() {
#[async_std::test] #[async_std::test]
async fn test_mag_cell() { async fn test_mag_cell() {
let mut entity_gateway = InMemoryGateway::new();
let mut entity_gateway = InMemoryGateway::default();
let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;

2
tests/test_rooms.rs

@ -13,7 +13,7 @@ use common::*;
#[async_std::test] #[async_std::test]
async fn test_item_ids_reset_when_rejoining_rooms() { async fn test_item_ids_reset_when_rejoining_rooms() {
let mut entity_gateway = InMemoryGateway::new();
let mut entity_gateway = InMemoryGateway::default();
let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a").await; let (_user2, char2) = new_user_character(&mut entity_gateway, "a2", "a").await;

26
tests/test_shops.rs

@ -13,7 +13,7 @@ use common::*;
#[async_std::test] #[async_std::test]
async fn test_player_opens_weapon_shop() { async fn test_player_opens_weapon_shop() {
let mut entity_gateway = InMemoryGateway::new();
let mut entity_gateway = InMemoryGateway::default();
let (_user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a").await; let (_user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
char1.exp = 80000000; char1.exp = 80000000;
@ -43,7 +43,7 @@ async fn test_player_opens_weapon_shop() {
#[async_std::test] #[async_std::test]
async fn test_player_opens_tool_shop() { async fn test_player_opens_tool_shop() {
let mut entity_gateway = InMemoryGateway::new();
let mut entity_gateway = InMemoryGateway::default();
let (_user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a").await; let (_user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
char1.exp = 80000000; char1.exp = 80000000;
@ -73,7 +73,7 @@ async fn test_player_opens_tool_shop() {
#[async_std::test] #[async_std::test]
async fn test_player_opens_armor_shop() { async fn test_player_opens_armor_shop() {
let mut entity_gateway = InMemoryGateway::new();
let mut entity_gateway = InMemoryGateway::default();
let (_user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a").await; let (_user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
char1.exp = 80000000; char1.exp = 80000000;
@ -103,7 +103,7 @@ async fn test_player_opens_armor_shop() {
#[async_std::test] #[async_std::test]
async fn test_player_buys_from_weapon_shop() { async fn test_player_buys_from_weapon_shop() {
let mut entity_gateway = InMemoryGateway::new();
let mut entity_gateway = InMemoryGateway::default();
let (user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a").await; let (user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
char1.exp = 80000000; char1.exp = 80000000;
@ -142,7 +142,7 @@ async fn test_player_buys_from_weapon_shop() {
#[async_std::test] #[async_std::test]
async fn test_player_buys_from_tool_shop() { async fn test_player_buys_from_tool_shop() {
let mut entity_gateway = InMemoryGateway::new();
let mut entity_gateway = InMemoryGateway::default();
let (user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a").await; let (user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
char1.exp = 80000000; char1.exp = 80000000;
@ -180,7 +180,7 @@ async fn test_player_buys_from_tool_shop() {
#[async_std::test] #[async_std::test]
async fn test_player_buys_multiple_from_tool_shop() { async fn test_player_buys_multiple_from_tool_shop() {
let mut entity_gateway = InMemoryGateway::new();
let mut entity_gateway = InMemoryGateway::default();
let (user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a").await; let (user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
char1.exp = 80000000; char1.exp = 80000000;
@ -222,7 +222,7 @@ async fn test_player_buys_multiple_from_tool_shop() {
#[async_std::test] #[async_std::test]
async fn test_player_buys_from_armor_shop() { async fn test_player_buys_from_armor_shop() {
let mut entity_gateway = InMemoryGateway::new();
let mut entity_gateway = InMemoryGateway::default();
let (user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a").await; let (user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
char1.exp = 80000000; char1.exp = 80000000;
@ -264,7 +264,7 @@ async fn test_player_sells_to_shop() {
#[async_std::test] #[async_std::test]
async fn test_other_clients_see_purchase() { async fn test_other_clients_see_purchase() {
let mut entity_gateway = InMemoryGateway::new();
let mut entity_gateway = InMemoryGateway::default();
let (_user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a").await; let (_user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "a").await; let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "a").await;
@ -307,7 +307,7 @@ async fn test_other_clients_see_purchase() {
#[async_std::test] #[async_std::test]
async fn test_other_clients_see_stacked_purchase() { async fn test_other_clients_see_stacked_purchase() {
let mut entity_gateway = InMemoryGateway::new();
let mut entity_gateway = InMemoryGateway::default();
let (_user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a").await; let (_user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "a").await; let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "a").await;
@ -361,7 +361,7 @@ async fn test_other_clients_see_stacked_purchase() {
#[async_std::test] #[async_std::test]
async fn test_buying_item_without_enough_mseseta() { async fn test_buying_item_without_enough_mseseta() {
let mut entity_gateway = InMemoryGateway::new();
let mut entity_gateway = InMemoryGateway::default();
let (user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await; let (user1, char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
@ -397,7 +397,7 @@ async fn test_buying_item_without_enough_mseseta() {
#[async_std::test] #[async_std::test]
async fn test_player_double_buys_from_tool_shop() { async fn test_player_double_buys_from_tool_shop() {
let mut entity_gateway = InMemoryGateway::new();
let mut entity_gateway = InMemoryGateway::default();
let (user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a").await; let (user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
char1.exp = 80000000; char1.exp = 80000000;
@ -463,7 +463,7 @@ async fn test_player_double_buys_from_tool_shop() {
#[async_std::test] #[async_std::test]
async fn test_techs_disappear_from_shop_when_bought() { async fn test_techs_disappear_from_shop_when_bought() {
let mut entity_gateway = InMemoryGateway::new();
let mut entity_gateway = InMemoryGateway::default();
let (_user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a").await; let (_user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
char1.exp = 80000000; char1.exp = 80000000;
@ -525,7 +525,7 @@ async fn test_techs_disappear_from_shop_when_bought() {
// TOOD: this is not deterministic and can randomly fail // TOOD: this is not deterministic and can randomly fail
#[async_std::test] #[async_std::test]
async fn test_units_disappear_from_shop_when_bought() { async fn test_units_disappear_from_shop_when_bought() {
let mut entity_gateway = InMemoryGateway::new();
let mut entity_gateway = InMemoryGateway::default();
let (_user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a").await; let (_user1, mut char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
char1.exp = 80000000; char1.exp = 80000000;

Loading…
Cancel
Save