Skip to content

Commit

Permalink
update to v0.4.3; more work on searching with similar names; opt king…
Browse files Browse the repository at this point in the history
…slayer cmdline use
  • Loading branch information
Zaechus committed Oct 29, 2019
1 parent 07822b3 commit f9ed3c3
Show file tree
Hide file tree
Showing 23 changed files with 280 additions and 57 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "kingslayer"
version = "0.4.2"
version = "0.4.3"
authors = ["Maxwell Anderson <[email protected]>"]
edition = "2018"
license = "MIT"
Expand All @@ -13,7 +13,7 @@ exclude = ["*.yml"]

[dependencies]
rand = { version = "0.7", features = ["wasm-bindgen"] }
rayon = "1.0"
rayon = "1.2"
serde = { version = "1.0", features = ["derive"] }
ron = "0.5"
serde_json = "1.0"
Expand Down
35 changes: 33 additions & 2 deletions data/test_world.ron
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,15 @@ rooms: {
),
"door": Pathway(
target: "Closet",
desc: "The door leads back into the room.",
desc: "There is a door off to the side.",
inspect: "The door is plain and wooden.",
opening: Some(Closed)
),
"s": Pathway(
target: "Bedroom",
desc: "There is a doorway to the south.",
inspect: "The doorway is plain and wooden.",
),
},
items: [
Thing(Thing(
Expand Down Expand Up @@ -61,6 +66,32 @@ rooms: {
damage: 6
)),
]
)
),
"Bedroom": Room(
name: "Bedroom",
desc: "You are in a small bedroom.",
paths: {
"n": Pathway(
target: "Central Room",
desc: "There is a doorway to the north.",
inspect: "The doorway is plain and wooden."
),
},
items: [
Container(Container(
name: "large capsule",
desc: "There is a large capsule here.",
inspect: "The capsule appears to be able to hold things.",
opening: Open,
contents: [
Thing(Thing(
name: "red block",
desc: "There is a red block.",
inspect: "It is a red cube."
)),
]
)),
]
),
}
)
4 changes: 1 addition & 3 deletions src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ use std::{

use rayon::prelude::*;

use serde::{Deserialize, Serialize};

use crate::{
entity::Entity,
input::{read_line, Lexer, Parser},
Expand All @@ -18,7 +16,7 @@ use crate::{
};

/// The Cli type provides a simple way to interface into the mechanics of Kingslayer with custom worlds
#[derive(Debug, Serialize, Deserialize)]
#[derive(Debug)]
pub struct Cli {
lexer: Lexer,
player: RefCell<Box<Player>>,
Expand Down
4 changes: 2 additions & 2 deletions src/entity/ally.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use serde::{Deserialize, Serialize};
use serde::Deserialize;

use super::Entity;

#[derive(Debug, Serialize, Deserialize)]
#[derive(Debug, Deserialize)]
pub struct Ally {
name: String,
desc: String,
Expand Down
4 changes: 2 additions & 2 deletions src/entity/closeable.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use serde::{Deserialize, Serialize};
use serde::Deserialize;

use crate::types::CmdResult;

#[derive(Copy, Clone, Debug, Serialize, Deserialize)]
#[derive(Copy, Clone, Debug, Deserialize)]
pub enum Opening {
Open,
Closed,
Expand Down
4 changes: 2 additions & 2 deletions src/entity/enemy.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use rand::Rng;

use serde::{Deserialize, Serialize};
use serde::Deserialize;

use super::Entity;
use crate::types::Items;

#[derive(Debug, Serialize, Deserialize)]
#[derive(Debug, Deserialize)]
pub struct Enemy {
name: String,
desc: String,
Expand Down
4 changes: 2 additions & 2 deletions src/entity/item/armor.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use serde::{Deserialize, Serialize};
use serde::Deserialize;

use crate::entity::Entity;

// An object to be interacted with by the user
#[derive(Debug, Serialize, Deserialize)]
#[derive(Debug, Deserialize)]
pub struct Armor {
name: String,
desc: String,
Expand Down
4 changes: 2 additions & 2 deletions src/entity/item/container.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use rayon::prelude::*;

use serde::{Deserialize, Serialize};
use serde::Deserialize;

use super::Item;
use crate::{
Expand All @@ -9,7 +9,7 @@ use crate::{
};

// An object to be interacted with by the user
#[derive(Debug, Serialize, Deserialize)]
#[derive(Debug, Deserialize)]
pub struct Container {
name: String,
desc: String,
Expand Down
4 changes: 2 additions & 2 deletions src/entity/item/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use serde::{Deserialize, Serialize};
use serde::Deserialize;

use crate::entity::Entity;

Expand All @@ -12,7 +12,7 @@ pub use container::Container;
pub use thing::Thing;
pub use weapon::Weapon;

#[derive(Debug, Serialize, Deserialize)]
#[derive(Debug, Deserialize)]
pub enum Item {
Armor(Armor),
Container(Container),
Expand Down
4 changes: 2 additions & 2 deletions src/entity/item/thing.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use serde::{Deserialize, Serialize};
use serde::Deserialize;

use crate::entity::Entity;

// An object to be interacted with by the user
#[derive(Debug, Serialize, Deserialize)]
#[derive(Debug, Deserialize)]
pub struct Thing {
name: String,
desc: String,
Expand Down
4 changes: 2 additions & 2 deletions src/entity/item/weapon.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use rand::Rng;

use serde::{Deserialize, Serialize};
use serde::Deserialize;

use crate::entity::Entity;

// An object to be interacted with by the user
#[derive(Debug, Serialize, Deserialize)]
#[derive(Debug, Deserialize)]
pub struct Weapon {
name: String,
desc: String,
Expand Down
4 changes: 2 additions & 2 deletions src/entity/pathway.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use serde::{Deserialize, Serialize};
use serde::Deserialize;

use super::{Closeable, Entity, Opening};
use crate::types::{Action, CmdResult};

#[derive(Debug, Serialize, Deserialize)]
#[derive(Debug, Deserialize)]
pub struct Pathway {
target: String,
#[serde(default)]
Expand Down
31 changes: 25 additions & 6 deletions src/entity/room.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use rayon::prelude::*;

use serde::{Deserialize, Serialize};
use serde::Deserialize;

use super::{
Closeable, Entity,
Expand All @@ -9,7 +9,7 @@ use super::{
use crate::types::{Action, Allies, CmdResult, Enemies, Items, PathMap};

// A section of the world connected by paths
#[derive(Debug, Serialize, Deserialize)]
#[derive(Debug, Deserialize)]
pub struct Room {
name: String,
desc: String,
Expand Down Expand Up @@ -130,8 +130,7 @@ impl Room {
pub fn open(&mut self, name: &str) -> CmdResult {
if let Some(path) = self.paths.get_mut(name) {
if path.is_closed() {
path.open();
CmdResult::new(Action::Active, "Opened.".to_owned())
path.open()
} else {
CmdResult::already_opened(name)
}
Expand All @@ -141,6 +140,16 @@ impl Room {
} else {
CmdResult::not_container(name)
}
} else if let Some(item) = self.find_similar_item(name) {
if let Some(item) = self.items.get_mut(item) {
if let Container(ref mut item) = **item {
item.open()
} else {
CmdResult::not_container(name)
}
} else {
CmdResult::no_item_here(name)
}
} else {
CmdResult::no_item_here(name)
}
Expand All @@ -155,11 +164,21 @@ impl Room {
CmdResult::new(Action::Active, "Closed.".to_owned())
}
} else if let Some(item) = self.items.par_iter_mut().find_any(|x| x.name() == name) {
if let Container(ref mut container) = **item {
container.close()
if let Container(ref mut item) = **item {
item.close()
} else {
CmdResult::not_container(name)
}
} else if let Some(item) = self.find_similar_item(name) {
if let Some(item) = self.items.get_mut(item) {
if let Container(ref mut item) = **item {
item.close()
} else {
CmdResult::not_container(name)
}
} else {
CmdResult::no_item_here(name)
}
} else {
CmdResult::no_item_here(name)
}
Expand Down
4 changes: 2 additions & 2 deletions src/input/lexer.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use rayon::prelude::*;

use serde::{Deserialize, Serialize};
use serde::Deserialize;

use crate::types::CmdTokens;

#[derive(Debug, Serialize, Deserialize)]
#[derive(Debug, Deserialize)]
pub struct Lexer {
filter_out: Vec<String>,
}
Expand Down
4 changes: 2 additions & 2 deletions src/input/parser.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use serde::{Deserialize, Serialize};
use serde::Deserialize;

use crate::{
cli::Cli,
Expand All @@ -8,7 +8,7 @@ use crate::{
world::World,
};

#[derive(Serialize, Deserialize)]
#[derive(Deserialize)]
pub struct Parser;

impl Parser {
Expand Down
4 changes: 2 additions & 2 deletions src/inventory/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use rayon::prelude::*;

use serde::{Deserialize, Serialize};
use serde::Deserialize;

use crate::{
entity::{
Expand All @@ -10,7 +10,7 @@ use crate::{
types::{Action, CmdResult, Items},
};

#[derive(Debug, Serialize, Deserialize)]
#[derive(Debug, Deserialize)]
pub struct Inventory {
items: Items,
}
Expand Down
Loading

0 comments on commit f9ed3c3

Please sign in to comment.