Skip to content

Commit

Permalink
feat: allow disabling of discovery pausing
Browse files Browse the repository at this point in the history
  • Loading branch information
zr3 committed Jan 15, 2024
1 parent 420d378 commit 06125bc
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 27 deletions.
19 changes: 13 additions & 6 deletions wild-thyme/src/gui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,11 @@ pub fn draw_ui(ecs: &World, ctx: &mut Rltk) {
let tooltip = &get_visible_tooltips(ecs)[current as usize];
draw_tooltip_at_pos(ecs, ctx, (tooltip.0.x, tooltip.0.y));
ctx.print_color(
5,
0,
0,
RGB::from_hex("#f0f0f0").expect("hardcoded"),
RGB::named(rltk::BLACK),
"VIEWING tips! Press any key..",
"SPOTTING things! Press [SPACE]..",
);
}
RunState::HighlightItem {} => {
Expand All @@ -133,11 +133,18 @@ pub fn draw_ui(ecs: &World, ctx: &mut Rltk) {
draw_tooltip_at_pos(ecs, ctx, (position.x, position.y));
}
ctx.print_color(
5,
0,
0,
RGB::from_hex("#a07030").expect("hardcoded"),
RGB::named(rltk::BLACK),
format!("SPOTTED new things! Press [SPACE].."),
format!("SPOTTED something new! Press [SPACE].."),
);
ctx.print_color(
0,
1,
RGB::from_hex("#704000").expect("hardcoded"),
RGB::named(rltk::BLACK),
format!("(press [ESC] to stop tips)"),
);
}
_ => {}
Expand Down Expand Up @@ -617,7 +624,7 @@ pub fn game_over(ctx: &mut Rltk, stats: &Stats) -> GameOverResult {
27,
RGB::named(rltk::WHITE),
RGB::named(rltk::BLACK),
"press [ENTER] to try again",
"[ENTER] to try again",
);

match ctx.key {
Expand All @@ -632,7 +639,7 @@ pub fn cake_judge(ctx: &mut Rltk, stats: &Stats) -> GameOverResult {
7,
RGB::named(rltk::WHITE),
RGB::named(rltk::BLACK),
"you baked...",
"YOU baked...",
);
ctx.print_color_centered(
9,
Expand Down
2 changes: 1 addition & 1 deletion wild-thyme/src/item_tutorial_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl<'a> System<'a> for ItemTutorialSystem {
let _ = positions.insert(highlight_entity, position.clone());
let _ = highlights.insert(highlight_entity, HighlightItem {});
// log to record the new sighting
log.log(format!("YOU saw {}.", name.name));
log.log(format!("YOU saw {} for the first time.", name.name));
}
// set runstate to view stack of new things and log
if !new_sights.is_empty() {
Expand Down
53 changes: 33 additions & 20 deletions wild-thyme/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
const IS_ITEM_HIGHLIGHT_ENABLED: bool = true;

use std::collections::HashMap;

use hunger_system::HungerSystem;
Expand Down Expand Up @@ -94,6 +92,9 @@ pub enum RunState {
pub struct State {
pub ecs: World,
}
pub struct UIConfig {
highlight_discoveries: bool,
}
impl GameState for State {
fn tick(&mut self, ctx: &mut Rltk) {
let mut newrunstate;
Expand Down Expand Up @@ -140,7 +141,7 @@ impl GameState for State {

// main loop
RunState::PreRound => {
if IS_ITEM_HIGHLIGHT_ENABLED {
if self.ecs.fetch::<UIConfig>().highlight_discoveries {
let mut item_tutorial = item_tutorial_system::ItemTutorialSystem {};
item_tutorial.run_now(&self.ecs);
}
Expand Down Expand Up @@ -418,8 +419,7 @@ impl GameState for State {
}
}
RunState::ShowTooltips { current, total } => match ctx.key {
None => {}
Some(_) => {
Some(rltk::VirtualKeyCode::Space) => {
if current < total - 1 {
newrunstate = RunState::ShowTooltips {
current: current + 1,
Expand All @@ -429,27 +429,37 @@ impl GameState for State {
newrunstate = RunState::AwaitingInput;
}
}
_ => {}
},
RunState::HighlightItem {} => match ctx.key {
Some(rltk::VirtualKeyCode::Space) => {
let mut to_delete = Vec::new();
{
for (entity, _highlight_item) in (
&self.ecs.entities(),
&self.ecs.read_storage::<HighlightItem>(),
)
.join()
RunState::HighlightItem {} => {
match ctx.key {
Some(rltk::VirtualKeyCode::Space) | Some(rltk::VirtualKeyCode::Escape) => {
let mut to_delete = Vec::new();
{
to_delete.push(entity);
for (entity, _highlight_item) in (
&self.ecs.entities(),
&self.ecs.read_storage::<HighlightItem>(),
)
.join()
{
to_delete.push(entity);
}
}
for entity in to_delete {
let _ = self.ecs.delete_entity(entity);
}
newrunstate = RunState::PreRound;
}
for entity in to_delete {
let _ = self.ecs.delete_entity(entity);
_ => {}
}
match ctx.key {
Some(rltk::VirtualKeyCode::Escape) => {
let mut ui_config = self.ecs.write_resource::<UIConfig>();
ui_config.highlight_discoveries = false;
}
newrunstate = RunState::PreRound;
_ => {}
}
_ => {}
},
}
}

{
Expand Down Expand Up @@ -726,6 +736,9 @@ fn main() -> rltk::BError {
gs.ecs.insert(rltk::RandomNumberGenerator::new());
gs.ecs.insert(spawn_system::SpawnBuilder::new());
gs.ecs.insert(rex_assets::RexAssets::new());
gs.ecs.insert(UIConfig {
highlight_discoveries: true,
});

// build the first level
gs.reset_game();
Expand Down

0 comments on commit 06125bc

Please sign in to comment.