Skip to content

Commit 72ced35

Browse files
committed
update to 0.5.1; fix issues with saving and loading
1 parent ff02e86 commit 72ced35

File tree

5 files changed

+264
-23
lines changed

5 files changed

+264
-23
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "kingslayer"
3-
version = "0.5.0"
3+
version = "0.5.1"
44
authors = ["Maxwell Anderson <[email protected]>"]
55
edition = "2018"
66
license = "MIT"

justfile

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,4 @@ c:
1515
cargo doc
1616
cargo build
1717

18-
cargo test
19-
20-
docs:
21-
cargo doc --document-private-items --open
18+
cargo test

src/cli/mod.rs

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use std::{
33
convert::TryInto,
44
fs::{self, File},
55
io::{self, BufReader, Read, Write},
6-
path::Path,
76
};
87

98
use rayon::prelude::*;
@@ -181,26 +180,15 @@ Some available commands:
181180

182181
fn save(&self) -> CmdResult {
183182
let saved = ron::ser::to_string(&self).expect("Error serializing world save file.");
184-
let file = if Path::new("worlds/").exists() {
185-
File::create("worlds/world.save.ron")
186-
} else {
187-
match fs::create_dir(Path::new("worlds")) {
188-
Ok(()) => File::create("worlds/world.save.ron"),
189-
Err(err) => Result::Err(err),
190-
}
191-
};
192183

193-
if let Ok(mut file) = file {
184+
if let Ok(mut file) = File::create("world.save.ron") {
194185
if let Ok(()) = file.write_all(saved.as_bytes()) {
195-
CmdResult::new(
196-
Action::Passive,
197-
String::from("Saved to 'worlds/world.save.ron'."),
198-
)
186+
CmdResult::new(Action::Passive, String::from("Saved to 'world.save.ron'."))
199187
} else {
200-
CmdResult::new(Action::Passive, String::from("Error saving world. 1"))
188+
CmdResult::new(Action::Passive, String::from("Error saving world."))
201189
}
202190
} else {
203-
CmdResult::new(Action::Passive, String::from("Error saving world. 2"))
191+
CmdResult::new(Action::Passive, String::from("Error saving world."))
204192
}
205193
}
206194
}

src/main.rs

