From d465592c0fc52dcb96505c2f20d12d10f607b4fd Mon Sep 17 00:00:00 2001 From: Llywelwyn Date: Sun, 16 Jun 2024 10:31:06 +0100 Subject: [PATCH 1/7] abstracts ui drawing --- src/gui/mod.rs | 103 +++++++++++++++++++++++-------------------------- 1 file changed, 48 insertions(+), 55 deletions(-) diff --git a/src/gui/mod.rs b/src/gui/mod.rs index 5a50698..c28ff0b 100644 --- a/src/gui/mod.rs +++ b/src/gui/mod.rs @@ -106,6 +106,50 @@ pub fn draw_lerping_bar( ctx.print(sx + width, sy, "]"); } +fn draw_xp(ctx: &mut BTerm, pt: Point, pool: &Pools) { + ctx.print_color( + pt.x, + pt.y, + RGB::named(WHITE), + RGB::named(BLACK), + format!("XP{}/{}", pool.level, pool.xp) + ); +} + +fn calc_ac(ecs: &World, skills: &Skills, stats: &Pools, attr: &Attributes) -> i32 { + let skill_ac_bonus = gamesystem::skill_bonus(Skill::Defence, skills); + let mut armour_ac_bonus = 0; + let equipped = ecs.read_storage::(); + let ac = ecs.read_storage::(); + let player_entity = ecs.fetch::(); + for (wielded, ac) in (&equipped, &ac).join() { + if wielded.owner == *player_entity { + armour_ac_bonus += ac.amount; + } + } + stats.bac - attr.dexterity.bonus / 2 - skill_ac_bonus - armour_ac_bonus +} + +fn draw_ac(ctx: &mut BTerm, pt: Point, ac: i32) { + ctx.print_color(pt.x, pt.y, RGB::named(PINK), RGB::named(BLACK), "AC"); + ctx.print_color(pt.x + 2, pt.y, RGB::named(WHITE), RGB::named(BLACK), ac); +} + +fn draw_attributes(ctx: &mut BTerm, pt: Point, a: &Attributes) { + ctx.print_color(pt.x, pt.y, RGB::named(RED), RGB::named(BLACK), "STR"); + ctx.print_color(pt.x + 3, pt.y, RGB::named(WHITE), RGB::named(BLACK), a.strength.base); + ctx.print_color(pt.x + 7, pt.y, RGB::named(GREEN), RGB::named(BLACK), "DEX"); + ctx.print_color(pt.x + 10, pt.y, RGB::named(WHITE), RGB::named(BLACK), a.dexterity.base); + ctx.print_color(pt.x + 14, pt.y, RGB::named(ORANGE), RGB::named(BLACK), "CON"); + ctx.print_color(pt.x + 17, pt.y, RGB::named(WHITE), RGB::named(BLACK), a.constitution.base); + ctx.print_color(pt.x, 54, RGB::named(CYAN), RGB::named(BLACK), "INT"); + ctx.print_color(pt.x + 3, pt.y + 1, RGB::named(WHITE), RGB::named(BLACK), a.intelligence.base); + ctx.print_color(pt.x + 7, pt.y + 1, RGB::named(YELLOW), RGB::named(BLACK), "WIS"); + ctx.print_color(pt.x + 10, pt.y + 1, RGB::named(WHITE), RGB::named(BLACK), a.wisdom.base); + ctx.print_color(pt.x + 14, pt.y + 1, RGB::named(PURPLE), RGB::named(BLACK), "CHA"); + ctx.print_color(pt.x + 17, pt.y + 1, RGB::named(WHITE), RGB::named(BLACK), a.charisma.base); +} + pub fn draw_ui(ecs: &World, ctx: &mut BTerm) { // Render stats let pools = ecs.read_storage::(); @@ -142,61 +186,9 @@ pub fn draw_ui(ecs: &World, ctx: &mut BTerm) { RGB::named(BLUE), RGB::named(BLACK) ); - // Draw AC - let skill_ac_bonus = gamesystem::skill_bonus(Skill::Defence, &*skills); - let mut armour_ac_bonus = 0; - let equipped = ecs.read_storage::(); - let ac = ecs.read_storage::(); - let player_entity = ecs.fetch::(); - for (wielded, ac) in (&equipped, &ac).join() { - if wielded.owner == *player_entity { - armour_ac_bonus += ac.amount; - } - } - let armour_class = - stats.bac - attributes.dexterity.bonus / 2 - skill_ac_bonus - armour_ac_bonus; - ctx.print_color(26, 53, RGB::named(PINK), RGB::named(BLACK), "AC"); - ctx.print_color(28, 53, RGB::named(WHITE), RGB::named(BLACK), armour_class); - // Draw level - ctx.print_color( - 26, - 54, - RGB::named(WHITE), - RGB::named(BLACK), - format!("XP{}/{}", stats.level, stats.xp) - ); - // Draw attributes - let x = 38; - ctx.print_color(x, 53, RGB::named(RED), RGB::named(BLACK), "STR"); - ctx.print_color(x + 3, 53, RGB::named(WHITE), RGB::named(BLACK), attributes.strength.base); - ctx.print_color(x + 7, 53, RGB::named(GREEN), RGB::named(BLACK), "DEX"); - ctx.print_color( - x + 10, - 53, - RGB::named(WHITE), - RGB::named(BLACK), - attributes.dexterity.base - ); - ctx.print_color(x + 14, 53, RGB::named(ORANGE), RGB::named(BLACK), "CON"); - ctx.print_color( - x + 17, - 53, - RGB::named(WHITE), - RGB::named(BLACK), - attributes.constitution.base - ); - ctx.print_color(x, 54, RGB::named(CYAN), RGB::named(BLACK), "INT"); - ctx.print_color( - x + 3, - 54, - RGB::named(WHITE), - RGB::named(BLACK), - attributes.intelligence.base - ); - ctx.print_color(x + 7, 54, RGB::named(YELLOW), RGB::named(BLACK), "WIS"); - ctx.print_color(x + 10, 54, RGB::named(WHITE), RGB::named(BLACK), attributes.wisdom.base); - ctx.print_color(x + 14, 54, RGB::named(PURPLE), RGB::named(BLACK), "CHA"); - ctx.print_color(x + 17, 54, RGB::named(WHITE), RGB::named(BLACK), attributes.charisma.base); + draw_ac(ctx, Point::new(26, 53), calc_ac(ecs, skills, stats, attributes)); + draw_xp(ctx, Point::new(26, 54), stats); + draw_attributes(ctx, Point::new(38, 53), attributes); // Draw hunger match hunger.state { HungerState::Satiated => { @@ -247,6 +239,7 @@ pub fn draw_ui(ecs: &World, ctx: &mut BTerm) { } } // Burden + let player_entity = ecs.fetch::(); if let Some(burden) = burden.get(*player_entity) { match burden.level { crate::BurdenLevel::Burdened => { From 6324449c1601e85121494bab73cdb88c3368407a Mon Sep 17 00:00:00 2001 From: Llywelwyn Date: Mon, 17 Jun 2024 23:19:20 +0100 Subject: [PATCH 2/7] draw_hunger() --- src/gui/mod.rs | 101 +++++++++++++++++++++++++------------------------ 1 file changed, 52 insertions(+), 49 deletions(-) diff --git a/src/gui/mod.rs b/src/gui/mod.rs index c28ff0b..bde2cf0 100644 --- a/src/gui/mod.rs +++ b/src/gui/mod.rs @@ -150,6 +150,57 @@ fn draw_attributes(ctx: &mut BTerm, pt: Point, a: &Attributes) { ctx.print_color(pt.x + 17, pt.y + 1, RGB::named(WHITE), RGB::named(BLACK), a.charisma.base); } +fn draw_hunger(ctx: &mut BTerm, pt: Point, hunger: &HungerClock) { + match hunger.state { + HungerState::Satiated => { + ctx.print_color_right( + 70, + 53, + get_hunger_colour(hunger.state), + RGB::named(BLACK), + "Satiated" + ); + } + HungerState::Normal => {} + HungerState::Hungry => { + ctx.print_color_right( + 70, + 53, + get_hunger_colour(hunger.state), + RGB::named(BLACK), + "Hungry" + ); + } + HungerState::Weak => { + ctx.print_color_right( + 70, + 53, + get_hunger_colour(hunger.state), + RGB::named(BLACK), + "Weak" + ); + } + HungerState::Fainting => { + ctx.print_color_right( + 70, + 53, + get_hunger_colour(hunger.state), + RGB::named(BLACK), + "Fainting" + ); + } + HungerState::Starving => { + ctx.print_color_right( + 70, + 53, + get_hunger_colour(hunger.state), + RGB::named(BLACK), + "Starving" + ); + } + } +} + pub fn draw_ui(ecs: &World, ctx: &mut BTerm) { // Render stats let pools = ecs.read_storage::(); @@ -189,55 +240,7 @@ pub fn draw_ui(ecs: &World, ctx: &mut BTerm) { draw_ac(ctx, Point::new(26, 53), calc_ac(ecs, skills, stats, attributes)); draw_xp(ctx, Point::new(26, 54), stats); draw_attributes(ctx, Point::new(38, 53), attributes); - // Draw hunger - match hunger.state { - HungerState::Satiated => { - ctx.print_color_right( - 70, - 53, - get_hunger_colour(hunger.state), - RGB::named(BLACK), - "Satiated" - ); - } - HungerState::Normal => {} - HungerState::Hungry => { - ctx.print_color_right( - 70, - 53, - get_hunger_colour(hunger.state), - RGB::named(BLACK), - "Hungry" - ); - } - HungerState::Weak => { - ctx.print_color_right( - 70, - 53, - get_hunger_colour(hunger.state), - RGB::named(BLACK), - "Weak" - ); - } - HungerState::Fainting => { - ctx.print_color_right( - 70, - 53, - get_hunger_colour(hunger.state), - RGB::named(BLACK), - "Fainting" - ); - } - HungerState::Starving => { - ctx.print_color_right( - 70, - 53, - get_hunger_colour(hunger.state), - RGB::named(BLACK), - "Starving" - ); - } - } + draw_hunger(ctx, Point::new(70, 53), hunger); // Burden let player_entity = ecs.fetch::(); if let Some(burden) = burden.get(*player_entity) { From 99c17f85213c3f5fbaa8d369bdc6bed75bfab696 Mon Sep 17 00:00:00 2001 From: Llywelwyn Date: Mon, 17 Jun 2024 23:22:30 +0100 Subject: [PATCH 3/7] draw hunger uses Point --- src/gui/mod.rs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/gui/mod.rs b/src/gui/mod.rs index bde2cf0..7604527 100644 --- a/src/gui/mod.rs +++ b/src/gui/mod.rs @@ -154,8 +154,8 @@ fn draw_hunger(ctx: &mut BTerm, pt: Point, hunger: &HungerClock) { match hunger.state { HungerState::Satiated => { ctx.print_color_right( - 70, - 53, + pt.x, + pt.y, get_hunger_colour(hunger.state), RGB::named(BLACK), "Satiated" @@ -164,8 +164,8 @@ fn draw_hunger(ctx: &mut BTerm, pt: Point, hunger: &HungerClock) { HungerState::Normal => {} HungerState::Hungry => { ctx.print_color_right( - 70, - 53, + pt.x, + pt.y, get_hunger_colour(hunger.state), RGB::named(BLACK), "Hungry" @@ -173,8 +173,8 @@ fn draw_hunger(ctx: &mut BTerm, pt: Point, hunger: &HungerClock) { } HungerState::Weak => { ctx.print_color_right( - 70, - 53, + pt.x, + pt.y, get_hunger_colour(hunger.state), RGB::named(BLACK), "Weak" @@ -182,8 +182,8 @@ fn draw_hunger(ctx: &mut BTerm, pt: Point, hunger: &HungerClock) { } HungerState::Fainting => { ctx.print_color_right( - 70, - 53, + pt.x, + pt.y, get_hunger_colour(hunger.state), RGB::named(BLACK), "Fainting" @@ -191,8 +191,8 @@ fn draw_hunger(ctx: &mut BTerm, pt: Point, hunger: &HungerClock) { } HungerState::Starving => { ctx.print_color_right( - 70, - 53, + pt.x, + pt.y, get_hunger_colour(hunger.state), RGB::named(BLACK), "Starving" From bdcd55c8a583422819908a841ef46fe4f978e4bb Mon Sep 17 00:00:00 2001 From: Lewis Wynne Date: Sun, 9 Mar 2025 10:50:35 +0000 Subject: [PATCH 4/7] Fixes miscoloured logs (fixes #26) --- src/ai/turn_status_system.rs | 4 ---- src/effects/triggers.rs | 4 ---- 2 files changed, 8 deletions(-) diff --git a/src/ai/turn_status_system.rs b/src/ai/turn_status_system.rs index db3acaa..e072e45 100644 --- a/src/ai/turn_status_system.rs +++ b/src/ai/turn_status_system.rs @@ -65,9 +65,7 @@ impl<'a> System<'a> for TurnStatusSystem { not_confused.push(entity); if entity == *player_entity { logger = logger - .colour(renderable_colour(&renderables, entity)) .append("You") - .colour(WHITE) .append("snap out of it."); log = true; } else { @@ -94,9 +92,7 @@ impl<'a> System<'a> for TurnStatusSystem { not_my_turn.push(entity); if entity == *player_entity { logger = logger - .colour(renderable_colour(&renderables, entity)) .append("You") - .colour(WHITE) .append("are confused!"); log = true; gamelog::record_event(EVENT::PlayerConfused(1)); diff --git a/src/effects/triggers.rs b/src/effects/triggers.rs index fb54eed..cb4e5d3 100644 --- a/src/effects/triggers.rs +++ b/src/effects/triggers.rs @@ -223,9 +223,7 @@ fn handle_healing( let renderables = ecs.read_storage::(); if ecs.read_storage::().get(target).is_some() { logger = logger - .colour(renderable_colour(&renderables, target)) .append("You") - .colour(WHITE) .append(HEAL_PLAYER_HIT) .buc(event.buc.clone(), None, Some(HEAL_PLAYER_HIT_BLESSED)); } else { @@ -267,9 +265,7 @@ fn handle_damage( let player_viewshed = viewsheds.get(*ecs.fetch::()).unwrap(); if ecs.read_storage::().get(target).is_some() { logger = logger - .colour(renderable_colour(&renderables, target)) .append("You") - .colour(WHITE) .append(DAMAGE_PLAYER_HIT); event.log = true; } else if From 45b9b330396c31cbf1d7fcab8466ba8cb6d005f2 Mon Sep 17 00:00:00 2001 From: Llywelwyn <82828093+Llywelwyn@users.noreply.github.com> Date: Sun, 9 Mar 2025 11:02:16 +0000 Subject: [PATCH 5/7] Update cargo-build-test.yml --- .github/workflows/cargo-build-test.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/cargo-build-test.yml b/.github/workflows/cargo-build-test.yml index d54fa2f..ae0ca42 100644 --- a/.github/workflows/cargo-build-test.yml +++ b/.github/workflows/cargo-build-test.yml @@ -16,6 +16,8 @@ jobs: steps: - uses: actions/checkout@v3 + - name: Deps + run: sudo dnf install fontconfig-devel - name: Build run: cargo build --verbose - name: Run tests From 0584d07a1f9bf45d9f591f399a1b22e720a5072f Mon Sep 17 00:00:00 2001 From: Llywelwyn <82828093+Llywelwyn@users.noreply.github.com> Date: Sun, 9 Mar 2025 11:04:32 +0000 Subject: [PATCH 6/7] Update cargo-build-test.yml to use ubuntu-22.04 --- .github/workflows/cargo-build-test.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/cargo-build-test.yml b/.github/workflows/cargo-build-test.yml index ae0ca42..cafaa58 100644 --- a/.github/workflows/cargo-build-test.yml +++ b/.github/workflows/cargo-build-test.yml @@ -12,12 +12,10 @@ env: jobs: build: - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v3 - - name: Deps - run: sudo dnf install fontconfig-devel - name: Build run: cargo build --verbose - name: Run tests From c29b93337c5e3a29ebbf286cbd0bb86369faeccd Mon Sep 17 00:00:00 2001 From: Llywelwyn <82828093+Llywelwyn@users.noreply.github.com> Date: Sun, 9 Mar 2025 11:12:11 +0000 Subject: [PATCH 7/7] Update README.md --- README.md | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 9127091..c1809cf 100644 --- a/README.md +++ b/README.md @@ -2,18 +2,18 @@ #### using _rltk/bracket-lib_, and _specs_ -check out the page in the header for the wasm version, pick [a release of your choice](https://github.com/Llywelwyn/rust-rl/releases), or build manually with: +[![Rust](https://github.com/Llywelwyn/rust-rl/actions/workflows/cargo-build-test.yml/badge.svg)](https://github.com/Llywelwyn/rust-rl/actions/workflows/cargo-build-test.yml) + +check out the page in the header for the wasm version, pick [a release](https://github.com/Llywelwyn/rust-rl/releases), or build manually with: `git clone https://github.com/Llywelwyn/rust-rl/ && cd rust-rl && cargo build --release`, ![image](https://github.com/Llywelwyn/rust-rl/assets/82828093/b05e4f0b-2062-4abe-9fee-c679f9ef420d) -this year for roguelikedev does the complete tutorial, i followed along with thebracket's [_roguelike tutorial - in rust_](https://bfnightly.bracketproductions.com). the notes i made during the sprint are being kept below for posterity - further changes since then are noted in [changelog.txt](https://github.com/Llywelwyn/rust-rl/blob/9150ed39e45bee536060cdc769d274e639021012/changelog.txt), and in the release notes. - -i'm also working on translating over my progress into blog entries on my site @ [llyw.co.uk](https://llyw.co.uk/), with a larger focus on some of the more interesting implementation details. - --- +
+ boring details about the sprint where this project started
week 1 @@ -157,3 +157,4 @@ i'm also working on translating over my progress into blog entries on my site @ ![squares](https://github.com/Llywelwyn/rust-rl/assets/82828093/b752e1cb-340d-475d-84ae-68fdb4977a80)
+