Skip to content

Commit ff93e43

Browse files
authored
Better wall glyphs and equip messages (#18)
* changing equip messaging but also ran into an glyph issue * experiment with terminal * disable debug prints for debugging terminal emulator backend * tentative fix for cp 437 issue * fix CP437 rendering issue * rm commented code * added a failing test for equip message issue (#19) * fixed #19: equip messages issue * add example story twee file; fix equip/unequip message * drafted a macro for formatting action messages * macro is working * fixing warnings * switched from tuple to struct for passing ecs data; updated death message * utils_ecs -> util_ecs * fixes for item removal messaging * power and defense changes are now displayed when equipping and unequipping items
1 parent 32df603 commit ff93e43

14 files changed

+503
-97
lines changed

Cargo.lock

+10-10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+4-1
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ edition = "2021"
66
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
77

88
[dependencies]
9-
bracket-lib = { git = "https://github.com/amethyst/bracket-lib.git", rev = "851f6f08675444fb6fa088b9e67bee9fd75554c6", features = [
9+
# bracket-lib = { path = "../bracket-lib/", default-features = false, features = [
10+
bracket-lib = { git = "https://github.com/bbarker/bracket-lib.git", rev = "d85c17ac21ab1dc6f10e01cc4a7fd711e16fe7be", features = [
1011
"serde",
1112
] }
13+
1214
#have to use git rev to support wasm; see https://github.com/amethyst/bracket-lib/issues/301
1315
enum_derive = "0.1.7"
1416
frunk = "0.4.1" # Note, currently not using this - but worth a look
@@ -22,3 +24,4 @@ once_cell = "1.5.2"
2224
indexmap = "1.9.3"
2325
# FunctionalRust = { git = "https://github.com/politrons/FunctionalRust.git", rev = "1f34793" }
2426
paste = "1.0.14"
27+
# lens-rs = "0.3.2"

resources/example_story.tw

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
:: Start {"position":"150,25"}
2+
The hero receives a call to adventure.
3+
[[Accept the call->FirstChallenge]]
4+
5+
:: FirstChallenge {"position":"425,25"}
6+
The hero faces their first challenge.
7+
[[Overcome the challenge->MentorMeeting]]
8+
9+
:: MentorMeeting {"position":"550,250"}
10+
The hero meets a mentor who provides guidance.
11+
[[Learn from the mentor->Climax]]
12+
13+
:: Climax {"position":"300,450"}
14+
The hero faces the ultimate challenge.
15+
[[Defeat the villain->Resolution]]
16+
17+
:: Resolution {"position":"50,250"}
18+
The hero returns, transformed by the journey.

shell.nix

+5
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,12 @@
2525
# qemu
2626
llvmPackages_latest.lld
2727
python3
28+
# Only for building bracket-lib, I think:
29+
alsa-lib
30+
systemd
2831
];
32+
# Only for building bracket-lib, I think:
33+
nativeBuildInputs = [ pkgs.pkg-config ];
2934
RUSTC_VERSION = pkgs.lib.readFile ./rust-toolchain;
3035
# https://github.com/rust-lang/rust-bindgen#environment-variables
3136
LIBCLANG_PATH = pkgs.lib.makeLibraryPath [ pkgs.llvmPackages_latest.libclang.lib ];

src/components.rs

+8
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,14 @@ pub struct Name {
254254
pub name: String,
255255
}
256256

257+
const DEBUG_NAME: &str = "<no name for entity>";
258+
259+
pub fn debug_name() -> Name {
260+
Name {
261+
name: DEBUG_NAME.to_string(),
262+
}
263+
}
264+
257265
#[derive(Component, Deserialize, Serialize, Clone, Debug)]
258266
pub struct Player {}
259267

src/damage_system.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::{
22
components::{Name, Player, Position, Positionable},
3+
entity_action_msg,
34
gamelog::GameLog,
45
map::Map,
56
RunState,
@@ -35,17 +36,16 @@ pub fn delete_the_dead(ecs: &mut World) -> Option<RunState> {
3536
let entities = ecs.entities();
3637
let mut log = ecs.write_resource::<GameLog>();
3738
let combat_stats = ecs.read_storage::<CombatStats>();
38-
let names = ecs.read_storage::<Name>();
3939
let positions = ecs.read_storage::<Position>();
4040
let players = ecs.read_storage::<Player>();
4141
(&entities, &combat_stats, &positions)
4242
.join()
4343
.for_each(|(ent, stats, pos)| {
4444
if stats.hp < 1 {
4545
dead.push(ent);
46-
if let Some(victim_name) = names.get(ent) {
47-
log.entries.push(format!("{} is dead.", victim_name.name));
48-
}
46+
log.entries
47+
.push(entity_action_msg!(ecs, "<SUBJ> {} dead.", ent, "are"));
48+
4949
if let Some(_player) = players.get(ent) {
5050
{
5151
newrunstate_opt = Some(RunState::GameOver);

src/equipment.rs

+12-11
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ pub struct Equipment {
241241
pub allowed_slots: EquipSlotAllowed,
242242
pub material: Material,
243243
pub quality: u8,
244-
pub special_melee_modifier: i16,
244+
pub special_power_modifier: i16,
245245
pub special_defense_modifier: i16,
246246
}
247247

@@ -257,7 +257,7 @@ impl Equipment {
257257
equipment_type,
258258
material,
259259
quality,
260-
special_melee_modifier: 0,
260+
special_power_modifier: 0,
261261
special_defense_modifier: 0,
262262
}
263263
}
@@ -304,12 +304,12 @@ impl Equipment {
304304
format!("{}{}{}", self.material, infix, self.equipment_type)
305305
}
306306

307-
pub fn melee_bonus(&self) -> i16 {
307+
pub fn power_bonus(&self) -> i16 {
308308
let derived_bonus = match self.equipment_type {
309309
EquipmentType::Weapon(_) => self.equipment_type.bonus() + self.material.bonus(),
310310
_ => 0,
311311
};
312-
derived_bonus + self.special_melee_modifier
312+
derived_bonus + self.special_power_modifier
313313
}
314314

315315
pub fn defense_bonus(&self) -> i16 {
@@ -336,25 +336,26 @@ impl Equipment {
336336
}
337337
}
338338

339-
pub type EntityEquipmentMap = HashMap<EquipSlot, Equipment>;
339+
pub type EntityEquipmentMap = HashMap<EquipSlot, (Equipment, Entity)>;
340340

341341
pub fn get_equipped_items<I: Join, E: Join>(
342+
entities: &Entities,
342343
items: I,
343344
equipped: E,
344-
entity: Entity,
345+
owner: Entity,
345346
) -> EntityEquipmentMap
346347
where
347348
I::Type: IsItem,
348349
E::Type: IsEquipped,
349350
{
350351
let mut equipped_items = HashMap::new();
351352
// Get all Equipped items and join with Items and filter those by the owner
352-
(items, equipped)
353+
(entities, items, equipped)
353354
.join()
354-
.map(|(item, eqpd)| (item.from(), eqpd.from()))
355-
.filter(|(_, eqpd)| eqpd.owner == entity)
356-
.filter_map(|(item, eqpd)| match item {
357-
Item::Equippable(equipment) => Some((equipment, eqpd)),
355+
.map(|(ent, item, eqpd)| (ent, item.from(), eqpd.from()))
356+
.filter(|(_, _, eqpd)| eqpd.owner == owner)
357+
.filter_map(|(ent, item, eqpd)| match item {
358+
Item::Equippable(equipment) => Some(((equipment, ent), eqpd)),
358359
_ => None,
359360
})
360361
.for_each(|(item, eqpd)| {

0 commit comments

Comments
 (0)