Lines changed: 257 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,263 @@ fn main() {
88

99
cli.start();
1010
} else {
11-
let cli = Cli::from_file("worlds/world.ron");
11+
let cli = Cli::from_ron_str(
12+
r#"
13+
(world: World(
14+
curr_room: "Brig",
15+
rooms: {
16+
"Brig": Room(
17+
name: "Brig",
18+
desc: "You are in a small wooden room with a wood pillar in the middle.
19+
The ground slowly creaks and rocks beneath you.",
20+
paths: [
21+
Pathway(
22+
directions: ["door", "n"],
23+
target: "Hold 1",
24+
desc: "There is a door on the north side.",
25+
inspect: "The door is plain and wooden.",
26+
opening: Some(Closed),
27+
),
28+
]
29+
),
30+
"Hold 1": Room(
31+
name: "Hold",
32+
desc: "You are in the middle of a spacious hold. Crates and barrels array the sides.",
33+
paths: [
34+
Pathway(
35+
directions: ["door", "s"],
36+
target: "Brig",
37+
desc: "There is a door at the south end of the hold.",
38+
inspect: "The door is plain and wooden.",
39+
opening: Some(Open),
40+
),
41+
Pathway(
42+
directions: ["n"],
43+
target: "Hold 2",
44+
desc: "The hold continues to the north.",
45+
inspect: "This end of the hold is too dark to see into.",
46+
),
47+
],
48+
),
49+
"Hold 2": Room(
50+
name: "Hold",
51+
desc: "You are at the end of a spacious hold. Crates and barrels array the sides.",
52+
paths: [
53+
Pathway(
54+
directions: ["hatch", "u"],
55+
target: "Crew Deck 1",
56+
desc: "There is a hatch above you.",
57+
inspect: "It looks like a metal grate.",
58+
opening: Some(Closed),
59+
),
60+
Pathway(
61+
directions: ["s"],
62+
target: "Hold 1",
63+
desc: "The hold continues to the south.",
64+
inspect: "The middle of the hold is lit by a lantern.",
65+
),
66+
]
67+
),
68+
"Crew Deck 1": Room(
69+
name: "Crew Deck",
70+
desc: "You are on a deck with dirty hammocks hanging everywhere.",
71+
paths: [
72+
Pathway(
73+
directions: ["hatch", "d"],
74+
target: "Hold 2",
75+
desc: "There is a hatch on the ground",
76+
inspect: "It looks like a metal grate.",
77+
opening: Some(Open),
78+
),
79+
Pathway(
80+
directions: ["s"],
81+
target: "Crew Deck 2",
82+
desc: "The deck continues to the south.",
83+
inspect: "There is a doorway at the south end of the deck.",
84+
),
85+
]
86+
),
87+
"Crew Deck 2": Room(
88+
name: "Crew Deck",
89+
desc: "You are on a deck with dirty hammocks hanging everywhere.",
90+
paths: [
91+
Pathway(
92+
directions: ["opening", "u"],
93+
target: "Cannon Deck 2",
94+
desc: "There is an opening above you.",
95+
inspect: "You think you might be able to see the light of day.",
96+
),
97+
Pathway(
98+
directions: ["n"],
99+
target: "Crew Deck 1",
100+
desc: "The deck continues to the north.",
101+
inspect: "There is a hatch at the north end of the deck.",
102+
),
103+
Pathway(
104+
directions: ["empty doorway", "s"],
105+
target: "Infirmary",
106+
desc: "There is an empty doorway to the south.",
107+
inspect: "The doorway flickers with lantern light.",
108+
),
109+
]
110+
),
111+
"Infirmary": Room(
112+
name: "Infirmary",
113+
desc: "You are in a room with a few empty beds against one wall.",
114+
paths: [
115+
Pathway(
116+
directions: ["doorway", "n"],
117+
target: "Crew Deck 2",
118+
desc: "The doorway leads back into the crew's quarters.",
119+
inspect: "The doorway flickers with lantern light.",
120+
),
121+
]
122+
),
123+
"Cannon Deck 1": Room(
124+
name: "Cannon Deck",
125+
desc: "This deck has cannons lining each side.",
126+
paths: [
127+
Pathway(
128+
directions: ["s"],
129+
target: "Cannon Deck 2",
130+
desc: "The deck continues to the south.",
131+
inspect: "This ship sure has a lot of cannons.",
132+
),
133+
Pathway(
134+
directions: ["hatch", "u"],
135+
target: "Main Deck",
136+
desc: "A hatch above you bring in bright sunlight.",
137+
inspect: "The hatch is a double-hinged grate made of old rusty metal.",
138+
opening: Some(Closed),
139+
),
140+
],
141+
),
142+
"Cannon Deck 2": Room(
143+
name: "Cannon Deck",
144+
desc: "This deck has cannons lining each side.",
145+
paths: [
146+
Pathway(
147+
directions: ["n"],
148+
target: "Cannon Deck 1",
149+
desc: "The deck continues to the north.",
150+
inspect: "This ship sure has a lot of cannons.",
151+
),
152+
Pathway(
153+
directions: ["doorway", "s"],
154+
target: "Empty Room",
155+
desc: "There is a doorway to the south.",
156+
inspect: "The doorway is completely dark.",
157+
),
158+
Pathway(
159+
directions: ["opening", "d"],
160+
target: "Crew Deck 2",
161+
desc: "There is an opening below you.",
162+
inspect: "You can see hammocks through the opening.",
163+
),
164+
]
165+
),
166+
"Empty Room": Room(
167+
name: "Empty Room",
168+
desc: "The room is dark and empty.",
169+
paths: [
170+
Pathway(
171+
directions: ["doorway", "n"],
172+
target: "Cannon Deck 2",
173+
desc: "The doorway leads back into the cannon deck.",
174+
inspect: "You see many cannons.",
175+
),
176+
]
177+
),
178+
"Main Deck": Room(
179+
name: "Main Deck",
180+
desc: "The vast open sea surrounds the ship you stand on.",
181+
paths: [
182+
Pathway(
183+
directions: ["hatch", "d"],
184+
target: "Cannon Deck 1",
185+
desc: "There is a hatch below you.",
186+
inspect: "The hatch is a double-hinged grate made of old rusty metal.",
187+
opening: Some(Open),
188+
),
189+
Pathway(
190+
directions: ["mast", "platform", "u"],
191+
target: "Platform",
192+
desc: "There is a platform above you on the central mast.",
193+
inspect: "The platform can be reached through holds on the mast.",
194+
),
195+
Pathway(
196+
directions: ["stairs", "s"],
197+
target: "Sterncastle",
198+
desc: "Stairs towards the south lead upwards onto the sterncastle.",
199+
inspect: "The stairs are old and dirty.",
200+
),
201+
Pathway(
202+
directions: ["door"],
203+
target: "Captains Cabin",
204+
desc: "There is door on the wall beneath the sterncastle of the ship.",
205+
inspect: "The door is large with a small dim window in the center.",
206+
opening: Some(Closed),
207+
),
208+
]
209+
),
210+
"Sterncastle": Room(
211+
name: "Sterncastle",
212+
desc: "You are on the sterncastle of the ship. There is another mast in the center and a the ships wheel.",
213+
paths: [
214+
Pathway(
215+
directions: ["stairs", "n", "d"],
216+
target: "Main Deck",
217+
desc: "The stairs lead back onto the main deck.",
218+
inspect: "The stairs are old and dirty.",
219+
),
220+
],
221+
),
222+
"Captains Cabin": Room(
223+
name: "Captains Cabin",
224+
desc: "You stand in a large cabin with the captains belongins littering the ground and hanging on the walls.",
225+
paths: [
226+
Pathway(
227+
directions: ["door", "n"],
228+
target: "Main Deck",
229+
desc: "There is door at the north end of the room.",
230+
inspect: "The door is large with a small dim window in the center.",
231+
opening: Some(Open),
232+
),
233+
],
234+
),
235+
"Platform": Room(
236+
name: "Platform",
237+
desc: "You stand on a platform several feet above the main deck.",
238+
paths: [
239+
Pathway(
240+
directions: ["d"],
241+
target: "Main Deck",
242+
desc: "The main deck is below you.",
243+
inspect: "The main deck is several feet below.",
244+
),
245+
Pathway(
246+
directions: ["crows nest", "u"],
247+
target: "Crows Nest",
248+
desc: "There is a crows nest above you on the central mast.",
249+
inspect: "The crows nest can be reached through holds and rigging on the mast.",
250+
),
251+
]
252+
),
253+
"Crows Nest": Room(
254+
name: "Crows Nest",
255+
desc: "You are in a crows nest overlooking the entire ship and sea.",
256+
paths: [
257+
Pathway(
258+
directions: ["mast", "platform", "d"],
259+
target: "Platform",
260+
desc: "There is a platform below you on the central mast.",
261+
inspect: "The platform can be reached through holds on the mast.",
262+
),
263+
]
264+
),
265+
}))
266+
"#,
267+
);
12268
cli.add_item(
13269
"Brig",
14270
Item::Weapon(Weapon::new("stick", "It's short but stout.", 4)),

0 commit comments

Comments
 (0)