From c2c7e0bd52d2ee7bb80d29334d24b41615f4e36e Mon Sep 17 00:00:00 2001 From: Llywelwyn Date: Wed, 23 Aug 2023 01:22:09 +0100 Subject: [PATCH] sorry - swapping from rustfmt to prettier-rust --- .prettierrc.json | 3 + benches/systems_benchmark.rs | 4 +- raws/mobs.json | 66 +- src/ai/adjacent_ai_system.rs | 18 +- src/ai/approach_ai_system.rs | 18 +- src/ai/chase_ai_system.rs | 18 +- src/ai/default_move_system.rs | 46 +- src/ai/encumbrance_system.rs | 8 +- src/ai/energy_system.rs | 11 +- src/ai/flee_ai_system.rs | 16 +- src/ai/mod.rs | 2 +- src/ai/quip_system.rs | 5 +- src/ai/regen_system.rs | 19 +- src/ai/turn_status_system.rs | 12 +- src/ai/visible_ai_system.rs | 22 +- src/camera.rs | 17 +- src/components.rs | 10 +- src/config/entity.rs | 2 + src/damage_system.rs | 29 +- src/effects/damage.rs | 42 +- src/effects/hunger.rs | 2 +- src/effects/mod.rs | 59 +- src/effects/particles.rs | 55 +- src/effects/targeting.rs | 2 +- src/effects/triggers.rs | 61 +- src/gamelog/builder.rs | 2 +- src/gamelog/logstore.rs | 89 +- src/gamelog/mod.rs | 4 +- src/gamesystem.rs | 17 +- src/gui/character_creation.rs | 165 +- src/gui/cheat_menu.rs | 21 +- src/gui/identify_menu.rs | 73 +- src/gui/mod.rs | 423 +++-- src/gui/remove_curse_menu.rs | 55 +- src/gui/tooltip.rs | 8 +- src/hunger_system.rs | 90 +- src/inventory/collection_system.rs | 42 +- src/inventory/drop_system.rs | 42 +- src/inventory/equip_system.rs | 37 +- src/inventory/identification_system.rs | 2 +- src/inventory/mod.rs | 10 +- src/inventory/remove_system.rs | 28 +- src/inventory/use_system.rs | 31 +- src/main.rs | 131 +- src/map/dungeon.rs | 52 +- src/map/interval_spawning_system.rs | 6 +- src/map/mod.rs | 14 +- src/map/themes.rs | 45 +- src/map/tiletype.rs | 4 +- src/map_builders/area_starting_points.rs | 34 +- src/map_builders/bsp_dungeon.rs | 2 +- src/map_builders/bsp_interior.rs | 4 +- src/map_builders/cellular_automata.rs | 18 +- src/map_builders/common.rs | 4 +- src/map_builders/cull_unreachable.rs | 4 +- src/map_builders/distant_exit.rs | 4 +- src/map_builders/dla.rs | 20 +- src/map_builders/door_placement.rs | 38 +- src/map_builders/drunkard.rs | 14 +- src/map_builders/fill_edges.rs | 2 +- src/map_builders/forest.rs | 26 +- src/map_builders/maze.rs | 14 +- src/map_builders/mod.rs | 44 +- src/map_builders/room_based_spawner.rs | 4 +- src/map_builders/room_based_stairs.rs | 2 +- .../room_based_starting_position.rs | 2 +- src/map_builders/room_corner_rounding.rs | 6 +- src/map_builders/room_draw.rs | 9 +- src/map_builders/room_exploder.rs | 2 +- src/map_builders/room_sorter.rs | 43 +- src/map_builders/rooms_corridors_bresenham.rs | 4 +- src/map_builders/rooms_corridors_bsp.rs | 2 +- src/map_builders/rooms_corridors_dogleg.rs | 4 +- src/map_builders/rooms_corridors_nearest.rs | 11 +- src/map_builders/rooms_corridors_spawner.rs | 4 +- src/map_builders/simple_map.rs | 8 +- src/map_builders/town.rs | 96 +- src/map_builders/voronoi.rs | 6 +- src/map_builders/voronoi_spawning.rs | 4 +- src/melee_combat_system.rs | 141 +- src/particle_system.rs | 31 +- src/player.rs | 250 ++- src/raws/mod.rs | 4 +- src/raws/rawmaster.rs | 200 +- src/raws/reaction_structs.rs | 2 +- src/rect.rs | 2 +- src/saveload_system.rs | 13 +- src/spatial/map_indexing_system.rs | 2 +- src/spatial/mod.rs | 15 +- src/spawner.rs | 76 +- src/trigger_system.rs | 34 +- src/visibility_system.rs | 27 +- wasm/rust-llyrl.js | 1648 +++++++++-------- 93 files changed, 2797 insertions(+), 2021 deletions(-) create mode 100644 .prettierrc.json diff --git a/.prettierrc.json b/.prettierrc.json new file mode 100644 index 0000000..be3ac71 --- /dev/null +++ b/.prettierrc.json @@ -0,0 +1,3 @@ +{ + "printWidth": 120 +} \ No newline at end of file diff --git a/benches/systems_benchmark.rs b/benches/systems_benchmark.rs index 3bde091..b2acdbc 100644 --- a/benches/systems_benchmark.rs +++ b/benches/systems_benchmark.rs @@ -1,4 +1,4 @@ -use criterion::{black_box, criterion_group, criterion_main, Criterion}; +use criterion::{ black_box, criterion_group, criterion_main, Criterion }; use rltk::RGB; /// Benchmarks methods from rltk used to desaturate non-visible tiles. @@ -6,7 +6,7 @@ use rltk::RGB; // third alternative is directly setting the desaturated value, if it // is known in advance. fn nonvisible_benchmark(c: &mut Criterion) { - let bg = black_box(RGB::from_f32(0.4, 0., 0.)); + let bg = black_box(RGB::from_f32(0.4, 0.0, 0.0)); c.bench_function("rgb -> greyscale", |b| b.iter(|| bg.to_greyscale())); c.bench_function("rgb -> desaturate", |b| b.iter(|| bg.desaturate())); diff --git a/raws/mobs.json b/raws/mobs.json index 5819010..30a9052 100644 --- a/raws/mobs.json +++ b/raws/mobs.json @@ -62,7 +62,7 @@ "renderable": { "glyph": "@", "fg": "#034efc", "bg": "#000000", "order": 1 }, "flags": ["NEUTRAL", "RANDOM_PATH", "IS_HUMAN"], "level": 2, - "vision_range": 4, + "vision_range": 16, "attacks": [{ "name": "hits", "hit_bonus": 0, "damage": "1d8" }], "equipped": ["equip_shortsword", "equip_body_leather"], "quips": ["You wont catch me down the mine.", "Staying out of trouble?"] @@ -73,7 +73,7 @@ "renderable": { "glyph": "r", "fg": "#aa6000", "bg": "#000000", "order": 1 }, "flags": [], "bac": 6, - "vision_range": 8, + "vision_range": 16, "attacks": [{ "name": "bites", "hit_bonus": 0, "damage": "1d2" }], "loot": { "table": "food", "chance": 0.1 } }, @@ -83,7 +83,7 @@ "renderable": { "glyph": "c", "fg": "#BB6000", "bg": "#000000", "order": 1 }, "flags": ["HERBIVORE"], "bac": 8, - "vision_range": 4, + "vision_range": 16, "attacks": [{ "name": "bites", "hit_bonus": 0, "damage": "1d3" }] }, { @@ -92,7 +92,7 @@ "renderable": { "glyph": "q", "fg": "#a57037", "bg": "#000000", "order": 1 }, "flags": ["HERBIVORE"], "bac": 8, - "vision_range": 8, + "vision_range": 16, "attacks": [{ "name": "kicks", "hit_bonus": 0, "damage": "1d2" }] }, { @@ -101,7 +101,7 @@ "renderable": { "glyph": "q", "fg": "#e7e7e7", "bg": "#000000", "order": 1 }, "flags": ["HERBIVORE", "SMALL_GROUP"], "bac": 10, - "vision_range": 4, + "vision_range": 16, "attacks": [{ "name": "kicks", "hit_bonus": 0, "damage": "1d2" }] }, { @@ -110,7 +110,7 @@ "renderable": { "glyph": "c", "fg": "#fae478", "bg": "#000000", "order": 1 }, "flags": ["HERBIVORE"], "bac": 10, - "vision_range": 4, + "vision_range": 16, "attacks": [{ "name": "bites", "hit_bonus": 0, "damage": "1d2" }] }, { @@ -121,7 +121,7 @@ "level": 3, "bac": 6, "speed": 16, - "vision_range": 8, + "vision_range": 16, "attacks": [ { "name": "kicks", "hit_bonus": 0, "damage": "1d6" }, { "name": "bites", "hit_bonus": 0, "damage": "1d2" } @@ -136,7 +136,7 @@ "level": 5, "bac": 5, "speed": 20, - "vision_range": 8, + "vision_range": 16, "attacks": [ { "name": "kicks", "hit_bonus": 0, "damage": "1d8" }, { "name": "bites", "hit_bonus": 0, "damage": "1d3" } @@ -150,7 +150,7 @@ "level": 7, "bac": 4, "speed": 24, - "vision_range": 8, + "vision_range": 16, "attacks": [ { "name": "kicks", "hit_bonus": 0, "damage": "1d10" }, { "name": "bites", "hit_bonus": 0, "damage": "1d4" } @@ -163,7 +163,7 @@ "flags": ["SMALL_GROUP"], "level": 1, "bac": 7, - "vision_range": 8, + "vision_range": 16, "attacks": [{ "name": "bites", "hit_bonus": 0, "damage": "1d3" }], "loot": { "table": "scrolls", "chance": 0.05 } }, @@ -175,7 +175,7 @@ "level": 2, "bac": 6, "speed": 18, - "vision_range": 12, + "vision_range": 16, "quips": ["", "", ""], "attacks": [{ "name": "bites", "hit_bonus": 0, "damage": "1d6" }] }, @@ -187,7 +187,7 @@ "level": 4, "bac": 5, "speed": 16, - "vision_range": 12, + "vision_range": 16, "attacks": [{ "name": "bites", "hit_bonus": 0, "damage": "1d6" }] }, { @@ -198,7 +198,7 @@ "level": 6, "bac": 4, "speed": 15, - "vision_range": 12, + "vision_range": 16, "attacks": [{ "name": "bites", "hit_bonus": 0, "damage": "2d4" }] }, { @@ -208,7 +208,7 @@ "flags": ["SMALL_GROUP", "IS_GNOME"], "level": 1, "speed": 6, - "vision_range": 12, + "vision_range": 16, "attacks": [{ "name": "claws", "hit_bonus": 0, "damage": "1d6" }], "loot": { "table": "wands", "chance": 0.05 } }, @@ -219,7 +219,7 @@ "flags": ["MINDLESS"], "level": 1, "speed": 6, - "vision_range": 7, + "vision_range": 12, "attacks": [{ "name": "claws", "hit_bonus": 0, "damage": "1d4" }], "loot": { "table": "wands", "chance": 0.05 } }, @@ -230,7 +230,7 @@ "flags": [], "level": 1, "speed": 9, - "vision_range": 12, + "vision_range": 16, "attacks": [{ "name": "hits", "hit_bonus": 0, "damage": "1d4" }] }, { @@ -240,7 +240,7 @@ "flags": [], "level": 1, "speed": 6, - "vision_range": 7, + "vision_range": 16, "attacks": [{ "name": "hits", "hit_bonus": 0, "damage": "1d4" }], "loot": { "table": "food", "chance": 0.05 } }, @@ -251,7 +251,7 @@ "flags": ["MINDLESS"], "level": 1, "speed": 6, - "vision_range": 7, + "vision_range": 12, "attacks": [{ "name": "claws", "hit_bonus": 0, "damage": "1d4" }], "loot": { "table": "scrolls", "chance": 0.05 } }, @@ -262,7 +262,7 @@ "flags": [], "level": 1, "speed": 6, - "vision_range": 8, + "vision_range": 12, "attacks": [{ "name": "hits", "hit_bonus": 0, "damage": "1d6" }], "loot": { "table": "food", "chance": 0.05 } }, @@ -274,7 +274,7 @@ "level": 2, "bac": 9, "speed": 6, - "vision_range": 8, + "vision_range": 12, "attacks": [{ "name": "claws", "hit_bonus": 0, "damage": "1d6" }], "loot": { "table": "potions", "chance": 0.05 } }, @@ -286,7 +286,7 @@ "level": 2, "bac": 10, "speed": 6, - "vision_range": 8, + "vision_range": 16, "attacks": [{ "name": "hacks", "hit_bonus": 0, "damage": "1d8" }], "equipped": ["equip_feet_iron"], "loot": { "table": "equipment", "chance": 0.05 } @@ -299,7 +299,7 @@ "level": 2, "bac": 9, "speed": 6, - "vision_range": 8, + "vision_range": 12, "attacks": [{ "name": "claws", "hit_bonus": 0, "damage": "1d6" }], "loot": { "table": "equipment", "chance": 0.05 } }, @@ -310,7 +310,7 @@ "flags": [], "level": 2, "speed": 6, - "vision_range": 7, + "vision_range": 12, "attacks": [{ "name": "hits", "hit_bonus": 0, "damage": "2d4" }], "loot": { "table": "food", "chance": 0.05 } }, @@ -322,7 +322,7 @@ "level": 1, "bac": 3, "speed": 12, - "vision_range": 12, + "vision_range": 16, "attacks": [{ "name": "bites", "hit_bonus": 0, "damage": "1d2" }], "loot": { "table": "scrolls", "chance": 0.05 } }, @@ -332,7 +332,7 @@ "renderable": { "glyph": "d", "fg": "#AA5500", "bg": "#000000", "order": 1 }, "flags": ["CARNIVORE", "SMALL_GROUP"], "bac": 7, - "vision_range": 12, + "vision_range": 16, "attacks": [{ "name": "bites", "hit_bonus": 0, "damage": "1d2" }] }, { @@ -341,7 +341,7 @@ "renderable": { "glyph": "d", "fg": "#FF0000", "bg": "#000000", "order": 1 }, "flags": ["CARNIVORE"], "bac": 7, - "vision_range": 12, + "vision_range": 16, "attacks": [{ "name": "bites", "hit_bonus": 0, "damage": "1d3" }] }, { @@ -351,7 +351,7 @@ "flags": ["CARNIVORE", "SMALL_GROUP"], "level": 1, "bac": 7, - "vision_range": 12, + "vision_range": 16, "attacks": [{ "name": "bites", "hit_bonus": 0, "damage": "1d4" }] }, { @@ -361,7 +361,7 @@ "flags": ["CARNIVORE"], "level": 5, "bac": 4, - "vision_range": 12, + "vision_range": 16, "attacks": [{ "name": "bites", "hit_bonus": 0, "damage": "2d4" }] }, { @@ -371,7 +371,7 @@ "flags": [], "level": 2, "speed": 9, - "vision_range": 12, + "vision_range": 16, "attacks": [{ "name": "hits", "hit_bonus": 0, "damage": "1d8" }], "loot": { "table": "wands", "chance": 0.05 } }, @@ -382,7 +382,7 @@ "flags": ["SMALL_GROUP"], "level": 1, "speed": 9, - "vision_range": 12, + "vision_range": 16, "attacks": [{ "name": "hits", "hit_bonus": 0, "damage": "1d6" }], "loot": { "table": "equipment", "chance": 0.05 } }, @@ -393,7 +393,7 @@ "flags": ["LARGE_GROUP"], "level": 2, "speed": 9, - "vision_range": 11, + "vision_range": 16, "attacks": [{ "name": "hits", "hit_bonus": 0, "damage": "1d6" }], "loot": { "table": "equipment", "chance": 0.05 } }, @@ -404,7 +404,7 @@ "flags": ["MULTIATTACK"], "level": 5, "speed": 5, - "vision_range": 12, + "vision_range": 16, "attacks": [ { "name": "hits", "hit_bonus": 0, "damage": "2d4" }, { "name": "hits", "hit_bonus": 0, "damage": "2d4" } @@ -419,7 +419,7 @@ "level": 5, "bac": 5, "speed": 10, - "vision_range": 8, + "vision_range": 16, "attacks": [{ "name": "hits", "hit_bonus": 0, "damage": "2d5" }], "loot": { "table": "food", "chance": 0.05 } } diff --git a/src/ai/adjacent_ai_system.rs b/src/ai/adjacent_ai_system.rs index 5a930ba..5586948 100644 --- a/src/ai/adjacent_ai_system.rs +++ b/src/ai/adjacent_ai_system.rs @@ -1,4 +1,4 @@ -use crate::{raws::Reaction, Faction, HasAncestry, Map, Position, TakingTurn, WantsToMelee}; +use crate::{ raws::Reaction, Faction, HasAncestry, Map, Position, TakingTurn, WantsToMelee }; use specs::prelude::*; pub struct AdjacentAI {} @@ -34,22 +34,22 @@ impl<'a> System<'a> for AdjacentAI { evaluate(entity, idx + 1, &ancestries, &factions, &mut reactions); } if pos.y > 0 { - evaluate(entity, idx - w as usize, &ancestries, &factions, &mut reactions); + evaluate(entity, idx - (w as usize), &ancestries, &factions, &mut reactions); } if pos.y < h - 1 { - evaluate(entity, idx + w as usize, &ancestries, &factions, &mut reactions); + evaluate(entity, idx + (w as usize), &ancestries, &factions, &mut reactions); } if pos.y > 0 && pos.x > 0 { - evaluate(entity, (idx - w as usize) - 1, &ancestries, &factions, &mut reactions); + evaluate(entity, idx - (w as usize) - 1, &ancestries, &factions, &mut reactions); } if pos.y > 0 && pos.x < w - 1 { - evaluate(entity, (idx - w as usize) + 1, &ancestries, &factions, &mut reactions); + evaluate(entity, idx - (w as usize) + 1, &ancestries, &factions, &mut reactions); } if pos.y < h - 1 && pos.x > 0 { - evaluate(entity, (idx + w as usize) - 1, &ancestries, &factions, &mut reactions); + evaluate(entity, idx + (w as usize) - 1, &ancestries, &factions, &mut reactions); } if pos.y < h - 1 && pos.x < w - 1 { - evaluate(entity, (idx + w as usize) + 1, &ancestries, &factions, &mut reactions); + evaluate(entity, idx + (w as usize) + 1, &ancestries, &factions, &mut reactions); } let mut done = false; @@ -79,7 +79,7 @@ fn evaluate( idx: usize, ancestries: &ReadStorage, factions: &ReadStorage, - reactions: &mut Vec<(Entity, Reaction)>, + reactions: &mut Vec<(Entity, Reaction)> ) { crate::spatial::for_each_tile_content(idx, |other_entity| { let result = crate::raws::get_reactions( @@ -87,7 +87,7 @@ fn evaluate( other_entity, &factions, &ancestries, - &crate::raws::RAWS.lock().unwrap(), + &crate::raws::RAWS.lock().unwrap() ); reactions.push((other_entity, result)); }); diff --git a/src/ai/approach_ai_system.rs b/src/ai/approach_ai_system.rs index 33bc9ec..f303e03 100644 --- a/src/ai/approach_ai_system.rs +++ b/src/ai/approach_ai_system.rs @@ -1,4 +1,4 @@ -use crate::{EntityMoved, Map, Position, TakingTurn, Telepath, Viewshed, WantsToApproach}; +use crate::{ EntityMoved, Map, Position, TakingTurn, Telepath, Viewshed, WantsToApproach }; use rltk::prelude::*; use specs::prelude::*; @@ -29,19 +29,23 @@ impl<'a> System<'a> for ApproachAI { entities, ) = data; let mut turn_done: Vec = Vec::new(); - for (entity, mut pos, approach, mut viewshed, _turn) in - (&entities, &mut positions, &wants_to_approach, &mut viewsheds, &turns).join() - { + for (entity, mut pos, approach, mut viewshed, _turn) in ( + &entities, + &mut positions, + &wants_to_approach, + &mut viewsheds, + &turns, + ).join() { turn_done.push(entity); let path = a_star_search( map.xy_idx(pos.x, pos.y) as i32, map.xy_idx(approach.idx % map.width, approach.idx / map.width) as i32, - &mut *map, + &mut *map ); if path.success && path.steps.len() > 1 { let idx = map.xy_idx(pos.x, pos.y); - pos.x = path.steps[1] as i32 % map.width; - pos.y = path.steps[1] as i32 / map.width; + pos.x = (path.steps[1] as i32) % map.width; + pos.y = (path.steps[1] as i32) / map.width; entity_moved.insert(entity, EntityMoved {}).expect("Unable to insert EntityMoved"); let new_idx = map.xy_idx(pos.x, pos.y); crate::spatial::move_entity(entity, idx, new_idx); diff --git a/src/ai/chase_ai_system.rs b/src/ai/chase_ai_system.rs index bf264b2..cb7942f 100644 --- a/src/ai/chase_ai_system.rs +++ b/src/ai/chase_ai_system.rs @@ -1,4 +1,4 @@ -use crate::{Chasing, EntityMoved, Map, Position, TakingTurn, Telepath, Viewshed}; +use crate::{ Chasing, EntityMoved, Map, Position, TakingTurn, Telepath, Viewshed }; use rltk::prelude::*; use specs::prelude::*; use std::collections::HashMap; @@ -48,20 +48,24 @@ impl<'a> System<'a> for ChaseAI { // stored in the HashMap. If successful, follow the path. If not, remove // the chasing component. let mut turn_done: Vec = Vec::new(); - for (entity, _turn, mut pos, _chase, mut viewshed) in - (&entities, &turns, &mut positions, &chasing, &mut viewsheds).join() - { + for (entity, _turn, mut pos, _chase, mut viewshed) in ( + &entities, + &turns, + &mut positions, + &chasing, + &mut viewsheds, + ).join() { turn_done.push(entity); let target_pos = targets[&entity]; let path = a_star_search( map.xy_idx(pos.x, pos.y) as i32, map.xy_idx(target_pos.0, target_pos.1) as i32, - &mut *map, + &mut *map ); if path.success && path.steps.len() > 1 && path.steps.len() < MAX_CHASE_DISTANCE { let idx = map.xy_idx(pos.x, pos.y); - pos.x = path.steps[1] as i32 % map.width; - pos.y = path.steps[1] as i32 / map.width; + pos.x = (path.steps[1] as i32) % map.width; + pos.y = (path.steps[1] as i32) / map.width; entity_moved.insert(entity, EntityMoved {}).expect("Failed to insert EntityMoved"); let new_idx = map.xy_idx(pos.x, pos.y); crate::spatial::move_entity(entity, idx, new_idx); diff --git a/src/ai/default_move_system.rs b/src/ai/default_move_system.rs index f32f05f..ef2514c 100644 --- a/src/ai/default_move_system.rs +++ b/src/ai/default_move_system.rs @@ -1,4 +1,4 @@ -use crate::{tile_walkable, EntityMoved, Map, MoveMode, Movement, Position, TakingTurn, Telepath, Viewshed}; +use crate::{ tile_walkable, EntityMoved, Map, MoveMode, Movement, Position, TakingTurn, Telepath, Viewshed }; use specs::prelude::*; // Rolling a 1d8+x to decide where to move, where x are the number @@ -33,9 +33,13 @@ impl<'a> System<'a> for DefaultAI { entities, ) = data; let mut turn_done: Vec = Vec::new(); - for (entity, _turn, mut pos, mut move_mode, mut viewshed) in - (&entities, &turns, &mut positions, &mut move_mode, &mut viewsheds).join() - { + for (entity, _turn, mut pos, mut move_mode, mut viewshed) in ( + &entities, + &turns, + &mut positions, + &mut move_mode, + &mut viewsheds, + ).join() { turn_done.push(entity); match &mut move_mode.mode { Movement::Static => {} @@ -44,25 +48,33 @@ impl<'a> System<'a> for DefaultAI { let mut y = pos.y; let move_roll = rng.roll_dice(1, 8 + CHANCE_OF_REMAINING_STATIONARY); match move_roll { - 1 => x -= 1, - 2 => x += 1, - 3 => y -= 1, - 4 => y += 1, + 1 => { + x -= 1; + } + 2 => { + x += 1; + } + 3 => { + y -= 1; + } + 4 => { + y += 1; + } 5 => { x -= 1; - y -= 1 + y -= 1; } 6 => { x += 1; - y -= 1 + y -= 1; } 7 => { x -= 1; - y += 1 + y += 1; } 8 => { x += 1; - y += 1 + y += 1; } _ => {} } @@ -88,8 +100,8 @@ impl<'a> System<'a> for DefaultAI { let idx = map.xy_idx(pos.x, pos.y); if path.len() > 1 { if !crate::spatial::is_blocked(path[1] as usize) { - pos.x = path[1] as i32 % map.width; - pos.y = path[1] as i32 / map.width; + pos.x = (path[1] as i32) % map.width; + pos.y = (path[1] as i32) / map.width; entity_moved.insert(entity, EntityMoved {}).expect("Unable to insert EntityMoved"); let new_idx = map.xy_idx(pos.x, pos.y); crate::spatial::move_entity(entity, idx, new_idx); @@ -110,10 +122,12 @@ impl<'a> System<'a> for DefaultAI { let path = rltk::a_star_search( map.xy_idx(pos.x, pos.y) as i32, map.xy_idx(target_x, target_y) as i32, - &mut *map, + &mut *map ); if path.success && path.steps.len() > 1 { - move_mode.mode = Movement::RandomWaypoint { path: Some(path.steps) }; + move_mode.mode = Movement::RandomWaypoint { + path: Some(path.steps), + }; } } } diff --git a/src/ai/encumbrance_system.rs b/src/ai/encumbrance_system.rs index ceb2815..53aaed3 100644 --- a/src/ai/encumbrance_system.rs +++ b/src/ai/encumbrance_system.rs @@ -1,4 +1,4 @@ -use crate::{gamelog, Attributes, Burden, EquipmentChanged, Equipped, InBackpack, Item, Pools}; +use crate::{ gamelog, Attributes, Burden, EquipmentChanged, Equipped, InBackpack, Item, Pools }; use specs::prelude::*; use std::collections::HashMap; @@ -52,7 +52,7 @@ impl<'a> System<'a> for EncumbranceSystem { if let Some(attr) = attributes.get(*entity) { let carry_capacity_lbs = (attr.strength.base + attr.strength.modifiers) * CARRY_CAPACITY_PER_STRENGTH; - if pool.weight as i32 > 3 * carry_capacity_lbs { + if (pool.weight as i32) > 3 * carry_capacity_lbs { // Overloaded burdened .insert(*entity, Burden { level: crate::BurdenLevel::Overloaded }) @@ -60,7 +60,7 @@ impl<'a> System<'a> for EncumbranceSystem { if *entity == *player { gamelog::Logger::new().append("You're overloaded!").log(); } - } else if pool.weight as i32 > 2 * carry_capacity_lbs { + } else if (pool.weight as i32) > 2 * carry_capacity_lbs { // Strained burdened .insert(*entity, Burden { level: crate::BurdenLevel::Strained }) @@ -68,7 +68,7 @@ impl<'a> System<'a> for EncumbranceSystem { if *entity == *player { gamelog::Logger::new().append("You're strained.").log(); } - } else if pool.weight as i32 > carry_capacity_lbs { + } else if (pool.weight as i32) > carry_capacity_lbs { // Burdened burdened .insert(*entity, Burden { level: crate::BurdenLevel::Burdened }) diff --git a/src/ai/energy_system.rs b/src/ai/energy_system.rs index 65b4020..c24c7c7 100644 --- a/src/ai/energy_system.rs +++ b/src/ai/energy_system.rs @@ -1,5 +1,5 @@ use crate::config::entity::*; -use crate::{Burden, BurdenLevel, Clock, Energy, Name, Position, RunState, TakingTurn, LOG_TICKS}; +use crate::{ Burden, BurdenLevel, Clock, Energy, Name, Position, RunState, TakingTurn, LOG_TICKS }; use rltk::prelude::*; use specs::prelude::*; @@ -68,7 +68,7 @@ impl<'a> System<'a> for EnergySystem { 1.0 }; // Every entity has a POTENTIAL equal to their speed. - let mut energy_potential: i32 = (energy.speed as f32 * burden_modifier) as i32; + let mut energy_potential: i32 = ((energy.speed as f32) * burden_modifier) as i32; // Increment current energy by NORMAL_SPEED for every // whole number of NORMAL_SPEEDS in their POTENTIAL. while energy_potential >= NORMAL_SPEED { @@ -103,10 +103,9 @@ impl<'a> System<'a> for EnergySystem { turns.insert(entity, TakingTurn {}).expect("Unable to insert turn."); if LOG_TICKS { let name = if let Some(name) = names.get(entity) { &name.name } else { "Unknown entity" }; - console::log(format!( - "ENERGY SYSTEM: {} granted a turn. [leftover energy: {}].", - name, energy.current - )); + console::log( + format!("ENERGY SYSTEM: {} granted a turn. [leftover energy: {}].", name, energy.current) + ); } } } diff --git a/src/ai/flee_ai_system.rs b/src/ai/flee_ai_system.rs index 10c34a3..ce6f8b0 100644 --- a/src/ai/flee_ai_system.rs +++ b/src/ai/flee_ai_system.rs @@ -1,4 +1,4 @@ -use crate::{EntityMoved, Map, Position, TakingTurn, Telepath, Viewshed, WantsToFlee}; +use crate::{ EntityMoved, Map, Position, TakingTurn, Telepath, Viewshed, WantsToFlee }; use rltk::prelude::*; use specs::prelude::*; @@ -29,9 +29,13 @@ impl<'a> System<'a> for FleeAI { entities, ) = data; let mut turn_done: Vec = Vec::new(); - for (entity, _turn, mut pos, fleeing, mut viewshed) in - (&entities, &turns, &mut positions, &wants_to_flee, &mut viewsheds).join() - { + for (entity, _turn, mut pos, fleeing, mut viewshed) in ( + &entities, + &turns, + &mut positions, + &wants_to_flee, + &mut viewsheds, + ).join() { turn_done.push(entity); let my_idx = map.xy_idx(pos.x, pos.y); map.populate_blocked(); @@ -44,8 +48,8 @@ impl<'a> System<'a> for FleeAI { if let Some(is_telepath) = telepaths.get_mut(entity) { is_telepath.dirty = true; } - pos.x = flee_target as i32 % map.width; - pos.y = flee_target as i32 / map.width; + pos.x = (flee_target as i32) % map.width; + pos.y = (flee_target as i32) / map.width; entity_moved.insert(entity, EntityMoved {}).expect("Unable to insert EntityMoved"); } } diff --git a/src/ai/mod.rs b/src/ai/mod.rs index 77a64e8..112f3c5 100644 --- a/src/ai/mod.rs +++ b/src/ai/mod.rs @@ -7,7 +7,7 @@ pub use quip_system::QuipSystem; mod regen_system; pub use regen_system::RegenSystem; mod encumbrance_system; -pub use encumbrance_system::{EncumbranceSystem, CARRY_CAPACITY_PER_STRENGTH}; +pub use encumbrance_system::{ EncumbranceSystem, CARRY_CAPACITY_PER_STRENGTH }; mod adjacent_ai_system; pub use adjacent_ai_system::AdjacentAI; mod visible_ai_system; diff --git a/src/ai/quip_system.rs b/src/ai/quip_system.rs index 7ccda9e..6b535a9 100644 --- a/src/ai/quip_system.rs +++ b/src/ai/quip_system.rs @@ -1,4 +1,4 @@ -use crate::{gamelog, gui::renderable_colour, Name, Quips, Renderable, TakingTurn, Viewshed}; +use crate::{ gamelog, gui::renderable_colour, Name, Quips, Renderable, TakingTurn, Viewshed }; use rltk::prelude::*; use specs::prelude::*; @@ -26,7 +26,8 @@ impl<'a> System<'a> for QuipSystem { } else { (rng.roll_dice(1, quip.available.len() as i32) - 1) as usize }; - gamelog::Logger::new() + gamelog::Logger + ::new() .append("The") .colour(renderable_colour(&renderables, entity)) .append(&name.name) diff --git a/src/ai/regen_system.rs b/src/ai/regen_system.rs index 6ae6f0e..8ac4437 100644 --- a/src/ai/regen_system.rs +++ b/src/ai/regen_system.rs @@ -1,5 +1,14 @@ use crate::{ - gamelog, gui::Class, Attributes, Clock, HasClass, Player, Pools, Position, RandomNumberGenerator, TakingTurn, + gamelog, + gui::Class, + Attributes, + Clock, + HasClass, + Player, + Pools, + Position, + RandomNumberGenerator, + TakingTurn, }; use specs::prelude::*; @@ -55,8 +64,8 @@ impl<'a> System<'a> for RegenSystem { for (e, _p, pool) in (&entities, &positions, &mut pools).join() { let is_wizard = if let Some(class) = classes.get(e) { class.name == Class::Wizard } else { false }; let numerator = if is_wizard { WIZARD_MP_REGEN_MOD } else { NONWIZARD_MP_REGEN_MOD }; - let multiplier: f32 = numerator as f32 / MP_REGEN_DIVISOR as f32; - let mp_regen_tick = ((MP_REGEN_BASE - pool.level) as f32 * multiplier) as i32; + let multiplier: f32 = (numerator as f32) / (MP_REGEN_DIVISOR as f32); + let mp_regen_tick = (((MP_REGEN_BASE - pool.level) as f32) * multiplier) as i32; if current_turn % mp_regen_tick == 0 { try_mana_regen_tick(pool, rng.roll_dice(1, get_mana_regen_per_tick(e, &attributes))); } @@ -66,7 +75,7 @@ impl<'a> System<'a> for RegenSystem { fn get_player_hp_regen_turn(level: i32) -> i32 { if level < 10 { - return (42 / (level + 2)) + 1; + return 42 / (level + 2) + 1; } else { return 3; } @@ -86,7 +95,7 @@ fn try_hp_regen_tick(pool: &mut Pools, amount: i32) { fn get_mana_regen_per_tick(e: Entity, attributes: &ReadStorage) -> i32 { let regen = if let Some(attributes) = attributes.get(e) { - ((attributes.intelligence.bonus + attributes.wisdom.bonus) / 2) + MIN_MP_REGEN_PER_TURN + (attributes.intelligence.bonus + attributes.wisdom.bonus) / 2 + MIN_MP_REGEN_PER_TURN } else { MIN_MP_REGEN_PER_TURN }; diff --git a/src/ai/turn_status_system.rs b/src/ai/turn_status_system.rs index 0945bfc..17f2db6 100644 --- a/src/ai/turn_status_system.rs +++ b/src/ai/turn_status_system.rs @@ -1,8 +1,12 @@ use crate::{ - effects::{add_effect, EffectType, Targets}, + effects::{ add_effect, EffectType, Targets }, gamelog, gui::renderable_colour, - Clock, Confusion, Name, Renderable, TakingTurn, + Clock, + Confusion, + Name, + Renderable, + TakingTurn, }; use rltk::prelude::*; use specs::prelude::*; @@ -63,7 +67,7 @@ impl<'a> System<'a> for TurnStatusSystem { lifespan: 200.0, delay: 0.0, }, - Targets::Entity { target: entity }, + Targets::Entity { target: entity } ); } else { not_my_turn.push(entity); @@ -93,7 +97,7 @@ impl<'a> System<'a> for TurnStatusSystem { lifespan: 200.0, delay: 0.0, }, - Targets::Entity { target: entity }, + Targets::Entity { target: entity } ); } } diff --git a/src/ai/visible_ai_system.rs b/src/ai/visible_ai_system.rs index ade98c5..6ed85d2 100644 --- a/src/ai/visible_ai_system.rs +++ b/src/ai/visible_ai_system.rs @@ -1,6 +1,16 @@ use crate::{ - raws::Reaction, Chasing, Faction, HasAncestry, Map, Mind, Position, TakingTurn, Telepath, Viewshed, - WantsToApproach, WantsToFlee, + raws::Reaction, + Chasing, + Faction, + HasAncestry, + Map, + Mind, + Position, + TakingTurn, + Telepath, + Viewshed, + WantsToApproach, + WantsToFlee, }; use rltk::prelude::*; use specs::prelude::*; @@ -70,10 +80,10 @@ impl<'a> System<'a> for VisibleAI { } } reactions.sort_by(|(a, _, _), (b, _, _)| { - let (a_x, a_y) = (a % map.width as usize, a / map.width as usize); + let (a_x, a_y) = (a % (map.width as usize), a / (map.width as usize)); let dist_a = DistanceAlg::PythagorasSquared.distance2d(Point::new(a_x, a_y), Point::new(pos.x, pos.y)); let dist_a_estimate = dist_a as i32; - let (b_x, b_y) = (b % map.width as usize, b / map.width as usize); + let (b_x, b_y) = (b % (map.width as usize), b / (map.width as usize)); let dist_b = DistanceAlg::PythagorasSquared.distance2d(Point::new(b_x, b_y), Point::new(pos.x, pos.y)); let dist_b_estimate = dist_b as i32; return dist_b_estimate.cmp(&dist_a_estimate); @@ -110,7 +120,7 @@ fn evaluate( ancestries: &ReadStorage, factions: &ReadStorage, reactions: &mut Vec<(usize, Reaction, Entity)>, - minds: Option<&ReadStorage>, + minds: Option<&ReadStorage> ) { crate::spatial::for_each_tile_content(idx, |other_entity| { let mut check = true; @@ -129,7 +139,7 @@ fn evaluate( other_entity, &factions, &ancestries, - &crate::raws::RAWS.lock().unwrap(), + &crate::raws::RAWS.lock().unwrap() ), other_entity, )); diff --git a/src/camera.rs b/src/camera.rs index 3e779ab..0a5f8e8 100644 --- a/src/camera.rs +++ b/src/camera.rs @@ -1,4 +1,4 @@ -use super::{Hidden, Map, Mind, Position, Prop, Renderable}; +use super::{ Hidden, Map, Mind, Position, Prop, Renderable }; use rltk::prelude::*; use specs::prelude::*; use std::ops::Mul; @@ -15,8 +15,8 @@ pub fn get_screen_bounds(ecs: &World, _ctx: &mut Rltk) -> (i32, i32, i32, i32, i let min_x = player_pos.x - centre_x; let min_y = player_pos.y - centre_y; - let max_x = min_x + x_chars as i32; - let max_y = min_y + y_chars as i32; + let max_x = min_x + (x_chars as i32); + let max_y = min_y + (y_chars as i32); (min_x, max_x, min_y, max_y, x_offset, y_offset) } @@ -33,8 +33,11 @@ pub fn render_camera(ecs: &World, ctx: &mut Rltk) { if t_x >= 0 && t_x < map.width && t_y >= 0 && t_y < map.height { let idx = map.xy_idx(t_x, t_y); if map.revealed_tiles[idx] { - let (glyph, fg, bg) = - crate::map::themes::get_tile_renderables_for_id(idx, &*map, Some(*ecs.fetch::())); + let (glyph, fg, bg) = crate::map::themes::get_tile_renderables_for_id( + idx, + &*map, + Some(*ecs.fetch::()) + ); ctx.set(x + x_offset, y + y_offset, fg, bg, glyph); } } else if SHOW_BOUNDARIES { @@ -108,9 +111,9 @@ pub fn render_debug_map(map: &Map, ctx: &mut Rltk) { let center_y = (y_chars / 2) as i32; let min_x = player_pos.x - center_x; - let max_x = min_x + x_chars as i32; + let max_x = min_x + (x_chars as i32); let min_y = player_pos.y - center_y; - let max_y = min_y + y_chars as i32; + let max_y = min_y + (y_chars as i32); let map_width = map.width; let map_height = map.height; diff --git a/src/components.rs b/src/components.rs index 88cbb33..8cd93ae 100644 --- a/src/components.rs +++ b/src/components.rs @@ -1,10 +1,10 @@ use crate::gui::Ancestry; use crate::gui::Class; use rltk::RGB; -use serde::{Deserialize, Serialize}; +use serde::{ Deserialize, Serialize }; use specs::error::NoError; use specs::prelude::*; -use specs::saveload::{ConvertSaveload, Marker}; +use specs::saveload::{ ConvertSaveload, Marker }; use specs_derive::*; use std::collections::HashMap; @@ -57,7 +57,9 @@ pub struct Faction { pub enum Movement { Static, Random, - RandomWaypoint { path: Option> }, + RandomWaypoint { + path: Option>, + }, } #[derive(Component, Debug, Serialize, Deserialize, Clone)] @@ -237,7 +239,7 @@ pub struct Beatitude { #[derive(Component, Debug, Serialize, Deserialize, Clone)] pub struct Item { pub weight: f32, // in lbs - pub value: f32, // base + pub value: f32, // base } #[derive(Debug, Serialize, Deserialize, Clone, Eq, PartialEq, Hash)] diff --git a/src/config/entity.rs b/src/config/entity.rs index 1ce3448..3580bda 100644 --- a/src/config/entity.rs +++ b/src/config/entity.rs @@ -1,3 +1,5 @@ +// prettier-ignore +#[rustfmt::skip] pub const DEFAULT_VIEWSHED_STANDARD: i32 = 16; // Standard viewshed radius for almost all entities. pub const NORMAL_SPEED: i32 = 12; // Normal speed for almost all entities. diff --git a/src/damage_system.rs b/src/damage_system.rs index ea76b3c..25ebaec 100644 --- a/src/damage_system.rs +++ b/src/damage_system.rs @@ -1,5 +1,15 @@ use super::{ - gamelog, gui::renderable_colour, Equipped, InBackpack, Item, LootTable, Name, Player, Pools, Position, Renderable, + gamelog, + gui::renderable_colour, + Equipped, + InBackpack, + Item, + LootTable, + Name, + Player, + Pools, + Position, + Renderable, RunState, }; use rltk::prelude::*; @@ -24,7 +34,8 @@ pub fn delete_the_dead(ecs: &mut World) { if let Some(victim_name) = victim_name { let item = items.get(entity); if let Some(_item) = item { - gamelog::Logger::new() + gamelog::Logger + ::new() .append("The") .colour(renderable_colour(&renderables, entity)) .append(&victim_name.name) @@ -32,7 +43,8 @@ pub fn delete_the_dead(ecs: &mut World) { .append("is destroyed!") .log(); } else { - gamelog::Logger::new() + gamelog::Logger + ::new() .append("The") .colour(renderable_colour(&renderables, entity)) .append(&victim_name.name) @@ -41,7 +53,7 @@ pub fn delete_the_dead(ecs: &mut World) { .log(); } } - dead.push(entity) + dead.push(entity); } // The player died, go to GameOver. Some(_) => { @@ -60,7 +72,7 @@ pub fn delete_the_dead(ecs: &mut World) { &loot.0, None, crate::raws::SpawnType::AtPosition { x: loot.1.x, y: loot.1.y }, - 0, + 0 ); } for item in items_to_delete { @@ -104,8 +116,11 @@ fn handle_dead_entity_items(ecs: &mut World, dead: &Vec) -> (Vec if let Some(table) = loot_tables.get(*victim) { let roll: f32 = rng.rand(); if roll < table.chance { - let potential_drop = - crate::raws::roll_on_loot_table(&crate::raws::RAWS.lock().unwrap(), &mut rng, &table.table); + let potential_drop = crate::raws::roll_on_loot_table( + &crate::raws::RAWS.lock().unwrap(), + &mut rng, + &table.table + ); if let Some(id) = potential_drop { if let Some(pos) = pos { to_spawn.push((id, pos.clone())); diff --git a/src/effects/damage.rs b/src/effects/damage.rs index 35a5906..7613d42 100644 --- a/src/effects/damage.rs +++ b/src/effects/damage.rs @@ -1,8 +1,15 @@ -use super::{add_effect, targeting, EffectSpawner, EffectType, Entity, Targets, World}; +use super::{ add_effect, targeting, EffectSpawner, EffectType, Entity, Targets, World }; use crate::{ gamelog, - gamesystem::{hp_per_level, mana_per_level}, - Attributes, Confusion, Destructible, GrantsXP, Map, Player, Pools, DEFAULT_PARTICLE_LIFETIME, + gamesystem::{ hp_per_level, mana_per_level }, + Attributes, + Confusion, + Destructible, + GrantsXP, + Map, + Player, + Pools, + DEFAULT_PARTICLE_LIFETIME, LONG_PARTICLE_LIFETIME, }; use rltk::prelude::*; @@ -24,7 +31,7 @@ pub fn inflict_damage(ecs: &mut World, damage: &EffectSpawner, target: Entity) { lifespan: DEFAULT_PARTICLE_LIFETIME, delay: 0.0, }, - Targets::Entity { target }, + Targets::Entity { target } ); if target_pool.hit_points.current < 1 { super::DEAD_ENTITIES.lock().unwrap().push_back(target); @@ -57,7 +64,7 @@ pub fn heal_damage(ecs: &mut World, heal: &EffectSpawner, target: Entity) { lifespan: DEFAULT_PARTICLE_LIFETIME, delay: 0.0, }, - Targets::Entity { target }, + Targets::Entity { target } ); } } @@ -98,7 +105,7 @@ pub fn bloodstain(ecs: &mut World, target: usize) { // - If we're in bounds and the tile is unbloodied, bloody it and return. // - If we ever leave bounds, return. // - Roll a dice on each failed attempt, with an increasing change to return (soft-capping max spread) - if spread > 0 && spread < (map.height * map.width) { + if spread > 0 && spread < map.height * map.width { if !map.bloodstains.contains(&(spread as usize)) { map.bloodstains.insert(spread as usize); return; @@ -117,9 +124,9 @@ fn get_next_level_requirement(level: i32) -> i32 { if level == 0 { return 5; } else if level < 10 { - return 20 * 2_i32.pow(level as u32 - 1); + return 20 * (2_i32).pow((level as u32) - 1); } else if level < 20 { - return 10000 * 2_i32.pow(level as u32 - 10); + return 10000 * (2_i32).pow((level as u32) - 10); } else if level < 30 { return 10000000 * (level - 19); } @@ -155,7 +162,8 @@ pub fn entity_death(ecs: &mut World, effect: &EffectSpawner, target: Entity) { // If it was the PLAYER that levelled up: if ecs.read_storage::().get(source).is_some() { gamelog::record_event("player_level", 1); - gamelog::Logger::new() + gamelog::Logger + ::new() .append("Welcome to experience level") .append(source_pools.level) .append(".") @@ -171,9 +179,9 @@ pub fn entity_death(ecs: &mut World, effect: &EffectSpawner, target: Entity) { fg: RGB::named(GOLD), bg: RGB::named(BLACK), lifespan: LONG_PARTICLE_LIFETIME, - delay: i as f32 * 100.0, + delay: (i as f32) * 100.0, }, - Targets::Tile { target: map.xy_idx(player_pos.x, player_pos.y - i) }, + Targets::Tile { target: map.xy_idx(player_pos.x, player_pos.y - i) } ); if i > 2 { add_effect( @@ -183,9 +191,9 @@ pub fn entity_death(ecs: &mut World, effect: &EffectSpawner, target: Entity) { fg: RGB::named(GOLD), bg: RGB::named(BLACK), lifespan: LONG_PARTICLE_LIFETIME, - delay: i as f32 * 100.0, + delay: (i as f32) * 100.0, }, - Targets::Tile { target: map.xy_idx(player_pos.x + (i - 2), player_pos.y - i) }, + Targets::Tile { target: map.xy_idx(player_pos.x + (i - 2), player_pos.y - i) } ); add_effect( None, @@ -194,9 +202,9 @@ pub fn entity_death(ecs: &mut World, effect: &EffectSpawner, target: Entity) { fg: RGB::named(GOLD), bg: RGB::named(BLACK), lifespan: LONG_PARTICLE_LIFETIME, - delay: i as f32 * 100.0, + delay: (i as f32) * 100.0, }, - Targets::Tile { target: map.xy_idx(player_pos.x - (i - 2), player_pos.y - i) }, + Targets::Tile { target: map.xy_idx(player_pos.x - (i - 2), player_pos.y - i) } ); } } @@ -208,11 +216,11 @@ pub fn entity_death(ecs: &mut World, effect: &EffectSpawner, target: Entity) { let mut rng = ecs.write_resource::(); let hp_gained = hp_per_level( &mut rng, - source_attributes.constitution.base + source_attributes.constitution.modifiers, + source_attributes.constitution.base + source_attributes.constitution.modifiers ); let mana_gained = mana_per_level( &mut rng, - source_attributes.intelligence.base + source_attributes.intelligence.modifiers, + source_attributes.intelligence.base + source_attributes.intelligence.modifiers ); source_pools.hit_points.max += hp_gained; source_pools.hit_points.current += hp_gained; diff --git a/src/effects/hunger.rs b/src/effects/hunger.rs index 826d9fc..2384bb5 100644 --- a/src/effects/hunger.rs +++ b/src/effects/hunger.rs @@ -1,4 +1,4 @@ -use super::{EffectSpawner, EffectType}; +use super::{ EffectSpawner, EffectType }; use crate::HungerClock; use specs::prelude::*; diff --git a/src/effects/mod.rs b/src/effects/mod.rs index 2ae7567..7d154f1 100644 --- a/src/effects/mod.rs +++ b/src/effects/mod.rs @@ -23,24 +23,51 @@ lazy_static! { } pub enum EffectType { - Damage { amount: i32 }, - Healing { amount: i32, increment_max: bool }, - Confusion { turns: i32 }, + Damage { + amount: i32, + }, + Healing { + amount: i32, + increment_max: bool, + }, + Confusion { + turns: i32, + }, Bloodstain, - Particle { glyph: FontCharType, fg: RGB, bg: RGB, lifespan: f32, delay: f32 }, + Particle { + glyph: FontCharType, + fg: RGB, + bg: RGB, + lifespan: f32, + delay: f32, + }, EntityDeath, - ItemUse { item: Entity }, - ModifyNutrition { amount: i32 }, - TriggerFire { trigger: Entity }, + ItemUse { + item: Entity, + }, + ModifyNutrition { + amount: i32, + }, + TriggerFire { + trigger: Entity, + }, } #[derive(Clone)] #[allow(dead_code)] pub enum Targets { - Entity { target: Entity }, - EntityList { targets: Vec }, - Tile { target: usize }, - TileList { targets: Vec }, + Entity { + target: Entity, + }, + EntityList { + targets: Vec, + }, + Tile { + target: usize, + }, + TileList { + targets: Vec, + }, } pub struct EffectSpawner { @@ -61,7 +88,9 @@ pub fn run_effects_queue(ecs: &mut World) { loop { let dead_entity: Option = DEAD_ENTITIES.lock().unwrap().pop_front(); if let Some(dead_entity) = dead_entity { - EFFECT_QUEUE.lock().unwrap().retain(|x| x.source != Some(dead_entity)); + EFFECT_QUEUE.lock() + .unwrap() + .retain(|x| x.source != Some(dead_entity)); } else { break; } @@ -147,9 +176,5 @@ fn affect_entity(ecs: &mut World, effect: &EffectSpawner, target: Entity) { } pub fn get_noncursed(buc: &BUC) -> bool { - if buc == &BUC::Cursed { - false - } else { - true - } + if buc == &BUC::Cursed { false } else { true } } diff --git a/src/effects/particles.rs b/src/effects/particles.rs index 6b7e491..c1c1bc6 100644 --- a/src/effects/particles.rs +++ b/src/effects/particles.rs @@ -1,5 +1,5 @@ -use super::{add_effect, targeting, EffectSpawner, EffectType, Targets}; -use crate::{Map, ParticleBuilder, SpawnParticleBurst, SpawnParticleLine, SpawnParticleSimple}; +use super::{ add_effect, targeting, EffectSpawner, EffectType, Targets }; +use crate::{ Map, ParticleBuilder, SpawnParticleBurst, SpawnParticleLine, SpawnParticleSimple }; use rltk::prelude::*; use specs::prelude::*; @@ -26,7 +26,7 @@ pub fn handle_simple_particles(ecs: &World, entity: Entity, target: &Targets) { lifespan: part.lifetime_ms, delay: 0.0, }, - target.clone(), + target.clone() ); } } @@ -39,33 +39,33 @@ pub fn handle_burst_particles(ecs: &World, entity: Entity, target: &Targets) { ecs, start_pos, end_pos, - &SpawnParticleLine { + &(SpawnParticleLine { glyph: part.head_glyph, tail_glyph: part.tail_glyph, colour: part.colour, trail_colour: part.trail_colour, lifetime_ms: part.trail_lifetime_ms, // 75.0 is good here. trail_lifetime_ms: part.trail_lifetime_ms, - }, + }) ); let map = ecs.fetch::(); let line = line2d( LineAlg::Bresenham, Point::new(start_pos % map.width, start_pos / map.width), - Point::new(end_pos % map.width, end_pos / map.width), + Point::new(end_pos % map.width, end_pos / map.width) ); - let burst_delay = line.len() as f32 * part.trail_lifetime_ms; + let burst_delay = (line.len() as f32) * part.trail_lifetime_ms; for i in 0..10 { add_effect( None, EffectType::Particle { glyph: part.glyph, - fg: part.colour.lerp(part.lerp, i as f32 * 0.1), + fg: part.colour.lerp(part.lerp, (i as f32) * 0.1), bg: RGB::named(BLACK), lifespan: part.lifetime_ms / 10.0, // ~50-80 is good here. - delay: burst_delay + (i as f32 * part.lifetime_ms / 10.0), // above + burst_delay + delay: burst_delay + ((i as f32) * part.lifetime_ms) / 10.0, // above + burst_delay }, - target.clone(), + target.clone() ); } } @@ -74,27 +74,31 @@ pub fn handle_burst_particles(ecs: &World, entity: Entity, target: &Targets) { fn get_centre(ecs: &World, target: &Targets) -> i32 { match target { - Targets::Tile { target } => return *target as i32, + Targets::Tile { target } => { + return *target as i32; + } Targets::TileList { targets } => { let map = ecs.fetch::(); let (mut count, mut sum_x, mut sum_y) = (0, 0, 0); for target in targets { - sum_x += *target as i32 % map.width; - sum_y += *target as i32 / map.width; + sum_x += (*target as i32) % map.width; + sum_y += (*target as i32) / map.width; count += 1; } let (mean_x, mean_y) = (sum_x / count, sum_y / count); let centre = map.xy_idx(mean_x, mean_y); return centre as i32; } - Targets::Entity { target } => return targeting::entity_position(ecs, *target).unwrap() as i32, + Targets::Entity { target } => { + return targeting::entity_position(ecs, *target).unwrap() as i32; + } Targets::EntityList { targets } => { let map = ecs.fetch::(); let (mut count, mut sum_x, mut sum_y) = (0, 0, 0); for target in targets { if let Some(pos) = targeting::entity_position(ecs, *target) { - sum_x += pos as i32 % map.width; - sum_y += pos as i32 / map.width; + sum_x += (pos as i32) % map.width; + sum_y += (pos as i32) / map.width; count += 1; } } @@ -118,11 +122,12 @@ pub fn handle_line_particles(ecs: &World, entity: Entity, target: &Targets) { spawn_line_particles(ecs, start_pos, end_pos as i32, part); } } - Targets::EntityList { targets } => targets.iter().for_each(|target| { - if let Some(end_pos) = targeting::entity_position(ecs, *target) { - spawn_line_particles(ecs, start_pos, end_pos as i32, part); - } - }), + Targets::EntityList { targets } => + targets.iter().for_each(|target| { + if let Some(end_pos) = targeting::entity_position(ecs, *target) { + spawn_line_particles(ecs, start_pos, end_pos as i32, part); + } + }), } } } @@ -141,9 +146,9 @@ fn spawn_line_particles(ecs: &World, start: i32, end: i32, part: &SpawnParticleL fg: part.colour, bg: RGB::named(BLACK), lifespan: part.lifetime_ms, - delay: i as f32 * part.lifetime_ms, + delay: (i as f32) * part.lifetime_ms, }, - Targets::Tile { target: map.xy_idx(pt.x, pt.y) }, + Targets::Tile { target: map.xy_idx(pt.x, pt.y) } ); if i > 0 { add_effect( @@ -153,9 +158,9 @@ fn spawn_line_particles(ecs: &World, start: i32, end: i32, part: &SpawnParticleL fg: part.trail_colour, bg: RGB::named(BLACK), lifespan: part.trail_lifetime_ms, - delay: i as f32 * part.lifetime_ms, + delay: (i as f32) * part.lifetime_ms, }, - Targets::Tile { target: map.xy_idx(line[i - 1].x, line[i - 1].y) }, + Targets::Tile { target: map.xy_idx(line[i - 1].x, line[i - 1].y) } ); } } diff --git a/src/effects/targeting.rs b/src/effects/targeting.rs index 4d3ed85..05b99c1 100644 --- a/src/effects/targeting.rs +++ b/src/effects/targeting.rs @@ -1,4 +1,4 @@ -use crate::{Equipped, InBackpack, Map, Position}; +use crate::{ Equipped, InBackpack, Map, Position }; use rltk::prelude::*; use specs::prelude::*; diff --git a/src/effects/triggers.rs b/src/effects/triggers.rs index 812bae5..a89b6bb 100644 --- a/src/effects/triggers.rs +++ b/src/effects/triggers.rs @@ -1,9 +1,34 @@ -use super::{add_effect, get_noncursed, messages::*, particles, spatial, EffectType, Entity, Targets, World}; +use super::{ add_effect, get_noncursed, messages::*, particles, spatial, EffectType, Entity, Targets, World }; use crate::{ - gamelog, gui::item_colour_ecs, gui::obfuscate_name_ecs, gui::renderable_colour, Beatitude, Charges, Confusion, - Consumable, Destructible, Equipped, Hidden, InBackpack, InflictsDamage, Item, MagicMapper, MasterDungeonMap, Name, - ObfuscatedName, Player, Prop, ProvidesHealing, ProvidesIdentify, ProvidesNutrition, ProvidesRemoveCurse, - RandomNumberGenerator, Renderable, RunState, SingleActivation, BUC, + gamelog, + gui::item_colour_ecs, + gui::obfuscate_name_ecs, + gui::renderable_colour, + Beatitude, + Charges, + Confusion, + Consumable, + Destructible, + Equipped, + Hidden, + InBackpack, + InflictsDamage, + Item, + MagicMapper, + MasterDungeonMap, + Name, + ObfuscatedName, + Player, + Prop, + ProvidesHealing, + ProvidesIdentify, + ProvidesNutrition, + ProvidesRemoveCurse, + RandomNumberGenerator, + Renderable, + RunState, + SingleActivation, + BUC, }; use rltk::prelude::*; use specs::prelude::*; @@ -85,7 +110,7 @@ fn event_trigger(source: Option, entity: Entity, target: &Targets, ecs: fn handle_restore_nutrition( ecs: &mut World, event: &mut EventInfo, - mut logger: gamelog::Logger, + mut logger: gamelog::Logger ) -> (gamelog::Logger, bool) { if ecs.read_storage::().get(event.entity).is_some() { let amount = match event.buc { @@ -131,7 +156,7 @@ fn handle_healing(ecs: &mut World, event: &mut EventInfo, mut logger: gamelog::L add_effect( event.source, EffectType::Healing { amount: roll, increment_max: get_noncursed(&event.buc) }, - event.target.clone(), + event.target.clone() ); for target in get_entity_targets(&event.target) { if ecs.read_storage::().get(target).is_some() || ecs.read_storage::().get(target).is_some() { @@ -238,11 +263,13 @@ fn handle_identify(ecs: &mut World, event: &mut EventInfo, mut logger: gamelog:: ) .join() .filter(|(_e, _i, bp, _o, name)| { - bp.owner == event.source.unwrap() - && (!dm.identified_items.contains(&name.name.clone()) - || !beatitudes.get(event.source.unwrap()).map(|beatitude| beatitude.known).unwrap_or(true)) - }) - { + bp.owner == event.source.unwrap() && + (!dm.identified_items.contains(&name.name.clone()) || + !beatitudes + .get(event.source.unwrap()) + .map(|beatitude| beatitude.known) + .unwrap_or(true)) + }) { to_identify.push((e, name.name.clone())); } for item in to_identify { @@ -276,8 +303,7 @@ fn handle_remove_curse(ecs: &mut World, event: &mut EventInfo, mut logger: gamel &ecs.read_storage::(), ) .join() - .filter(|(_e, _i, bp, b)| bp.owner == event.source.unwrap() && b.buc == BUC::Cursed) - { + .filter(|(_e, _i, bp, b)| bp.owner == event.source.unwrap() && b.buc == BUC::Cursed) { to_decurse.push(entity); } } @@ -291,14 +317,15 @@ fn handle_remove_curse(ecs: &mut World, event: &mut EventInfo, mut logger: gamel &ecs.read_storage::(), ) .join() - .filter(|(_e, _i, e, b)| e.owner == event.source.unwrap() && b.buc == BUC::Cursed) - { + .filter(|(_e, _i, e, b)| e.owner == event.source.unwrap() && b.buc == BUC::Cursed) { to_decurse.push(entity); } if to_decurse.len() == 0 { match event.buc { BUC::Uncursed => select_single(ecs, RunState::ShowRemoveCurse), - BUC::Blessed => logger = logger.append(REMOVECURSE_BLESSED_FAILED), + BUC::Blessed => { + logger = logger.append(REMOVECURSE_BLESSED_FAILED); + } _ => {} } return (logger, true); diff --git a/src/gamelog/builder.rs b/src/gamelog/builder.rs index e5c0237..7cd39fe 100644 --- a/src/gamelog/builder.rs +++ b/src/gamelog/builder.rs @@ -1,4 +1,4 @@ -use super::{append_entry, LogFragment}; +use super::{ append_entry, LogFragment }; use crate::BUC; use rltk::prelude::*; diff --git a/src/gamelog/logstore.rs b/src/gamelog/logstore.rs index ae3299f..876dce0 100644 --- a/src/gamelog/logstore.rs +++ b/src/gamelog/logstore.rs @@ -1,4 +1,4 @@ -use super::{events, LogFragment, Logger}; +use super::{ events, LogFragment, Logger }; use rltk::prelude::*; use std::sync::Mutex; @@ -23,50 +23,55 @@ pub fn print_log(console: &mut Box, pos: Point, _descending: bool, let mut y = pos.y; let mut x = pos.x; // Reverse the log, take the number we want to show, and iterate through them - LOG.lock().unwrap().iter().rev().take(len).for_each(|log| { - let mut entry_len = -2; - // Iterate through each message fragment, and get the total length - // in lines, by adding the length of every fragment and dividing it - // by the maximum length we desire. Then shuffle our start-y by that much. - log.iter().for_each(|frag| { - entry_len += frag.text.len() as i32; - }); - let lines = entry_len / maximum_len; - y -= lines; - let mut i = 0; - log.iter().for_each(|frag| { - // Split every fragment up into single characters. - let parts = frag.text.split(""); - for part in parts { - // This is an extremely hacky solution to a problem I don't understand yet. - // -- without this, the lines *here* and the line count *above* wont match. - if part == "" || part == "\\" { - continue; - } - if i > entry_len { - break; - } - i += 1; - if x + part.len() as i32 > pos.x + maximum_len { - if y > pos.y - len as i32 { - console.print(x, y, "-"); + LOG.lock() + .unwrap() + .iter() + .rev() + .take(len) + .for_each(|log| { + let mut entry_len = -2; + // Iterate through each message fragment, and get the total length + // in lines, by adding the length of every fragment and dividing it + // by the maximum length we desire. Then shuffle our start-y by that much. + log.iter().for_each(|frag| { + entry_len += frag.text.len() as i32; + }); + let lines = entry_len / maximum_len; + y -= lines; + let mut i = 0; + log.iter().for_each(|frag| { + // Split every fragment up into single characters. + let parts = frag.text.split(""); + for part in parts { + // This is an extremely hacky solution to a problem I don't understand yet. + // -- without this, the lines *here* and the line count *above* wont match. + if part == "" || part == "\\" { + continue; } - y += 1; - x = pos.x; + if i > entry_len { + break; + } + i += 1; + if x + (part.len() as i32) > pos.x + maximum_len { + if y > pos.y - (len as i32) { + console.print(x, y, "-"); + } + y += 1; + x = pos.x; + } + // Stay within bounds + if y > pos.y - (len as i32) { + console.print_color(x, y, frag.colour.into(), RGB::named(rltk::BLACK).into(), part); + } + x += part.len() as i32; } - // Stay within bounds - if y > pos.y - len as i32 { - console.print_color(x, y, frag.colour.into(), RGB::named(rltk::BLACK).into(), part); - } - x += part.len() as i32; - } + }); + // Take away one from the y-axis, because we want to start each entry + // on a new line, and go up an additional amount depending on how many + // lines our *previous* entry took. + y -= 1 + lines; + x = pos.x; }); - // Take away one from the y-axis, because we want to start each entry - // on a new line, and go up an additional amount depending on how many - // lines our *previous* entry took. - y -= 1 + lines; - x = pos.x; - }); } pub fn setup_log() { diff --git a/src/gamelog/mod.rs b/src/gamelog/mod.rs index e83d6c3..621482c 100644 --- a/src/gamelog/mod.rs +++ b/src/gamelog/mod.rs @@ -4,11 +4,11 @@ mod builder; pub use builder::*; mod logstore; use logstore::*; -pub use logstore::{clear_log, clone_log, print_log, restore_log, setup_log}; +pub use logstore::{ clear_log, clone_log, print_log, restore_log, setup_log }; mod events; pub use events::*; -use serde::{Deserialize, Serialize}; +use serde::{ Deserialize, Serialize }; #[derive(Serialize, Deserialize, Clone)] pub struct LogFragment { pub colour: RGB, diff --git a/src/gamesystem.rs b/src/gamesystem.rs index f1150fa..a4566c4 100644 --- a/src/gamesystem.rs +++ b/src/gamesystem.rs @@ -1,5 +1,5 @@ -use super::{Skill, Skills}; -use crate::gui::{Ancestry, Class}; +use super::{ Skill, Skills }; +use crate::gui::{ Ancestry, Class }; use rltk::prelude::*; use std::cmp::max; @@ -80,7 +80,7 @@ pub fn roll_4d6(rng: &mut rltk::RandomNumberGenerator) -> i32 { pub fn get_attribute_rolls( rng: &mut RandomNumberGenerator, class: Class, - ancestry: Ancestry, + ancestry: Ancestry ) -> (i32, i32, i32, i32, i32, i32) { let (mut str, mut dex, mut con, mut int, mut wis, mut cha) = match class { Class::Fighter => (10, 8, 10, 6, 6, 8), @@ -96,14 +96,15 @@ pub fn get_attribute_rolls( Class::Villager => [15, 15, 25, 15, 15, 15], }; let ancestry_maximums: [i32; 6] = match ancestry { - Ancestry::Human => [19, 19, 19, 19, 19, 19], // 114 - Ancestry::Elf => [15, 18, 15, 20, 20, 18], // 106 - Ancestry::Dwarf => [19, 17, 20, 16, 16, 16], // 106 - Ancestry::Gnome => [16, 18, 16, 20, 18, 18], // 106 + Ancestry::Human => [19, 19, 19, 19, 19, 19], // 114 + Ancestry::Elf => [15, 18, 15, 20, 20, 18], // 106 + Ancestry::Dwarf => [19, 17, 20, 16, 16, 16], // 106 + Ancestry::Gnome => [16, 18, 16, 20, 18, 18], // 106 Ancestry::Catfolk => [16, 20, 16, 16, 18, 20], // 106 _ => [18, 18, 18, 18, 18, 18], }; - let improve_table = crate::random_table::RandomTable::new() + let improve_table = crate::random_table::RandomTable + ::new() .add("Strength", improve_chance[0]) .add("Dexterity", improve_chance[1]) .add("Constitution", improve_chance[2]) diff --git a/src/gui/character_creation.rs b/src/gui/character_creation.rs index 8db2bf0..d3da4d3 100644 --- a/src/gui/character_creation.rs +++ b/src/gui/character_creation.rs @@ -1,10 +1,21 @@ -use super::{gamesystem::attr_bonus, gamesystem::get_attribute_rolls, Attributes, Pools, Renderable, RunState, State}; +use super::{ gamesystem::attr_bonus, gamesystem::get_attribute_rolls, Attributes, Pools, Renderable, RunState, State }; use crate::config::entity::NORMAL_SPEED; use crate::{ - raws, Attribute, Energy, HasAncestry, HasClass, KnownSpell, KnownSpells, Pool, Skill, Skills, Telepath, BUC, + raws, + Attribute, + Energy, + HasAncestry, + HasClass, + KnownSpell, + KnownSpells, + Pool, + Skill, + Skills, + Telepath, + BUC, }; use rltk::prelude::*; -use serde::{Deserialize, Serialize}; +use serde::{ Deserialize, Serialize }; use specs::prelude::*; use std::collections::HashMap; @@ -79,8 +90,14 @@ lazy_static! { #[derive(PartialEq, Copy, Clone)] pub enum CharCreateResult { - NoSelection { ancestry: Ancestry, class: Class }, - Selected { ancestry: Ancestry, class: Class }, + NoSelection { + ancestry: Ancestry, + class: Class, + }, + Selected { + ancestry: Ancestry, + class: Class, + }, } /// Handles the player character creation screen. @@ -177,20 +194,45 @@ pub fn character_creation(gs: &mut State, ctx: &mut Rltk) -> CharCreateResult { } match ctx.key { - None => return CharCreateResult::NoSelection { ancestry, class }, - Some(key) => match key { - VirtualKeyCode::Escape => return CharCreateResult::Selected { ancestry: Ancestry::NULL, class }, - VirtualKeyCode::Return => return CharCreateResult::Selected { ancestry, class }, - VirtualKeyCode::H => return CharCreateResult::NoSelection { ancestry: Ancestry::Human, class }, - VirtualKeyCode::E => return CharCreateResult::NoSelection { ancestry: Ancestry::Elf, class }, - VirtualKeyCode::D => return CharCreateResult::NoSelection { ancestry: Ancestry::Dwarf, class }, - VirtualKeyCode::C => return CharCreateResult::NoSelection { ancestry: Ancestry::Catfolk, class }, - VirtualKeyCode::F => return CharCreateResult::NoSelection { ancestry, class: Class::Fighter }, - VirtualKeyCode::R => return CharCreateResult::NoSelection { ancestry, class: Class::Rogue }, - VirtualKeyCode::W => return CharCreateResult::NoSelection { ancestry, class: Class::Wizard }, - VirtualKeyCode::V => return CharCreateResult::NoSelection { ancestry, class: Class::Villager }, - _ => return CharCreateResult::NoSelection { ancestry, class }, - }, + None => { + return CharCreateResult::NoSelection { ancestry, class }; + } + Some(key) => + match key { + VirtualKeyCode::Escape => { + return CharCreateResult::Selected { ancestry: Ancestry::NULL, class }; + } + VirtualKeyCode::Return => { + return CharCreateResult::Selected { ancestry, class }; + } + VirtualKeyCode::H => { + return CharCreateResult::NoSelection { ancestry: Ancestry::Human, class }; + } + VirtualKeyCode::E => { + return CharCreateResult::NoSelection { ancestry: Ancestry::Elf, class }; + } + VirtualKeyCode::D => { + return CharCreateResult::NoSelection { ancestry: Ancestry::Dwarf, class }; + } + VirtualKeyCode::C => { + return CharCreateResult::NoSelection { ancestry: Ancestry::Catfolk, class }; + } + VirtualKeyCode::F => { + return CharCreateResult::NoSelection { ancestry, class: Class::Fighter }; + } + VirtualKeyCode::R => { + return CharCreateResult::NoSelection { ancestry, class: Class::Rogue }; + } + VirtualKeyCode::W => { + return CharCreateResult::NoSelection { ancestry, class: Class::Wizard }; + } + VirtualKeyCode::V => { + return CharCreateResult::NoSelection { ancestry, class: Class::Villager }; + } + _ => { + return CharCreateResult::NoSelection { ancestry, class }; + } + } } } return CharCreateResult::NoSelection { ancestry: Ancestry::Human, class: Class::Fighter }; @@ -214,29 +256,23 @@ pub fn setup_player_ancestry(ecs: &mut World, ancestry: Ancestry) { Ancestry::Human => {} Ancestry::Dwarf => { renderables - .insert( - *player, - Renderable { - glyph: rltk::to_cp437('h'), - fg: RGB::named(rltk::RED), - bg: RGB::named(rltk::BLACK), - render_order: 0, - }, - ) + .insert(*player, Renderable { + glyph: rltk::to_cp437('h'), + fg: RGB::named(rltk::RED), + bg: RGB::named(rltk::BLACK), + render_order: 0, + }) .expect("Unable to insert renderable component"); *player_skills.skills.entry(Skill::Defence).or_insert(0) += 1; } Ancestry::Elf => { renderables - .insert( - *player, - Renderable { - glyph: rltk::to_cp437('@'), - fg: RGB::named(rltk::GREEN), - bg: RGB::named(rltk::BLACK), - render_order: 0, - }, - ) + .insert(*player, Renderable { + glyph: rltk::to_cp437('@'), + fg: RGB::named(rltk::GREEN), + bg: RGB::named(rltk::BLACK), + render_order: 0, + }) .expect("Unable to insert renderable component"); let mut telepaths = ecs.write_storage::(); telepaths @@ -267,43 +303,36 @@ pub fn setup_player_class(ecs: &mut World, class: Class, ancestry: Ancestry) { if class == Class::Wizard { let mut spells = ecs.write_storage::(); spells - .insert( - player, - KnownSpells { spells: vec![KnownSpell { display_name: "zap".to_string(), mana_cost: 1 }] }, - ) + .insert(player, KnownSpells { + spells: vec![KnownSpell { display_name: "zap".to_string(), mana_cost: 1 }], + }) .expect("Unable to insert known spells component"); } let mut rng = ecs.write_resource::(); let mut attributes = ecs.write_storage::(); let (str, dex, con, int, wis, cha) = get_attribute_rolls(&mut rng, class, ancestry); attributes - .insert( - player, - Attributes { - strength: Attribute { base: str, modifiers: 0, bonus: attr_bonus(str) }, - dexterity: Attribute { base: dex, modifiers: 0, bonus: attr_bonus(dex) }, - constitution: Attribute { base: con, modifiers: 0, bonus: attr_bonus(con) }, - intelligence: Attribute { base: int, modifiers: 0, bonus: attr_bonus(int) }, - wisdom: Attribute { base: wis, modifiers: 0, bonus: attr_bonus(wis) }, - charisma: Attribute { base: cha, modifiers: 0, bonus: attr_bonus(cha) }, - }, - ) + .insert(player, Attributes { + strength: Attribute { base: str, modifiers: 0, bonus: attr_bonus(str) }, + dexterity: Attribute { base: dex, modifiers: 0, bonus: attr_bonus(dex) }, + constitution: Attribute { base: con, modifiers: 0, bonus: attr_bonus(con) }, + intelligence: Attribute { base: int, modifiers: 0, bonus: attr_bonus(int) }, + wisdom: Attribute { base: wis, modifiers: 0, bonus: attr_bonus(wis) }, + charisma: Attribute { base: cha, modifiers: 0, bonus: attr_bonus(cha) }, + }) .expect("Unable to insert attributes component"); let mut pools = ecs.write_storage::(); pools - .insert( - player, - Pools { - hit_points: Pool { current: 8 + attr_bonus(con), max: 8 + attr_bonus(con) }, - mana: Pool { current: 1 + attr_bonus(int), max: 1 + attr_bonus(int) }, - xp: 0, - level: 1, - bac: 10, - weight: 0.0, - god: false, - }, - ) + .insert(player, Pools { + hit_points: Pool { current: 8 + attr_bonus(con), max: 8 + attr_bonus(con) }, + mana: Pool { current: 1 + attr_bonus(int), max: 1 + attr_bonus(int) }, + xp: 0, + level: 1, + bac: 10, + weight: 0.0, + god: false, + }) .expect("Unable to insert pools component"); } @@ -318,7 +347,7 @@ pub fn setup_player_class(ecs: &mut World, class: Class, ancestry: Ancestry) { item, buc, raws::SpawnType::Equipped { by: player }, - 0, + 0 ); } for item in starts_with.1.iter() { @@ -328,7 +357,7 @@ pub fn setup_player_class(ecs: &mut World, class: Class, ancestry: Ancestry) { item, None, raws::SpawnType::Carried { by: player }, - 0, + 0 ); } } @@ -343,7 +372,7 @@ fn get_starting_inventory(class: Class, rng: &mut RandomNumberGenerator) -> (Vec equipped = vec![ "equip_shortsword".to_string(), "equip_body_ringmail".to_string(), - "equip_mediumshield".to_string(), + "equip_mediumshield".to_string() ]; } Class::Rogue => { @@ -371,7 +400,7 @@ fn pick_random_table_item( push_to: &mut Vec, table: &'static str, dice: &'static str, - difficulty: Option, + difficulty: Option ) { let (n, d, m) = raws::parse_dice_string(dice); for _i in 0..rng.roll_dice(n, d) + m { diff --git a/src/gui/cheat_menu.rs b/src/gui/cheat_menu.rs index 76ece1b..6831d9c 100644 --- a/src/gui/cheat_menu.rs +++ b/src/gui/cheat_menu.rs @@ -19,7 +19,7 @@ pub fn show_cheat_menu(_gs: &mut State, ctx: &mut Rltk) -> CheatMenuResult { 1 + y_offset, RGB::named(rltk::RED), RGB::named(rltk::BLACK), - "DEBUG MENU! [aA-zZ][Esc.]", + "DEBUG MENU! [aA-zZ][Esc.]" ); let x = 1 + x_offset; let mut y = 3 + y_offset; @@ -50,14 +50,15 @@ pub fn show_cheat_menu(_gs: &mut State, ctx: &mut Rltk) -> CheatMenuResult { // Match keys match ctx.key { None => CheatMenuResult::NoResponse, - Some(key) => match key { - VirtualKeyCode::A => CheatMenuResult::Ascend, - VirtualKeyCode::D => CheatMenuResult::Descend, - VirtualKeyCode::H => CheatMenuResult::Heal, - VirtualKeyCode::M => CheatMenuResult::MagicMap, - VirtualKeyCode::G => CheatMenuResult::GodMode, - VirtualKeyCode::Escape => CheatMenuResult::Cancel, - _ => CheatMenuResult::NoResponse, - }, + Some(key) => + match key { + VirtualKeyCode::A => CheatMenuResult::Ascend, + VirtualKeyCode::D => CheatMenuResult::Descend, + VirtualKeyCode::H => CheatMenuResult::Heal, + VirtualKeyCode::M => CheatMenuResult::MagicMap, + VirtualKeyCode::G => CheatMenuResult::GodMode, + VirtualKeyCode::Escape => CheatMenuResult::Cancel, + _ => CheatMenuResult::NoResponse, + } } } diff --git a/src/gui/identify_menu.rs b/src/gui/identify_menu.rs index 729144b..da4439d 100644 --- a/src/gui/identify_menu.rs +++ b/src/gui/identify_menu.rs @@ -1,9 +1,24 @@ use super::{ - get_max_inventory_width, item_colour_ecs, obfuscate_name_ecs, print_options, renderable_colour, ItemMenuResult, + get_max_inventory_width, + item_colour_ecs, + obfuscate_name_ecs, + print_options, + renderable_colour, + ItemMenuResult, UniqueInventoryItem, }; use crate::{ - gamelog, Beatitude, Entity, Equipped, InBackpack, Item, MasterDungeonMap, Name, ObfuscatedName, Renderable, State, + gamelog, + Beatitude, + Entity, + Equipped, + InBackpack, + Item, + MasterDungeonMap, + Name, + ObfuscatedName, + Renderable, + State, }; use rltk::prelude::*; use specs::prelude::*; @@ -41,8 +56,12 @@ pub fn identify(gs: &mut State, ctx: &mut Rltk) -> (ItemMenuResult, Option (ItemMenuResult, Option (ItemMenuResult, Option (ItemMenuResult, Option (ItemMenuResult::NoResponse, None), - Some(key) => match key { - VirtualKeyCode::Escape => (ItemMenuResult::Cancel, None), - _ => { - let selection = rltk::letter_to_option(key); - if selection > -1 && selection < count as i32 { - let item = inventory_ids.iter().nth(selection as usize).unwrap().1; - gamelog::Logger::new() - .append("You identify the") - .colour(item_colour_ecs(&gs.ecs, *item)) - .append_n(obfuscate_name_ecs(&gs.ecs, *item).0) - .colour(WHITE) - .append("!") - .log(); - return (ItemMenuResult::Selected, Some(*item)); + Some(key) => + match key { + VirtualKeyCode::Escape => (ItemMenuResult::Cancel, None), + _ => { + let selection = rltk::letter_to_option(key); + if selection > -1 && selection < (count as i32) { + let item = inventory_ids + .iter() + .nth(selection as usize) + .unwrap().1; + gamelog::Logger + ::new() + .append("You identify the") + .colour(item_colour_ecs(&gs.ecs, *item)) + .append_n(obfuscate_name_ecs(&gs.ecs, *item).0) + .colour(WHITE) + .append("!") + .log(); + return (ItemMenuResult::Selected, Some(*item)); + } + (ItemMenuResult::NoResponse, None) } - (ItemMenuResult::NoResponse, None) } - }, } } diff --git a/src/gui/mod.rs b/src/gui/mod.rs index cb5277c..aa9f15b 100644 --- a/src/gui/mod.rs +++ b/src/gui/mod.rs @@ -1,8 +1,38 @@ use super::{ - ai::CARRY_CAPACITY_PER_STRENGTH, camera, gamelog, gamesystem, hunger_system::get_hunger_colour, - rex_assets::RexAssets, ArmourClassBonus, Attributes, Beatitude, Burden, Charges, Equipped, Hidden, HungerClock, - HungerState, InBackpack, KnownSpells, MagicItem, Map, MasterDungeonMap, Name, ObfuscatedName, Player, Point, Pools, - Position, Prop, Renderable, RunState, Skill, Skills, State, Viewshed, BUC, + ai::CARRY_CAPACITY_PER_STRENGTH, + camera, + gamelog, + gamesystem, + hunger_system::get_hunger_colour, + rex_assets::RexAssets, + ArmourClassBonus, + Attributes, + Beatitude, + Burden, + Charges, + Equipped, + Hidden, + HungerClock, + HungerState, + InBackpack, + KnownSpells, + MagicItem, + Map, + MasterDungeonMap, + Name, + ObfuscatedName, + Player, + Point, + Pools, + Position, + Prop, + Renderable, + RunState, + Skill, + Skills, + State, + Viewshed, + BUC, }; use rltk::prelude::*; use specs::prelude::*; @@ -25,11 +55,12 @@ pub fn yes_no(ctx: &mut Rltk, question: String) -> Option { ctx.print_color_centered(17, RGB::named(rltk::CYAN), RGB::named(rltk::BLACK), "(y)es or (n)o"); match ctx.key { None => None, - Some(key) => match key { - VirtualKeyCode::Y => Some(true), - VirtualKeyCode::N => Some(false), - _ => None, - }, + Some(key) => + match key { + VirtualKeyCode::Y => Some(true), + VirtualKeyCode::N => Some(false), + _ => None, + } } } @@ -41,10 +72,10 @@ pub fn draw_lerping_bar( n: i32, max: i32, full_colour: RGB, - empty_colour: RGB, + empty_colour: RGB ) { - let percent = n as f32 / max as f32; - let fill_width = (percent * width as f32) as i32; + let percent = (n as f32) / (max as f32); + let fill_width = (percent * (width as f32)) as i32; let bg = empty_colour.lerp(full_colour, percent); let fg = RGB::named(rltk::BLACK); for x in 0..width { @@ -78,7 +109,7 @@ pub fn draw_ui(ecs: &World, ctx: &mut Rltk) { stats.hit_points.current, stats.hit_points.max, RGB::from_u8(0, 255, 0), - RGB::from_u8(255, 0, 0), + RGB::from_u8(255, 0, 0) ); draw_lerping_bar( ctx, @@ -88,7 +119,7 @@ pub fn draw_ui(ecs: &World, ctx: &mut Rltk) { stats.mana.current, stats.mana.max, RGB::named(rltk::BLUE), - RGB::named(rltk::BLACK), + RGB::named(rltk::BLACK) ); // Draw AC let skill_ac_bonus = gamesystem::skill_bonus(Skill::Defence, &*skills); @@ -101,7 +132,7 @@ pub fn draw_ui(ecs: &World, ctx: &mut Rltk) { armour_ac_bonus += ac.amount; } } - let armour_class = stats.bac - (attributes.dexterity.bonus / 2) - skill_ac_bonus - armour_ac_bonus; + let armour_class = stats.bac - attributes.dexterity.bonus / 2 - skill_ac_bonus - armour_ac_bonus; ctx.print_color(26, 53, RGB::named(rltk::PINK), RGB::named(rltk::BLACK), "AC"); ctx.print_color(28, 53, RGB::named(rltk::WHITE), RGB::named(rltk::BLACK), armour_class); // Draw level @@ -110,7 +141,7 @@ pub fn draw_ui(ecs: &World, ctx: &mut Rltk) { 54, RGB::named(rltk::WHITE), RGB::named(rltk::BLACK), - format!("XP{}/{}", stats.level, stats.xp), + format!("XP{}/{}", stats.level, stats.xp) ); // Draw attributes let x = 38; @@ -129,33 +160,33 @@ pub fn draw_ui(ecs: &World, ctx: &mut Rltk) { // Draw hunger match hunger.state { HungerState::Satiated => { - ctx.print_color_right(70, 53, get_hunger_colour(hunger.state), RGB::named(rltk::BLACK), "Satiated") + ctx.print_color_right(70, 53, get_hunger_colour(hunger.state), RGB::named(rltk::BLACK), "Satiated"); } HungerState::Normal => {} HungerState::Hungry => { - ctx.print_color_right(70, 53, get_hunger_colour(hunger.state), RGB::named(rltk::BLACK), "Hungry") + ctx.print_color_right(70, 53, get_hunger_colour(hunger.state), RGB::named(rltk::BLACK), "Hungry"); } HungerState::Weak => { - ctx.print_color_right(70, 53, get_hunger_colour(hunger.state), RGB::named(rltk::BLACK), "Weak") + ctx.print_color_right(70, 53, get_hunger_colour(hunger.state), RGB::named(rltk::BLACK), "Weak"); } HungerState::Fainting => { - ctx.print_color_right(70, 53, get_hunger_colour(hunger.state), RGB::named(rltk::BLACK), "Fainting") + ctx.print_color_right(70, 53, get_hunger_colour(hunger.state), RGB::named(rltk::BLACK), "Fainting"); } HungerState::Starving => { - ctx.print_color_right(70, 53, get_hunger_colour(hunger.state), RGB::named(rltk::BLACK), "Starving") + ctx.print_color_right(70, 53, get_hunger_colour(hunger.state), RGB::named(rltk::BLACK), "Starving"); } } // Burden if let Some(burden) = burden.get(*player_entity) { match burden.level { crate::BurdenLevel::Burdened => { - ctx.print_color_right(70, 50, RGB::named(rltk::BROWN1), RGB::named(rltk::BLACK), "Burdened") + ctx.print_color_right(70, 50, RGB::named(rltk::BROWN1), RGB::named(rltk::BLACK), "Burdened"); } crate::BurdenLevel::Strained => { - ctx.print_color_right(70, 50, RGB::named(rltk::ORANGE), RGB::named(rltk::BLACK), "Strained") + ctx.print_color_right(70, 50, RGB::named(rltk::ORANGE), RGB::named(rltk::BLACK), "Strained"); } crate::BurdenLevel::Overloaded => { - ctx.print_color_right(70, 50, RGB::named(rltk::RED), RGB::named(rltk::BLACK), "Overloaded") + ctx.print_color_right(70, 50, RGB::named(rltk::RED), RGB::named(rltk::BLACK), "Overloaded"); } } } @@ -166,9 +197,9 @@ pub fn draw_ui(ecs: &World, ctx: &mut Rltk) { let renderables = ecs.read_storage::(); let mut equipment: Vec<(String, RGB, RGB, rltk::FontCharType)> = Vec::new(); let entities = ecs.entities(); - for (entity, _equipped, renderable) in - (&entities, &equipped, &renderables).join().filter(|item| item.1.owner == *player_entity) - { + for (entity, _equipped, renderable) in (&entities, &equipped, &renderables) + .join() + .filter(|item| item.1.owner == *player_entity) { equipment.push(( obfuscate_name_ecs(ecs, entity).0, RGB::named(item_colour_ecs(ecs, entity)), @@ -182,7 +213,7 @@ pub fn draw_ui(ecs: &World, ctx: &mut Rltk) { let mut j = 0; for item in equipment { y += 1; - ctx.set(72, y, RGB::named(rltk::YELLOW), RGB::named(rltk::BLACK), 97 + j as rltk::FontCharType); + ctx.set(72, y, RGB::named(rltk::YELLOW), RGB::named(rltk::BLACK), 97 + (j as rltk::FontCharType)); j += 1; ctx.set(74, y, item.2, RGB::named(rltk::BLACK), item.3); ctx.print_color(76, y, item.1, RGB::named(rltk::BLACK), &item.0); @@ -202,7 +233,7 @@ pub fn draw_ui(ecs: &World, ctx: &mut Rltk) { "[{:.1}/{} lbs]", stats.weight, (attributes.strength.base + attributes.strength.modifiers) * CARRY_CAPACITY_PER_STRENGTH - ), + ) ); y += 1; let (player_inventory, _inventory_ids) = get_player_inventory(&ecs); @@ -222,7 +253,7 @@ pub fn draw_ui(ecs: &World, ctx: &mut Rltk) { y, RGB::named(CYAN), RGB::named(BLACK), - &format!("{} ({})", "Force Bolt - NYI!", spell.mana_cost), + &format!("{} ({})", "Force Bolt - NYI!", spell.mana_cost) ); index += 1; y += 1; @@ -298,7 +329,7 @@ pub fn draw_ui(ecs: &World, ctx: &mut Rltk) { 54, RGB::named(rltk::YELLOW), RGB::named(rltk::BLACK), - &format!("T{}", crate::gamelog::get_event_count("turns")), + &format!("T{}", crate::gamelog::get_event_count("turns")) ); // Boxes and tooltips last, so they draw over everything else. @@ -312,7 +343,7 @@ pub fn draw_ui(ecs: &World, ctx: &mut Rltk) { pub fn get_input_direction( ecs: &mut World, ctx: &mut Rltk, - function: fn(i: i32, j: i32, ecs: &mut World) -> RunState, + function: fn(i: i32, j: i32, ecs: &mut World) -> RunState ) -> RunState { let (_, _, _, _, x_offset, y_offset) = camera::get_screen_bounds(ecs, ctx); @@ -321,24 +352,47 @@ pub fn get_input_direction( 1 + y_offset, RGB::named(rltk::WHITE), RGB::named(rltk::BLACK), - "In what direction? [0-9]/[YUHJKLBN]", + "In what direction? [0-9]/[YUHJKLBN]" ); match ctx.key { - None => return RunState::ActionWithDirection { function }, - Some(key) => match key { - VirtualKeyCode::Escape => return RunState::AwaitingInput, - // Cardinals - VirtualKeyCode::Left | VirtualKeyCode::Numpad4 | VirtualKeyCode::H => return function(-1, 0, ecs), - VirtualKeyCode::Right | VirtualKeyCode::Numpad6 | VirtualKeyCode::L => return function(1, 0, ecs), - VirtualKeyCode::Up | VirtualKeyCode::Numpad8 | VirtualKeyCode::K => return function(0, -1, ecs), - VirtualKeyCode::Down | VirtualKeyCode::Numpad2 | VirtualKeyCode::J => return function(0, 1, ecs), - // Diagonals - VirtualKeyCode::Numpad9 | VirtualKeyCode::U => return function(1, -1, ecs), - VirtualKeyCode::Numpad7 | VirtualKeyCode::Y => return function(-1, -1, ecs), - VirtualKeyCode::Numpad3 | VirtualKeyCode::N => return function(1, 1, ecs), - VirtualKeyCode::Numpad1 | VirtualKeyCode::B => return function(-1, 1, ecs), - _ => return RunState::ActionWithDirection { function }, - }, + None => { + return RunState::ActionWithDirection { function }; + } + Some(key) => + match key { + VirtualKeyCode::Escape => { + return RunState::AwaitingInput; + } + // Cardinals + VirtualKeyCode::Left | VirtualKeyCode::Numpad4 | VirtualKeyCode::H => { + return function(-1, 0, ecs); + } + VirtualKeyCode::Right | VirtualKeyCode::Numpad6 | VirtualKeyCode::L => { + return function(1, 0, ecs); + } + VirtualKeyCode::Up | VirtualKeyCode::Numpad8 | VirtualKeyCode::K => { + return function(0, -1, ecs); + } + VirtualKeyCode::Down | VirtualKeyCode::Numpad2 | VirtualKeyCode::J => { + return function(0, 1, ecs); + } + // Diagonals + VirtualKeyCode::Numpad9 | VirtualKeyCode::U => { + return function(1, -1, ecs); + } + VirtualKeyCode::Numpad7 | VirtualKeyCode::Y => { + return function(-1, -1, ecs); + } + VirtualKeyCode::Numpad3 | VirtualKeyCode::N => { + return function(1, 1, ecs); + } + VirtualKeyCode::Numpad1 | VirtualKeyCode::B => { + return function(-1, 1, ecs); + } + _ => { + return RunState::ActionWithDirection { function }; + } + } } } @@ -353,7 +407,7 @@ pub fn print_options( inventory: BTreeMap, mut x: i32, mut y: i32, - ctx: &mut Rltk, + ctx: &mut Rltk ) -> (i32, i32) { let mut j = 0; let initial_x: i32 = x; @@ -362,10 +416,10 @@ pub fn print_options( x = initial_x; // Print the character required to access this item. i.e. (a) if j < 26 { - ctx.set(x, y, RGB::named(rltk::YELLOW), RGB::named(rltk::BLACK), 97 + j as rltk::FontCharType); + ctx.set(x, y, RGB::named(rltk::YELLOW), RGB::named(rltk::BLACK), 97 + (j as rltk::FontCharType)); } else { // If we somehow have more than 26, start using capitals - ctx.set(x, y, RGB::named(rltk::YELLOW), RGB::named(rltk::BLACK), 65 - 26 + j as rltk::FontCharType); + ctx.set(x, y, RGB::named(rltk::YELLOW), RGB::named(rltk::BLACK), 65 - 26 + (j as rltk::FontCharType)); } x += 2; @@ -380,15 +434,14 @@ pub fn print_options( ctx.print_color(x, y, fg, RGB::named(rltk::BLACK), item_count); x += 2; ctx.print_color(x, y, fg, RGB::named(rltk::BLACK), item.display_name.plural.to_string()); - let this_width = x - initial_x + item.display_name.plural.len() as i32; + let this_width = x - initial_x + (item.display_name.plural.len() as i32); width = if width > this_width { width } else { this_width }; } else { if item.display_name.singular.to_lowercase().ends_with("s") { ctx.print_color(x, y, fg, RGB::named(rltk::BLACK), "some"); x += 5; - } else if ['a', 'e', 'i', 'o', 'u'] - .iter() - .any(|&v| item.display_name.singular.to_lowercase().starts_with(v)) + } else if + ['a', 'e', 'i', 'o', 'u'].iter().any(|&v| item.display_name.singular.to_lowercase().starts_with(v)) { // If one and starts with a vowel, print 'an' // i.e. (a) an apple @@ -401,7 +454,7 @@ pub fn print_options( x += 2; } ctx.print_color(x, y, fg, RGB::named(rltk::BLACK), item.display_name.singular.to_string()); - let this_width = x - initial_x + item.display_name.singular.len() as i32; + let this_width = x - initial_x + (item.display_name.singular.len() as i32); width = if width > this_width { width } else { this_width }; } @@ -442,7 +495,7 @@ pub fn obfuscate_name( obfuscated_names: &ReadStorage, beatitudes: &ReadStorage, dm: &MasterDungeonMap, - wand: Option<&ReadStorage>, + wand: Option<&ReadStorage> ) -> (String, String) { let (mut singular, mut plural) = ("nameless item (bug)".to_string(), "nameless items (bug)".to_string()); if let Some(name) = names.get(item) { @@ -537,9 +590,15 @@ pub fn item_colour_ecs(ecs: &World, item: Entity) -> (u8, u8, u8) { if let Some(beatitude) = ecs.read_storage::().get(item) { if beatitude.known { match beatitude.buc { - BUC::Blessed => return GREEN, - BUC::Uncursed => return WHITE, - BUC::Cursed => return RED, + BUC::Blessed => { + return GREEN; + } + BUC::Uncursed => { + return WHITE; + } + BUC::Cursed => { + return RED; + } } } else { // Unidentified magic item @@ -554,9 +613,15 @@ pub fn item_colour(item: Entity, beatitudes: &ReadStorage) -> (u8, u8 if let Some(beatitude) = beatitudes.get(item) { if beatitude.known { match beatitude.buc { - BUC::Blessed => return GREEN, - BUC::Uncursed => return WHITE, - BUC::Cursed => return RED, + BUC::Blessed => { + return GREEN; + } + BUC::Uncursed => { + return WHITE; + } + BUC::Cursed => { + return RED; + } } } else { // Unidentified magic item @@ -601,16 +666,17 @@ pub fn show_help(ctx: &mut Rltk) -> YesNoResult { match ctx.key { None => YesNoResult::NoSelection, - Some(key) => match key { - VirtualKeyCode::Escape => YesNoResult::Yes, - VirtualKeyCode::Slash => { - if ctx.shift { - return YesNoResult::Yes; + Some(key) => + match key { + VirtualKeyCode::Escape => YesNoResult::Yes, + VirtualKeyCode::Slash => { + if ctx.shift { + return YesNoResult::Yes; + } + return YesNoResult::NoSelection; } - return YesNoResult::NoSelection; + _ => YesNoResult::NoSelection, } - _ => YesNoResult::NoSelection, - }, } } @@ -638,13 +704,16 @@ pub fn get_player_inventory(ecs: &World) -> (BTreeMap, let mut inventory_ids: BTreeMap = BTreeMap::new(); let mut player_inventory: BTreeMap = BTreeMap::new(); - for (entity, _pack, name, renderable) in - (&entities, &backpack, &names, &renderables).join().filter(|item| item.1.owner == *player_entity) - { + for (entity, _pack, name, renderable) in (&entities, &backpack, &names, &renderables) + .join() + .filter(|item| item.1.owner == *player_entity) { // RGB can't be used as a key. This is converting the RGB (tuple of f32) into a tuple of u8s. let item_colour = item_colour_ecs(ecs, entity); - let renderables = - ((renderable.fg.r * 255.0) as u8, (renderable.fg.g * 255.0) as u8, (renderable.fg.b * 255.0) as u8); + let renderables = ( + (renderable.fg.r * 255.0) as u8, + (renderable.fg.g * 255.0) as u8, + (renderable.fg.b * 255.0) as u8, + ); let (singular, plural) = obfuscate_name_ecs(ecs, entity); player_inventory .entry(UniqueInventoryItem { @@ -654,7 +723,9 @@ pub fn get_player_inventory(ecs: &World) -> (BTreeMap, glyph: renderable.glyph, name: name.name.clone(), }) - .and_modify(|count| *count += 1) + .and_modify(|count| { + *count += 1; + }) .or_insert(1); inventory_ids.entry(singular).or_insert(entity); } @@ -673,7 +744,7 @@ pub fn show_inventory(gs: &mut State, ctx: &mut Rltk) -> (ItemMenuResult, Option 1 + y_offset, RGB::named(rltk::WHITE), RGB::named(rltk::BLACK), - "Interact with what item? [aA-zZ][Esc.]", + "Interact with what item? [aA-zZ][Esc.]" ); let x = 1 + x_offset; @@ -684,16 +755,25 @@ pub fn show_inventory(gs: &mut State, ctx: &mut Rltk) -> (ItemMenuResult, Option match ctx.key { None => (ItemMenuResult::NoResponse, None), - Some(key) => match key { - VirtualKeyCode::Escape => (ItemMenuResult::Cancel, None), - _ => { - let selection = letter_to_option::letter_to_option(key, ctx.shift); - if selection > -1 && selection < count as i32 { - return (ItemMenuResult::Selected, Some(*inventory_ids.iter().nth(selection as usize).unwrap().1)); + Some(key) => + match key { + VirtualKeyCode::Escape => (ItemMenuResult::Cancel, None), + _ => { + let selection = letter_to_option::letter_to_option(key, ctx.shift); + if selection > -1 && selection < (count as i32) { + return ( + ItemMenuResult::Selected, + Some( + *inventory_ids + .iter() + .nth(selection as usize) + .unwrap().1 + ), + ); + } + (ItemMenuResult::NoResponse, None) } - (ItemMenuResult::NoResponse, None) } - }, } } @@ -708,7 +788,7 @@ pub fn drop_item_menu(gs: &mut State, ctx: &mut Rltk) -> (ItemMenuResult, Option 1 + y_offset, RGB::named(rltk::WHITE), RGB::named(rltk::BLACK), - "Drop what? [aA-zZ][Esc.]", + "Drop what? [aA-zZ][Esc.]" ); let x = 1 + x_offset; @@ -719,16 +799,25 @@ pub fn drop_item_menu(gs: &mut State, ctx: &mut Rltk) -> (ItemMenuResult, Option match ctx.key { None => (ItemMenuResult::NoResponse, None), - Some(key) => match key { - VirtualKeyCode::Escape => (ItemMenuResult::Cancel, None), - _ => { - let selection = rltk::letter_to_option(key); - if selection > -1 && selection < count as i32 { - return (ItemMenuResult::Selected, Some(*inventory_ids.iter().nth(selection as usize).unwrap().1)); + Some(key) => + match key { + VirtualKeyCode::Escape => (ItemMenuResult::Cancel, None), + _ => { + let selection = rltk::letter_to_option(key); + if selection > -1 && selection < (count as i32) { + return ( + ItemMenuResult::Selected, + Some( + *inventory_ids + .iter() + .nth(selection as usize) + .unwrap().1 + ), + ); + } + (ItemMenuResult::NoResponse, None) } - (ItemMenuResult::NoResponse, None) } - }, } } @@ -746,7 +835,7 @@ pub fn remove_item_menu(gs: &mut State, ctx: &mut Rltk) -> (ItemMenuResult, Opti 1 + y_offset, RGB::named(rltk::WHITE), RGB::named(rltk::BLACK), - "Unequip what? [aA-zZ][Esc.]", + "Unequip what? [aA-zZ][Esc.]" ); let mut equippable: Vec<(Entity, String)> = Vec::new(); @@ -772,7 +861,7 @@ pub fn remove_item_menu(gs: &mut State, ctx: &mut Rltk) -> (ItemMenuResult, Opti } else { (RGB::named(rltk::WHITE), rltk::to_cp437('-')) }; - ctx.set(x + 1, y, RGB::named(rltk::YELLOW), RGB::named(rltk::BLACK), 97 + j as rltk::FontCharType); + ctx.set(x + 1, y, RGB::named(rltk::YELLOW), RGB::named(rltk::BLACK), 97 + (j as rltk::FontCharType)); ctx.set(x + 3, y, fg, RGB::named(rltk::BLACK), glyph); fg = RGB::named(item_colour_ecs(&gs.ecs, *e)); ctx.print_color(x + 5, y, fg, RGB::named(rltk::BLACK), name); @@ -782,16 +871,17 @@ pub fn remove_item_menu(gs: &mut State, ctx: &mut Rltk) -> (ItemMenuResult, Opti match ctx.key { None => (ItemMenuResult::NoResponse, None), - Some(key) => match key { - VirtualKeyCode::Escape => (ItemMenuResult::Cancel, None), - _ => { - let selection = rltk::letter_to_option(key); - if selection > -1 && selection < count as i32 { - return (ItemMenuResult::Selected, Some(equippable[selection as usize].0)); + Some(key) => + match key { + VirtualKeyCode::Escape => (ItemMenuResult::Cancel, None), + _ => { + let selection = rltk::letter_to_option(key); + if selection > -1 && selection < (count as i32) { + return (ItemMenuResult::Selected, Some(equippable[selection as usize].0)); + } + (ItemMenuResult::NoResponse, None) } - (ItemMenuResult::NoResponse, None) } - }, } } @@ -806,7 +896,7 @@ pub fn ranged_target(gs: &mut State, ctx: &mut Rltk, range: i32, aoe: i32) -> (I 1 + y_offset, RGB::named(rltk::WHITE), RGB::named(rltk::BLACK), - "Targeting which tile? [mouse input]", + "Targeting which tile? [mouse input]" ); // Highlight available cells @@ -816,10 +906,10 @@ pub fn ranged_target(gs: &mut State, ctx: &mut Rltk, range: i32, aoe: i32) -> (I // We have a viewshed for idx in visible.visible_tiles.iter() { let distance = rltk::DistanceAlg::Pythagoras.distance2d(*player_pos, *idx); - if distance <= range as f32 { + if distance <= (range as f32) { let screen_x = idx.x - min_x; let screen_y = idx.y - min_y; - if screen_x > 1 && screen_x < (max_x - min_x) - 1 && screen_y > 1 && screen_y < (max_y - min_y) - 1 { + if screen_x > 1 && screen_x < max_x - min_x - 1 && screen_y > 1 && screen_y < max_y - min_y - 1 { ctx.set_bg(screen_x + x_offset, screen_y + y_offset, RGB::named(rltk::BLUE)); available_cells.push(idx); } @@ -845,8 +935,11 @@ pub fn ranged_target(gs: &mut State, ctx: &mut Rltk, range: i32, aoe: i32) -> (I if aoe > 0 { // We adjust for camera position when getting FOV, but then we need to adjust back // when iterating through the tiles themselves, by taking away min_x/min_y. - let mut blast_tiles = - rltk::field_of_view(Point::new(mouse_pos_adjusted.0, mouse_pos_adjusted.1), aoe, &*map); + let mut blast_tiles = rltk::field_of_view( + Point::new(mouse_pos_adjusted.0, mouse_pos_adjusted.1), + aoe, + &*map + ); blast_tiles.retain(|p| p.x > 0 && p.x < map.width - 1 && p.y > 0 && p.y < map.height - 1); for tile in blast_tiles.iter() { ctx.set_bg(tile.x - min_x + x_offset, tile.y - min_y + y_offset, RGB::named(rltk::DARKCYAN)); @@ -875,8 +968,12 @@ pub enum MainMenuSelection { #[derive(PartialEq, Copy, Clone)] pub enum MainMenuResult { - NoSelection { selected: MainMenuSelection }, - Selected { selected: MainMenuSelection }, + NoSelection { + selected: MainMenuSelection, + }, + Selected { + selected: MainMenuSelection, + }, } pub fn main_menu(gs: &mut State, ctx: &mut Rltk) -> MainMenuResult { @@ -924,42 +1021,63 @@ pub fn main_menu(gs: &mut State, ctx: &mut Rltk) -> MainMenuResult { } match ctx.key { - None => return MainMenuResult::NoSelection { selected: selection }, - Some(key) => match key { - VirtualKeyCode::Escape | VirtualKeyCode::C => { - return MainMenuResult::NoSelection { selected: MainMenuSelection::Quit } - } - VirtualKeyCode::N => return MainMenuResult::NoSelection { selected: MainMenuSelection::NewGame }, - VirtualKeyCode::L => return MainMenuResult::NoSelection { selected: MainMenuSelection::LoadGame }, - VirtualKeyCode::Up | VirtualKeyCode::Numpad8 | VirtualKeyCode::K => { - let mut new_selection; - match selection { - MainMenuSelection::NewGame => new_selection = MainMenuSelection::LoadGame, - MainMenuSelection::LoadGame => new_selection = MainMenuSelection::Quit, - MainMenuSelection::Quit => new_selection = MainMenuSelection::NewGame, + None => { + return MainMenuResult::NoSelection { selected: selection }; + } + Some(key) => + match key { + VirtualKeyCode::Escape | VirtualKeyCode::C => { + return MainMenuResult::NoSelection { selected: MainMenuSelection::Quit }; } - if new_selection == MainMenuSelection::LoadGame && !save_exists { - new_selection = MainMenuSelection::NewGame; + VirtualKeyCode::N => { + return MainMenuResult::NoSelection { selected: MainMenuSelection::NewGame }; } - return MainMenuResult::NoSelection { selected: new_selection }; - } - VirtualKeyCode::Down | VirtualKeyCode::Numpad2 | VirtualKeyCode::J => { - let mut new_selection; - match selection { - MainMenuSelection::NewGame => new_selection = MainMenuSelection::Quit, - MainMenuSelection::LoadGame => new_selection = MainMenuSelection::NewGame, - MainMenuSelection::Quit => new_selection = MainMenuSelection::LoadGame, + VirtualKeyCode::L => { + return MainMenuResult::NoSelection { selected: MainMenuSelection::LoadGame }; } - if new_selection == MainMenuSelection::LoadGame && !save_exists { - new_selection = MainMenuSelection::Quit; + VirtualKeyCode::Up | VirtualKeyCode::Numpad8 | VirtualKeyCode::K => { + let mut new_selection; + match selection { + MainMenuSelection::NewGame => { + new_selection = MainMenuSelection::LoadGame; + } + MainMenuSelection::LoadGame => { + new_selection = MainMenuSelection::Quit; + } + MainMenuSelection::Quit => { + new_selection = MainMenuSelection::NewGame; + } + } + if new_selection == MainMenuSelection::LoadGame && !save_exists { + new_selection = MainMenuSelection::NewGame; + } + return MainMenuResult::NoSelection { selected: new_selection }; + } + VirtualKeyCode::Down | VirtualKeyCode::Numpad2 | VirtualKeyCode::J => { + let mut new_selection; + match selection { + MainMenuSelection::NewGame => { + new_selection = MainMenuSelection::Quit; + } + MainMenuSelection::LoadGame => { + new_selection = MainMenuSelection::NewGame; + } + MainMenuSelection::Quit => { + new_selection = MainMenuSelection::LoadGame; + } + } + if new_selection == MainMenuSelection::LoadGame && !save_exists { + new_selection = MainMenuSelection::Quit; + } + return MainMenuResult::NoSelection { selected: new_selection }; + } + VirtualKeyCode::Return | VirtualKeyCode::NumpadEnter => { + return MainMenuResult::Selected { selected: selection }; + } + _ => { + return MainMenuResult::NoSelection { selected: selection }; } - return MainMenuResult::NoSelection { selected: new_selection }; } - VirtualKeyCode::Return | VirtualKeyCode::NumpadEnter => { - return MainMenuResult::Selected { selected: selection } - } - _ => return MainMenuResult::NoSelection { selected: selection }, - }, } } MainMenuResult::NoSelection { selected: MainMenuSelection::NewGame } @@ -986,7 +1104,7 @@ pub fn game_over(ctx: &mut Rltk) -> YesNoResult { y, RGB::named(rltk::GREEN), RGB::named(rltk::BLACK), - format!("You survived for {} turns.", crate::gamelog::get_event_count("turns")), + format!("You survived for {} turns.", crate::gamelog::get_event_count("turns")) ); y += 2; ctx.print_color(x, y, RGB::named(rltk::GREEN), RGB::named(rltk::BLACK), format!("And in the process, you")); @@ -997,7 +1115,7 @@ pub fn game_over(ctx: &mut Rltk) -> YesNoResult { y, RGB::named(rltk::WHITE), RGB::named(rltk::BLACK), - format!("- descended {} floor(s)", crate::gamelog::get_event_count("descended")), + format!("- descended {} floor(s)", crate::gamelog::get_event_count("descended")) ); y += 1; } @@ -1011,7 +1129,7 @@ pub fn game_over(ctx: &mut Rltk) -> YesNoResult { "- kicked {} time(s), breaking {} object(s)", crate::gamelog::get_event_count("kick_count"), crate::gamelog::get_event_count("broken_doors") - ), + ) ); y += 1; } @@ -1021,7 +1139,7 @@ pub fn game_over(ctx: &mut Rltk) -> YesNoResult { y, RGB::named(rltk::WHITE), RGB::named(rltk::BLACK), - format!("- slew {} other creature(s)", crate::gamelog::get_event_count("death_count")), + format!("- slew {} other creature(s)", crate::gamelog::get_event_count("death_count")) ); y += 1; } @@ -1031,15 +1149,16 @@ pub fn game_over(ctx: &mut Rltk) -> YesNoResult { y, RGB::named(rltk::WHITE), RGB::named(rltk::BLACK), - format!("- forgot the controls {} time(s)", crate::gamelog::get_event_count("looked_for_help")), + format!("- forgot the controls {} time(s)", crate::gamelog::get_event_count("looked_for_help")) ); } match ctx.key { None => YesNoResult::NoSelection, - Some(key) => match key { - VirtualKeyCode::Escape => YesNoResult::Yes, - _ => YesNoResult::NoSelection, - }, + Some(key) => + match key { + VirtualKeyCode::Escape => YesNoResult::Yes, + _ => YesNoResult::NoSelection, + } } } diff --git a/src/gui/remove_curse_menu.rs b/src/gui/remove_curse_menu.rs index 4e6ba34..80cd8b0 100644 --- a/src/gui/remove_curse_menu.rs +++ b/src/gui/remove_curse_menu.rs @@ -1,8 +1,13 @@ use super::{ - get_max_inventory_width, item_colour_ecs, obfuscate_name_ecs, print_options, renderable_colour, ItemMenuResult, + get_max_inventory_width, + item_colour_ecs, + obfuscate_name_ecs, + print_options, + renderable_colour, + ItemMenuResult, UniqueInventoryItem, }; -use crate::{gamelog, Beatitude, Entity, Equipped, InBackpack, Item, Name, Renderable, State, BUC}; +use crate::{ gamelog, Beatitude, Entity, Equipped, InBackpack, Item, Name, Renderable, State, BUC }; use rltk::prelude::*; use specs::prelude::*; use std::collections::BTreeMap; @@ -58,7 +63,8 @@ pub fn remove_curse(gs: &mut State, ctx: &mut Rltk) -> (ItemMenuResult, Option (ItemMenuResult, Option (ItemMenuResult, Option (ItemMenuResult::NoResponse, None), - Some(key) => match key { - VirtualKeyCode::Escape => (ItemMenuResult::Cancel, None), - _ => { - let selection = rltk::letter_to_option(key); - if selection > -1 && selection < count as i32 { - let item = inventory_ids.iter().nth(selection as usize).unwrap().1; - gamelog::Logger::new() - .append("You decurse the") - .colour(item_colour_ecs(&gs.ecs, *item)) - .append_n(obfuscate_name_ecs(&gs.ecs, *item).0) - .colour(WHITE) - .append("!") - .log(); - return (ItemMenuResult::Selected, Some(*item)); + Some(key) => + match key { + VirtualKeyCode::Escape => (ItemMenuResult::Cancel, None), + _ => { + let selection = rltk::letter_to_option(key); + if selection > -1 && selection < (count as i32) { + let item = inventory_ids + .iter() + .nth(selection as usize) + .unwrap().1; + gamelog::Logger + ::new() + .append("You decurse the") + .colour(item_colour_ecs(&gs.ecs, *item)) + .append_n(obfuscate_name_ecs(&gs.ecs, *item).0) + .colour(WHITE) + .append("!") + .log(); + return (ItemMenuResult::Selected, Some(*item)); + } + (ItemMenuResult::NoResponse, None) } - (ItemMenuResult::NoResponse, None) } - }, } } diff --git a/src/gui/tooltip.rs b/src/gui/tooltip.rs index 528ff08..effc56a 100644 --- a/src/gui/tooltip.rs +++ b/src/gui/tooltip.rs @@ -1,4 +1,4 @@ -use super::{camera::get_screen_bounds, Attributes, Hidden, Map, Name, Pools, Position, Renderable, Rltk, World, RGB}; +use super::{ camera::get_screen_bounds, Attributes, Hidden, Map, Name, Pools, Position, Renderable, Rltk, World, RGB }; use rltk::prelude::*; use specs::prelude::*; @@ -26,15 +26,15 @@ impl Tooltip { max = s.0.len(); } } - return max as i32 + 2i32; + return (max as i32) + 2i32; } fn height(&self) -> i32 { - return self.lines.len() as i32 + 2i32; + return (self.lines.len() as i32) + 2i32; } fn render(&self, ctx: &mut Rltk, x: i32, y: i32) { ctx.draw_box(x, y, self.width() - 1, self.height() - 1, RGB::named(WHITE), RGB::named(BLACK)); for (i, s) in self.lines.iter().enumerate() { - ctx.print_color(x + 1, y + i as i32 + 1, s.1, RGB::named(BLACK), &s.0); + ctx.print_color(x + 1, y + (i as i32) + 1, s.1, RGB::named(BLACK), &s.0); } } } diff --git a/src/hunger_system.rs b/src/hunger_system.rs index c3f274a..8c2b4ec 100644 --- a/src/hunger_system.rs +++ b/src/hunger_system.rs @@ -1,6 +1,11 @@ use super::{ - effects::{add_effect, EffectType, Targets}, - gamelog, Clock, HungerClock, HungerState, TakingTurn, LOG_TICKS, + effects::{ add_effect, EffectType, Targets }, + gamelog, + Clock, + HungerClock, + HungerState, + TakingTurn, + LOG_TICKS, }; use rltk::prelude::*; use specs::prelude::*; @@ -74,10 +79,9 @@ impl<'a> System<'a> for HungerSystem { add_effect(None, EffectType::Damage { amount: 1 }, Targets::Entity { target: entity }); } if LOG_TICKS && entity == *player_entity { - rltk::console::log(format!( - "HUNGER SYSTEM: Ticked for player entity. [clock: {}]", - hunger_clock.duration - )); + rltk::console::log( + format!("HUNGER SYSTEM: Ticked for player entity. [clock: {}]", hunger_clock.duration) + ); } if hunger_clock.state == initial_state { continue; @@ -87,39 +91,49 @@ impl<'a> System<'a> for HungerSystem { } // Things which only happen to the player. match hunger_clock.state { - HungerState::Satiated => gamelog::Logger::new() - .append("You feel") - .colour(get_hunger_colour(hunger_clock.state)) - .append_n("satiated") - .colour(WHITE) - .period() - .log(), + HungerState::Satiated => + gamelog::Logger + ::new() + .append("You feel") + .colour(get_hunger_colour(hunger_clock.state)) + .append_n("satiated") + .colour(WHITE) + .period() + .log(), HungerState::Normal => {} - HungerState::Hungry => gamelog::Logger::new() - .append("You feel") - .colour(get_hunger_colour(hunger_clock.state)) - .append_n("hungry") - .colour(WHITE) - .period() - .log(), - HungerState::Weak => gamelog::Logger::new() - .append("You feel") - .colour(get_hunger_colour(hunger_clock.state)) - .append_n("weak with hunger") - .colour(WHITE) - .period() - .log(), - HungerState::Fainting => gamelog::Logger::new() - .append("You feel") - .colour(get_hunger_colour(hunger_clock.state)) - .append_n("hungry enough to faint") - .colour(WHITE) - .period() - .log(), - _ => gamelog::Logger::new() - .colour(get_hunger_colour(hunger_clock.state)) - .append_n("You can't go on without food!") - .log(), + HungerState::Hungry => + gamelog::Logger + ::new() + .append("You feel") + .colour(get_hunger_colour(hunger_clock.state)) + .append_n("hungry") + .colour(WHITE) + .period() + .log(), + HungerState::Weak => + gamelog::Logger + ::new() + .append("You feel") + .colour(get_hunger_colour(hunger_clock.state)) + .append_n("weak with hunger") + .colour(WHITE) + .period() + .log(), + HungerState::Fainting => + gamelog::Logger + ::new() + .append("You feel") + .colour(get_hunger_colour(hunger_clock.state)) + .append_n("hungry enough to faint") + .colour(WHITE) + .period() + .log(), + _ => + gamelog::Logger + ::new() + .colour(get_hunger_colour(hunger_clock.state)) + .append_n("You can't go on without food!") + .log(), } } } diff --git a/src/inventory/collection_system.rs b/src/inventory/collection_system.rs index f1f5a32..7a21b7c 100644 --- a/src/inventory/collection_system.rs +++ b/src/inventory/collection_system.rs @@ -1,6 +1,16 @@ use crate::{ - gamelog, gui::obfuscate_name, Beatitude, Charges, EquipmentChanged, InBackpack, MagicItem, MasterDungeonMap, Name, - ObfuscatedName, Position, WantsToPickupItem, + gamelog, + gui::obfuscate_name, + Beatitude, + Charges, + EquipmentChanged, + InBackpack, + MagicItem, + MasterDungeonMap, + Name, + ObfuscatedName, + Position, + WantsToPickupItem, }; use specs::prelude::*; @@ -45,21 +55,23 @@ impl<'a> System<'a> for ItemCollectionSystem { .expect("Unable to insert EquipmentChanged."); if pickup.collected_by == *player_entity { - gamelog::Logger::new() + gamelog::Logger + ::new() .append("You pick up the") - .item_name_n(format!( - "{}", - obfuscate_name( - pickup.item, - &names, - &magic_items, - &obfuscated_names, - &beatitudes, - &dm, - Some(&wands) + .item_name_n( + format!( + "{}", + obfuscate_name( + pickup.item, + &names, + &magic_items, + &obfuscated_names, + &beatitudes, + &dm, + Some(&wands) + ).0 ) - .0 - )) + ) .period() .log(); } diff --git a/src/inventory/drop_system.rs b/src/inventory/drop_system.rs index d3bd7e9..f5cc0f6 100644 --- a/src/inventory/drop_system.rs +++ b/src/inventory/drop_system.rs @@ -1,6 +1,16 @@ use crate::{ - gamelog, gui::obfuscate_name, Beatitude, Charges, EquipmentChanged, InBackpack, MagicItem, MasterDungeonMap, Name, - ObfuscatedName, Position, WantsToDropItem, + gamelog, + gui::obfuscate_name, + Beatitude, + Charges, + EquipmentChanged, + InBackpack, + MagicItem, + MasterDungeonMap, + Name, + ObfuscatedName, + Position, + WantsToDropItem, }; use specs::prelude::*; @@ -53,21 +63,23 @@ impl<'a> System<'a> for ItemDropSystem { backpack.remove(to_drop.item); if entity == *player_entity { - gamelog::Logger::new() + gamelog::Logger + ::new() .append("You drop the") - .item_name_n(format!( - "{}", - obfuscate_name( - to_drop.item, - &names, - &magic_items, - &obfuscated_names, - &beatitudes, - &dm, - Some(&wands) + .item_name_n( + format!( + "{}", + obfuscate_name( + to_drop.item, + &names, + &magic_items, + &obfuscated_names, + &beatitudes, + &dm, + Some(&wands) + ).0 ) - .0 - )) + ) .period() .log(); } diff --git a/src/inventory/equip_system.rs b/src/inventory/equip_system.rs index 7f0fde0..acf5780 100644 --- a/src/inventory/equip_system.rs +++ b/src/inventory/equip_system.rs @@ -1,8 +1,19 @@ use crate::{ gamelog, - gui::{item_colour, obfuscate_name}, - Beatitude, EquipmentChanged, Equippable, Equipped, IdentifiedBeatitude, IdentifiedItem, InBackpack, MagicItem, - MasterDungeonMap, Name, ObfuscatedName, WantsToUseItem, BUC, + gui::{ item_colour, obfuscate_name }, + Beatitude, + EquipmentChanged, + Equippable, + Equipped, + IdentifiedBeatitude, + IdentifiedItem, + InBackpack, + MagicItem, + MasterDungeonMap, + Name, + ObfuscatedName, + WantsToUseItem, + BUC, }; use specs::prelude::*; @@ -70,9 +81,8 @@ impl<'a> System<'a> for ItemEquipSystem { &obfuscated_names, &beatitudes, &dm, - None, - ) - .0, + None + ).0 ) .colour(rltk::WHITE) .append("!"); @@ -96,8 +106,7 @@ impl<'a> System<'a> for ItemEquipSystem { .append("You remove your") .colour(item_colour(*item, &beatitudes)) .append_n( - obfuscate_name(*item, &names, &magic_items, &obfuscated_names, &beatitudes, &dm, None) - .0, + obfuscate_name(*item, &names, &magic_items, &obfuscated_names, &beatitudes, &dm, None).0 ) .colour(rltk::WHITE) .period(); @@ -121,18 +130,16 @@ impl<'a> System<'a> for ItemEquipSystem { &obfuscated_names, &beatitudes, &dm, - None, - ) - .0, + None + ).0 ) .colour(rltk::WHITE) .period(); logger.log(); identified_items - .insert( - target, - IdentifiedItem { name: names.get(wants_to_use_item.item).unwrap().name.clone() }, - ) + .insert(target, IdentifiedItem { + name: names.get(wants_to_use_item.item).unwrap().name.clone(), + }) .expect("Unable to insert IdentifiedItem"); identified_beatitude .insert(wants_to_use_item.item, IdentifiedBeatitude {}) diff --git a/src/inventory/identification_system.rs b/src/inventory/identification_system.rs index 0c0fd2b..e1d49f4 100644 --- a/src/inventory/identification_system.rs +++ b/src/inventory/identification_system.rs @@ -1,4 +1,4 @@ -use crate::{Beatitude, IdentifiedBeatitude, IdentifiedItem, Item, MasterDungeonMap, Name, ObfuscatedName, Player}; +use crate::{ Beatitude, IdentifiedBeatitude, IdentifiedItem, Item, MasterDungeonMap, Name, ObfuscatedName, Player }; use specs::prelude::*; pub struct ItemIdentificationSystem {} diff --git a/src/inventory/mod.rs b/src/inventory/mod.rs index 948f991..eceaccb 100644 --- a/src/inventory/mod.rs +++ b/src/inventory/mod.rs @@ -5,7 +5,11 @@ mod identification_system; mod remove_system; mod use_system; -pub use { - collection_system::ItemCollectionSystem, drop_system::ItemDropSystem, equip_system::ItemEquipSystem, - identification_system::ItemIdentificationSystem, remove_system::ItemRemoveSystem, use_system::ItemUseSystem, +pub use self::{ + collection_system::ItemCollectionSystem, + drop_system::ItemDropSystem, + equip_system::ItemEquipSystem, + identification_system::ItemIdentificationSystem, + remove_system::ItemRemoveSystem, + use_system::ItemUseSystem, }; diff --git a/src/inventory/remove_system.rs b/src/inventory/remove_system.rs index d2da401..d9b9587 100644 --- a/src/inventory/remove_system.rs +++ b/src/inventory/remove_system.rs @@ -1,7 +1,15 @@ use crate::{ gamelog, - gui::{item_colour, obfuscate_name}, - Beatitude, Equipped, InBackpack, MagicItem, MasterDungeonMap, Name, ObfuscatedName, WantsToRemoveItem, BUC, + gui::{ item_colour, obfuscate_name }, + Beatitude, + Equipped, + InBackpack, + MagicItem, + MasterDungeonMap, + Name, + ObfuscatedName, + WantsToRemoveItem, + BUC, }; use rltk::prelude::*; use specs::prelude::*; @@ -43,7 +51,8 @@ impl<'a> System<'a> for ItemRemoveSystem { // If cursed, can't remove! if beatitude.buc == BUC::Cursed { can_remove = false; - gamelog::Logger::new() + gamelog::Logger + ::new() .append("You can't remove the") .colour(item_colour(to_remove.item, &beatitudes)) .append_n( @@ -54,9 +63,8 @@ impl<'a> System<'a> for ItemRemoveSystem { &obfuscated_names, &beatitudes, &dm, - None, - ) - .0, + None + ).0 ) .colour(WHITE) .append("!") @@ -70,7 +78,8 @@ impl<'a> System<'a> for ItemRemoveSystem { equipped.remove(to_remove.item); if let Some(_) = names.get(to_remove.item) { if entity == *player_entity { - gamelog::Logger::new() + gamelog::Logger + ::new() .append("You unequip the") .colour(item_colour(to_remove.item, &beatitudes)) .append_n( @@ -81,9 +90,8 @@ impl<'a> System<'a> for ItemRemoveSystem { &obfuscated_names, &beatitudes, &dm, - None, - ) - .0, + None + ).0 ) .colour(WHITE) .period() diff --git a/src/inventory/use_system.rs b/src/inventory/use_system.rs index fc51fe6..4b7955a 100644 --- a/src/inventory/use_system.rs +++ b/src/inventory/use_system.rs @@ -1,6 +1,11 @@ use crate::{ - effects::{add_effect, aoe_tiles, EffectType, Targets}, - EquipmentChanged, IdentifiedItem, Map, Name, WantsToUseItem, AOE, + effects::{ add_effect, aoe_tiles, EffectType, Targets }, + EquipmentChanged, + IdentifiedItem, + Map, + Name, + WantsToUseItem, + AOE, }; use specs::prelude::*; @@ -32,20 +37,16 @@ impl<'a> System<'a> for ItemUseSystem { .expect("Unable to insert"); } // Call the effects system - add_effect( - Some(entity), - EffectType::ItemUse { item: useitem.item }, - match useitem.target { - None => Targets::Entity { target: *player_entity }, - Some(target) => { - if let Some(aoe) = aoe.get(useitem.item) { - Targets::TileList { targets: aoe_tiles(&*map, target, aoe.radius) } - } else { - Targets::Tile { target: map.xy_idx(target.x, target.y) } - } + add_effect(Some(entity), EffectType::ItemUse { item: useitem.item }, match useitem.target { + None => Targets::Entity { target: *player_entity }, + Some(target) => { + if let Some(aoe) = aoe.get(useitem.item) { + Targets::TileList { targets: aoe_tiles(&*map, target, aoe.radius) } + } else { + Targets::Tile { target: map.xy_idx(target.x, target.y) } } - }, - ); + } + }); } wants_use.clear(); } diff --git a/src/main.rs b/src/main.rs index 0d61adf..a8d653d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,6 @@ -use rltk::{GameState, Point, RandomNumberGenerator, Rltk}; +use rltk::{ GameState, Point, RandomNumberGenerator, Rltk }; use specs::prelude::*; -use specs::saveload::{SimpleMarker, SimpleMarkerAllocator}; +use specs::saveload::{ SimpleMarker, SimpleMarkerAllocator }; extern crate serde; pub mod camera; @@ -27,7 +27,7 @@ mod trigger_system; use melee_combat_system::MeleeCombatSystem; mod inventory; mod particle_system; -use particle_system::{ParticleBuilder, DEFAULT_PARTICLE_LIFETIME, LONG_PARTICLE_LIFETIME}; +use particle_system::{ ParticleBuilder, DEFAULT_PARTICLE_LIFETIME, LONG_PARTICLE_LIFETIME }; mod ai; mod config; mod effects; @@ -48,23 +48,37 @@ pub const LOG_TICKS: bool = false; pub enum RunState { AwaitingInput, // Player's turn PreRun, - Ticking, // Tick systems + Ticking, // Tick systems ShowCheatMenu, // Teleport, godmode, etc. - for debugging ShowInventory, ShowDropItem, ShowRemoveItem, - ShowTargeting { range: i32, item: Entity, aoe: i32 }, + ShowTargeting { + range: i32, + item: Entity, + aoe: i32, + }, ShowRemoveCurse, ShowIdentify, - ActionWithDirection { function: fn(i: i32, j: i32, ecs: &mut World) -> RunState }, - MainMenu { menu_selection: gui::MainMenuSelection }, - CharacterCreation { ancestry: gui::Ancestry, class: gui::Class }, + ActionWithDirection { + function: fn(i: i32, j: i32, ecs: &mut World) -> RunState, + }, + MainMenu { + menu_selection: gui::MainMenuSelection, + }, + CharacterCreation { + ancestry: gui::Ancestry, + class: gui::Class, + }, SaveGame, GameOver, NextLevel, PreviousLevel, HelpScreen, - MagicMapReveal { row: i32, cursed: bool }, // Animates magic mapping effect + MagicMapReveal { + row: i32, + cursed: bool, + }, // Animates magic mapping effect MapGeneration, } @@ -260,20 +274,30 @@ impl GameState for State { self.ecs.maintain(); try_spawn_interval(&mut self.ecs); match *self.ecs.fetch::() { - RunState::AwaitingInput => new_runstate = RunState::AwaitingInput, - RunState::MagicMapReveal { row, cursed } => { - new_runstate = RunState::MagicMapReveal { row: row, cursed: cursed } + RunState::AwaitingInput => { + new_runstate = RunState::AwaitingInput; + } + RunState::MagicMapReveal { row, cursed } => { + new_runstate = RunState::MagicMapReveal { row: row, cursed: cursed }; + } + RunState::ShowRemoveCurse => { + new_runstate = RunState::ShowRemoveCurse; + } + RunState::ShowIdentify => { + new_runstate = RunState::ShowIdentify; + } + _ => { + new_runstate = RunState::Ticking; } - RunState::ShowRemoveCurse => new_runstate = RunState::ShowRemoveCurse, - RunState::ShowIdentify => new_runstate = RunState::ShowIdentify, - _ => new_runstate = RunState::Ticking, } } } RunState::ShowCheatMenu => { let result = gui::show_cheat_menu(self, ctx); match result { - gui::CheatMenuResult::Cancel => new_runstate = RunState::AwaitingInput, + gui::CheatMenuResult::Cancel => { + new_runstate = RunState::AwaitingInput; + } gui::CheatMenuResult::NoResponse => {} gui::CheatMenuResult::Ascend => { self.goto_level(-1); @@ -312,7 +336,9 @@ impl GameState for State { RunState::ShowInventory => { let result = gui::show_inventory(self, ctx); match result.0 { - gui::ItemMenuResult::Cancel => new_runstate = RunState::AwaitingInput, + gui::ItemMenuResult::Cancel => { + new_runstate = RunState::AwaitingInput; + } gui::ItemMenuResult::NoResponse => {} gui::ItemMenuResult::Selected => { let item_entity = result.1.unwrap(); @@ -326,10 +352,13 @@ impl GameState for State { range: ranged_item.range, item: item_entity, aoe: aoe_item.radius, - } + }; } else { - new_runstate = - RunState::ShowTargeting { range: ranged_item.range, item: item_entity, aoe: 0 } + new_runstate = RunState::ShowTargeting { + range: ranged_item.range, + item: item_entity, + aoe: 0, + }; } } else { let mut intent = self.ecs.write_storage::(); @@ -344,7 +373,9 @@ impl GameState for State { RunState::ShowDropItem => { let result = gui::drop_item_menu(self, ctx); match result.0 { - gui::ItemMenuResult::Cancel => new_runstate = RunState::AwaitingInput, + gui::ItemMenuResult::Cancel => { + new_runstate = RunState::AwaitingInput; + } gui::ItemMenuResult::NoResponse => {} gui::ItemMenuResult::Selected => { let item_entity = result.1.unwrap(); @@ -359,7 +390,9 @@ impl GameState for State { RunState::ShowRemoveItem => { let result = gui::remove_item_menu(self, ctx); match result.0 { - gui::ItemMenuResult::Cancel => new_runstate = RunState::AwaitingInput, + gui::ItemMenuResult::Cancel => { + new_runstate = RunState::AwaitingInput; + } gui::ItemMenuResult::NoResponse => {} gui::ItemMenuResult::Selected => { let item_entity = result.1.unwrap(); @@ -374,7 +407,9 @@ impl GameState for State { RunState::ShowTargeting { range, item, aoe } => { let result = gui::ranged_target(self, ctx, range, aoe); match result.0 { - gui::ItemMenuResult::Cancel => new_runstate = RunState::AwaitingInput, + gui::ItemMenuResult::Cancel => { + new_runstate = RunState::AwaitingInput; + } gui::ItemMenuResult::NoResponse => {} gui::ItemMenuResult::Selected => { let mut intent = self.ecs.write_storage::(); @@ -388,7 +423,9 @@ impl GameState for State { RunState::ShowRemoveCurse => { let result = gui::remove_curse(self, ctx); match result.0 { - gui::ItemMenuResult::Cancel => new_runstate = RunState::AwaitingInput, + gui::ItemMenuResult::Cancel => { + new_runstate = RunState::AwaitingInput; + } gui::ItemMenuResult::NoResponse => {} gui::ItemMenuResult::Selected => { let item_entity = result.1.unwrap(); @@ -403,7 +440,9 @@ impl GameState for State { RunState::ShowIdentify => { let result = gui::identify(self, ctx); match result.0 { - gui::ItemMenuResult::Cancel => new_runstate = RunState::AwaitingInput, + gui::ItemMenuResult::Cancel => { + new_runstate = RunState::AwaitingInput; + } gui::ItemMenuResult::NoResponse => {} gui::ItemMenuResult::Selected => { let item_entity = result.1.unwrap(); @@ -425,31 +464,32 @@ impl GameState for State { let result = gui::main_menu(self, ctx); match result { gui::MainMenuResult::NoSelection { selected } => { - new_runstate = RunState::MainMenu { menu_selection: selected } + new_runstate = RunState::MainMenu { menu_selection: selected }; } - gui::MainMenuResult::Selected { selected } => match selected { - gui::MainMenuSelection::NewGame => { - new_runstate = RunState::CharacterCreation { - ancestry: gui::Ancestry::Human, - class: gui::Class::Fighter, + gui::MainMenuResult::Selected { selected } => + match selected { + gui::MainMenuSelection::NewGame => { + new_runstate = RunState::CharacterCreation { + ancestry: gui::Ancestry::Human, + class: gui::Class::Fighter, + }; + } + gui::MainMenuSelection::LoadGame => { + saveload_system::load_game(&mut self.ecs); + new_runstate = RunState::AwaitingInput; + saveload_system::delete_save(); + } + gui::MainMenuSelection::Quit => { + ::std::process::exit(0); } } - gui::MainMenuSelection::LoadGame => { - saveload_system::load_game(&mut self.ecs); - new_runstate = RunState::AwaitingInput; - saveload_system::delete_save(); - } - gui::MainMenuSelection::Quit => { - ::std::process::exit(0); - } - }, } } RunState::CharacterCreation { .. } => { let result = gui::character_creation(self, ctx); match result { gui::CharCreateResult::NoSelection { ancestry, class } => { - new_runstate = RunState::CharacterCreation { ancestry, class } + new_runstate = RunState::CharacterCreation { ancestry, class }; } gui::CharCreateResult::Selected { ancestry, class } => { if ancestry == gui::Ancestry::NULL { @@ -473,8 +513,9 @@ impl GameState for State { gui::YesNoResult::Yes => { self.game_over_cleanup(); new_runstate = RunState::MapGeneration; - self.mapgen_next_state = - Some(RunState::MainMenu { menu_selection: gui::MainMenuSelection::NewGame }); + self.mapgen_next_state = Some(RunState::MainMenu { + menu_selection: gui::MainMenuSelection::NewGame, + }); } } } @@ -508,7 +549,7 @@ impl GameState for State { if x % 2 == 0 { idx = map.xy_idx(x as i32, row); } else { - idx = map.xy_idx(x as i32, (map.height as i32 - 1) - (row)); + idx = map.xy_idx(x as i32, (map.height as i32) - 1 - row); } if !cursed { map.revealed_tiles[idx] = true; @@ -527,7 +568,7 @@ impl GameState for State { } } - if row as usize == map.height as usize - 1 { + if (row as usize) == (map.height as usize) - 1 { new_runstate = RunState::Ticking; } else { new_runstate = RunState::MagicMapReveal { row: row + 1, cursed: cursed }; diff --git a/src/map/dungeon.rs b/src/map/dungeon.rs index 9c2d84d..5da701c 100644 --- a/src/map/dungeon.rs +++ b/src/map/dungeon.rs @@ -1,9 +1,9 @@ -use super::{Map, TileType}; -use crate::{gamelog, map_builders, OtherLevelPosition, Position, Telepath, Viewshed}; +use super::{ Map, TileType }; +use crate::{ gamelog, map_builders, OtherLevelPosition, Position, Telepath, Viewshed }; use rltk::prelude::*; -use serde::{Deserialize, Serialize}; +use serde::{ Deserialize, Serialize }; use specs::prelude::*; -use std::collections::{HashMap, HashSet}; +use std::collections::{ HashMap, HashSet }; #[derive(Default, Serialize, Deserialize, Clone)] pub struct MasterDungeonMap { @@ -108,18 +108,42 @@ fn make_scroll_name(rng: &mut RandomNumberGenerator) -> String { } const POTION_COLOURS: &[&str] = &[ - "red", "orange", "yellow", "green", "blue", "indigo", "violet", "black", "white", "silver", "gold", "rainbow", - "blood", "purple", "cyan", "brown", "grey", "octarine", + "red", + "orange", + "yellow", + "green", + "blue", + "indigo", + "violet", + "black", + "white", + "silver", + "gold", + "rainbow", + "blood", + "purple", + "cyan", + "brown", + "grey", + "octarine", +]; +const POTION_ADJECTIVES: &[&str] = &[ + "swirling", + "viscous", + "effervescent", + "slimy", + "oily", + "metallic", + "prismatic", + "goopy", ]; -const POTION_ADJECTIVES: &[&str] = - &["swirling", "viscous", "effervescent", "slimy", "oily", "metallic", "prismatic", "goopy"]; fn make_potion_name(rng: &mut RandomNumberGenerator, used_names: &mut HashSet) -> String { loop { let mut name: String = - POTION_ADJECTIVES[rng.roll_dice(1, POTION_ADJECTIVES.len() as i32) as usize - 1].to_string(); + POTION_ADJECTIVES[(rng.roll_dice(1, POTION_ADJECTIVES.len() as i32) as usize) - 1].to_string(); name += " "; - name += POTION_COLOURS[rng.roll_dice(1, POTION_COLOURS.len() as i32) as usize - 1]; + name += POTION_COLOURS[(rng.roll_dice(1, POTION_COLOURS.len() as i32) as usize) - 1]; name += " potion"; if !used_names.contains(&name) { @@ -153,7 +177,7 @@ const WAND_TYPES: &[&str] = &[ fn make_wand_name(rng: &mut RandomNumberGenerator, used_names: &mut HashSet) -> String { loop { - let mut name: String = WAND_TYPES[rng.roll_dice(1, WAND_TYPES.len() as i32) as usize - 1].to_string(); + let mut name: String = WAND_TYPES[(rng.roll_dice(1, WAND_TYPES.len() as i32) as usize) - 1].to_string(); name += " wand"; if !used_names.contains(&name) { @@ -189,12 +213,12 @@ fn transition_to_existing_map(ecs: &mut World, new_id: i32, offset: i32) { for (idx, tt) in map.tiles.iter().enumerate() { if *tt == stair_type { let mut player_position = ecs.write_resource::(); - *player_position = Point::new(idx as i32 % w, idx as i32 / w); + *player_position = Point::new((idx as i32) % w, (idx as i32) / w); let mut position_components = ecs.write_storage::(); let player_pos_component = position_components.get_mut(*player_entity); if let Some(player_pos_component) = player_pos_component { - player_pos_component.x = idx as i32 % w; - player_pos_component.y = idx as i32 / w; + player_pos_component.x = (idx as i32) % w; + player_pos_component.y = (idx as i32) / w; } } } diff --git a/src/map/interval_spawning_system.rs b/src/map/interval_spawning_system.rs index 71c4071..07c6976 100644 --- a/src/map/interval_spawning_system.rs +++ b/src/map/interval_spawning_system.rs @@ -1,4 +1,4 @@ -use crate::{gamelog, raws, spawner, Clock, Map, RandomNumberGenerator, TakingTurn, LOG_SPAWNING}; +use crate::{ gamelog, raws, spawner, Clock, Map, RandomNumberGenerator, TakingTurn, LOG_SPAWNING }; use specs::prelude::*; const TRY_SPAWN_CHANCE: i32 = 70; @@ -48,7 +48,7 @@ fn spawn_random_mob_in_free_nonvisible_tile(ecs: &mut World) { let roll = raws::get_mob_spawn_amount(&mut rng, &spawn_type, player_level); for _i in 0..roll { let idx = get_random_idx_from_tiles(&mut rng, &mut available_tiles); - spawn_locations.push((idx as i32 % map.width, idx as i32 / map.width)); + spawn_locations.push(((idx as i32) % map.width, (idx as i32) / map.width)); } // Dropping resources for borrow-checker. std::mem::drop(map); @@ -64,7 +64,7 @@ fn spawn_random_mob_in_free_nonvisible_tile(ecs: &mut World) { &key, None, raws::SpawnType::AtPosition { x: idx.0, y: idx.1 }, - difficulty, + difficulty ); } } diff --git a/src/map/mod.rs b/src/map/mod.rs index e639ca4..238828c 100644 --- a/src/map/mod.rs +++ b/src/map/mod.rs @@ -1,14 +1,14 @@ -use rltk::{Algorithm2D, BaseMap, Point}; -use serde::{Deserialize, Serialize}; +use rltk::{ Algorithm2D, BaseMap, Point }; +use serde::{ Deserialize, Serialize }; use std::collections::HashSet; pub mod colours; mod glyphs; mod tiletype; -pub use tiletype::{tile_cost, tile_opaque, tile_walkable, TileType}; +pub use tiletype::{ tile_cost, tile_opaque, tile_walkable, TileType }; mod interval_spawning_system; pub use interval_spawning_system::try_spawn_interval; pub mod dungeon; -pub use dungeon::{level_transition, MasterDungeonMap}; +pub use dungeon::{ level_transition, MasterDungeonMap }; pub mod themes; pub use colours::NON_VISIBLE_MULTIPLIER; @@ -65,9 +65,9 @@ impl Map { let mut rng = rltk::RandomNumberGenerator::new(); for idx in 0..map.colour_offset.len() { - let red_roll: f32 = (rng.roll_dice(1, TWICE_OFFSET - 1) + 1 - OFFSET_PERCENT) as f32 / 100f32 + 1.0; - let green_roll: f32 = (rng.roll_dice(1, TWICE_OFFSET - 1) + 1 - OFFSET_PERCENT) as f32 / 100f32 + 1.0; - let blue_roll: f32 = (rng.roll_dice(1, TWICE_OFFSET - 1) + 1 - OFFSET_PERCENT) as f32 / 100f32 + 1.0; + let red_roll: f32 = ((rng.roll_dice(1, TWICE_OFFSET - 1) + 1 - OFFSET_PERCENT) as f32) / 100f32 + 1.0; + let green_roll: f32 = ((rng.roll_dice(1, TWICE_OFFSET - 1) + 1 - OFFSET_PERCENT) as f32) / 100f32 + 1.0; + let blue_roll: f32 = ((rng.roll_dice(1, TWICE_OFFSET - 1) + 1 - OFFSET_PERCENT) as f32) / 100f32 + 1.0; map.colour_offset[idx] = (red_roll, green_roll, blue_roll); } diff --git a/src/map/themes.rs b/src/map/themes.rs index c6b7046..8c52488 100644 --- a/src/map/themes.rs +++ b/src/map/themes.rs @@ -1,6 +1,6 @@ -use super::{colours::*, glyphs::*, Map, Point, TileType}; +use super::{ colours::*, glyphs::*, Map, Point, TileType }; use rltk::prelude::*; -use std::ops::{Add, Mul}; +use std::ops::{ Add, Mul }; const DARKEN_TILES_BY_DISTANCE: bool = true; @@ -12,7 +12,7 @@ pub fn get_tile_renderables_for_id(idx: usize, map: &Map, other_pos: Option bool { } fn wall_glyph(map: &Map, x: i32, y: i32) -> rltk::FontCharType { - if x < 1 || x > map.width - 2 || y < 1 || y > map.height - 2 as i32 { + if x < 1 || x > map.width - 2 || y < 1 || y > map.height - (2 as i32) { return 35; } let mut mask: u8 = 0; @@ -126,16 +128,16 @@ fn wall_glyph(map: &Map, x: i32, y: i32) -> rltk::FontCharType { } match mask { - 0 => 254, // ■ (254) square pillar; but maybe ○ (9) looks better - 1 => 186, // Wall only to the north - 2 => 186, // Wall only to the south - 3 => 186, // Wall to the north and south - 4 => 205, // Wall only to the west - 5 => 188, // Wall to the north and west - 6 => 187, // Wall to the south and west - 7 => 185, // Wall to the north, south and west - 8 => 205, // Wall only to the east - 9 => 200, // Wall to the north and east + 0 => 254, // ■ (254) square pillar; but maybe ○ (9) looks better + 1 => 186, // Wall only to the north + 2 => 186, // Wall only to the south + 3 => 186, // Wall to the north and south + 4 => 205, // Wall only to the west + 5 => 188, // Wall to the north and west + 6 => 187, // Wall to the south and west + 7 => 185, // Wall to the north, south and west + 8 => 205, // Wall only to the east + 9 => 200, // Wall to the north and east 10 => 201, // Wall to the south and east 11 => 204, // Wall to the north, south and east 12 => 205, // Wall to the east and west @@ -194,7 +196,7 @@ fn wall_glyph(map: &Map, x: i32, y: i32) -> rltk::FontCharType { 205 => 202, 175 => 204, 203 => 204, - 61 => 205, // NEW cases + 61 => 205, // NEW cases 125 => 205, // NEW cases 189 => 205, // NEW cases 206 => 205, @@ -204,7 +206,7 @@ fn wall_glyph(map: &Map, x: i32, y: i32) -> rltk::FontCharType { 253 => 205, 254 => 205, 167 => 186, // NSW, NW, SW - 91 => 186, // NSE, NE, SE + 91 => 186, // NSE, NE, SE 183 => 186, // NSW, NW, SW, NE 123 => 186, // NSE, NE, SE, NW 231 => 186, // NSW, NW, SW, SE @@ -215,7 +217,7 @@ fn wall_glyph(map: &Map, x: i32, y: i32) -> rltk::FontCharType { 191 => 201, // Everything except NW 223 => 188, // Everything except SE 239 => 200, // Everything except SW - _ => 35, // We missed one? + _ => 35, // We missed one? } } @@ -251,8 +253,9 @@ pub fn multiply_by_float(rgb: rltk::RGB, offsets: (f32, f32, f32)) -> RGB { fn darken_by_distance(pos: Point, other_pos: Point) -> f32 { let distance = DistanceAlg::Pythagoras.distance2d(pos, other_pos) as f32; // Get distance in tiles. - let interp_factor = (distance - START_DARKEN_AT_N_TILES) - / (MAX_DARKEN_AT_N_TILES * crate::config::entity::DEFAULT_VIEWSHED_STANDARD as f32 - START_DARKEN_AT_N_TILES); + let interp_factor = + (distance - START_DARKEN_AT_N_TILES) / + (MAX_DARKEN_AT_N_TILES * (crate::config::entity::DEFAULT_VIEWSHED_STANDARD as f32) - START_DARKEN_AT_N_TILES); let interp_factor = interp_factor.max(0.0).min(1.0); // Clamp [0-1] return 1.0 - interp_factor * (1.0 - MAX_DARKENING); } diff --git a/src/map/tiletype.rs b/src/map/tiletype.rs index d34c13e..73d37f2 100644 --- a/src/map/tiletype.rs +++ b/src/map/tiletype.rs @@ -1,4 +1,4 @@ -use serde::{Deserialize, Serialize}; +use serde::{ Deserialize, Serialize }; #[derive(PartialEq, Eq, Hash, Copy, Clone, Serialize, Deserialize)] pub enum TileType { @@ -26,7 +26,7 @@ pub enum TileType { pub fn tile_walkable(tt: TileType) -> bool { match tt { - TileType::Floor + | TileType::Floor | TileType::WoodFloor | TileType::Gravel | TileType::Road diff --git a/src/map_builders/area_starting_points.rs b/src/map_builders/area_starting_points.rs index aea8996..23c014f 100644 --- a/src/map_builders/area_starting_points.rs +++ b/src/map_builders/area_starting_points.rs @@ -1,4 +1,4 @@ -use super::{BuilderMap, MetaMapBuilder, Position}; +use super::{ BuilderMap, MetaMapBuilder, Position }; use rltk::RandomNumberGenerator; #[allow(dead_code)] @@ -37,14 +37,26 @@ impl AreaStartingPosition { let seed_y; match self.x { - XStart::LEFT => seed_x = 1, - XStart::CENTRE => seed_x = build_data.map.width / 2, - XStart::RIGHT => seed_x = build_data.map.width - 2, + XStart::LEFT => { + seed_x = 1; + } + XStart::CENTRE => { + seed_x = build_data.map.width / 2; + } + XStart::RIGHT => { + seed_x = build_data.map.width - 2; + } } match self.y { - YStart::TOP => seed_y = 1, - YStart::CENTRE => seed_y = build_data.map.height / 2, - YStart::BOTTOM => seed_y = build_data.map.height - 2, + YStart::TOP => { + seed_y = 1; + } + YStart::CENTRE => { + seed_y = build_data.map.height / 2; + } + YStart::BOTTOM => { + seed_y = build_data.map.height - 2; + } } let mut available_floors: Vec<(usize, f32)> = Vec::new(); @@ -53,8 +65,8 @@ impl AreaStartingPosition { available_floors.push(( idx, rltk::DistanceAlg::PythagorasSquared.distance2d( - rltk::Point::new(idx as i32 % build_data.map.width, idx as i32 / build_data.map.width), - rltk::Point::new(seed_x, seed_y), + rltk::Point::new((idx as i32) % build_data.map.width, (idx as i32) / build_data.map.width), + rltk::Point::new(seed_x, seed_y) ), )); } @@ -65,8 +77,8 @@ impl AreaStartingPosition { available_floors.sort_by(|a, b| a.1.partial_cmp(&b.1).unwrap()); - let start_x = available_floors[0].0 as i32 % build_data.map.width; - let start_y = available_floors[0].0 as i32 / build_data.map.width; + let start_x = (available_floors[0].0 as i32) % build_data.map.width; + let start_y = (available_floors[0].0 as i32) / build_data.map.width; build_data.starting_position = Some(Position { x: start_x, y: start_y }); } diff --git a/src/map_builders/bsp_dungeon.rs b/src/map_builders/bsp_dungeon.rs index 8746400..95ddd15 100644 --- a/src/map_builders/bsp_dungeon.rs +++ b/src/map_builders/bsp_dungeon.rs @@ -1,4 +1,4 @@ -use super::{BuilderMap, InitialMapBuilder, Rect, TileType}; +use super::{ BuilderMap, InitialMapBuilder, Rect, TileType }; use rltk::RandomNumberGenerator; pub struct BspDungeonBuilder { diff --git a/src/map_builders/bsp_interior.rs b/src/map_builders/bsp_interior.rs index a2ab03d..e4ad7e9 100644 --- a/src/map_builders/bsp_interior.rs +++ b/src/map_builders/bsp_interior.rs @@ -1,4 +1,4 @@ -use super::{draw_corridor, BuilderMap, InitialMapBuilder, Rect, TileType}; +use super::{ draw_corridor, BuilderMap, InitialMapBuilder, Rect, TileType }; use rltk::RandomNumberGenerator; const MIN_ROOM_SIZE: i32 = 8; @@ -36,7 +36,7 @@ impl BspInteriorBuilder { for y in room.y1..room.y2 { for x in room.x1..room.x2 { let idx = build_data.map.xy_idx(x, y); - if idx > 0 && idx < ((build_data.map.width * build_data.map.height) - 1) as usize { + if idx > 0 && idx < ((build_data.map.width * build_data.map.height - 1) as usize) { build_data.map.tiles[idx] = TileType::Floor; } } diff --git a/src/map_builders/cellular_automata.rs b/src/map_builders/cellular_automata.rs index 17dd869..2830bd8 100644 --- a/src/map_builders/cellular_automata.rs +++ b/src/map_builders/cellular_automata.rs @@ -1,4 +1,4 @@ -use super::{BuilderMap, InitialMapBuilder, MetaMapBuilder, TileType}; +use super::{ BuilderMap, InitialMapBuilder, MetaMapBuilder, TileType }; use rltk::RandomNumberGenerator; pub struct CellularAutomataBuilder {} @@ -31,9 +31,9 @@ impl CellularAutomataBuilder { let roll = rng.roll_dice(1, 100); let idx = build_data.map.xy_idx(x, y); if roll > 55 { - build_data.map.tiles[idx] = TileType::Floor + build_data.map.tiles[idx] = TileType::Floor; } else { - build_data.map.tiles[idx] = TileType::Wall + build_data.map.tiles[idx] = TileType::Wall; } } } @@ -58,22 +58,22 @@ impl CellularAutomataBuilder { if build_data.map.tiles[idx + 1] == TileType::Wall { neighbors += 1; } - if build_data.map.tiles[idx - build_data.map.width as usize] == TileType::Wall { + if build_data.map.tiles[idx - (build_data.map.width as usize)] == TileType::Wall { neighbors += 1; } - if build_data.map.tiles[idx + build_data.map.width as usize] == TileType::Wall { + if build_data.map.tiles[idx + (build_data.map.width as usize)] == TileType::Wall { neighbors += 1; } - if build_data.map.tiles[idx - (build_data.map.width as usize - 1)] == TileType::Wall { + if build_data.map.tiles[idx - ((build_data.map.width as usize) - 1)] == TileType::Wall { neighbors += 1; } - if build_data.map.tiles[idx - (build_data.map.width as usize + 1)] == TileType::Wall { + if build_data.map.tiles[idx - ((build_data.map.width as usize) + 1)] == TileType::Wall { neighbors += 1; } - if build_data.map.tiles[idx + (build_data.map.width as usize - 1)] == TileType::Wall { + if build_data.map.tiles[idx + ((build_data.map.width as usize) - 1)] == TileType::Wall { neighbors += 1; } - if build_data.map.tiles[idx + (build_data.map.width as usize + 1)] == TileType::Wall { + if build_data.map.tiles[idx + ((build_data.map.width as usize) + 1)] == TileType::Wall { neighbors += 1; } diff --git a/src/map_builders/common.rs b/src/map_builders/common.rs index 80c5343..ffed6fa 100644 --- a/src/map_builders/common.rs +++ b/src/map_builders/common.rs @@ -1,5 +1,5 @@ -use super::{Map, Rect, TileType}; -use std::cmp::{max, min}; +use super::{ Map, Rect, TileType }; +use std::cmp::{ max, min }; #[allow(dead_code)] pub fn apply_room_to_map(map: &mut Map, room: &Rect) { diff --git a/src/map_builders/cull_unreachable.rs b/src/map_builders/cull_unreachable.rs index 4b2213b..2b0e0e9 100644 --- a/src/map_builders/cull_unreachable.rs +++ b/src/map_builders/cull_unreachable.rs @@ -1,4 +1,4 @@ -use super::{BuilderMap, MetaMapBuilder, TileType}; +use super::{ BuilderMap, MetaMapBuilder, TileType }; use rltk::RandomNumberGenerator; pub struct CullUnreachable {} @@ -25,7 +25,7 @@ impl CullUnreachable { build_data.map.height as usize, &map_starts, &build_data.map, - 1000.0, + 1000.0 ); for (i, tile) in build_data.map.tiles.iter_mut().enumerate() { if *tile == TileType::Floor { diff --git a/src/map_builders/distant_exit.rs b/src/map_builders/distant_exit.rs index 74873ec..b3728b7 100644 --- a/src/map_builders/distant_exit.rs +++ b/src/map_builders/distant_exit.rs @@ -1,4 +1,4 @@ -use super::{BuilderMap, MetaMapBuilder, TileType}; +use super::{ BuilderMap, MetaMapBuilder, TileType }; use rltk::RandomNumberGenerator; pub struct DistantExit {} @@ -25,7 +25,7 @@ impl DistantExit { build_data.map.height as usize, &map_starts, &build_data.map, - 1000.0, + 1000.0 ); let mut exit_tile = (0, 0.0f32); for (i, tile) in build_data.map.tiles.iter_mut().enumerate() { diff --git a/src/map_builders/dla.rs b/src/map_builders/dla.rs index 2cb5fa3..c5d97fc 100644 --- a/src/map_builders/dla.rs +++ b/src/map_builders/dla.rs @@ -1,4 +1,4 @@ -use super::{paint, BuilderMap, InitialMapBuilder, MetaMapBuilder, Position, Symmetry, TileType}; +use super::{ paint, BuilderMap, InitialMapBuilder, MetaMapBuilder, Position, Symmetry, TileType }; use rltk::RandomNumberGenerator; #[derive(PartialEq, Copy, Clone)] @@ -100,13 +100,16 @@ impl DLABuilder { build_data.map.tiles[start_idx] = TileType::Floor; build_data.map.tiles[start_idx - 1] = TileType::Floor; build_data.map.tiles[start_idx + 1] = TileType::Floor; - build_data.map.tiles[start_idx - build_data.map.width as usize] = TileType::Floor; - build_data.map.tiles[start_idx + build_data.map.width as usize] = TileType::Floor; + build_data.map.tiles[start_idx - (build_data.map.width as usize)] = TileType::Floor; + build_data.map.tiles[start_idx + (build_data.map.width as usize)] = TileType::Floor; // Random walker let total_tiles = build_data.map.width * build_data.map.height; - let desired_floor_tiles = (self.floor_percent * total_tiles as f32) as usize; - let mut floor_tile_count = build_data.map.tiles.iter().filter(|a| **a == TileType::Floor).count(); + let desired_floor_tiles = (self.floor_percent * (total_tiles as f32)) as usize; + let mut floor_tile_count = build_data.map.tiles + .iter() + .filter(|a| **a == TileType::Floor) + .count(); while floor_tile_count < desired_floor_tiles { match self.algorithm { DLAAlgorithm::WalkInwards => { @@ -189,7 +192,7 @@ impl DLABuilder { let mut path = rltk::line2d( rltk::LineAlg::Bresenham, rltk::Point::new(digger_x, digger_y), - rltk::Point::new(starting_position.x, starting_position.y), + rltk::Point::new(starting_position.x, starting_position.y) ); while build_data.map.tiles[digger_idx] == TileType::Wall && !path.is_empty() { @@ -206,7 +209,10 @@ impl DLABuilder { build_data.take_snapshot(); - floor_tile_count = build_data.map.tiles.iter().filter(|a| **a == TileType::Floor).count(); + floor_tile_count = build_data.map.tiles + .iter() + .filter(|a| **a == TileType::Floor) + .count(); } } } diff --git a/src/map_builders/door_placement.rs b/src/map_builders/door_placement.rs index 5c26eb9..e19f8e7 100644 --- a/src/map_builders/door_placement.rs +++ b/src/map_builders/door_placement.rs @@ -1,4 +1,4 @@ -use super::{BuilderMap, MetaMapBuilder, TileType}; +use super::{ BuilderMap, MetaMapBuilder, TileType }; use rltk::RandomNumberGenerator; pub struct DoorPlacement {} @@ -45,27 +45,35 @@ impl DoorPlacement { } } - let x = idx % build_data.map.width as usize; - let y = idx / build_data.map.width as usize; + let x = idx % (build_data.map.width as usize); + let y = idx / (build_data.map.width as usize); // Check for east-west door possibility - if build_data.map.tiles[idx] == TileType::Floor - && (x > 1 && build_data.map.tiles[idx - 1] == TileType::Floor) - && (x < build_data.map.width as usize - 2 && build_data.map.tiles[idx + 1] == TileType::Floor) - && (y > 1 && build_data.map.tiles[idx - build_data.map.width as usize] == TileType::Wall) - && (y < build_data.map.height as usize - 2 - && build_data.map.tiles[idx + build_data.map.width as usize] == TileType::Wall) + if + build_data.map.tiles[idx] == TileType::Floor && + x > 1 && + build_data.map.tiles[idx - 1] == TileType::Floor && + x < (build_data.map.width as usize) - 2 && + build_data.map.tiles[idx + 1] == TileType::Floor && + y > 1 && + build_data.map.tiles[idx - (build_data.map.width as usize)] == TileType::Wall && + y < (build_data.map.height as usize) - 2 && + build_data.map.tiles[idx + (build_data.map.width as usize)] == TileType::Wall { return true; } // Check for north-south door possibility - if build_data.map.tiles[idx] == TileType::Floor - && (x > 1 && build_data.map.tiles[idx - 1] == TileType::Wall) - && (x < build_data.map.width as usize - 2 && build_data.map.tiles[idx + 1] == TileType::Wall) - && (y > 1 && build_data.map.tiles[idx - build_data.map.width as usize] == TileType::Floor) - && (y < build_data.map.height as usize - 2 - && build_data.map.tiles[idx + build_data.map.width as usize] == TileType::Floor) + if + build_data.map.tiles[idx] == TileType::Floor && + x > 1 && + build_data.map.tiles[idx - 1] == TileType::Wall && + x < (build_data.map.width as usize) - 2 && + build_data.map.tiles[idx + 1] == TileType::Wall && + y > 1 && + build_data.map.tiles[idx - (build_data.map.width as usize)] == TileType::Floor && + y < (build_data.map.height as usize) - 2 && + build_data.map.tiles[idx + (build_data.map.width as usize)] == TileType::Floor { return true; } diff --git a/src/map_builders/drunkard.rs b/src/map_builders/drunkard.rs index 151e100..9e56892 100644 --- a/src/map_builders/drunkard.rs +++ b/src/map_builders/drunkard.rs @@ -1,4 +1,4 @@ -use super::{paint, BuilderMap, InitialMapBuilder, MetaMapBuilder, Position, Symmetry, TileType}; +use super::{ paint, BuilderMap, InitialMapBuilder, MetaMapBuilder, Position, Symmetry, TileType }; use rltk::RandomNumberGenerator; #[derive(PartialEq, Copy, Clone)] @@ -112,8 +112,11 @@ impl DrunkardsWalkBuilder { build_data.map.tiles[start_idx] = TileType::Floor; let total_tiles = build_data.map.width * build_data.map.height; - let desired_floor_tiles = (self.settings.floor_percent * total_tiles as f32) as usize; - let mut floor_tile_count = build_data.map.tiles.iter().filter(|a| **a == TileType::Floor).count(); + let desired_floor_tiles = (self.settings.floor_percent * (total_tiles as f32)) as usize; + let mut floor_tile_count = build_data.map.tiles + .iter() + .filter(|a| **a == TileType::Floor) + .count(); let mut digger_count = 0; while floor_tile_count < desired_floor_tiles { let mut did_something = false; @@ -180,7 +183,10 @@ impl DrunkardsWalkBuilder { *t = TileType::Floor; } } - floor_tile_count = build_data.map.tiles.iter().filter(|a| **a == TileType::Floor).count(); + floor_tile_count = build_data.map.tiles + .iter() + .filter(|a| **a == TileType::Floor) + .count(); } } } diff --git a/src/map_builders/fill_edges.rs b/src/map_builders/fill_edges.rs index 3c80bc4..9b42c81 100644 --- a/src/map_builders/fill_edges.rs +++ b/src/map_builders/fill_edges.rs @@ -1,4 +1,4 @@ -use super::{BuilderMap, MetaMapBuilder, TileType}; +use super::{ BuilderMap, MetaMapBuilder, TileType }; use rltk::RandomNumberGenerator; pub struct FillEdges { diff --git a/src/map_builders/forest.rs b/src/map_builders/forest.rs index e83bfe7..5b21f6d 100644 --- a/src/map_builders/forest.rs +++ b/src/map_builders/forest.rs @@ -1,6 +1,14 @@ use super::{ - AreaStartingPosition, BuilderChain, BuilderMap, CellularAutomataBuilder, CullUnreachable, MetaMapBuilder, TileType, - VoronoiSpawning, XStart, YStart, + AreaStartingPosition, + BuilderChain, + BuilderMap, + CellularAutomataBuilder, + CullUnreachable, + MetaMapBuilder, + TileType, + VoronoiSpawning, + XStart, + YStart, }; use rltk::prelude::*; @@ -10,7 +18,7 @@ pub fn forest_builder( width: i32, height: i32, difficulty: i32, - initial_player_level: i32, + initial_player_level: i32 ) -> BuilderChain { let mut chain = BuilderChain::new(new_id, width, height, difficulty, "the woods", initial_player_level); chain.start_with(CellularAutomataBuilder::new()); @@ -44,8 +52,8 @@ impl RoadExit { available_floors.push(( idx, DistanceAlg::PythagorasSquared.distance2d( - Point::new(idx as i32 % build_data.map.width, idx as i32 / build_data.map.width), - Point::new(seed_x, seed_y), + Point::new((idx as i32) % build_data.map.width, (idx as i32) / build_data.map.width), + Point::new(seed_x, seed_y) ), )); } @@ -54,8 +62,8 @@ impl RoadExit { panic!("No valid floors to start on."); } available_floors.sort_by(|a, b| a.1.partial_cmp(&b.1).unwrap()); - let end_x = available_floors[0].0 as i32 % build_data.map.width; - let end_y = available_floors[0].0 as i32 / build_data.map.width; + let end_x = (available_floors[0].0 as i32) % build_data.map.width; + let end_y = (available_floors[0].0 as i32) / build_data.map.width; return (end_x, end_y); } @@ -78,8 +86,8 @@ impl RoadExit { let path = a_star_search(start_idx, end_idx, &mut build_data.map); for idx in path.steps.iter() { - let x = *idx as i32 % build_data.map.width; - let y = *idx as i32 / build_data.map.width; + let x = (*idx as i32) % build_data.map.width; + let y = (*idx as i32) / build_data.map.width; self.paint_road(build_data, x, y); self.paint_road(build_data, x - 1, y); self.paint_road(build_data, x + 1, y); diff --git a/src/map_builders/maze.rs b/src/map_builders/maze.rs index 5d37496..5ca908c 100644 --- a/src/map_builders/maze.rs +++ b/src/map_builders/maze.rs @@ -1,4 +1,4 @@ -use super::{BuilderMap, InitialMapBuilder, Map, TileType}; +use super::{ BuilderMap, InitialMapBuilder, Map, TileType }; use rltk::RandomNumberGenerator; pub struct MazeBuilder {} @@ -19,7 +19,7 @@ impl MazeBuilder { #[allow(clippy::map_entry)] fn build(&mut self, rng: &mut RandomNumberGenerator, build_data: &mut BuilderMap) { // Maze gen - let mut maze = Grid::new((build_data.map.width / 2) - 2, (build_data.map.height / 2) - 2, rng); + let mut maze = Grid::new(build_data.map.width / 2 - 2, build_data.map.height / 2 - 2, rng); maze.generate_maze(build_data); } } @@ -90,7 +90,7 @@ impl<'a> Grid<'a> { if row < 0 || column < 0 || column > self.width - 1 || row > self.height - 1 { -1 } else { - column + (row * self.width) + column + row * self.width } } @@ -178,16 +178,16 @@ impl<'a> Grid<'a> { map.tiles[idx] = TileType::Floor; if !cell.walls[TOP] { - map.tiles[idx - map.width as usize] = TileType::Floor + map.tiles[idx - (map.width as usize)] = TileType::Floor; } if !cell.walls[RIGHT] { - map.tiles[idx + 1] = TileType::Floor + map.tiles[idx + 1] = TileType::Floor; } if !cell.walls[BOTTOM] { - map.tiles[idx + map.width as usize] = TileType::Floor + map.tiles[idx + (map.width as usize)] = TileType::Floor; } if !cell.walls[LEFT] { - map.tiles[idx - 1] = TileType::Floor + map.tiles[idx - 1] = TileType::Floor; } } } diff --git a/src/map_builders/mod.rs b/src/map_builders/mod.rs index 69a46ef..7349eba 100644 --- a/src/map_builders/mod.rs +++ b/src/map_builders/mod.rs @@ -1,4 +1,4 @@ -use super::{spawner, Map, Position, Rect, TileType, SHOW_MAPGEN}; +use super::{ spawner, Map, Position, Rect, TileType, SHOW_MAPGEN }; mod bsp_dungeon; use bsp_dungeon::BspDungeonBuilder; mod bsp_interior; @@ -26,7 +26,7 @@ use room_based_stairs::*; mod room_based_starting_position; use room_based_starting_position::*; mod area_starting_points; -use area_starting_points::{AreaStartingPosition, XStart, YStart}; +use area_starting_points::{ AreaStartingPosition, XStart, YStart }; mod cull_unreachable; use cull_unreachable::CullUnreachable; mod distant_exit; @@ -45,7 +45,7 @@ use rooms_corridors_dogleg::DoglegCorridors; mod rooms_corridors_bsp; use rooms_corridors_bsp::BspCorridors; mod room_sorter; -use room_sorter::{RoomSort, RoomSorter}; +use room_sorter::{ RoomSort, RoomSorter }; mod room_draw; use room_draw::RoomDrawer; mod rooms_corridors_nearest; @@ -101,7 +101,7 @@ impl BuilderChain { height: i32, difficulty: i32, name: S, - initial_player_level: i32, + initial_player_level: i32 ) -> BuilderChain { BuilderChain { starter: None, @@ -122,7 +122,9 @@ impl BuilderChain { pub fn start_with(&mut self, starter: Box) { match self.starter { - None => self.starter = Some(starter), + None => { + self.starter = Some(starter); + } Some(_) => panic!("You can only have one starting builder."), }; } @@ -168,17 +170,29 @@ fn random_start_position(rng: &mut rltk::RandomNumberGenerator) -> (XStart, YSta let x; let xroll = rng.roll_dice(1, 3); match xroll { - 1 => x = XStart::LEFT, - 2 => x = XStart::CENTRE, - _ => x = XStart::RIGHT, + 1 => { + x = XStart::LEFT; + } + 2 => { + x = XStart::CENTRE; + } + _ => { + x = XStart::RIGHT; + } } let y; let yroll = rng.roll_dice(1, 3); match yroll { - 1 => y = YStart::BOTTOM, - 2 => y = YStart::CENTRE, - _ => y = YStart::TOP, + 1 => { + y = YStart::BOTTOM; + } + 2 => { + y = YStart::CENTRE; + } + _ => { + y = YStart::TOP; + } } (x, y) @@ -305,7 +319,7 @@ pub fn random_builder( width: i32, height: i32, difficulty: i32, - initial_player_level: i32, + initial_player_level: i32 ) -> BuilderChain { rltk::console::log(format!("DEBUGINFO: Building random (ID:{}, DIFF:{})", new_id, difficulty)); let mut builder = BuilderChain::new(new_id, width, height, difficulty, "the dungeon", initial_player_level); @@ -313,7 +327,9 @@ pub fn random_builder( let mut want_doors = true; match type_roll { 1 => random_room_builder(rng, &mut builder), - _ => want_doors = random_shape_builder(rng, &mut builder), + _ => { + want_doors = random_shape_builder(rng, &mut builder); + } } /* @@ -354,7 +370,7 @@ pub fn level_builder( rng: &mut rltk::RandomNumberGenerator, width: i32, height: i32, - initial_player_level: i32, + initial_player_level: i32 ) -> BuilderChain { // TODO: With difficulty and ID/depth decoupled, this can be used for branches later. let difficulty = new_id; diff --git a/src/map_builders/room_based_spawner.rs b/src/map_builders/room_based_spawner.rs index 6d8f981..107ea22 100644 --- a/src/map_builders/room_based_spawner.rs +++ b/src/map_builders/room_based_spawner.rs @@ -1,4 +1,4 @@ -use super::{spawner, BuilderMap, MetaMapBuilder}; +use super::{ spawner, BuilderMap, MetaMapBuilder }; use rltk::RandomNumberGenerator; pub struct RoomBasedSpawner {} @@ -23,7 +23,7 @@ impl RoomBasedSpawner { rng, room, &mut build_data.spawn_list, - build_data.initial_player_level, + build_data.initial_player_level ); } } else { diff --git a/src/map_builders/room_based_stairs.rs b/src/map_builders/room_based_stairs.rs index 1c1a268..d1d42c0 100644 --- a/src/map_builders/room_based_stairs.rs +++ b/src/map_builders/room_based_stairs.rs @@ -1,4 +1,4 @@ -use super::{BuilderMap, MetaMapBuilder, TileType}; +use super::{ BuilderMap, MetaMapBuilder, TileType }; use rltk::RandomNumberGenerator; pub struct RoomBasedStairs {} diff --git a/src/map_builders/room_based_starting_position.rs b/src/map_builders/room_based_starting_position.rs index 0550f03..dbb6110 100644 --- a/src/map_builders/room_based_starting_position.rs +++ b/src/map_builders/room_based_starting_position.rs @@ -1,4 +1,4 @@ -use super::{BuilderMap, MetaMapBuilder, Position}; +use super::{ BuilderMap, MetaMapBuilder, Position }; use rltk::RandomNumberGenerator; pub struct RoomBasedStartingPosition {} diff --git a/src/map_builders/room_corner_rounding.rs b/src/map_builders/room_corner_rounding.rs index e87a465..6af2b5e 100644 --- a/src/map_builders/room_corner_rounding.rs +++ b/src/map_builders/room_corner_rounding.rs @@ -1,4 +1,4 @@ -use super::{BuilderMap, MetaMapBuilder, Rect, TileType}; +use super::{ BuilderMap, MetaMapBuilder, Rect, TileType }; use rltk::RandomNumberGenerator; pub struct RoomCornerRounder {} @@ -23,13 +23,13 @@ impl RoomCornerRounder { if x > 0 && build_data.map.tiles[idx - 1] == TileType::Wall { neighbour_walls += 1; } - if y > 0 && build_data.map.tiles[idx - w as usize] == TileType::Wall { + if y > 0 && build_data.map.tiles[idx - (w as usize)] == TileType::Wall { neighbour_walls += 1; } if x < w - 2 && build_data.map.tiles[idx + 1] == TileType::Wall { neighbour_walls += 1; } - if y < h - 2 && build_data.map.tiles[idx + w as usize] == TileType::Wall { + if y < h - 2 && build_data.map.tiles[idx + (w as usize)] == TileType::Wall { neighbour_walls += 1; } if neighbour_walls == 2 { diff --git a/src/map_builders/room_draw.rs b/src/map_builders/room_draw.rs index 1dcac3b..54cbaff 100644 --- a/src/map_builders/room_draw.rs +++ b/src/map_builders/room_draw.rs @@ -1,4 +1,4 @@ -use super::{BuilderMap, MetaMapBuilder, Rect, TileType}; +use super::{ BuilderMap, MetaMapBuilder, Rect, TileType }; use rltk::RandomNumberGenerator; pub struct RoomDrawer {} @@ -19,7 +19,7 @@ impl RoomDrawer { for y in room.y1 + 1..=room.y2 { for x in room.x1 + 1..=room.x2 { let idx = build_data.map.xy_idx(x, y); - if idx > 0 && idx < ((build_data.map.width * build_data.map.height) - 1) as usize { + if idx > 0 && idx < ((build_data.map.width * build_data.map.height - 1) as usize) { build_data.map.tiles[idx] = TileType::Floor; } } @@ -27,15 +27,14 @@ impl RoomDrawer { } fn circle(&mut self, build_data: &mut BuilderMap, room: &Rect) { - let radius = i32::min(room.x2 - room.x1, room.y2 - room.y1) as f32 / 2.0; + let radius = (i32::min(room.x2 - room.x1, room.y2 - room.y1) as f32) / 2.0; let center = room.centre(); let center_pt = rltk::Point::new(center.0, center.1); for y in room.y1..=room.y2 { for x in room.x1..=room.x2 { let idx = build_data.map.xy_idx(x, y); let distance = rltk::DistanceAlg::Pythagoras.distance2d(center_pt, rltk::Point::new(x, y)); - if idx > 0 && idx < ((build_data.map.width * build_data.map.height) - 1) as usize && distance <= radius - { + if idx > 0 && idx < ((build_data.map.width * build_data.map.height - 1) as usize) && distance <= radius { build_data.map.tiles[idx] = TileType::Floor; } } diff --git a/src/map_builders/room_exploder.rs b/src/map_builders/room_exploder.rs index 18c997b..d6d43db 100644 --- a/src/map_builders/room_exploder.rs +++ b/src/map_builders/room_exploder.rs @@ -1,4 +1,4 @@ -use super::{paint, BuilderMap, MetaMapBuilder, Rect, Symmetry, TileType}; +use super::{ paint, BuilderMap, MetaMapBuilder, Rect, Symmetry, TileType }; use rltk::RandomNumberGenerator; pub struct RoomExploder {} diff --git a/src/map_builders/room_sorter.rs b/src/map_builders/room_sorter.rs index 7cd082d..6c635c5 100644 --- a/src/map_builders/room_sorter.rs +++ b/src/map_builders/room_sorter.rs @@ -1,4 +1,4 @@ -use super::{BuilderMap, MetaMapBuilder, Rect}; +use super::{ BuilderMap, MetaMapBuilder, Rect }; use rltk::RandomNumberGenerator; #[allow(dead_code)] @@ -29,19 +29,38 @@ impl RoomSorter { fn sorter(&mut self, _rng: &mut RandomNumberGenerator, build_data: &mut BuilderMap) { match self.sort_by { - RoomSort::LEFTMOST => build_data.rooms.as_mut().unwrap().sort_by(|a, b| a.x1.cmp(&b.x1)), - RoomSort::RIGHTMOST => build_data.rooms.as_mut().unwrap().sort_by(|a, b| b.x2.cmp(&a.x2)), - RoomSort::TOPMOST => build_data.rooms.as_mut().unwrap().sort_by(|a, b| a.y1.cmp(&b.y1)), - RoomSort::BOTTOMMOST => build_data.rooms.as_mut().unwrap().sort_by(|a, b| b.y2.cmp(&a.y2)), + RoomSort::LEFTMOST => + build_data.rooms + .as_mut() + .unwrap() + .sort_by(|a, b| a.x1.cmp(&b.x1)), + RoomSort::RIGHTMOST => + build_data.rooms + .as_mut() + .unwrap() + .sort_by(|a, b| b.x2.cmp(&a.x2)), + RoomSort::TOPMOST => + build_data.rooms + .as_mut() + .unwrap() + .sort_by(|a, b| a.y1.cmp(&b.y1)), + RoomSort::BOTTOMMOST => + build_data.rooms + .as_mut() + .unwrap() + .sort_by(|a, b| b.y2.cmp(&a.y2)), RoomSort::CENTRAL => { let map_centre = rltk::Point::new(build_data.map.width / 2, build_data.map.height / 2); - build_data.rooms.as_mut().unwrap().sort_by(|a: &Rect, b: &Rect| { - let a_centre_pt = rltk::Point::new(a.centre().0, a.centre().1); - let b_centre_pt = rltk::Point::new(b.centre().0, b.centre().1); - let distance_a = rltk::DistanceAlg::Pythagoras.distance2d(a_centre_pt, map_centre); - let distance_b = rltk::DistanceAlg::Pythagoras.distance2d(b_centre_pt, map_centre); - return distance_a.partial_cmp(&distance_b).unwrap(); - }) + build_data.rooms + .as_mut() + .unwrap() + .sort_by(|a: &Rect, b: &Rect| { + let a_centre_pt = rltk::Point::new(a.centre().0, a.centre().1); + let b_centre_pt = rltk::Point::new(b.centre().0, b.centre().1); + let distance_a = rltk::DistanceAlg::Pythagoras.distance2d(a_centre_pt, map_centre); + let distance_b = rltk::DistanceAlg::Pythagoras.distance2d(b_centre_pt, map_centre); + return distance_a.partial_cmp(&distance_b).unwrap(); + }) } } } diff --git a/src/map_builders/rooms_corridors_bresenham.rs b/src/map_builders/rooms_corridors_bresenham.rs index 66c6290..5750636 100644 --- a/src/map_builders/rooms_corridors_bresenham.rs +++ b/src/map_builders/rooms_corridors_bresenham.rs @@ -1,4 +1,4 @@ -use super::{BuilderMap, MetaMapBuilder, Rect, TileType}; +use super::{ BuilderMap, MetaMapBuilder, Rect, TileType }; use rltk::RandomNumberGenerator; use std::collections::HashSet; @@ -46,7 +46,7 @@ impl BresenhamCorridors { let line = rltk::line2d( rltk::LineAlg::Bresenham, room_centre_pt, - rltk::Point::new(dest_centre.0, dest_centre.1), + rltk::Point::new(dest_centre.0, dest_centre.1) ); let mut corridor = Vec::new(); for cell in line.iter() { diff --git a/src/map_builders/rooms_corridors_bsp.rs b/src/map_builders/rooms_corridors_bsp.rs index 2cf2dee..6b4f764 100644 --- a/src/map_builders/rooms_corridors_bsp.rs +++ b/src/map_builders/rooms_corridors_bsp.rs @@ -1,4 +1,4 @@ -use super::{draw_corridor, BuilderMap, MetaMapBuilder, Rect}; +use super::{ draw_corridor, BuilderMap, MetaMapBuilder, Rect }; use rltk::RandomNumberGenerator; pub struct BspCorridors {} diff --git a/src/map_builders/rooms_corridors_dogleg.rs b/src/map_builders/rooms_corridors_dogleg.rs index 854b92f..fe2a1cf 100644 --- a/src/map_builders/rooms_corridors_dogleg.rs +++ b/src/map_builders/rooms_corridors_dogleg.rs @@ -1,4 +1,4 @@ -use super::{apply_horizontal_tunnel, apply_vertical_tunnel, BuilderMap, MetaMapBuilder, Rect}; +use super::{ apply_horizontal_tunnel, apply_vertical_tunnel, BuilderMap, MetaMapBuilder, Rect }; use rltk::RandomNumberGenerator; pub struct DoglegCorridors {} @@ -28,7 +28,7 @@ impl DoglegCorridors { for (i, room) in rooms.iter().enumerate() { if i > 0 { let (new_x, new_y) = room.centre(); - let (prev_x, prev_y) = rooms[i as usize - 1].centre(); + let (prev_x, prev_y) = rooms[(i as usize) - 1].centre(); if rng.range(0, 2) == 1 { let mut c1 = apply_horizontal_tunnel(&mut build_data.map, prev_x, new_x, prev_y); let mut c2 = apply_vertical_tunnel(&mut build_data.map, prev_y, new_y, new_x); diff --git a/src/map_builders/rooms_corridors_nearest.rs b/src/map_builders/rooms_corridors_nearest.rs index 7bad650..c52046f 100644 --- a/src/map_builders/rooms_corridors_nearest.rs +++ b/src/map_builders/rooms_corridors_nearest.rs @@ -1,4 +1,4 @@ -use super::{draw_corridor, BuilderMap, MetaMapBuilder, Rect}; +use super::{ draw_corridor, BuilderMap, MetaMapBuilder, Rect }; use rltk::RandomNumberGenerator; use std::collections::HashSet; @@ -43,8 +43,13 @@ impl NearestCorridors { if !room_distance.is_empty() { room_distance.sort_by(|a, b| a.1.partial_cmp(&b.1).unwrap()); let dest_centre = rooms[room_distance[0].0].centre(); - let corridor = - draw_corridor(&mut build_data.map, room_centre.0, room_centre.1, dest_centre.0, dest_centre.1); + let corridor = draw_corridor( + &mut build_data.map, + room_centre.0, + room_centre.1, + dest_centre.0, + dest_centre.1 + ); connected.insert(i); build_data.take_snapshot(); corridors.push(corridor); diff --git a/src/map_builders/rooms_corridors_spawner.rs b/src/map_builders/rooms_corridors_spawner.rs index 2a7d9b6..06d5912 100644 --- a/src/map_builders/rooms_corridors_spawner.rs +++ b/src/map_builders/rooms_corridors_spawner.rs @@ -1,4 +1,4 @@ -use super::{spawner, BuilderMap, MetaMapBuilder}; +use super::{ spawner, BuilderMap, MetaMapBuilder }; use rltk::RandomNumberGenerator; pub struct CorridorSpawner {} @@ -23,7 +23,7 @@ impl CorridorSpawner { rng, &corridor, &mut build_data.spawn_list, - build_data.initial_player_level, + build_data.initial_player_level ); } } else { diff --git a/src/map_builders/simple_map.rs b/src/map_builders/simple_map.rs index d0b03b9..ec88960 100644 --- a/src/map_builders/simple_map.rs +++ b/src/map_builders/simple_map.rs @@ -1,4 +1,4 @@ -use super::{BuilderMap, InitialMapBuilder, Rect}; +use super::{ BuilderMap, InitialMapBuilder, Rect }; use rltk::RandomNumberGenerator; pub struct SimpleMapBuilder { @@ -22,9 +22,9 @@ impl SimpleMapBuilder { let (max_rooms, min_size, max_size); if let Some(room_params) = room_params { - (max_rooms, min_size, max_size) = (room_params.0, room_params.1, room_params.2) + (max_rooms, min_size, max_size) = (room_params.0, room_params.1, room_params.2); } else { - (max_rooms, min_size, max_size) = (DEFAULT_MAX_ROOMS, DEFAULT_MIN_SIZE, DEFAULT_MAX_SIZE) + (max_rooms, min_size, max_size) = (DEFAULT_MAX_ROOMS, DEFAULT_MIN_SIZE, DEFAULT_MAX_SIZE); } Box::new(SimpleMapBuilder { room_params: (max_rooms, min_size, max_size) }) @@ -42,7 +42,7 @@ impl SimpleMapBuilder { let mut ok = true; for other_room in rooms.iter() { if new_room.intersect(other_room) { - ok = false + ok = false; } } if ok { diff --git a/src/map_builders/town.rs b/src/map_builders/town.rs index 9f6122d..ee4a1d5 100644 --- a/src/map_builders/town.rs +++ b/src/map_builders/town.rs @@ -1,4 +1,4 @@ -use super::{BuilderChain, BuilderMap, InitialMapBuilder, Position, TileType}; +use super::{ BuilderChain, BuilderMap, InitialMapBuilder, Position, TileType }; use std::collections::HashSet; pub fn town_builder( @@ -7,7 +7,7 @@ pub fn town_builder( width: i32, height: i32, difficulty: i32, - initial_player_level: i32, + initial_player_level: i32 ) -> BuilderChain { rltk::console::log(format!("DEBUGINFO: Building town (ID:{}, DIFF:{})", new_id, difficulty)); let mut chain = BuilderChain::new(new_id, width, height, difficulty, "the town", initial_player_level); @@ -78,7 +78,7 @@ impl TownBuilder { building_size[2].2 = BuildingTag::Mine; building_size[3].2 = BuildingTag::PlayerHouse; for b in building_size.iter_mut().skip(4) { - b.2 = BuildingTag::NPCHouse + b.2 = BuildingTag::NPCHouse; } let last_idx = building_size.len() - 1; building_size[last_idx].2 = BuildingTag::Abandoned; @@ -91,7 +91,7 @@ impl TownBuilder { rng: &mut rltk::RandomNumberGenerator, build_data: &mut BuilderMap, buildings: &[(i32, i32, i32, i32)], - building_index: &[(usize, i32, BuildingTag)], + building_index: &[(usize, i32, BuildingTag)] ) { for (i, building) in buildings.iter().enumerate() { let build_tag = &building_index[i].2; @@ -123,7 +123,7 @@ impl TownBuilder { &mut self, build_data: &mut BuilderMap, rng: &mut rltk::RandomNumberGenerator, - available_building_tiles: &mut HashSet, + available_building_tiles: &mut HashSet ) { for idx in available_building_tiles.iter() { if rng.roll_dice(1, 40) == 1 { @@ -161,15 +161,16 @@ impl TownBuilder { build_data: &mut BuilderMap, rng: &mut rltk::RandomNumberGenerator, to_place: &mut Vec<&str>, - avoid_tile: usize, + avoid_tile: usize ) { for y in building.1..building.1 + building.3 { for x in building.0..building.0 + building.2 { let idx = build_data.map.xy_idx(x, y); - if build_data.map.tiles[idx] == TileType::WoodFloor - && idx != avoid_tile - && rng.roll_dice(1, 3) == 1 - && !to_place.is_empty() + if + build_data.map.tiles[idx] == TileType::WoodFloor && + idx != avoid_tile && + rng.roll_dice(1, 3) == 1 && + !to_place.is_empty() { let entity_tag = to_place[0]; to_place.remove(0); @@ -183,12 +184,14 @@ impl TownBuilder { &mut self, building: &(i32, i32, i32, i32), build_data: &mut BuilderMap, - rng: &mut rltk::RandomNumberGenerator, + rng: &mut rltk::RandomNumberGenerator ) { // Place player - build_data.starting_position = - Some(Position { x: building.0 + (building.2 / 2), y: building.1 + (building.3 / 2) }); - let player_idx = build_data.map.xy_idx(building.0 + (building.2 / 2), building.1 + (building.3 / 2)); + build_data.starting_position = Some(Position { + x: building.0 + building.2 / 2, + y: building.1 + building.3 / 2, + }); + let player_idx = build_data.map.xy_idx(building.0 + building.2 / 2, building.1 + building.3 / 2); // Place other items let mut to_place: Vec<&str> = vec![ @@ -200,7 +203,7 @@ impl TownBuilder { "prop_table", "prop_table", "prop_chair", - "prop_chair", + "prop_chair" ]; self.random_building_spawn(building, build_data, rng, &mut to_place, player_idx); } @@ -209,7 +212,7 @@ impl TownBuilder { &mut self, building: &(i32, i32, i32, i32), build_data: &mut BuilderMap, - rng: &mut rltk::RandomNumberGenerator, + rng: &mut rltk::RandomNumberGenerator ) { let mut to_place: Vec<&str> = vec![ "npc_priest", @@ -220,7 +223,7 @@ impl TownBuilder { "prop_table", "prop_table", "prop_candle", - "prop_candle", + "prop_candle" ]; self.random_building_spawn(building, build_data, rng, &mut to_place, 0) } @@ -229,10 +232,10 @@ impl TownBuilder { &mut self, building: &(i32, i32, i32, i32), build_data: &mut BuilderMap, - rng: &mut rltk::RandomNumberGenerator, + rng: &mut rltk::RandomNumberGenerator ) { // Place exit - let exit_idx = build_data.map.xy_idx(building.0 + (building.2 / 2), building.1 + (building.3 / 2)); + let exit_idx = build_data.map.xy_idx(building.0 + building.2 / 2, building.1 + building.3 / 2); build_data.map.tiles[exit_idx] = TileType::DownStair; let mut to_place: Vec<&str> = vec!["npc_miner", "npc_miner", "npc_guard", "prop_chair"]; self.random_building_spawn(building, build_data, rng, &mut to_place, exit_idx) @@ -242,7 +245,7 @@ impl TownBuilder { &mut self, building: &(i32, i32, i32, i32), build_data: &mut BuilderMap, - rng: &mut rltk::RandomNumberGenerator, + rng: &mut rltk::RandomNumberGenerator ) { let mut to_place: Vec<&str> = vec!["prop_bed", "prop_table", "dog_little", "prop_chair", "prop_chair"]; self.random_building_spawn(building, build_data, rng, &mut to_place, 0); @@ -252,7 +255,7 @@ impl TownBuilder { &mut self, building: &(i32, i32, i32, i32), build_data: &mut BuilderMap, - rng: &mut rltk::RandomNumberGenerator, + rng: &mut rltk::RandomNumberGenerator ) { let mut to_place: Vec<&str> = vec!["npc_townsperson", "prop_bed", "prop_table", "prop_chair"]; self.random_building_spawn(building, build_data, rng, &mut to_place, 0); @@ -262,7 +265,7 @@ impl TownBuilder { &mut self, building: &(i32, i32, i32, i32), build_data: &mut BuilderMap, - rng: &mut rltk::RandomNumberGenerator, + rng: &mut rltk::RandomNumberGenerator ) { let mut to_place: Vec<&str> = vec!["rat", "rat", "rat", "prop_table", "prop_chair"]; self.random_building_spawn(building, build_data, rng, &mut to_place, 0); @@ -285,7 +288,7 @@ impl TownBuilder { let sand_width = shallow_width + 4; for y in 0..build_data.height { - let n_water = (f32::sin(n) * variance as f32) as i32 + minimum_width + rng.roll_dice(1, 2); + let n_water = ((f32::sin(n) * (variance as f32)) as i32) + minimum_width + rng.roll_dice(1, 2); water_width.push(n_water); n += 0.1; for x in 0..n_water { @@ -323,10 +326,10 @@ impl TownBuilder { let start_roll = rng.roll_dice(1, 4); let largest_water_width; - if water_width[y as usize] > water_width[y as usize + 1] { + if water_width[y as usize] > water_width[(y as usize) + 1] { largest_water_width = water_width[y as usize]; } else { - largest_water_width = water_width[y as usize + 1]; + largest_water_width = water_width[(y as usize) + 1]; } // Make pier length @@ -360,7 +363,7 @@ impl TownBuilder { fn town_walls( &mut self, rng: &mut rltk::RandomNumberGenerator, - build_data: &mut BuilderMap, + build_data: &mut BuilderMap ) -> (HashSet, i32) { let mut available_building_tiles: HashSet = HashSet::new(); @@ -370,7 +373,7 @@ impl TownBuilder { const HALF_PATH_THICKNESS: i32 = 3; let wall_gap_y = - (build_data.height / 2) + rng.roll_dice(1, PATH_OFFSET_FROM_CENTRE * 2) - 1 - PATH_OFFSET_FROM_CENTRE; + build_data.height / 2 + rng.roll_dice(1, PATH_OFFSET_FROM_CENTRE * 2) - 1 - PATH_OFFSET_FROM_CENTRE; for y in BORDER..build_data.height - BORDER { if !(y > wall_gap_y - HALF_PATH_THICKNESS && y < wall_gap_y + HALF_PATH_THICKNESS) { @@ -384,14 +387,19 @@ impl TownBuilder { let gravel_idx = build_data.map.xy_idx(x, y); let roll = rng.roll_dice(1, 6); match roll { - 1 => build_data.map.tiles[gravel_idx] = TileType::Foliage, - 2 => build_data.map.tiles[gravel_idx] = TileType::HeavyFoliage, + 1 => { + build_data.map.tiles[gravel_idx] = TileType::Foliage; + } + 2 => { + build_data.map.tiles[gravel_idx] = TileType::HeavyFoliage; + } _ => {} } - if y > BORDER + 1 - && y < build_data.height - BORDER - 1 - && x > OFFSET_FROM_LEFT + 2 - && x < build_data.width - BORDER - 1 + if + y > BORDER + 1 && + y < build_data.height - BORDER - 1 && + x > OFFSET_FROM_LEFT + 2 && + x < build_data.width - BORDER - 1 { available_building_tiles.insert(gravel_idx); } @@ -420,7 +428,7 @@ impl TownBuilder { &mut self, rng: &mut rltk::RandomNumberGenerator, build_data: &mut BuilderMap, - available_building_tiles: &mut HashSet, + available_building_tiles: &mut HashSet ) -> Vec<(i32, i32, i32, i32)> { let mut buildings: Vec<(i32, i32, i32, i32)> = Vec::new(); let mut n_buildings = 0; @@ -458,9 +466,9 @@ impl TownBuilder { build_data.map.tiles[idx] = TileType::WoodFloor; available_building_tiles.remove(&idx); available_building_tiles.remove(&(idx + 1)); - available_building_tiles.remove(&(idx + build_data.width as usize)); + available_building_tiles.remove(&(idx + (build_data.width as usize))); available_building_tiles.remove(&(idx - 1)); - available_building_tiles.remove(&(idx - build_data.width as usize)); + available_building_tiles.remove(&(idx - (build_data.width as usize))); } } build_data.take_snapshot(); @@ -480,10 +488,10 @@ impl TownBuilder { if build_data.map.tiles[idx + 1] != TileType::WoodFloor { neighbours += 1; } - if build_data.map.tiles[idx - build_data.width as usize] != TileType::WoodFloor { + if build_data.map.tiles[idx - (build_data.width as usize)] != TileType::WoodFloor { neighbours += 1; } - if build_data.map.tiles[idx + build_data.width as usize] != TileType::WoodFloor { + if build_data.map.tiles[idx + (build_data.width as usize)] != TileType::WoodFloor { neighbours += 1; } if neighbours > 0 { @@ -503,12 +511,12 @@ impl TownBuilder { rng: &mut rltk::RandomNumberGenerator, build_data: &mut BuilderMap, buildings: &mut Vec<(i32, i32, i32, i32)>, - wall_gap_y: i32, + wall_gap_y: i32 ) -> Vec { let mut doors = Vec::new(); for building in buildings.iter() { let door_x = building.0 + 1 + rng.roll_dice(1, building.2 - 3); - let cy = building.1 + (building.3 / 2); + let cy = building.1 + building.3 / 2; let idx = if cy > wall_gap_y { // Door on north wall build_data.map.xy_idx(door_x, building.1) @@ -529,7 +537,7 @@ impl TownBuilder { tiles: &[usize], tiletype: TileType, new_road_tiletype: TileType, - include_new_tiles: bool, + include_new_tiles: bool ) { let mut roads = self.find_tiletype(build_data, tiletype); @@ -537,15 +545,15 @@ impl TownBuilder { for tile_idx in tiles.iter() { let mut nearest_tiletype: Vec<(usize, f32)> = Vec::new(); let tile_pt = rltk::Point::new( - *tile_idx as i32 % build_data.map.width as i32, - *tile_idx as i32 / build_data.map.width as i32, + (*tile_idx as i32) % (build_data.map.width as i32), + (*tile_idx as i32) / (build_data.map.width as i32) ); for r in roads.iter() { nearest_tiletype.push(( *r, rltk::DistanceAlg::Manhattan.distance2d( tile_pt, - rltk::Point::new(*r as i32 % build_data.map.width, *r as i32 / build_data.map.width), + rltk::Point::new((*r as i32) % build_data.map.width, (*r as i32) / build_data.map.width) ), )); } diff --git a/src/map_builders/voronoi.rs b/src/map_builders/voronoi.rs index b48bcb7..80d814e 100644 --- a/src/map_builders/voronoi.rs +++ b/src/map_builders/voronoi.rs @@ -1,4 +1,4 @@ -use super::{BuilderMap, InitialMapBuilder, TileType}; +use super::{ BuilderMap, InitialMapBuilder, TileType }; use rltk::RandomNumberGenerator; #[derive(PartialEq, Copy, Clone)] @@ -55,8 +55,8 @@ impl VoronoiBuilder { let mut voronoi_distance = vec![(0, 0.0f32); self.n_seeds]; let mut voronoi_membership: Vec = vec![0; build_data.map.width as usize * build_data.map.height as usize]; for (i, vid) in voronoi_membership.iter_mut().enumerate() { - let x = i as i32 % build_data.map.width; - let y = i as i32 / build_data.map.width; + let x = (i as i32) % build_data.map.width; + let y = (i as i32) / build_data.map.width; for (seed, pos) in voronoi_seeds.iter().enumerate() { let distance; diff --git a/src/map_builders/voronoi_spawning.rs b/src/map_builders/voronoi_spawning.rs index 81e15b4..3e21a05 100644 --- a/src/map_builders/voronoi_spawning.rs +++ b/src/map_builders/voronoi_spawning.rs @@ -1,4 +1,4 @@ -use super::{spawner, BuilderMap, MetaMapBuilder, TileType}; +use super::{ spawner, BuilderMap, MetaMapBuilder, TileType }; use rltk::RandomNumberGenerator; use std::collections::HashMap; @@ -47,7 +47,7 @@ impl VoronoiSpawning { rng, area.1, &mut build_data.spawn_list, - build_data.initial_player_level, + build_data.initial_player_level ); } } diff --git a/src/melee_combat_system.rs b/src/melee_combat_system.rs index 0d19607..9c320d3 100644 --- a/src/melee_combat_system.rs +++ b/src/melee_combat_system.rs @@ -1,9 +1,27 @@ use super::{ - effects::{add_effect, EffectType, Targets}, - gamelog, gamesystem, + effects::{ add_effect, EffectType, Targets }, + gamelog, + gamesystem, gui::renderable_colour, - ArmourClassBonus, Attributes, Blind, EquipmentSlot, Equipped, HungerClock, HungerState, MeleeWeapon, MultiAttack, - Name, NaturalAttacks, ParticleBuilder, Pools, Position, Renderable, Skill, Skills, ToHitBonus, WantsToMelee, + ArmourClassBonus, + Attributes, + Blind, + EquipmentSlot, + Equipped, + HungerClock, + HungerState, + MeleeWeapon, + MultiAttack, + Name, + NaturalAttacks, + ParticleBuilder, + Pools, + Position, + Renderable, + Skill, + Skills, + ToHitBonus, + WantsToMelee, WeaponAttribute, }; use rltk::prelude::*; @@ -74,9 +92,14 @@ impl<'a> System<'a> for MeleeCombatSystem { let mut logger = gamelog::Logger::new(); let mut something_to_log = false; - for (entity, wants_melee, name, attacker_attributes, attacker_skills, attacker_pools) in - (&entities, &wants_melee, &names, &attributes, &skills, &pools).join() - { + for (entity, wants_melee, name, attacker_attributes, attacker_skills, attacker_pools) in ( + &entities, + &wants_melee, + &names, + &attributes, + &skills, + &pools, + ).join() { // Create blank vector of attacks being attempted. let mut attacks: Vec<(MeleeWeapon, String)> = Vec::new(); let mut multi_attack = false; @@ -136,7 +159,7 @@ impl<'a> System<'a> for MeleeCombatSystem { let mut status_hit_bonus = 0; if let Some(_) = blind_entities.get(entity) { status_hit_bonus -= 4; - }; + } let hc = hunger_clock.get(entity); if let Some(hc) = hc { match hc.state { @@ -153,12 +176,13 @@ impl<'a> System<'a> for MeleeCombatSystem { } } // Total to-hit bonus - let attacker_bonuses = 1 // +1 for being in melee combat - + attacker_pools.level // + level - + attribute_hit_bonus // +- str/dex bonus depending on weapon used - + skill_hit_bonus // +- relevant skill modifier - + equipment_hit_bonus // +- any other to-hit modifiers from equipment - + status_hit_bonus; // +- any to-hit modifiers from status effects + let attacker_bonuses = + 1 + // +1 for being in melee combat + attacker_pools.level + // + level + attribute_hit_bonus + // +- str/dex bonus depending on weapon used + skill_hit_bonus + // +- relevant skill modifier + equipment_hit_bonus + // +- any other to-hit modifiers from equipment + status_hit_bonus; // +- any to-hit modifiers from status effects // Get armour class let bac = target_pools.bac; @@ -187,17 +211,19 @@ impl<'a> System<'a> for MeleeCombatSystem { let target_name = names.get(wants_melee.target).unwrap(); if COMBAT_LOGGING { - rltk::console::log(format!( - "ATTACKLOG: {} *{}* {}: rolled ({}) 1d20 vs. {} ({} + {}AC + {}to-hit)", - &name.name, - attack_verb, - &target_name.name, - d20, - target_number, - monster_v_player_bonus, - armour_class_roll, - attacker_bonuses - )); + rltk::console::log( + format!( + "ATTACKLOG: {} *{}* {}: rolled ({}) 1d20 vs. {} ({} + {}AC + {}to-hit)", + &name.name, + attack_verb, + &target_name.name, + d20, + target_number, + monster_v_player_bonus, + armour_class_roll, + attacker_bonuses + ) + ); } if d20 < target_number { @@ -206,8 +232,12 @@ impl<'a> System<'a> for MeleeCombatSystem { let skill_damage_bonus = gamesystem::skill_bonus(Skill::Melee, &*attacker_skills); let mut attribute_damage_bonus = weapon_info.damage_bonus; match weapon_info.attribute { - WeaponAttribute::Dexterity => attribute_damage_bonus += attacker_attributes.dexterity.bonus, - WeaponAttribute::Strength => attribute_damage_bonus += attacker_attributes.strength.bonus, + WeaponAttribute::Dexterity => { + attribute_damage_bonus += attacker_attributes.dexterity.bonus; + } + WeaponAttribute::Strength => { + attribute_damage_bonus += attacker_attributes.strength.bonus; + } WeaponAttribute::Finesse => { if attacker_attributes.dexterity.bonus > attacker_attributes.strength.bonus { attribute_damage_bonus += attacker_attributes.dexterity.bonus; @@ -219,37 +249,43 @@ impl<'a> System<'a> for MeleeCombatSystem { let mut damage = i32::max(0, base_damage + skill_damage_bonus + attribute_damage_bonus); if COMBAT_LOGGING { - rltk::console::log(format!( - "ATTACKLOG: {} HIT for {} ({}[{}d{}]+{}[skill]+{}[attr])", - &name.name, - damage, - base_damage, - weapon_info.damage_n_dice, - weapon_info.damage_die_type, - skill_damage_bonus, - attribute_damage_bonus - )); + rltk::console::log( + format!( + "ATTACKLOG: {} HIT for {} ({}[{}d{}]+{}[skill]+{}[attr])", + &name.name, + damage, + base_damage, + weapon_info.damage_n_dice, + weapon_info.damage_die_type, + skill_damage_bonus, + attribute_damage_bonus + ) + ); } if actual_armour_class < 0 { let ac_damage_reduction = rng.roll_dice(1, -actual_armour_class); damage = i32::min(1, damage - ac_damage_reduction); if COMBAT_LOGGING { - rltk::console::log(format!( - "ATTACKLOG: {} reduced their damage taken by {} (1dAC), and took {} hp damage.", - &target_name.name, ac_damage_reduction, damage - )); + rltk::console::log( + format!( + "ATTACKLOG: {} reduced their damage taken by {} (1dAC), and took {} hp damage.", + &target_name.name, + ac_damage_reduction, + damage + ) + ); } } let pos = positions.get(wants_melee.target); if let Some(pos) = pos { - particle_builder.damage_taken(pos.x, pos.y) + particle_builder.damage_taken(pos.x, pos.y); } add_effect( Some(entity), EffectType::Damage { amount: damage }, - Targets::Entity { target: wants_melee.target }, + Targets::Entity { target: wants_melee.target } ); if entity == *player_entity { something_to_log = true; @@ -269,7 +305,8 @@ impl<'a> System<'a> for MeleeCombatSystem { .append(attack_verb) .append("you!"); } else { - gamelog::Logger::new() // misses the . + gamelog::Logger + ::new() // misses the . .append("The") .colour(renderable_colour(&renderables, entity)) .append(&name.name) @@ -289,7 +326,7 @@ impl<'a> System<'a> for MeleeCombatSystem { let pos = positions.get(wants_melee.target); if let Some(pos) = pos { - particle_builder.attack_miss(pos.x, pos.y) + particle_builder.attack_miss(pos.x, pos.y); } if entity == *player_entity { something_to_log = true; @@ -304,7 +341,8 @@ impl<'a> System<'a> for MeleeCombatSystem { .colour(WHITE) .append("misses!"); } else { - gamelog::Logger::new() // misses the . + gamelog::Logger + ::new() // misses the . .append("The") .colour(renderable_colour(&renderables, entity)) .append(&name.name) @@ -330,7 +368,7 @@ fn get_natural_attacks( rng: &mut rltk::RandomNumberGenerator, nat: NaturalAttacks, multi_attack: bool, - attacks: &mut Vec<(MeleeWeapon, String)>, + attacks: &mut Vec<(MeleeWeapon, String)> ) { if !nat.attacks.is_empty() { if multi_attack { @@ -347,8 +385,11 @@ fn get_natural_attacks( )); } } else { - let attack_index = - if nat.attacks.len() == 1 { 0 } else { rng.roll_dice(1, nat.attacks.len() as i32) as usize - 1 }; + let attack_index = if nat.attacks.len() == 1 { + 0 + } else { + (rng.roll_dice(1, nat.attacks.len() as i32) as usize) - 1 + }; attacks.push(( MeleeWeapon { attribute: WeaponAttribute::Strength, @@ -367,7 +408,7 @@ fn get_weapon_attack( wielded: &Equipped, melee: &MeleeWeapon, entity: Entity, - attacks: &mut Vec<(MeleeWeapon, String)>, + attacks: &mut Vec<(MeleeWeapon, String)> ) -> bool { if wielded.owner == entity && wielded.slot == EquipmentSlot::Melee { attacks.push((melee.clone(), "hits".to_string())); diff --git a/src/particle_system.rs b/src/particle_system.rs index 558fc0d..aea4a8c 100644 --- a/src/particle_system.rs +++ b/src/particle_system.rs @@ -1,4 +1,4 @@ -use super::{ParticleLifetime, Position, Renderable, Rltk}; +use super::{ ParticleLifetime, Position, Renderable, Rltk }; use rltk::RGB; use specs::prelude::*; @@ -69,7 +69,10 @@ fn create_delayed_particles(ecs: &mut World, ctx: &Rltk) { let mut renderables = ecs.write_storage::(); let mut particles = ecs.write_storage::(); for handled in handled_particles { - let index = particle_builder.delayed_requests.iter().position(|x| x.particle == handled).unwrap(); + let index = particle_builder.delayed_requests + .iter() + .position(|x| x.particle == handled) + .unwrap(); particle_builder.delayed_requests.remove(index); let p = entities.create(); positions.insert(p, Position { x: handled.x, y: handled.y }).expect("Could not insert position"); @@ -113,8 +116,10 @@ impl ParticleBuilder { } pub fn delay(&mut self, x: i32, y: i32, fg: RGB, bg: RGB, glyph: rltk::FontCharType, lifetime: f32, delay: f32) { - self.delayed_requests - .push(DelayedParticleRequest { delay: delay, particle: ParticleRequest { x, y, fg, bg, glyph, lifetime } }); + self.delayed_requests.push(DelayedParticleRequest { + delay: delay, + particle: ParticleRequest { x, y, fg, bg, glyph, lifetime }, + }); } pub fn damage_taken(&mut self, x: i32, y: i32) { @@ -124,7 +129,7 @@ impl ParticleBuilder { rltk::RGB::named(rltk::ORANGE), rltk::RGB::named(rltk::BLACK), rltk::to_cp437('‼'), - DEFAULT_PARTICLE_LIFETIME, + DEFAULT_PARTICLE_LIFETIME ); } @@ -135,7 +140,7 @@ impl ParticleBuilder { rltk::RGB::named(rltk::CYAN), rltk::RGB::named(rltk::BLACK), rltk::to_cp437('‼'), - DEFAULT_PARTICLE_LIFETIME, + DEFAULT_PARTICLE_LIFETIME ); } @@ -146,7 +151,7 @@ impl ParticleBuilder { rltk::RGB::named(rltk::CHOCOLATE), rltk::RGB::named(rltk::BLACK), rltk::to_cp437('‼'), - SHORT_PARTICLE_LIFETIME, + SHORT_PARTICLE_LIFETIME ); } @@ -160,7 +165,7 @@ impl ParticleBuilder { bg: RGB, glyph: rltk::FontCharType, lifetime: f32, - secondary_fg: RGB, + secondary_fg: RGB ) { let eighth_l = lifetime / 8.0; let quarter_l = eighth_l * 2.0; @@ -231,10 +236,12 @@ impl<'a> System<'a> for ParticleSpawnSystem { let p = entities.create(); positions.insert(p, Position { x: new_particle.x, y: new_particle.y }).expect("Could not insert position"); renderables - .insert( - p, - Renderable { fg: new_particle.fg, bg: new_particle.bg, glyph: new_particle.glyph, render_order: 0 }, - ) + .insert(p, Renderable { + fg: new_particle.fg, + bg: new_particle.bg, + glyph: new_particle.glyph, + render_order: 0, + }) .expect("Could not insert renderables"); particles .insert(p, ParticleLifetime { lifetime_ms: new_particle.lifetime }) diff --git a/src/player.rs b/src/player.rs index 21da5d7..ddc0250 100644 --- a/src/player.rs +++ b/src/player.rs @@ -1,17 +1,39 @@ use super::{ - effects::{add_effect, EffectType, Targets}, + effects::{ add_effect, EffectType, Targets }, gamelog, gui::obfuscate_name_ecs, gui::renderable_colour, raws::Reaction, - Attributes, BlocksTile, BlocksVisibility, Door, EntityMoved, Faction, HasAncestry, Hidden, HungerClock, - HungerState, Item, Map, Name, ParticleBuilder, Player, Pools, Position, Renderable, RunState, State, Telepath, - TileType, Viewshed, WantsToMelee, WantsToPickupItem, + Attributes, + BlocksTile, + BlocksVisibility, + Door, + EntityMoved, + Faction, + HasAncestry, + Hidden, + HungerClock, + HungerState, + Item, + Map, + Name, + ParticleBuilder, + Player, + Pools, + Position, + Renderable, + RunState, + State, + Telepath, + TileType, + Viewshed, + WantsToMelee, + WantsToPickupItem, }; use rltk::prelude::*; -use rltk::{Point, RandomNumberGenerator, Rltk, VirtualKeyCode}; +use rltk::{ Point, RandomNumberGenerator, Rltk, VirtualKeyCode }; use specs::prelude::*; -use std::cmp::{max, min}; +use std::cmp::{ max, min }; pub fn try_door(i: i32, j: i32, ecs: &mut World) -> RunState { let mut positions = ecs.write_storage::(); @@ -35,10 +57,13 @@ pub fn try_door(i: i32, j: i32, ecs: &mut World) -> RunState { let delta_x = i; let delta_y = j; - if !(pos.x + delta_x < 0 - || pos.x + delta_x > map.width - 1 - || pos.y + delta_y < 0 - || pos.y + delta_y > map.height - 1) + if + !( + pos.x + delta_x < 0 || + pos.x + delta_x > map.width - 1 || + pos.y + delta_y < 0 || + pos.y + delta_y > map.height - 1 + ) { let destination_idx = map.xy_idx(pos.x + delta_x, pos.y + delta_y); @@ -120,10 +145,13 @@ pub fn open(i: i32, j: i32, ecs: &mut World) -> RunState { let delta_x = i; let delta_y = j; - if !(pos.x + delta_x < 0 - || pos.x + delta_x > map.width - 1 - || pos.y + delta_y < 0 - || pos.y + delta_y > map.height - 1) + if + !( + pos.x + delta_x < 0 || + pos.x + delta_x > map.width - 1 || + pos.y + delta_y < 0 || + pos.y + delta_y > map.height - 1 + ) { let destination_idx = map.xy_idx(pos.x + delta_x, pos.y + delta_y); @@ -190,10 +218,13 @@ pub fn kick(i: i32, j: i32, ecs: &mut World) -> RunState { let delta_x = i; let delta_y = j; - if !(pos.x + delta_x < 0 - || pos.x + delta_x > map.width - 1 - || pos.y + delta_y < 0 - || pos.y + delta_y > map.height - 1) + if + !( + pos.x + delta_x < 0 || + pos.x + delta_x > map.width - 1 || + pos.y + delta_y < 0 || + pos.y + delta_y > map.height - 1 + ) { let destination_idx = map.xy_idx(pos.x + delta_x, pos.y + delta_y); @@ -224,7 +255,8 @@ pub fn kick(i: i32, j: i32, ecs: &mut World) -> RunState { particle_builder.kick(pos.x + delta_x, pos.y + delta_y); // ~33% chance of breaking it down + str if rng.roll_dice(1, 10) + attributes.strength.bonus > 6 { - gamelog::Logger::new() + gamelog::Logger + ::new() .append("As you kick the") .item_name_n(target_name) .append(", it crashes open!") @@ -233,16 +265,17 @@ pub fn kick(i: i32, j: i32, ecs: &mut World) -> RunState { destroyed_pos = Some(Point::new(pos.x + delta_x, pos.y + delta_y)); gamelog::record_event("broken_doors", 1); return false; - // 66% chance of just kicking it. + // 66% chance of just kicking it. } else { - gamelog::Logger::new() + gamelog::Logger + ::new() .append("You kick the") .item_name_n(target_name) .period() .log(); return false; } - // If the door is open and there's nothing else on the tile, + // If the door is open and there's nothing else on the tile, } else if crate::spatial::length(destination_idx) == 1 { // Just kick the air. gamelog::Logger::new().append("You kick the open air.").log(); @@ -297,10 +330,11 @@ pub fn try_move_player(delta_x: i32, delta_y: i32, ecs: &mut World) -> RunState let mut result: Option; for (entity, _player, pos, viewshed) in (&entities, &mut players, &mut positions, &mut viewsheds).join() { - if pos.x + delta_x < 0 - || pos.x + delta_x > map.width - 1 - || pos.y + delta_y < 0 - || pos.y + delta_y > map.height - 1 + if + pos.x + delta_x < 0 || + pos.x + delta_x > map.width - 1 || + pos.y + delta_y < 0 || + pos.y + delta_y > map.height - 1 { return RunState::AwaitingInput; } @@ -317,7 +351,7 @@ pub fn try_move_player(delta_x: i32, delta_y: i32, ecs: &mut World) -> RunState entity, &factions, &ancestries, - &crate::raws::RAWS.lock().unwrap(), + &crate::raws::RAWS.lock().unwrap() ); if result != Reaction::Attack { hostile = false; @@ -408,7 +442,8 @@ pub fn try_move_player(delta_x: i32, delta_y: i32, ecs: &mut World) -> RunState for m in swap_entities.iter() { if let Some(name) = names.get(m.0) { let renderables = ecs.read_storage::(); - gamelog::Logger::new() + gamelog::Logger + ::new() .append("You swap places with the") .colour(renderable_colour(&renderables, m.0)) .append_n(&name.name) @@ -459,71 +494,98 @@ fn get_item(ecs: &mut World) -> RunState { pub fn player_input(gs: &mut State, ctx: &mut Rltk) -> RunState { match ctx.key { - None => return RunState::AwaitingInput, - Some(key) => match key { - // Cardinals - VirtualKeyCode::Left | VirtualKeyCode::Numpad4 | VirtualKeyCode::H => { - return try_move_player(-1, 0, &mut gs.ecs) - } - VirtualKeyCode::Right | VirtualKeyCode::Numpad6 | VirtualKeyCode::L => { - return try_move_player(1, 0, &mut gs.ecs); - } - VirtualKeyCode::Up | VirtualKeyCode::Numpad8 | VirtualKeyCode::K => { - return try_move_player(0, -1, &mut gs.ecs); - } - VirtualKeyCode::Down | VirtualKeyCode::Numpad2 | VirtualKeyCode::J => { - return try_move_player(0, 1, &mut gs.ecs); - } - // Diagonals - VirtualKeyCode::Numpad9 | VirtualKeyCode::U => return try_move_player(1, -1, &mut gs.ecs), - VirtualKeyCode::Numpad7 | VirtualKeyCode::Y => return try_move_player(-1, -1, &mut gs.ecs), - VirtualKeyCode::Numpad3 | VirtualKeyCode::N => return try_move_player(1, 1, &mut gs.ecs), - VirtualKeyCode::Numpad1 | VirtualKeyCode::B => return try_move_player(-1, 1, &mut gs.ecs), - // id - VirtualKeyCode::Period => { - if ctx.shift { - if !try_next_level(&mut gs.ecs) { - return RunState::AwaitingInput; + None => { + return RunState::AwaitingInput; + } + Some(key) => + match key { + // Cardinals + VirtualKeyCode::Left | VirtualKeyCode::Numpad4 | VirtualKeyCode::H => { + return try_move_player(-1, 0, &mut gs.ecs); + } + VirtualKeyCode::Right | VirtualKeyCode::Numpad6 | VirtualKeyCode::L => { + return try_move_player(1, 0, &mut gs.ecs); + } + VirtualKeyCode::Up | VirtualKeyCode::Numpad8 | VirtualKeyCode::K => { + return try_move_player(0, -1, &mut gs.ecs); + } + VirtualKeyCode::Down | VirtualKeyCode::Numpad2 | VirtualKeyCode::J => { + return try_move_player(0, 1, &mut gs.ecs); + } + // Diagonals + VirtualKeyCode::Numpad9 | VirtualKeyCode::U => { + return try_move_player(1, -1, &mut gs.ecs); + } + VirtualKeyCode::Numpad7 | VirtualKeyCode::Y => { + return try_move_player(-1, -1, &mut gs.ecs); + } + VirtualKeyCode::Numpad3 | VirtualKeyCode::N => { + return try_move_player(1, 1, &mut gs.ecs); + } + VirtualKeyCode::Numpad1 | VirtualKeyCode::B => { + return try_move_player(-1, 1, &mut gs.ecs); + } + // id + VirtualKeyCode::Period => { + if ctx.shift { + if !try_next_level(&mut gs.ecs) { + return RunState::AwaitingInput; + } + return RunState::NextLevel; // > to descend + } else { + return skip_turn(&mut gs.ecs); // (Wait a turn) } - return RunState::NextLevel; // > to descend - } else { - return skip_turn(&mut gs.ecs); // (Wait a turn) } - } - VirtualKeyCode::Comma => { - if ctx.shift { - if !try_previous_level(&mut gs.ecs) { - return RunState::AwaitingInput; + VirtualKeyCode::Comma => { + if ctx.shift { + if !try_previous_level(&mut gs.ecs) { + return RunState::AwaitingInput; + } + return RunState::PreviousLevel; // < to ascend } - return RunState::PreviousLevel; // < to ascend } - } - VirtualKeyCode::Slash => { - if ctx.shift { - return RunState::HelpScreen; + VirtualKeyCode::Slash => { + if ctx.shift { + return RunState::HelpScreen; + } + } + VirtualKeyCode::NumpadDecimal => { + return skip_turn(&mut gs.ecs); } - } - VirtualKeyCode::NumpadDecimal => { - return skip_turn(&mut gs.ecs); - } - // Items - VirtualKeyCode::C => return RunState::ActionWithDirection { function: try_door }, - VirtualKeyCode::O => return RunState::ActionWithDirection { function: open }, - VirtualKeyCode::F => return RunState::ActionWithDirection { function: kick }, - VirtualKeyCode::G => { - return get_item(&mut gs.ecs); + // Items + VirtualKeyCode::C => { + return RunState::ActionWithDirection { function: try_door }; + } + VirtualKeyCode::O => { + return RunState::ActionWithDirection { function: open }; + } + VirtualKeyCode::F => { + return RunState::ActionWithDirection { function: kick }; + } + VirtualKeyCode::G => { + return get_item(&mut gs.ecs); + } + VirtualKeyCode::I => { + return RunState::ShowInventory; + } + VirtualKeyCode::D => { + return RunState::ShowDropItem; + } + VirtualKeyCode::R => { + return RunState::ShowRemoveItem; + } + // Other + VirtualKeyCode::Minus => { + return RunState::ShowCheatMenu; + } + VirtualKeyCode::Escape => { + return RunState::SaveGame; + } + _ => { + return RunState::AwaitingInput; + } } - VirtualKeyCode::I => return RunState::ShowInventory, - VirtualKeyCode::D => return RunState::ShowDropItem, - VirtualKeyCode::R => return RunState::ShowRemoveItem, - // Other - VirtualKeyCode::Minus => return RunState::ShowCheatMenu, - VirtualKeyCode::Escape => return RunState::SaveGame, - _ => { - return RunState::AwaitingInput; - } - }, } return RunState::AwaitingInput; } @@ -573,7 +635,7 @@ fn skip_turn(ecs: &mut World) -> RunState { entity_id, &factions, &ancestries, - &crate::raws::RAWS.lock().unwrap(), + &crate::raws::RAWS.lock().unwrap() ); if result == Reaction::Attack { can_heal = false; @@ -587,9 +649,15 @@ fn skip_turn(ecs: &mut World) -> RunState { let player_hunger_clock = hunger_clocks.get(*player_entity); if let Some(clock) = player_hunger_clock { match clock.state { - HungerState::Hungry => can_heal = false, - HungerState::Weak => can_heal = false, - HungerState::Fainting => can_heal = false, + HungerState::Hungry => { + can_heal = false; + } + HungerState::Weak => { + can_heal = false; + } + HungerState::Fainting => { + can_heal = false; + } _ => {} } } @@ -599,7 +667,7 @@ fn skip_turn(ecs: &mut World) -> RunState { let pools = health_components.get_mut(*player_entity).unwrap(); let mut rng = ecs.write_resource::(); let roll = rng.roll_dice(1, 6); - if (roll == 6) && pools.hit_points.current < pools.hit_points.max { + if roll == 6 && pools.hit_points.current < pools.hit_points.max { pools.hit_points.current += 1; } } diff --git a/src/raws/mod.rs b/src/raws/mod.rs index 66c9c83..d336f1b 100644 --- a/src/raws/mod.rs +++ b/src/raws/mod.rs @@ -13,7 +13,7 @@ mod loot_table_structs; use loot_table_structs::*; mod reaction_structs; pub use reaction_structs::Reaction; -use reaction_structs::{AncestryData, FactionData}; +use reaction_structs::{ AncestryData, FactionData }; use std::sync::Mutex; lazy_static! { @@ -76,6 +76,6 @@ macro_rules! impl_ParseJson { return serde_json::from_str(&raw_string).expect("Failed to convert &str to json"); } })* - } + }; } impl_ParseJson!(for Vec, Vec, Vec, Vec, Vec, Vec, Vec); diff --git a/src/raws/rawmaster.rs b/src/raws/rawmaster.rs index fc265ba..f0cf5ec 100644 --- a/src/raws/rawmaster.rs +++ b/src/raws/rawmaster.rs @@ -1,4 +1,4 @@ -use super::{Raws, Reaction}; +use super::{ Raws, Reaction }; use crate::components::*; use crate::config::entity; use crate::gamesystem::*; @@ -8,8 +8,8 @@ use crate::LOG_SPAWNING; use regex::Regex; use rltk::prelude::*; use specs::prelude::*; -use specs::saveload::{MarkedBuilder, SimpleMarker}; -use std::collections::{HashMap, HashSet}; +use specs::saveload::{ MarkedBuilder, SimpleMarker }; +use std::collections::{ HashMap, HashSet }; /// Applies effects to the entity - e.g. "healing: 1d4+1", where /// effects are components on the entity with varying parameters. @@ -103,9 +103,16 @@ macro_rules! apply_flags { } pub enum SpawnType { - AtPosition { x: i32, y: i32 }, - Equipped { by: Entity }, - Carried { by: Entity }, + AtPosition { + x: i32, + y: i32, + }, + Equipped { + by: Entity, + }, + Carried { + by: Entity, + }, } pub struct RawMaster { @@ -164,27 +171,24 @@ impl RawMaster { self.table_index.insert(table.id.clone(), i); used_names.insert(table.id.clone()); for entry in table.table.iter() { - check_for_unspecified_entity(&used_names, &entry.id) + check_for_unspecified_entity(&used_names, &entry.id); } } for (i, loot_table) in self.raws.loot_tables.iter().enumerate() { check_for_duplicate_entries(&used_names, &loot_table.id); self.loot_index.insert(loot_table.id.clone(), i); for entry in loot_table.table.iter() { - check_for_unspecified_entity(&used_names, &entry.id) + check_for_unspecified_entity(&used_names, &entry.id); } } for faction in self.raws.factions.iter() { let mut reactions: HashMap = HashMap::new(); for other in faction.responses.iter() { - reactions.insert( - other.0.clone(), - match other.1.as_str() { - "flee" => Reaction::Flee, - "attack" => Reaction::Attack, - _ => Reaction::Ignore, - }, - ); + reactions.insert(other.0.clone(), match other.1.as_str() { + "flee" => Reaction::Flee, + "attack" => Reaction::Attack, + _ => Reaction::Ignore, + }); } self.faction_index.insert(faction.id.clone(), reactions); } @@ -213,7 +217,7 @@ pub fn spawn_named_entity( key: &str, buc: Option, pos: SpawnType, - map_difficulty: i32, + map_difficulty: i32 ) -> Option { if raws.item_index.contains_key(key) { return spawn_named_item(raws, ecs, key, buc, pos); @@ -230,7 +234,7 @@ pub fn spawn_named_item( ecs: &mut World, key: &str, buc: Option, - pos: SpawnType, + pos: SpawnType ) -> Option { if raws.item_index.contains_key(key) { let item_template = &raws.raws.items[raws.item_index[key]]; @@ -245,18 +249,10 @@ pub fn spawn_named_item( let player_entity = ecs.fetch::(); let known_beatitude = match pos { SpawnType::Equipped { by } => { - if by == *player_entity { - true - } else { - false - } + if by == *player_entity { true } else { false } } SpawnType::Carried { by } => { - if by == *player_entity { - true - } else { - false - } + if by == *player_entity { true } else { false } } _ => false, }; @@ -310,25 +306,25 @@ pub fn spawn_named_item( let singular = scroll_names[&item_template.name.name].clone(); let mut plural = singular.clone(); plural += "s"; - eb = eb.with(ObfuscatedName { name: singular, plural: plural }) + eb = eb.with(ObfuscatedName { name: singular, plural: plural }); } "potion" => { let singular = potion_names[&item_template.name.name].clone(); let mut plural = singular.clone(); plural += "s"; - eb = eb.with(ObfuscatedName { name: singular, plural: plural }) + eb = eb.with(ObfuscatedName { name: singular, plural: plural }); } "wand" => { let singular = wand_names[&item_template.name.name].clone(); let mut plural = singular.clone(); plural += "s"; - eb = eb.with(ObfuscatedName { name: singular, plural: plural }) + eb = eb.with(ObfuscatedName { name: singular, plural: plural }); } _ => { let singular = magic_item.naming.clone(); let mut plural = singular.clone(); plural += "s"; - eb = eb.with(ObfuscatedName { name: singular, plural: plural }) + eb = eb.with(ObfuscatedName { name: singular, plural: plural }); } } } @@ -362,7 +358,7 @@ pub fn spawn_named_mob( ecs: &mut World, key: &str, pos: SpawnType, - map_difficulty: i32, + map_difficulty: i32 ) -> Option { if raws.mob_index.contains_key(key) { let mob_template = &raws.raws.mobs[raws.mob_index[key]]; @@ -462,7 +458,7 @@ pub fn spawn_named_mob( mob_level += (player_level - base_mob_level) / 4; } // If the resulting mob level is more than 1.5x the base, lower it to that number - mob_level = i32::min(mob_level, (1.5 * base_mob_level as f32).trunc() as i32); + mob_level = i32::min(mob_level, (1.5 * (base_mob_level as f32)).trunc() as i32); // Should really use existing RNG here let mut rng = rltk::RandomNumberGenerator::new(); @@ -549,10 +545,20 @@ pub fn spawn_named_mob( } if LOG_SPAWNING { - rltk::console::log(format!( - "SPAWNLOG: {} ({}HP, {}MANA, {}BAC) spawned at level {} ({}[base], {}[map difficulty], {}[player level]), worth {} XP", - &mob_template.name, mob_hp, mob_mana, mob_bac, mob_level, base_mob_level, map_difficulty, player_level, xp_value - )); + rltk::console::log( + format!( + "SPAWNLOG: {} ({}HP, {}MANA, {}BAC) spawned at level {} ({}[base], {}[map difficulty], {}[player level]), worth {} XP", + &mob_template.name, + mob_hp, + mob_mana, + mob_bac, + mob_level, + base_mob_level, + map_difficulty, + player_level, + xp_value + ) + ); } let new_mob = eb.build(); @@ -605,11 +611,15 @@ fn spawn_position<'a>(pos: SpawnType, new_entity: EntityBuilder<'a>, tag: &str, let mut eb = new_entity; match pos { - SpawnType::AtPosition { x, y } => eb = eb.with(Position { x, y }), - SpawnType::Carried { by } => eb = eb.with(InBackpack { owner: by }), + SpawnType::AtPosition { x, y } => { + eb = eb.with(Position { x, y }); + } + SpawnType::Carried { by } => { + eb = eb.with(InBackpack { owner: by }); + } SpawnType::Equipped { by } => { let slot = find_slot_for_equippable_item(tag, raws); - eb = eb.with(Equipped { owner: by, slot }) + eb = eb.with(Equipped { owner: by, slot }); } } @@ -641,8 +651,7 @@ pub fn table_by_name(raws: &RawMaster, key: &str, optional_difficulty: Option = spawn_table - .table + let available_options: Vec<&SpawnTableEntry> = spawn_table.table .iter() .filter(|entry| entry.difficulty >= lower_bound && entry.difficulty <= upper_bound) .collect(); @@ -656,10 +665,15 @@ pub fn table_by_name(raws: &RawMaster, key: &str, optional_difficulty: Option EquipmentSlot { if let Some(flags) = &item.flags { for flag in flags { match flag.as_str() { - "EQUIP_MELEE" => return EquipmentSlot::Melee, - "EQUIP_SHIELD" => return EquipmentSlot::Shield, - "EQUIP_BODY" => return EquipmentSlot::Body, - "EQUIP_HEAD" => return EquipmentSlot::Head, - "EQUIP_FEET" => return EquipmentSlot::Feet, - "EQUIP_NECK" => return EquipmentSlot::Neck, - "EQUIP_BACK" => return EquipmentSlot::Back, - "EQUIP_HANDS" => return EquipmentSlot::Hands, + "EQUIP_MELEE" => { + return EquipmentSlot::Melee; + } + "EQUIP_SHIELD" => { + return EquipmentSlot::Shield; + } + "EQUIP_BODY" => { + return EquipmentSlot::Body; + } + "EQUIP_HEAD" => { + return EquipmentSlot::Head; + } + "EQUIP_FEET" => { + return EquipmentSlot::Feet; + } + "EQUIP_NECK" => { + return EquipmentSlot::Neck; + } + "EQUIP_BACK" => { + return EquipmentSlot::Back; + } + "EQUIP_HANDS" => { + return EquipmentSlot::Hands; + } _ => {} } } @@ -745,8 +775,12 @@ pub fn get_mob_spawn_type(raws: &RawMaster, key: &str) -> SpawnsAs { if let Some(flags) = &mob_template.flags { for flag in flags { match flag.as_str() { - "SMALL_GROUP" => return SpawnsAs::SmallGroup, - "LARGE_GROUP" => return SpawnsAs::LargeGroup, + "SMALL_GROUP" => { + return SpawnsAs::SmallGroup; + } + "LARGE_GROUP" => { + return SpawnsAs::LargeGroup; + } _ => {} } } @@ -761,29 +795,27 @@ pub fn get_mob_spawn_amount(rng: &mut RandomNumberGenerator, spawn_type: &Spawns SpawnsAs::Single => 1, // Small groups either spawn alone or as a small group (2-4). SpawnsAs::SmallGroup => { - if rng.roll_dice(1, 2) == 1 { - 1 - } else { - 4 - } + if rng.roll_dice(1, 2) == 1 { 1 } else { 4 } } // Large groups either spawn in a small group or as a large group (2-11). SpawnsAs::LargeGroup => { - if rng.roll_dice(1, 2) == 1 { - 4 - } else { - 11 - } + if rng.roll_dice(1, 2) == 1 { 4 } else { 11 } } }; let roll = if n == 1 { 1 } else { rng.roll_dice(2, n) }; // We want to constrain group sizes depending on player's level, so // we don't get large groups of mobs when the player is unequipped. match player_level { - 0..=2 => return i32::max(1, roll / 4), - 3..=4 => return i32::max(1, roll / 2), - _ => return roll, - }; + 0..=2 => { + return i32::max(1, roll / 4); + } + 3..=4 => { + return i32::max(1, roll / 2); + } + _ => { + return roll; + } + } } pub fn get_scroll_tags() -> Vec { @@ -879,7 +911,7 @@ pub fn get_reactions( other_entity: Entity, factions: &ReadStorage, ancestries: &ReadStorage, - raws: &RawMaster, + raws: &RawMaster ) -> Reaction { if let Some(this_ancestry) = ancestries.get(this_entity) { if let Some(other_ancestry) = ancestries.get(other_entity) { @@ -899,12 +931,24 @@ pub fn get_reactions( fn get_ancestry_string(ancestry: Ancestry) -> &'static str { match ancestry { - Ancestry::Human => return "human", - Ancestry::Elf => return "elf", - Ancestry::Dwarf => return "dwarf", - Ancestry::Catfolk => return "catfolk", - Ancestry::Gnome => return "gnome", - Ancestry::NULL => return "NULL", + Ancestry::Human => { + return "human"; + } + Ancestry::Elf => { + return "elf"; + } + Ancestry::Dwarf => { + return "dwarf"; + } + Ancestry::Catfolk => { + return "catfolk"; + } + Ancestry::Gnome => { + return "gnome"; + } + Ancestry::NULL => { + return "NULL"; + } } } diff --git a/src/raws/reaction_structs.rs b/src/raws/reaction_structs.rs index 6095089..2399444 100644 --- a/src/raws/reaction_structs.rs +++ b/src/raws/reaction_structs.rs @@ -1,5 +1,5 @@ use serde::Deserialize; -use std::collections::{HashMap, HashSet}; +use std::collections::{ HashMap, HashSet }; #[derive(Deserialize, Debug)] pub struct FactionData { diff --git a/src/rect.rs b/src/rect.rs index b705387..fcf395d 100644 --- a/src/rect.rs +++ b/src/rect.rs @@ -1,4 +1,4 @@ -use serde::{Deserialize, Serialize}; +use serde::{ Deserialize, Serialize }; #[derive(PartialEq, Copy, Clone, Serialize, Deserialize)] pub struct Rect { diff --git a/src/saveload_system.rs b/src/saveload_system.rs index 1738dc8..44471e8 100644 --- a/src/saveload_system.rs +++ b/src/saveload_system.rs @@ -1,13 +1,13 @@ use super::components::*; use specs::error::NoError; use specs::prelude::*; -use specs::saveload::{DeserializeComponents, MarkedBuilder, SerializeComponents, SimpleMarker, SimpleMarkerAllocator}; +use specs::saveload::{ DeserializeComponents, MarkedBuilder, SerializeComponents, SimpleMarker, SimpleMarkerAllocator }; use std::fs; use std::fs::File; use std::path::Path; macro_rules! serialize_individually { - ($ecs:expr, $ser:expr, $data:expr, $( $type:ty),*) => { + ($ecs:expr, $ser:expr, $data:expr, $($type:ty),*) => { $( SerializeComponents::>::serialize( &( $ecs.read_storage::<$type>(), ), @@ -28,8 +28,11 @@ pub fn save_game(ecs: &mut World) { // Create helper let mapcopy = ecs.get_mut::().unwrap().clone(); let dungeon_master = ecs.get_mut::().unwrap().clone(); - let savehelper = - ecs.create_entity().with(SerializationHelper { map: mapcopy }).marked::>().build(); + let savehelper = ecs + .create_entity() + .with(SerializationHelper { map: mapcopy }) + .marked::>() + .build(); let savehelper2 = ecs .create_entity() .with(DMSerializationHelper { @@ -138,7 +141,7 @@ pub fn does_save_exist() -> bool { } macro_rules! deserialize_individually { - ($ecs:expr, $de:expr, $data:expr, $( $type:ty),*) => { + ($ecs:expr, $de:expr, $data:expr, $($type:ty),*) => { $( DeserializeComponents::::deserialize( &mut ( &mut $ecs.write_storage::<$type>(), ), diff --git a/src/spatial/map_indexing_system.rs b/src/spatial/map_indexing_system.rs index 18aab7b..27300fe 100644 --- a/src/spatial/map_indexing_system.rs +++ b/src/spatial/map_indexing_system.rs @@ -1,4 +1,4 @@ -use crate::{spatial, BlocksTile, Map, Pools, Position}; +use crate::{ spatial, BlocksTile, Map, Pools, Position }; use specs::prelude::*; pub struct MapIndexingSystem {} diff --git a/src/spatial/mod.rs b/src/spatial/mod.rs index d2d6e83..ca5d5c7 100644 --- a/src/spatial/mod.rs +++ b/src/spatial/mod.rs @@ -1,4 +1,4 @@ -use crate::{tile_walkable, Map, RunState}; +use crate::{ tile_walkable, Map, RunState }; use specs::prelude::*; use std::sync::Mutex; @@ -94,10 +94,7 @@ pub fn is_blocked(idx: usize) -> bool { } /// Calls a function on every entity within a given tile idx. -pub fn for_each_tile_content(idx: usize, mut f: F) -where - F: FnMut(Entity), -{ +pub fn for_each_tile_content(idx: usize, mut f: F) where F: FnMut(Entity) { let lock = SPATIAL_MAP.lock().unwrap(); for entity in lock.tile_content[idx].iter() { f(entity.0); @@ -107,8 +104,7 @@ where /// Calls a function on every entity within a given tile idx, with the /// added ability to return a RunState mid-calc. pub fn for_each_tile_content_with_runstate(idx: usize, mut f: F) -> Option -where - F: FnMut(Entity) -> Option, + where F: FnMut(Entity) -> Option { let lock = SPATIAL_MAP.lock().unwrap(); for entity in lock.tile_content[idx].iter() { @@ -121,10 +117,7 @@ where /// Calls a function on every entity within a given tile idx, breaking if /// the closure ever returns false. -pub fn for_each_tile_content_with_bool(idx: usize, mut f: F) -where - F: FnMut(Entity) -> bool, -{ +pub fn for_each_tile_content_with_bool(idx: usize, mut f: F) where F: FnMut(Entity) -> bool { let lock = SPATIAL_MAP.lock().unwrap(); for entity in lock.tile_content[idx].iter() { if !f(entity.0) { diff --git a/src/spawner.rs b/src/spawner.rs index 62e85ed..9a63c8b 100644 --- a/src/spawner.rs +++ b/src/spawner.rs @@ -1,13 +1,34 @@ use super::{ - random_table::RandomTable, raws, Attribute, Attributes, Clock, Energy, EquipmentChanged, Faction, HungerClock, - HungerState, Map, Mind, Name, Player, Pool, Pools, Position, Rect, Renderable, SerializeMe, Skill, Skills, - TileType, Viewshed, + random_table::RandomTable, + raws, + Attribute, + Attributes, + Clock, + Energy, + EquipmentChanged, + Faction, + HungerClock, + HungerState, + Map, + Mind, + Name, + Player, + Pool, + Pools, + Position, + Rect, + Renderable, + SerializeMe, + Skill, + Skills, + TileType, + Viewshed, }; use crate::config::entity; use crate::gamesystem::*; -use rltk::{RandomNumberGenerator, RGB}; +use rltk::{ RandomNumberGenerator, RGB }; use specs::prelude::*; -use specs::saveload::{MarkedBuilder, SimpleMarker}; +use specs::saveload::{ MarkedBuilder, SimpleMarker }; use std::collections::HashMap; /// Spawns the player and returns his/her entity object. @@ -68,7 +89,7 @@ pub fn spawn_room( rng: &mut RandomNumberGenerator, room: &Rect, spawn_list: &mut Vec<(usize, String)>, - player_level: i32, + player_level: i32 ) { let mut possible_targets: Vec = Vec::new(); { @@ -91,7 +112,7 @@ pub fn spawn_region( rng: &mut RandomNumberGenerator, area: &[usize], spawn_list: &mut Vec<(usize, String)>, - player_level: i32, + player_level: i32 ) { let mut spawn_points: HashMap = HashMap::new(); let mut areas: Vec = Vec::from(area); @@ -105,9 +126,9 @@ pub fn spawn_region( let spawn_mob: bool = rng.roll_dice(1, 3) == 1; let num_items = match rng.roll_dice(1, 20) { 1..=2 => 1, // 10% chance of spawning 1 item - 3 => 2, // 5% chance of spawning 2 items - 4 => 3, // 5% chance of spawning 3 items - _ => 0, // 80% chance of spawning nothing + 3 => 2, // 5% chance of spawning 2 items + 4 => 3, // 5% chance of spawning 3 items + _ => 0, // 80% chance of spawning nothing }; let num_traps = match rng.roll_dice(1, 20) { 1 => 1, // 5% chance of spawning 1 trap @@ -143,13 +164,16 @@ fn entity_to_spawn_list( rng: &mut RandomNumberGenerator, possible_areas: &mut Vec, key: String, - spawn_points: &mut HashMap, + spawn_points: &mut HashMap ) { if possible_areas.len() == 0 { return; } - let array_idx = - if possible_areas.len() == 1 { 0usize } else { (rng.roll_dice(1, possible_areas.len() as i32) - 1) as usize }; + let array_idx = if possible_areas.len() == 1 { + 0usize + } else { + (rng.roll_dice(1, possible_areas.len() as i32) - 1) as usize + }; let map_idx = possible_areas[array_idx]; spawn_points.insert(map_idx, key); possible_areas.remove(array_idx); @@ -170,7 +194,7 @@ pub fn spawn_entity(ecs: &mut World, spawn: &(&usize, &String)) { &spawn.1, None, raws::SpawnType::AtPosition { x, y }, - map_difficulty, + map_difficulty ); if spawn_result.is_some() { return; @@ -191,12 +215,24 @@ fn debug_table() -> RandomTable { fn get_random_item_category(rng: &mut RandomNumberGenerator, difficulty: Option) -> RandomTable { let item_category = item_category_table().roll(rng); match item_category.as_ref() { - "equipment" => return equipment_table(difficulty), - "food" => return food_table(difficulty), - "potion" => return potion_table(difficulty), - "scroll" => return scroll_table(difficulty), - "wand" => return wand_table(difficulty), - _ => return debug_table(), + "equipment" => { + return equipment_table(difficulty); + } + "food" => { + return food_table(difficulty); + } + "potion" => { + return potion_table(difficulty); + } + "scroll" => { + return scroll_table(difficulty); + } + "wand" => { + return wand_table(difficulty); + } + _ => { + return debug_table(); + } }; } diff --git a/src/trigger_system.rs b/src/trigger_system.rs index 34f96ef..6eeddf4 100644 --- a/src/trigger_system.rs +++ b/src/trigger_system.rs @@ -1,8 +1,15 @@ use super::{ - effects::{add_effect, aoe_tiles, EffectType, Targets}, + effects::{ add_effect, aoe_tiles, EffectType, Targets }, gamelog, gui::renderable_colour, - EntityMoved, EntryTrigger, Map, Name, Point, Position, Renderable, AOE, + EntityMoved, + EntryTrigger, + Map, + Name, + Point, + Position, + Renderable, + AOE, }; use rltk::prelude::*; use specs::prelude::*; @@ -34,7 +41,8 @@ impl<'a> System<'a> for TriggerSystem { Some(_trigger) => { if map.visible_tiles[idx] == true { if let Some(name) = names.get(entity_id) { - gamelog::Logger::new() + gamelog::Logger + ::new() .append("The") .colour(renderable_colour(&renderables, entity_id)) .append(&name.name) @@ -43,17 +51,15 @@ impl<'a> System<'a> for TriggerSystem { .log(); } } - add_effect( - Some(entity_id), - EffectType::TriggerFire { trigger: entity_id }, - if let Some(aoe) = aoes.get(entity_id) { - Targets::TileList { - targets: aoe_tiles(&*map, Point::new(pos.x, pos.y), aoe.radius), - } - } else { - Targets::Tile { target: idx } - }, - ); + add_effect(Some(entity_id), EffectType::TriggerFire { trigger: entity_id }, if + let Some(aoe) = aoes.get(entity_id) + { + Targets::TileList { + targets: aoe_tiles(&*map, Point::new(pos.x, pos.y), aoe.radius), + } + } else { + Targets::Tile { target: idx } + }); } } } diff --git a/src/visibility_system.rs b/src/visibility_system.rs index c06b7e2..9496133 100644 --- a/src/visibility_system.rs +++ b/src/visibility_system.rs @@ -1,5 +1,5 @@ -use super::{gamelog, Blind, BlocksVisibility, Hidden, Map, Name, Player, Position, Telepath, Viewshed}; -use rltk::{FieldOfViewAlg::SymmetricShadowcasting, Point}; +use super::{ gamelog, Blind, BlocksVisibility, Hidden, Map, Name, Player, Position, Telepath, Viewshed }; +use rltk::{ FieldOfViewAlg::SymmetricShadowcasting, Point }; use specs::prelude::*; pub struct VisibilitySystem {} @@ -49,12 +49,12 @@ impl<'a> System<'a> for VisibilitySystem { let origin = Point::new(pos.x, pos.y); viewshed.visible_tiles = SymmetricShadowcasting.field_of_view(origin, range, &*map); viewshed.visible_tiles.retain(|p| { - p.x >= 0 - && p.x < map.width - && p.y >= 0 - && p.y < map.height - && (map.lit_tiles[map.xy_idx(p.x, p.y)] == true - || rltk::DistanceAlg::Pythagoras.distance2d(Point::new(p.x, p.y), origin) < 1.5) + p.x >= 0 && + p.x < map.width && + p.y >= 0 && + p.y < map.height && + (map.lit_tiles[map.xy_idx(p.x, p.y)] == true || + rltk::DistanceAlg::Pythagoras.distance2d(Point::new(p.x, p.y), origin) < 1.5) }); // If this is the player, reveal what they can see @@ -75,7 +75,8 @@ impl<'a> System<'a> for VisibilitySystem { if rng.roll_dice(1, 12) == 1 { let name = names.get(e); if let Some(name) = name { - gamelog::Logger::new() + gamelog::Logger + ::new() .append("You spot a") .item_name_n(&name.name) .period() @@ -121,11 +122,11 @@ pub fn fast_fov(p_x: i32, p_y: i32, r: i32) -> Vec { let mut i = 0; while i <= 360 { - let x: f32 = f32::cos(i as f32 * 0.01745 as f32); - let y: f32 = f32::sin(i as f32 * 0.01745 as f32); + let x: f32 = f32::cos((i as f32) * (0.01745 as f32)); + let y: f32 = f32::sin((i as f32) * (0.01745 as f32)); - let mut ox: f32 = p_x as f32 + 0.5 as f32; - let mut oy: f32 = p_y as f32 + 0.5 as f32; + let mut ox: f32 = (p_x as f32) + (0.5 as f32); + let mut oy: f32 = (p_y as f32) + (0.5 as f32); for _i in 0..r { visible_tiles.push(Point::new(ox as i32, oy as i32)); ox += x; diff --git a/wasm/rust-llyrl.js b/wasm/rust-llyrl.js index c16e6aa..f29d851 100644 --- a/wasm/rust-llyrl.js +++ b/wasm/rust-llyrl.js @@ -1,5 +1,5 @@ let wasm_bindgen; -(function() { +(function () { const __exports = {}; let script_src; if (typeof document !== 'undefined' && document.currentScript !== null) { @@ -11,861 +11,891 @@ let wasm_bindgen; heap.push(undefined, null, true, false); -function getObject(idx) { return heap[idx]; } + function getObject(idx) { return heap[idx]; } -let heap_next = heap.length; + let heap_next = heap.length; -function dropObject(idx) { - if (idx < 132) return; - heap[idx] = heap_next; - heap_next = idx; -} - -function takeObject(idx) { - const ret = getObject(idx); - dropObject(idx); - return ret; -} - -function addHeapObject(obj) { - if (heap_next === heap.length) heap.push(heap.length + 1); - const idx = heap_next; - heap_next = heap[idx]; - - heap[idx] = obj; - return idx; -} - -const cachedTextDecoder = (typeof TextDecoder !== 'undefined' ? new TextDecoder('utf-8', { ignoreBOM: true, fatal: true }) : { decode: () => { throw Error('TextDecoder not available') } } ); - -if (typeof TextDecoder !== 'undefined') { cachedTextDecoder.decode(); }; - -let cachedUint8Memory0 = null; - -function getUint8Memory0() { - if (cachedUint8Memory0 === null || cachedUint8Memory0.byteLength === 0) { - cachedUint8Memory0 = new Uint8Array(wasm.memory.buffer); + function dropObject(idx) { + if (idx < 132) return; + heap[idx] = heap_next; + heap_next = idx; } - return cachedUint8Memory0; -} -function getStringFromWasm0(ptr, len) { - ptr = ptr >>> 0; - return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len)); -} + function takeObject(idx) { + const ret = getObject(idx); + dropObject(idx); + return ret; + } -function debugString(val) { - // primitive types - const type = typeof val; - if (type == 'number' || type == 'boolean' || val == null) { - return `${val}`; + function addHeapObject(obj) { + if (heap_next === heap.length) heap.push(heap.length + 1); + const idx = heap_next; + heap_next = heap[idx]; + + heap[idx] = obj; + return idx; } - if (type == 'string') { - return `"${val}"`; + + const cachedTextDecoder = (typeof TextDecoder !== 'undefined' ? new TextDecoder('utf-8', { ignoreBOM: true, fatal: true }) : { decode: () => { throw Error('TextDecoder not available') } }); + + if (typeof TextDecoder !== 'undefined') { cachedTextDecoder.decode(); }; + + let cachedUint8Memory0 = null; + + function getUint8Memory0() { + if (cachedUint8Memory0 === null || cachedUint8Memory0.byteLength === 0) { + cachedUint8Memory0 = new Uint8Array(wasm.memory.buffer); + } + return cachedUint8Memory0; } - if (type == 'symbol') { - const description = val.description; - if (description == null) { - return 'Symbol'; + + function getStringFromWasm0(ptr, len) { + ptr = ptr >>> 0; + return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len)); + } + + function debugString(val) { + // primitive types + const type = typeof val; + if (type == 'number' || type == 'boolean' || val == null) { + return `${val}`; + } + if (type == 'string') { + return `"${val}"`; + } + if (type == 'symbol') { + const description = val.description; + if (description == null) { + return 'Symbol'; + } else { + return `Symbol(${description})`; + } + } + if (type == 'function') { + const name = val.name; + if (typeof name == 'string' && name.length > 0) { + return `Function(${name})`; + } else { + return 'Function'; + } + } + // objects + if (Array.isArray(val)) { + const length = val.length; + let debug = '['; + if (length > 0) { + debug += debugString(val[0]); + } + for (let i = 1; i < length; i++) { + debug += ', ' + debugString(val[i]); + } + debug += ']'; + return debug; + } + // Test for built-in + const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val)); + let className; + if (builtInMatches.length > 1) { + className = builtInMatches[1]; } else { - return `Symbol(${description})`; + // Failed to match the standard '[object ClassName]' + return toString.call(val); } - } - if (type == 'function') { - const name = val.name; - if (typeof name == 'string' && name.length > 0) { - return `Function(${name})`; - } else { - return 'Function'; + if (className == 'Object') { + // we're a user defined class or Object + // JSON.stringify avoids problems with cycles, and is generally much + // easier than looping through ownProperties of `val`. + try { + return 'Object(' + JSON.stringify(val) + ')'; + } catch (_) { + return 'Object'; + } } - } - // objects - if (Array.isArray(val)) { - const length = val.length; - let debug = '['; - if (length > 0) { - debug += debugString(val[0]); + // errors + if (val instanceof Error) { + return `${val.name}: ${val.message}\n${val.stack}`; } - for(let i = 1; i < length; i++) { - debug += ', ' + debugString(val[i]); + // TODO we could test for more things here, like `Set`s and `Map`s. + return className; + } + + let WASM_VECTOR_LEN = 0; + + const cachedTextEncoder = (typeof TextEncoder !== 'undefined' ? new TextEncoder('utf-8') : { encode: () => { throw Error('TextEncoder not available') } }); + + const encodeString = (typeof cachedTextEncoder.encodeInto === 'function' + ? function (arg, view) { + return cachedTextEncoder.encodeInto(arg, view); } - debug += ']'; - return debug; - } - // Test for built-in - const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val)); - let className; - if (builtInMatches.length > 1) { - className = builtInMatches[1]; - } else { - // Failed to match the standard '[object ClassName]' - return toString.call(val); - } - if (className == 'Object') { - // we're a user defined class or Object - // JSON.stringify avoids problems with cycles, and is generally much - // easier than looping through ownProperties of `val`. - try { - return 'Object(' + JSON.stringify(val) + ')'; - } catch (_) { - return 'Object'; + : function (arg, view) { + const buf = cachedTextEncoder.encode(arg); + view.set(buf); + return { + read: arg.length, + written: buf.length + }; + }); + + function passStringToWasm0(arg, malloc, realloc) { + + if (realloc === undefined) { + const buf = cachedTextEncoder.encode(arg); + const ptr = malloc(buf.length, 1) >>> 0; + getUint8Memory0().subarray(ptr, ptr + buf.length).set(buf); + WASM_VECTOR_LEN = buf.length; + return ptr; } - } - // errors - if (val instanceof Error) { - return `${val.name}: ${val.message}\n${val.stack}`; - } - // TODO we could test for more things here, like `Set`s and `Map`s. - return className; -} -let WASM_VECTOR_LEN = 0; + let len = arg.length; + let ptr = malloc(len, 1) >>> 0; -const cachedTextEncoder = (typeof TextEncoder !== 'undefined' ? new TextEncoder('utf-8') : { encode: () => { throw Error('TextEncoder not available') } } ); + const mem = getUint8Memory0(); -const encodeString = (typeof cachedTextEncoder.encodeInto === 'function' - ? function (arg, view) { - return cachedTextEncoder.encodeInto(arg, view); -} - : function (arg, view) { - const buf = cachedTextEncoder.encode(arg); - view.set(buf); - return { - read: arg.length, - written: buf.length - }; -}); + let offset = 0; -function passStringToWasm0(arg, malloc, realloc) { + for (; offset < len; offset++) { + const code = arg.charCodeAt(offset); + if (code > 0x7F) break; + mem[ptr + offset] = code; + } - if (realloc === undefined) { - const buf = cachedTextEncoder.encode(arg); - const ptr = malloc(buf.length, 1) >>> 0; - getUint8Memory0().subarray(ptr, ptr + buf.length).set(buf); - WASM_VECTOR_LEN = buf.length; + if (offset !== len) { + if (offset !== 0) { + arg = arg.slice(offset); + } + ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0; + const view = getUint8Memory0().subarray(ptr + offset, ptr + len); + const ret = encodeString(arg, view); + + offset += ret.written; + } + + WASM_VECTOR_LEN = offset; return ptr; } - let len = arg.length; - let ptr = malloc(len, 1) >>> 0; + let cachedInt32Memory0 = null; - const mem = getUint8Memory0(); - - let offset = 0; - - for (; offset < len; offset++) { - const code = arg.charCodeAt(offset); - if (code > 0x7F) break; - mem[ptr + offset] = code; - } - - if (offset !== len) { - if (offset !== 0) { - arg = arg.slice(offset); + function getInt32Memory0() { + if (cachedInt32Memory0 === null || cachedInt32Memory0.byteLength === 0) { + cachedInt32Memory0 = new Int32Array(wasm.memory.buffer); } - ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0; - const view = getUint8Memory0().subarray(ptr + offset, ptr + len); - const ret = encodeString(arg, view); - - offset += ret.written; + return cachedInt32Memory0; } - WASM_VECTOR_LEN = offset; - return ptr; -} - -let cachedInt32Memory0 = null; - -function getInt32Memory0() { - if (cachedInt32Memory0 === null || cachedInt32Memory0.byteLength === 0) { - cachedInt32Memory0 = new Int32Array(wasm.memory.buffer); - } - return cachedInt32Memory0; -} - -function makeMutClosure(arg0, arg1, dtor, f) { - const state = { a: arg0, b: arg1, cnt: 1, dtor }; - const real = (...args) => { - // First up with a closure we increment the internal reference - // count. This ensures that the Rust closure environment won't - // be deallocated while we're invoking it. - state.cnt++; - const a = state.a; - state.a = 0; - try { - return f(a, state.b, ...args); - } finally { - if (--state.cnt === 0) { - wasm.__wbindgen_export_2.get(state.dtor)(a, state.b); - - } else { - state.a = a; - } - } - }; - real.original = state; - - return real; -} -function __wbg_adapter_20(arg0, arg1) { - wasm._dyn_core__ops__function__FnMut_____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h648b303b06146952(arg0, arg1); -} - -function __wbg_adapter_23(arg0, arg1, arg2) { - wasm._dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h254fddd5612fbaed(arg0, arg1, addHeapObject(arg2)); -} - -function handleError(f, args) { - try { - return f.apply(this, args); - } catch (e) { - wasm.__wbindgen_exn_store(addHeapObject(e)); - } -} - -function getArrayU8FromWasm0(ptr, len) { - ptr = ptr >>> 0; - return getUint8Memory0().subarray(ptr / 1, ptr / 1 + len); -} - -function isLikeNone(x) { - return x === undefined || x === null; -} - -async function __wbg_load(module, imports) { - if (typeof Response === 'function' && module instanceof Response) { - if (typeof WebAssembly.instantiateStreaming === 'function') { + function makeMutClosure(arg0, arg1, dtor, f) { + const state = { a: arg0, b: arg1, cnt: 1, dtor }; + const real = (...args) => { + // First up with a closure we increment the internal reference + // count. This ensures that the Rust closure environment won't + // be deallocated while we're invoking it. + state.cnt++; + const a = state.a; + state.a = 0; try { - return await WebAssembly.instantiateStreaming(module, imports); - - } catch (e) { - if (module.headers.get('Content-Type') != 'application/wasm') { - console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e); + return f(a, state.b, ...args); + } finally { + if (--state.cnt === 0) { + wasm.__wbindgen_export_2.get(state.dtor)(a, state.b); } else { - throw e; + state.a = a; } } + }; + real.original = state; + + return real; + } + function __wbg_adapter_20(arg0, arg1) { + wasm._dyn_core__ops__function__FnMut_____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h648b303b06146952(arg0, arg1); + } + + function __wbg_adapter_23(arg0, arg1, arg2) { + wasm._dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h254fddd5612fbaed(arg0, arg1, addHeapObject(arg2)); + } + + function handleError(f, args) { + try { + return f.apply(this, args); + } catch (e) { + wasm.__wbindgen_exn_store(addHeapObject(e)); } + } - const bytes = await module.arrayBuffer(); - return await WebAssembly.instantiate(bytes, imports); + function getArrayU8FromWasm0(ptr, len) { + ptr = ptr >>> 0; + return getUint8Memory0().subarray(ptr / 1, ptr / 1 + len); + } - } else { - const instance = await WebAssembly.instantiate(module, imports); + function isLikeNone(x) { + return x === undefined || x === null; + } - if (instance instanceof WebAssembly.Instance) { - return { instance, module }; + async function __wbg_load(module, imports) { + if (typeof Response === 'function' && module instanceof Response) { + if (typeof WebAssembly.instantiateStreaming === 'function') { + try { + return await WebAssembly.instantiateStreaming(module, imports); + + } catch (e) { + if (module.headers.get('Content-Type') != 'application/wasm') { + console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e); + + } else { + throw e; + } + } + } + + const bytes = await module.arrayBuffer(); + return await WebAssembly.instantiate(bytes, imports); } else { - return instance; + const instance = await WebAssembly.instantiate(module, imports); + + if (instance instanceof WebAssembly.Instance) { + return { instance, module }; + + } else { + return instance; + } } } -} -function __wbg_get_imports() { - const imports = {}; - imports.wbg = {}; - imports.wbg.__wbindgen_cb_drop = function(arg0) { - const obj = takeObject(arg0).original; - if (obj.cnt-- == 1) { - obj.a = 0; - return true; - } - const ret = false; - return ret; - }; - imports.wbg.__wbindgen_object_drop_ref = function(arg0) { - takeObject(arg0); - }; - imports.wbg.__wbg_log_b09521c515df0f23 = function(arg0, arg1) { - console.log(getStringFromWasm0(arg0, arg1)); - }; - imports.wbg.__wbindgen_object_clone_ref = function(arg0) { - const ret = getObject(arg0); - return addHeapObject(ret); - }; - imports.wbg.__wbg_new_abda76e883ba8a5f = function() { - const ret = new Error(); - return addHeapObject(ret); - }; - imports.wbg.__wbg_stack_658279fe44541cf6 = function(arg0, arg1) { - const ret = getObject(arg1).stack; - const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); - const len1 = WASM_VECTOR_LEN; - getInt32Memory0()[arg0 / 4 + 1] = len1; - getInt32Memory0()[arg0 / 4 + 0] = ptr1; - }; - imports.wbg.__wbg_error_f851667af71bcfc6 = function(arg0, arg1) { - let deferred0_0; - let deferred0_1; - try { - deferred0_0 = arg0; - deferred0_1 = arg1; - console.error(getStringFromWasm0(arg0, arg1)); - } finally { - wasm.__wbindgen_free(deferred0_0, deferred0_1, 1); - } - }; - imports.wbg.__wbindgen_string_new = function(arg0, arg1) { - const ret = getStringFromWasm0(arg0, arg1); - return addHeapObject(ret); - }; - imports.wbg.__wbindgen_boolean_get = function(arg0) { - const v = getObject(arg0); - const ret = typeof(v) === 'boolean' ? (v ? 1 : 0) : 2; - return ret; - }; - imports.wbg.__wbg_randomFillSync_bf67eeddb65b346b = function() { return handleError(function (arg0, arg1, arg2) { - getObject(arg0).randomFillSync(getArrayU8FromWasm0(arg1, arg2)); - }, arguments) }; - imports.wbg.__wbg_getRandomValues_f6c9b08ef5448767 = function() { return handleError(function (arg0, arg1) { - getObject(arg0).getRandomValues(getObject(arg1)); - }, arguments) }; - imports.wbg.__wbg_self_1c2814d86e6e51e3 = function() { return handleError(function () { - const ret = self.self; - return addHeapObject(ret); - }, arguments) }; - imports.wbg.__wbg_crypto_70532d614bc7e028 = function(arg0) { - const ret = getObject(arg0).crypto; - return addHeapObject(ret); - }; - imports.wbg.__wbg_msCrypto_4e9b4dd0e1abade6 = function(arg0) { - const ret = getObject(arg0).msCrypto; - return addHeapObject(ret); - }; - imports.wbg.__wbindgen_is_undefined = function(arg0) { - const ret = getObject(arg0) === undefined; - return ret; - }; - imports.wbg.__wbg_static_accessor_MODULE_7781e47b50010688 = function() { - const ret = module; - return addHeapObject(ret); - }; - imports.wbg.__wbg_require_9ace3ae680954e98 = function() { return handleError(function (arg0, arg1, arg2) { - const ret = getObject(arg0).require(getStringFromWasm0(arg1, arg2)); - return addHeapObject(ret); - }, arguments) }; - imports.wbg.__wbg_instanceof_WebGl2RenderingContext_f921526c513bf717 = function(arg0) { - let result; - try { - result = getObject(arg0) instanceof WebGL2RenderingContext; - } catch { - result = false; - } - const ret = result; - return ret; - }; - imports.wbg.__wbg_bindVertexArray_8863a216d7b0a339 = function(arg0, arg1) { - getObject(arg0).bindVertexArray(getObject(arg1)); - }; - imports.wbg.__wbg_bufferData_21334671c4ba6004 = function(arg0, arg1, arg2, arg3) { - getObject(arg0).bufferData(arg1 >>> 0, getObject(arg2), arg3 >>> 0); - }; - imports.wbg.__wbg_createVertexArray_51d51e1e1e13e9f6 = function(arg0) { - const ret = getObject(arg0).createVertexArray(); - return isLikeNone(ret) ? 0 : addHeapObject(ret); - }; - imports.wbg.__wbg_texImage2D_07240affd06971e9 = function() { return handleError(function (arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) { - getObject(arg0).texImage2D(arg1 >>> 0, arg2, arg3, arg4, arg5, arg6, arg7 >>> 0, arg8 >>> 0, getObject(arg9)); - }, arguments) }; - imports.wbg.__wbg_attachShader_47256b6b3d42a22e = function(arg0, arg1, arg2) { - getObject(arg0).attachShader(getObject(arg1), getObject(arg2)); - }; - imports.wbg.__wbg_bindBuffer_24f6010e273fa400 = function(arg0, arg1, arg2) { - getObject(arg0).bindBuffer(arg1 >>> 0, getObject(arg2)); - }; - imports.wbg.__wbg_bindFramebuffer_a9573e340dab20fe = function(arg0, arg1, arg2) { - getObject(arg0).bindFramebuffer(arg1 >>> 0, getObject(arg2)); - }; - imports.wbg.__wbg_bindTexture_92d6d7f8bff9531e = function(arg0, arg1, arg2) { - getObject(arg0).bindTexture(arg1 >>> 0, getObject(arg2)); - }; - imports.wbg.__wbg_blendFunc_533de6de45b80a09 = function(arg0, arg1, arg2) { - getObject(arg0).blendFunc(arg1 >>> 0, arg2 >>> 0); - }; - imports.wbg.__wbg_clear_2db2efe323bfdf68 = function(arg0, arg1) { - getObject(arg0).clear(arg1 >>> 0); - }; - imports.wbg.__wbg_clearColor_7a7d04702f7e38e5 = function(arg0, arg1, arg2, arg3, arg4) { - getObject(arg0).clearColor(arg1, arg2, arg3, arg4); - }; - imports.wbg.__wbg_compileShader_6bf78b425d5c98e1 = function(arg0, arg1) { - getObject(arg0).compileShader(getObject(arg1)); - }; - imports.wbg.__wbg_createBuffer_323425af422748ac = function(arg0) { - const ret = getObject(arg0).createBuffer(); - return isLikeNone(ret) ? 0 : addHeapObject(ret); - }; - imports.wbg.__wbg_createFramebuffer_1684a99697ac9563 = function(arg0) { - const ret = getObject(arg0).createFramebuffer(); - return isLikeNone(ret) ? 0 : addHeapObject(ret); - }; - imports.wbg.__wbg_createProgram_4eaf3b97b5747a62 = function(arg0) { - const ret = getObject(arg0).createProgram(); - return isLikeNone(ret) ? 0 : addHeapObject(ret); - }; - imports.wbg.__wbg_createShader_429776c9dd6fb87b = function(arg0, arg1) { - const ret = getObject(arg0).createShader(arg1 >>> 0); - return isLikeNone(ret) ? 0 : addHeapObject(ret); - }; - imports.wbg.__wbg_createTexture_1bf4d6fec570124b = function(arg0) { - const ret = getObject(arg0).createTexture(); - return isLikeNone(ret) ? 0 : addHeapObject(ret); - }; - imports.wbg.__wbg_disable_e02106ca6c7002d6 = function(arg0, arg1) { - getObject(arg0).disable(arg1 >>> 0); - }; - imports.wbg.__wbg_drawArrays_c91ce3f736bf1f2a = function(arg0, arg1, arg2, arg3) { - getObject(arg0).drawArrays(arg1 >>> 0, arg2, arg3); - }; - imports.wbg.__wbg_drawElements_a9529eefaf2008bd = function(arg0, arg1, arg2, arg3, arg4) { - getObject(arg0).drawElements(arg1 >>> 0, arg2, arg3 >>> 0, arg4); - }; - imports.wbg.__wbg_enable_195891416c520019 = function(arg0, arg1) { - getObject(arg0).enable(arg1 >>> 0); - }; - imports.wbg.__wbg_enableVertexAttribArray_8804480c2ea0bb72 = function(arg0, arg1) { - getObject(arg0).enableVertexAttribArray(arg1 >>> 0); - }; - imports.wbg.__wbg_framebufferTexture2D_e88fcbd7f8523bb8 = function(arg0, arg1, arg2, arg3, arg4, arg5) { - getObject(arg0).framebufferTexture2D(arg1 >>> 0, arg2 >>> 0, arg3 >>> 0, getObject(arg4), arg5); - }; - imports.wbg.__wbg_getError_7191ad6ea53607fe = function(arg0) { - const ret = getObject(arg0).getError(); - return ret; - }; - imports.wbg.__wbg_getExtension_77909f6d51d49d4d = function() { return handleError(function (arg0, arg1, arg2) { - const ret = getObject(arg0).getExtension(getStringFromWasm0(arg1, arg2)); - return isLikeNone(ret) ? 0 : addHeapObject(ret); - }, arguments) }; - imports.wbg.__wbg_getProgramInfoLog_b81bc53188e286fa = function(arg0, arg1, arg2) { - const ret = getObject(arg1).getProgramInfoLog(getObject(arg2)); - var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); - var len1 = WASM_VECTOR_LEN; - getInt32Memory0()[arg0 / 4 + 1] = len1; - getInt32Memory0()[arg0 / 4 + 0] = ptr1; - }; - imports.wbg.__wbg_getProgramParameter_35522a0bfdfaad27 = function(arg0, arg1, arg2) { - const ret = getObject(arg0).getProgramParameter(getObject(arg1), arg2 >>> 0); - return addHeapObject(ret); - }; - imports.wbg.__wbg_getShaderInfoLog_968b93e75477d725 = function(arg0, arg1, arg2) { - const ret = getObject(arg1).getShaderInfoLog(getObject(arg2)); - var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); - var len1 = WASM_VECTOR_LEN; - getInt32Memory0()[arg0 / 4 + 1] = len1; - getInt32Memory0()[arg0 / 4 + 0] = ptr1; - }; - imports.wbg.__wbg_getShaderParameter_ac2727ae4fe7648e = function(arg0, arg1, arg2) { - const ret = getObject(arg0).getShaderParameter(getObject(arg1), arg2 >>> 0); - return addHeapObject(ret); - }; - imports.wbg.__wbg_getUniformLocation_9f6eb60c560a347b = function(arg0, arg1, arg2, arg3) { - const ret = getObject(arg0).getUniformLocation(getObject(arg1), getStringFromWasm0(arg2, arg3)); - return isLikeNone(ret) ? 0 : addHeapObject(ret); - }; - imports.wbg.__wbg_linkProgram_33998194075d71fb = function(arg0, arg1) { - getObject(arg0).linkProgram(getObject(arg1)); - }; - imports.wbg.__wbg_shaderSource_1cb7c64dc7d1a500 = function(arg0, arg1, arg2, arg3) { - getObject(arg0).shaderSource(getObject(arg1), getStringFromWasm0(arg2, arg3)); - }; - imports.wbg.__wbg_texParameteri_85dad939f62a15aa = function(arg0, arg1, arg2, arg3) { - getObject(arg0).texParameteri(arg1 >>> 0, arg2 >>> 0, arg3); - }; - imports.wbg.__wbg_uniform1i_d2e61a6a43889648 = function(arg0, arg1, arg2) { - getObject(arg0).uniform1i(getObject(arg1), arg2); - }; - imports.wbg.__wbg_uniform3f_8364a0959b6c1570 = function(arg0, arg1, arg2, arg3, arg4) { - getObject(arg0).uniform3f(getObject(arg1), arg2, arg3, arg4); - }; - imports.wbg.__wbg_useProgram_3683cf6f60939dcd = function(arg0, arg1) { - getObject(arg0).useProgram(getObject(arg1)); - }; - imports.wbg.__wbg_vertexAttribPointer_316ffe2f0458fde7 = function(arg0, arg1, arg2, arg3, arg4, arg5, arg6) { - getObject(arg0).vertexAttribPointer(arg1 >>> 0, arg2, arg3 >>> 0, arg4 !== 0, arg5, arg6); - }; - imports.wbg.__wbg_getElementById_cc0e0d931b0d9a28 = function(arg0, arg1, arg2) { - const ret = getObject(arg0).getElementById(getStringFromWasm0(arg1, arg2)); - return isLikeNone(ret) ? 0 : addHeapObject(ret); - }; - imports.wbg.__wbg_instanceof_HtmlCanvasElement_da5f9efa0688cf6d = function(arg0) { - let result; - try { - result = getObject(arg0) instanceof HTMLCanvasElement; - } catch { - result = false; - } - const ret = result; - return ret; - }; - imports.wbg.__wbg_setwidth_a667a942dba6656e = function(arg0, arg1) { - getObject(arg0).width = arg1 >>> 0; - }; - imports.wbg.__wbg_setheight_a747d440760fe5aa = function(arg0, arg1) { - getObject(arg0).height = arg1 >>> 0; - }; - imports.wbg.__wbg_getContext_7c5944ea807bf5d3 = function() { return handleError(function (arg0, arg1, arg2) { - const ret = getObject(arg0).getContext(getStringFromWasm0(arg1, arg2)); - return isLikeNone(ret) ? 0 : addHeapObject(ret); - }, arguments) }; - imports.wbg.__wbg_offsetX_5a58f16f6c3a41b6 = function(arg0) { - const ret = getObject(arg0).offsetX; - return ret; - }; - imports.wbg.__wbg_offsetY_c45b4956f6429a95 = function(arg0) { - const ret = getObject(arg0).offsetY; - return ret; - }; - imports.wbg.__wbg_now_0cfdc90c97d0c24b = function(arg0) { - const ret = getObject(arg0).now(); - return ret; - }; - imports.wbg.__wbg_instanceof_Window_9029196b662bc42a = function(arg0) { - let result; - try { - result = getObject(arg0) instanceof Window; - } catch { - result = false; - } - const ret = result; - return ret; - }; - imports.wbg.__wbg_charCode_75cea1a3a6d66388 = function(arg0) { - const ret = getObject(arg0).charCode; - return ret; - }; - imports.wbg.__wbg_keyCode_dfa86be31f5ef90c = function(arg0) { - const ret = getObject(arg0).keyCode; - return ret; - }; - imports.wbg.__wbg_code_96d6322b968b2d17 = function(arg0, arg1) { - const ret = getObject(arg1).code; - const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); - const len1 = WASM_VECTOR_LEN; - getInt32Memory0()[arg0 / 4 + 1] = len1; - getInt32Memory0()[arg0 / 4 + 0] = ptr1; - }; - imports.wbg.__wbg_getModifierState_5102ee8843516d2f = function(arg0, arg1, arg2) { - const ret = getObject(arg0).getModifierState(getStringFromWasm0(arg1, arg2)); - return ret; - }; - imports.wbg.__wbg_document_f7ace2b956f30a4f = function(arg0) { - const ret = getObject(arg0).document; - return isLikeNone(ret) ? 0 : addHeapObject(ret); - }; - imports.wbg.__wbg_performance_2c295061c8b01e0b = function(arg0) { - const ret = getObject(arg0).performance; - return isLikeNone(ret) ? 0 : addHeapObject(ret); - }; - imports.wbg.__wbg_setonkeydown_933cca3c9000a932 = function(arg0, arg1) { - getObject(arg0).onkeydown = getObject(arg1); - }; - imports.wbg.__wbg_setonkeyup_0dfb23e81d0afdde = function(arg0, arg1) { - getObject(arg0).onkeyup = getObject(arg1); - }; - imports.wbg.__wbg_requestAnimationFrame_d082200514b6674d = function() { return handleError(function (arg0, arg1) { - const ret = getObject(arg0).requestAnimationFrame(getObject(arg1)); - return ret; - }, arguments) }; - imports.wbg.__wbg_setonmousedown_4f38d9c057bbfcbd = function(arg0, arg1) { - getObject(arg0).onmousedown = getObject(arg1); - }; - imports.wbg.__wbg_setonmousemove_c0b17753786f3544 = function(arg0, arg1) { - getObject(arg0).onmousemove = getObject(arg1); - }; - imports.wbg.__wbg_setonmouseup_4b447fa380e33802 = function(arg0, arg1) { - getObject(arg0).onmouseup = getObject(arg1); - }; - imports.wbg.__wbg_bufferData_a11a9f65f31e7256 = function(arg0, arg1, arg2, arg3) { - getObject(arg0).bufferData(arg1 >>> 0, getObject(arg2), arg3 >>> 0); - }; - imports.wbg.__wbg_texImage2D_6175916e58c59bc7 = function() { return handleError(function (arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) { - getObject(arg0).texImage2D(arg1 >>> 0, arg2, arg3, arg4, arg5, arg6, arg7 >>> 0, arg8 >>> 0, getObject(arg9)); - }, arguments) }; - imports.wbg.__wbg_attachShader_b65b695055670cb5 = function(arg0, arg1, arg2) { - getObject(arg0).attachShader(getObject(arg1), getObject(arg2)); - }; - imports.wbg.__wbg_bindBuffer_313561e5bc0e533f = function(arg0, arg1, arg2) { - getObject(arg0).bindBuffer(arg1 >>> 0, getObject(arg2)); - }; - imports.wbg.__wbg_bindFramebuffer_56bf6536a4ced0ec = function(arg0, arg1, arg2) { - getObject(arg0).bindFramebuffer(arg1 >>> 0, getObject(arg2)); - }; - imports.wbg.__wbg_bindTexture_9cb5c770d1ba2cca = function(arg0, arg1, arg2) { - getObject(arg0).bindTexture(arg1 >>> 0, getObject(arg2)); - }; - imports.wbg.__wbg_blendFunc_fbe9d3a688fe71c3 = function(arg0, arg1, arg2) { - getObject(arg0).blendFunc(arg1 >>> 0, arg2 >>> 0); - }; - imports.wbg.__wbg_clear_2ccea1f65b510c97 = function(arg0, arg1) { - getObject(arg0).clear(arg1 >>> 0); - }; - imports.wbg.__wbg_clearColor_de587608b28bc7ed = function(arg0, arg1, arg2, arg3, arg4) { - getObject(arg0).clearColor(arg1, arg2, arg3, arg4); - }; - imports.wbg.__wbg_compileShader_d88d0a8cd9b72b4d = function(arg0, arg1) { - getObject(arg0).compileShader(getObject(arg1)); - }; - imports.wbg.__wbg_createBuffer_59051f4461e7c5e2 = function(arg0) { - const ret = getObject(arg0).createBuffer(); - return isLikeNone(ret) ? 0 : addHeapObject(ret); - }; - imports.wbg.__wbg_createFramebuffer_223c1212ad76affc = function(arg0) { - const ret = getObject(arg0).createFramebuffer(); - return isLikeNone(ret) ? 0 : addHeapObject(ret); - }; - imports.wbg.__wbg_createProgram_88dbe21c0b682e1a = function(arg0) { - const ret = getObject(arg0).createProgram(); - return isLikeNone(ret) ? 0 : addHeapObject(ret); - }; - imports.wbg.__wbg_createShader_9d7d388633caad18 = function(arg0, arg1) { - const ret = getObject(arg0).createShader(arg1 >>> 0); - return isLikeNone(ret) ? 0 : addHeapObject(ret); - }; - imports.wbg.__wbg_createTexture_9d0bb4d741b8ad76 = function(arg0) { - const ret = getObject(arg0).createTexture(); - return isLikeNone(ret) ? 0 : addHeapObject(ret); - }; - imports.wbg.__wbg_disable_5cf2070641fa2ed7 = function(arg0, arg1) { - getObject(arg0).disable(arg1 >>> 0); - }; - imports.wbg.__wbg_drawArrays_d5c7dc2b2376c85a = function(arg0, arg1, arg2, arg3) { - getObject(arg0).drawArrays(arg1 >>> 0, arg2, arg3); - }; - imports.wbg.__wbg_drawElements_3316ee0cd1117c2a = function(arg0, arg1, arg2, arg3, arg4) { - getObject(arg0).drawElements(arg1 >>> 0, arg2, arg3 >>> 0, arg4); - }; - imports.wbg.__wbg_enable_8965e69c596f0a94 = function(arg0, arg1) { - getObject(arg0).enable(arg1 >>> 0); - }; - imports.wbg.__wbg_enableVertexAttribArray_2b0475db43533cf2 = function(arg0, arg1) { - getObject(arg0).enableVertexAttribArray(arg1 >>> 0); - }; - imports.wbg.__wbg_framebufferTexture2D_953e69a8bec22fa9 = function(arg0, arg1, arg2, arg3, arg4, arg5) { - getObject(arg0).framebufferTexture2D(arg1 >>> 0, arg2 >>> 0, arg3 >>> 0, getObject(arg4), arg5); - }; - imports.wbg.__wbg_getError_1e5ec1ec9e58b323 = function(arg0) { - const ret = getObject(arg0).getError(); - return ret; - }; - imports.wbg.__wbg_getProgramInfoLog_0b7af4ad85fa52a4 = function(arg0, arg1, arg2) { - const ret = getObject(arg1).getProgramInfoLog(getObject(arg2)); - var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); - var len1 = WASM_VECTOR_LEN; - getInt32Memory0()[arg0 / 4 + 1] = len1; - getInt32Memory0()[arg0 / 4 + 0] = ptr1; - }; - imports.wbg.__wbg_getProgramParameter_2a3735278367f8bc = function(arg0, arg1, arg2) { - const ret = getObject(arg0).getProgramParameter(getObject(arg1), arg2 >>> 0); - return addHeapObject(ret); - }; - imports.wbg.__wbg_getShaderInfoLog_979aafa403ffb252 = function(arg0, arg1, arg2) { - const ret = getObject(arg1).getShaderInfoLog(getObject(arg2)); - var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); - var len1 = WASM_VECTOR_LEN; - getInt32Memory0()[arg0 / 4 + 1] = len1; - getInt32Memory0()[arg0 / 4 + 0] = ptr1; - }; - imports.wbg.__wbg_getShaderParameter_e8054f1d9026fb70 = function(arg0, arg1, arg2) { - const ret = getObject(arg0).getShaderParameter(getObject(arg1), arg2 >>> 0); - return addHeapObject(ret); - }; - imports.wbg.__wbg_getUniformLocation_688976233799a45a = function(arg0, arg1, arg2, arg3) { - const ret = getObject(arg0).getUniformLocation(getObject(arg1), getStringFromWasm0(arg2, arg3)); - return isLikeNone(ret) ? 0 : addHeapObject(ret); - }; - imports.wbg.__wbg_linkProgram_9a2d12d120d99917 = function(arg0, arg1) { - getObject(arg0).linkProgram(getObject(arg1)); - }; - imports.wbg.__wbg_shaderSource_f435f9b74440bb54 = function(arg0, arg1, arg2, arg3) { - getObject(arg0).shaderSource(getObject(arg1), getStringFromWasm0(arg2, arg3)); - }; - imports.wbg.__wbg_texParameteri_1f17358e51eb8069 = function(arg0, arg1, arg2, arg3) { - getObject(arg0).texParameteri(arg1 >>> 0, arg2 >>> 0, arg3); - }; - imports.wbg.__wbg_uniform1i_9f94ef0ba6b3cc66 = function(arg0, arg1, arg2) { - getObject(arg0).uniform1i(getObject(arg1), arg2); - }; - imports.wbg.__wbg_uniform3f_c682f4b32f713d1a = function(arg0, arg1, arg2, arg3, arg4) { - getObject(arg0).uniform3f(getObject(arg1), arg2, arg3, arg4); - }; - imports.wbg.__wbg_useProgram_019eb6df066fabf5 = function(arg0, arg1) { - getObject(arg0).useProgram(getObject(arg1)); - }; - imports.wbg.__wbg_vertexAttribPointer_ca11984ee8843c0a = function(arg0, arg1, arg2, arg3, arg4, arg5, arg6) { - getObject(arg0).vertexAttribPointer(arg1 >>> 0, arg2, arg3 >>> 0, arg4 !== 0, arg5, arg6); - }; - imports.wbg.__wbg_bindVertexArrayOES_b7d9da7e073aa6b5 = function(arg0, arg1) { - getObject(arg0).bindVertexArrayOES(getObject(arg1)); - }; - imports.wbg.__wbg_createVertexArrayOES_6a3c3a5a68201f8f = function(arg0) { - const ret = getObject(arg0).createVertexArrayOES(); - return isLikeNone(ret) ? 0 : addHeapObject(ret); - }; - imports.wbg.__wbg_newnoargs_581967eacc0e2604 = function(arg0, arg1) { - const ret = new Function(getStringFromWasm0(arg0, arg1)); - return addHeapObject(ret); - }; - imports.wbg.__wbg_get_97b561fb56f034b5 = function() { return handleError(function (arg0, arg1) { - const ret = Reflect.get(getObject(arg0), getObject(arg1)); - return addHeapObject(ret); - }, arguments) }; - imports.wbg.__wbg_call_cb65541d95d71282 = function() { return handleError(function (arg0, arg1) { - const ret = getObject(arg0).call(getObject(arg1)); - return addHeapObject(ret); - }, arguments) }; - imports.wbg.__wbg_self_1ff1d729e9aae938 = function() { return handleError(function () { - const ret = self.self; - return addHeapObject(ret); - }, arguments) }; - imports.wbg.__wbg_window_5f4faef6c12b79ec = function() { return handleError(function () { - const ret = window.window; - return addHeapObject(ret); - }, arguments) }; - imports.wbg.__wbg_globalThis_1d39714405582d3c = function() { return handleError(function () { - const ret = globalThis.globalThis; - return addHeapObject(ret); - }, arguments) }; - imports.wbg.__wbg_global_651f05c6a0944d1c = function() { return handleError(function () { - const ret = global.global; - return addHeapObject(ret); - }, arguments) }; - imports.wbg.__wbg_now_9c5990bda04c7e53 = function() { - const ret = Date.now(); - return ret; - }; - imports.wbg.__wbg_buffer_085ec1f694018c4f = function(arg0) { - const ret = getObject(arg0).buffer; - return addHeapObject(ret); - }; - imports.wbg.__wbg_newwithbyteoffsetandlength_828b952f0e692245 = function(arg0, arg1, arg2) { - const ret = new Int8Array(getObject(arg0), arg1 >>> 0, arg2 >>> 0); - return addHeapObject(ret); - }; - imports.wbg.__wbg_newwithbyteoffsetandlength_735ed5ea2ae07fe9 = function(arg0, arg1, arg2) { - const ret = new Int16Array(getObject(arg0), arg1 >>> 0, arg2 >>> 0); - return addHeapObject(ret); - }; - imports.wbg.__wbg_newwithbyteoffsetandlength_9f43b22ab631d1d6 = function(arg0, arg1, arg2) { - const ret = new Int32Array(getObject(arg0), arg1 >>> 0, arg2 >>> 0); - return addHeapObject(ret); - }; - imports.wbg.__wbg_newwithbyteoffsetandlength_6da8e527659b86aa = function(arg0, arg1, arg2) { - const ret = new Uint8Array(getObject(arg0), arg1 >>> 0, arg2 >>> 0); - return addHeapObject(ret); - }; - imports.wbg.__wbg_new_8125e318e6245eed = function(arg0) { - const ret = new Uint8Array(getObject(arg0)); - return addHeapObject(ret); - }; - imports.wbg.__wbg_set_5cf90238115182c3 = function(arg0, arg1, arg2) { - getObject(arg0).set(getObject(arg1), arg2 >>> 0); - }; - imports.wbg.__wbg_length_72e2208bbc0efc61 = function(arg0) { - const ret = getObject(arg0).length; - return ret; - }; - imports.wbg.__wbg_newwithbyteoffsetandlength_31ff1024ef0c63c7 = function(arg0, arg1, arg2) { - const ret = new Uint16Array(getObject(arg0), arg1 >>> 0, arg2 >>> 0); - return addHeapObject(ret); - }; - imports.wbg.__wbg_newwithbyteoffsetandlength_6df0e8c3efd2a5d3 = function(arg0, arg1, arg2) { - const ret = new Uint32Array(getObject(arg0), arg1 >>> 0, arg2 >>> 0); - return addHeapObject(ret); - }; - imports.wbg.__wbg_newwithbyteoffsetandlength_69193e31c844b792 = function(arg0, arg1, arg2) { - const ret = new Float32Array(getObject(arg0), arg1 >>> 0, arg2 >>> 0); - return addHeapObject(ret); - }; - imports.wbg.__wbg_newwithlength_e5d69174d6984cd7 = function(arg0) { - const ret = new Uint8Array(arg0 >>> 0); - return addHeapObject(ret); - }; - imports.wbg.__wbg_subarray_13db269f57aa838d = function(arg0, arg1, arg2) { - const ret = getObject(arg0).subarray(arg1 >>> 0, arg2 >>> 0); - return addHeapObject(ret); - }; - imports.wbg.__wbindgen_debug_string = function(arg0, arg1) { - const ret = debugString(getObject(arg1)); - const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); - const len1 = WASM_VECTOR_LEN; - getInt32Memory0()[arg0 / 4 + 1] = len1; - getInt32Memory0()[arg0 / 4 + 0] = ptr1; - }; - imports.wbg.__wbindgen_throw = function(arg0, arg1) { - throw new Error(getStringFromWasm0(arg0, arg1)); - }; - imports.wbg.__wbindgen_memory = function() { - const ret = wasm.memory; - return addHeapObject(ret); - }; - imports.wbg.__wbindgen_closure_wrapper694 = function(arg0, arg1, arg2) { - const ret = makeMutClosure(arg0, arg1, 124, __wbg_adapter_20); - return addHeapObject(ret); - }; - imports.wbg.__wbindgen_closure_wrapper2716 = function(arg0, arg1, arg2) { - const ret = makeMutClosure(arg0, arg1, 518, __wbg_adapter_23); - return addHeapObject(ret); - }; - imports.wbg.__wbindgen_closure_wrapper2718 = function(arg0, arg1, arg2) { - const ret = makeMutClosure(arg0, arg1, 518, __wbg_adapter_23); - return addHeapObject(ret); - }; + function __wbg_get_imports() { + const imports = {}; + imports.wbg = {}; + imports.wbg.__wbindgen_cb_drop = function (arg0) { + const obj = takeObject(arg0).original; + if (obj.cnt-- == 1) { + obj.a = 0; + return true; + } + const ret = false; + return ret; + }; + imports.wbg.__wbindgen_object_drop_ref = function (arg0) { + takeObject(arg0); + }; + imports.wbg.__wbg_log_b09521c515df0f23 = function (arg0, arg1) { + console.log(getStringFromWasm0(arg0, arg1)); + }; + imports.wbg.__wbindgen_object_clone_ref = function (arg0) { + const ret = getObject(arg0); + return addHeapObject(ret); + }; + imports.wbg.__wbg_new_abda76e883ba8a5f = function () { + const ret = new Error(); + return addHeapObject(ret); + }; + imports.wbg.__wbg_stack_658279fe44541cf6 = function (arg0, arg1) { + const ret = getObject(arg1).stack; + const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); + const len1 = WASM_VECTOR_LEN; + getInt32Memory0()[arg0 / 4 + 1] = len1; + getInt32Memory0()[arg0 / 4 + 0] = ptr1; + }; + imports.wbg.__wbg_error_f851667af71bcfc6 = function (arg0, arg1) { + let deferred0_0; + let deferred0_1; + try { + deferred0_0 = arg0; + deferred0_1 = arg1; + console.error(getStringFromWasm0(arg0, arg1)); + } finally { + wasm.__wbindgen_free(deferred0_0, deferred0_1, 1); + } + }; + imports.wbg.__wbindgen_string_new = function (arg0, arg1) { + const ret = getStringFromWasm0(arg0, arg1); + return addHeapObject(ret); + }; + imports.wbg.__wbindgen_boolean_get = function (arg0) { + const v = getObject(arg0); + const ret = typeof (v) === 'boolean' ? (v ? 1 : 0) : 2; + return ret; + }; + imports.wbg.__wbg_randomFillSync_bf67eeddb65b346b = function () { + return handleError(function (arg0, arg1, arg2) { + getObject(arg0).randomFillSync(getArrayU8FromWasm0(arg1, arg2)); + }, arguments) + }; + imports.wbg.__wbg_getRandomValues_f6c9b08ef5448767 = function () { + return handleError(function (arg0, arg1) { + getObject(arg0).getRandomValues(getObject(arg1)); + }, arguments) + }; + imports.wbg.__wbg_self_1c2814d86e6e51e3 = function () { + return handleError(function () { + const ret = self.self; + return addHeapObject(ret); + }, arguments) + }; + imports.wbg.__wbg_crypto_70532d614bc7e028 = function (arg0) { + const ret = getObject(arg0).crypto; + return addHeapObject(ret); + }; + imports.wbg.__wbg_msCrypto_4e9b4dd0e1abade6 = function (arg0) { + const ret = getObject(arg0).msCrypto; + return addHeapObject(ret); + }; + imports.wbg.__wbindgen_is_undefined = function (arg0) { + const ret = getObject(arg0) === undefined; + return ret; + }; + imports.wbg.__wbg_static_accessor_MODULE_7781e47b50010688 = function () { + const ret = module; + return addHeapObject(ret); + }; + imports.wbg.__wbg_require_9ace3ae680954e98 = function () { + return handleError(function (arg0, arg1, arg2) { + const ret = getObject(arg0).require(getStringFromWasm0(arg1, arg2)); + return addHeapObject(ret); + }, arguments) + }; + imports.wbg.__wbg_instanceof_WebGl2RenderingContext_f921526c513bf717 = function (arg0) { + let result; + try { + result = getObject(arg0) instanceof WebGL2RenderingContext; + } catch { + result = false; + } + const ret = result; + return ret; + }; + imports.wbg.__wbg_bindVertexArray_8863a216d7b0a339 = function (arg0, arg1) { + getObject(arg0).bindVertexArray(getObject(arg1)); + }; + imports.wbg.__wbg_bufferData_21334671c4ba6004 = function (arg0, arg1, arg2, arg3) { + getObject(arg0).bufferData(arg1 >>> 0, getObject(arg2), arg3 >>> 0); + }; + imports.wbg.__wbg_createVertexArray_51d51e1e1e13e9f6 = function (arg0) { + const ret = getObject(arg0).createVertexArray(); + return isLikeNone(ret) ? 0 : addHeapObject(ret); + }; + imports.wbg.__wbg_texImage2D_07240affd06971e9 = function () { + return handleError(function (arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) { + getObject(arg0).texImage2D(arg1 >>> 0, arg2, arg3, arg4, arg5, arg6, arg7 >>> 0, arg8 >>> 0, getObject(arg9)); + }, arguments) + }; + imports.wbg.__wbg_attachShader_47256b6b3d42a22e = function (arg0, arg1, arg2) { + getObject(arg0).attachShader(getObject(arg1), getObject(arg2)); + }; + imports.wbg.__wbg_bindBuffer_24f6010e273fa400 = function (arg0, arg1, arg2) { + getObject(arg0).bindBuffer(arg1 >>> 0, getObject(arg2)); + }; + imports.wbg.__wbg_bindFramebuffer_a9573e340dab20fe = function (arg0, arg1, arg2) { + getObject(arg0).bindFramebuffer(arg1 >>> 0, getObject(arg2)); + }; + imports.wbg.__wbg_bindTexture_92d6d7f8bff9531e = function (arg0, arg1, arg2) { + getObject(arg0).bindTexture(arg1 >>> 0, getObject(arg2)); + }; + imports.wbg.__wbg_blendFunc_533de6de45b80a09 = function (arg0, arg1, arg2) { + getObject(arg0).blendFunc(arg1 >>> 0, arg2 >>> 0); + }; + imports.wbg.__wbg_clear_2db2efe323bfdf68 = function (arg0, arg1) { + getObject(arg0).clear(arg1 >>> 0); + }; + imports.wbg.__wbg_clearColor_7a7d04702f7e38e5 = function (arg0, arg1, arg2, arg3, arg4) { + getObject(arg0).clearColor(arg1, arg2, arg3, arg4); + }; + imports.wbg.__wbg_compileShader_6bf78b425d5c98e1 = function (arg0, arg1) { + getObject(arg0).compileShader(getObject(arg1)); + }; + imports.wbg.__wbg_createBuffer_323425af422748ac = function (arg0) { + const ret = getObject(arg0).createBuffer(); + return isLikeNone(ret) ? 0 : addHeapObject(ret); + }; + imports.wbg.__wbg_createFramebuffer_1684a99697ac9563 = function (arg0) { + const ret = getObject(arg0).createFramebuffer(); + return isLikeNone(ret) ? 0 : addHeapObject(ret); + }; + imports.wbg.__wbg_createProgram_4eaf3b97b5747a62 = function (arg0) { + const ret = getObject(arg0).createProgram(); + return isLikeNone(ret) ? 0 : addHeapObject(ret); + }; + imports.wbg.__wbg_createShader_429776c9dd6fb87b = function (arg0, arg1) { + const ret = getObject(arg0).createShader(arg1 >>> 0); + return isLikeNone(ret) ? 0 : addHeapObject(ret); + }; + imports.wbg.__wbg_createTexture_1bf4d6fec570124b = function (arg0) { + const ret = getObject(arg0).createTexture(); + return isLikeNone(ret) ? 0 : addHeapObject(ret); + }; + imports.wbg.__wbg_disable_e02106ca6c7002d6 = function (arg0, arg1) { + getObject(arg0).disable(arg1 >>> 0); + }; + imports.wbg.__wbg_drawArrays_c91ce3f736bf1f2a = function (arg0, arg1, arg2, arg3) { + getObject(arg0).drawArrays(arg1 >>> 0, arg2, arg3); + }; + imports.wbg.__wbg_drawElements_a9529eefaf2008bd = function (arg0, arg1, arg2, arg3, arg4) { + getObject(arg0).drawElements(arg1 >>> 0, arg2, arg3 >>> 0, arg4); + }; + imports.wbg.__wbg_enable_195891416c520019 = function (arg0, arg1) { + getObject(arg0).enable(arg1 >>> 0); + }; + imports.wbg.__wbg_enableVertexAttribArray_8804480c2ea0bb72 = function (arg0, arg1) { + getObject(arg0).enableVertexAttribArray(arg1 >>> 0); + }; + imports.wbg.__wbg_framebufferTexture2D_e88fcbd7f8523bb8 = function (arg0, arg1, arg2, arg3, arg4, arg5) { + getObject(arg0).framebufferTexture2D(arg1 >>> 0, arg2 >>> 0, arg3 >>> 0, getObject(arg4), arg5); + }; + imports.wbg.__wbg_getError_7191ad6ea53607fe = function (arg0) { + const ret = getObject(arg0).getError(); + return ret; + }; + imports.wbg.__wbg_getExtension_77909f6d51d49d4d = function () { + return handleError(function (arg0, arg1, arg2) { + const ret = getObject(arg0).getExtension(getStringFromWasm0(arg1, arg2)); + return isLikeNone(ret) ? 0 : addHeapObject(ret); + }, arguments) + }; + imports.wbg.__wbg_getProgramInfoLog_b81bc53188e286fa = function (arg0, arg1, arg2) { + const ret = getObject(arg1).getProgramInfoLog(getObject(arg2)); + var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); + var len1 = WASM_VECTOR_LEN; + getInt32Memory0()[arg0 / 4 + 1] = len1; + getInt32Memory0()[arg0 / 4 + 0] = ptr1; + }; + imports.wbg.__wbg_getProgramParameter_35522a0bfdfaad27 = function (arg0, arg1, arg2) { + const ret = getObject(arg0).getProgramParameter(getObject(arg1), arg2 >>> 0); + return addHeapObject(ret); + }; + imports.wbg.__wbg_getShaderInfoLog_968b93e75477d725 = function (arg0, arg1, arg2) { + const ret = getObject(arg1).getShaderInfoLog(getObject(arg2)); + var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); + var len1 = WASM_VECTOR_LEN; + getInt32Memory0()[arg0 / 4 + 1] = len1; + getInt32Memory0()[arg0 / 4 + 0] = ptr1; + }; + imports.wbg.__wbg_getShaderParameter_ac2727ae4fe7648e = function (arg0, arg1, arg2) { + const ret = getObject(arg0).getShaderParameter(getObject(arg1), arg2 >>> 0); + return addHeapObject(ret); + }; + imports.wbg.__wbg_getUniformLocation_9f6eb60c560a347b = function (arg0, arg1, arg2, arg3) { + const ret = getObject(arg0).getUniformLocation(getObject(arg1), getStringFromWasm0(arg2, arg3)); + return isLikeNone(ret) ? 0 : addHeapObject(ret); + }; + imports.wbg.__wbg_linkProgram_33998194075d71fb = function (arg0, arg1) { + getObject(arg0).linkProgram(getObject(arg1)); + }; + imports.wbg.__wbg_shaderSource_1cb7c64dc7d1a500 = function (arg0, arg1, arg2, arg3) { + getObject(arg0).shaderSource(getObject(arg1), getStringFromWasm0(arg2, arg3)); + }; + imports.wbg.__wbg_texParameteri_85dad939f62a15aa = function (arg0, arg1, arg2, arg3) { + getObject(arg0).texParameteri(arg1 >>> 0, arg2 >>> 0, arg3); + }; + imports.wbg.__wbg_uniform1i_d2e61a6a43889648 = function (arg0, arg1, arg2) { + getObject(arg0).uniform1i(getObject(arg1), arg2); + }; + imports.wbg.__wbg_uniform3f_8364a0959b6c1570 = function (arg0, arg1, arg2, arg3, arg4) { + getObject(arg0).uniform3f(getObject(arg1), arg2, arg3, arg4); + }; + imports.wbg.__wbg_useProgram_3683cf6f60939dcd = function (arg0, arg1) { + getObject(arg0).useProgram(getObject(arg1)); + }; + imports.wbg.__wbg_vertexAttribPointer_316ffe2f0458fde7 = function (arg0, arg1, arg2, arg3, arg4, arg5, arg6) { + getObject(arg0).vertexAttribPointer(arg1 >>> 0, arg2, arg3 >>> 0, arg4 !== 0, arg5, arg6); + }; + imports.wbg.__wbg_getElementById_cc0e0d931b0d9a28 = function (arg0, arg1, arg2) { + const ret = getObject(arg0).getElementById(getStringFromWasm0(arg1, arg2)); + return isLikeNone(ret) ? 0 : addHeapObject(ret); + }; + imports.wbg.__wbg_instanceof_HtmlCanvasElement_da5f9efa0688cf6d = function (arg0) { + let result; + try { + result = getObject(arg0) instanceof HTMLCanvasElement; + } catch { + result = false; + } + const ret = result; + return ret; + }; + imports.wbg.__wbg_setwidth_a667a942dba6656e = function (arg0, arg1) { + getObject(arg0).width = arg1 >>> 0; + }; + imports.wbg.__wbg_setheight_a747d440760fe5aa = function (arg0, arg1) { + getObject(arg0).height = arg1 >>> 0; + }; + imports.wbg.__wbg_getContext_7c5944ea807bf5d3 = function () { + return handleError(function (arg0, arg1, arg2) { + const ret = getObject(arg0).getContext(getStringFromWasm0(arg1, arg2)); + return isLikeNone(ret) ? 0 : addHeapObject(ret); + }, arguments) + }; + imports.wbg.__wbg_offsetX_5a58f16f6c3a41b6 = function (arg0) { + const ret = getObject(arg0).offsetX; + return ret; + }; + imports.wbg.__wbg_offsetY_c45b4956f6429a95 = function (arg0) { + const ret = getObject(arg0).offsetY; + return ret; + }; + imports.wbg.__wbg_now_0cfdc90c97d0c24b = function (arg0) { + const ret = getObject(arg0).now(); + return ret; + }; + imports.wbg.__wbg_instanceof_Window_9029196b662bc42a = function (arg0) { + let result; + try { + result = getObject(arg0) instanceof Window; + } catch { + result = false; + } + const ret = result; + return ret; + }; + imports.wbg.__wbg_charCode_75cea1a3a6d66388 = function (arg0) { + const ret = getObject(arg0).charCode; + return ret; + }; + imports.wbg.__wbg_keyCode_dfa86be31f5ef90c = function (arg0) { + const ret = getObject(arg0).keyCode; + return ret; + }; + imports.wbg.__wbg_code_96d6322b968b2d17 = function (arg0, arg1) { + const ret = getObject(arg1).code; + const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); + const len1 = WASM_VECTOR_LEN; + getInt32Memory0()[arg0 / 4 + 1] = len1; + getInt32Memory0()[arg0 / 4 + 0] = ptr1; + }; + imports.wbg.__wbg_getModifierState_5102ee8843516d2f = function (arg0, arg1, arg2) { + const ret = getObject(arg0).getModifierState(getStringFromWasm0(arg1, arg2)); + return ret; + }; + imports.wbg.__wbg_document_f7ace2b956f30a4f = function (arg0) { + const ret = getObject(arg0).document; + return isLikeNone(ret) ? 0 : addHeapObject(ret); + }; + imports.wbg.__wbg_performance_2c295061c8b01e0b = function (arg0) { + const ret = getObject(arg0).performance; + return isLikeNone(ret) ? 0 : addHeapObject(ret); + }; + imports.wbg.__wbg_setonkeydown_933cca3c9000a932 = function (arg0, arg1) { + getObject(arg0).onkeydown = getObject(arg1); + }; + imports.wbg.__wbg_setonkeyup_0dfb23e81d0afdde = function (arg0, arg1) { + getObject(arg0).onkeyup = getObject(arg1); + }; + imports.wbg.__wbg_requestAnimationFrame_d082200514b6674d = function () { + return handleError(function (arg0, arg1) { + const ret = getObject(arg0).requestAnimationFrame(getObject(arg1)); + return ret; + }, arguments) + }; + imports.wbg.__wbg_setonmousedown_4f38d9c057bbfcbd = function (arg0, arg1) { + getObject(arg0).onmousedown = getObject(arg1); + }; + imports.wbg.__wbg_setonmousemove_c0b17753786f3544 = function (arg0, arg1) { + getObject(arg0).onmousemove = getObject(arg1); + }; + imports.wbg.__wbg_setonmouseup_4b447fa380e33802 = function (arg0, arg1) { + getObject(arg0).onmouseup = getObject(arg1); + }; + imports.wbg.__wbg_bufferData_a11a9f65f31e7256 = function (arg0, arg1, arg2, arg3) { + getObject(arg0).bufferData(arg1 >>> 0, getObject(arg2), arg3 >>> 0); + }; + imports.wbg.__wbg_texImage2D_6175916e58c59bc7 = function () { + return handleError(function (arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) { + getObject(arg0).texImage2D(arg1 >>> 0, arg2, arg3, arg4, arg5, arg6, arg7 >>> 0, arg8 >>> 0, getObject(arg9)); + }, arguments) + }; + imports.wbg.__wbg_attachShader_b65b695055670cb5 = function (arg0, arg1, arg2) { + getObject(arg0).attachShader(getObject(arg1), getObject(arg2)); + }; + imports.wbg.__wbg_bindBuffer_313561e5bc0e533f = function (arg0, arg1, arg2) { + getObject(arg0).bindBuffer(arg1 >>> 0, getObject(arg2)); + }; + imports.wbg.__wbg_bindFramebuffer_56bf6536a4ced0ec = function (arg0, arg1, arg2) { + getObject(arg0).bindFramebuffer(arg1 >>> 0, getObject(arg2)); + }; + imports.wbg.__wbg_bindTexture_9cb5c770d1ba2cca = function (arg0, arg1, arg2) { + getObject(arg0).bindTexture(arg1 >>> 0, getObject(arg2)); + }; + imports.wbg.__wbg_blendFunc_fbe9d3a688fe71c3 = function (arg0, arg1, arg2) { + getObject(arg0).blendFunc(arg1 >>> 0, arg2 >>> 0); + }; + imports.wbg.__wbg_clear_2ccea1f65b510c97 = function (arg0, arg1) { + getObject(arg0).clear(arg1 >>> 0); + }; + imports.wbg.__wbg_clearColor_de587608b28bc7ed = function (arg0, arg1, arg2, arg3, arg4) { + getObject(arg0).clearColor(arg1, arg2, arg3, arg4); + }; + imports.wbg.__wbg_compileShader_d88d0a8cd9b72b4d = function (arg0, arg1) { + getObject(arg0).compileShader(getObject(arg1)); + }; + imports.wbg.__wbg_createBuffer_59051f4461e7c5e2 = function (arg0) { + const ret = getObject(arg0).createBuffer(); + return isLikeNone(ret) ? 0 : addHeapObject(ret); + }; + imports.wbg.__wbg_createFramebuffer_223c1212ad76affc = function (arg0) { + const ret = getObject(arg0).createFramebuffer(); + return isLikeNone(ret) ? 0 : addHeapObject(ret); + }; + imports.wbg.__wbg_createProgram_88dbe21c0b682e1a = function (arg0) { + const ret = getObject(arg0).createProgram(); + return isLikeNone(ret) ? 0 : addHeapObject(ret); + }; + imports.wbg.__wbg_createShader_9d7d388633caad18 = function (arg0, arg1) { + const ret = getObject(arg0).createShader(arg1 >>> 0); + return isLikeNone(ret) ? 0 : addHeapObject(ret); + }; + imports.wbg.__wbg_createTexture_9d0bb4d741b8ad76 = function (arg0) { + const ret = getObject(arg0).createTexture(); + return isLikeNone(ret) ? 0 : addHeapObject(ret); + }; + imports.wbg.__wbg_disable_5cf2070641fa2ed7 = function (arg0, arg1) { + getObject(arg0).disable(arg1 >>> 0); + }; + imports.wbg.__wbg_drawArrays_d5c7dc2b2376c85a = function (arg0, arg1, arg2, arg3) { + getObject(arg0).drawArrays(arg1 >>> 0, arg2, arg3); + }; + imports.wbg.__wbg_drawElements_3316ee0cd1117c2a = function (arg0, arg1, arg2, arg3, arg4) { + getObject(arg0).drawElements(arg1 >>> 0, arg2, arg3 >>> 0, arg4); + }; + imports.wbg.__wbg_enable_8965e69c596f0a94 = function (arg0, arg1) { + getObject(arg0).enable(arg1 >>> 0); + }; + imports.wbg.__wbg_enableVertexAttribArray_2b0475db43533cf2 = function (arg0, arg1) { + getObject(arg0).enableVertexAttribArray(arg1 >>> 0); + }; + imports.wbg.__wbg_framebufferTexture2D_953e69a8bec22fa9 = function (arg0, arg1, arg2, arg3, arg4, arg5) { + getObject(arg0).framebufferTexture2D(arg1 >>> 0, arg2 >>> 0, arg3 >>> 0, getObject(arg4), arg5); + }; + imports.wbg.__wbg_getError_1e5ec1ec9e58b323 = function (arg0) { + const ret = getObject(arg0).getError(); + return ret; + }; + imports.wbg.__wbg_getProgramInfoLog_0b7af4ad85fa52a4 = function (arg0, arg1, arg2) { + const ret = getObject(arg1).getProgramInfoLog(getObject(arg2)); + var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); + var len1 = WASM_VECTOR_LEN; + getInt32Memory0()[arg0 / 4 + 1] = len1; + getInt32Memory0()[arg0 / 4 + 0] = ptr1; + }; + imports.wbg.__wbg_getProgramParameter_2a3735278367f8bc = function (arg0, arg1, arg2) { + const ret = getObject(arg0).getProgramParameter(getObject(arg1), arg2 >>> 0); + return addHeapObject(ret); + }; + imports.wbg.__wbg_getShaderInfoLog_979aafa403ffb252 = function (arg0, arg1, arg2) { + const ret = getObject(arg1).getShaderInfoLog(getObject(arg2)); + var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); + var len1 = WASM_VECTOR_LEN; + getInt32Memory0()[arg0 / 4 + 1] = len1; + getInt32Memory0()[arg0 / 4 + 0] = ptr1; + }; + imports.wbg.__wbg_getShaderParameter_e8054f1d9026fb70 = function (arg0, arg1, arg2) { + const ret = getObject(arg0).getShaderParameter(getObject(arg1), arg2 >>> 0); + return addHeapObject(ret); + }; + imports.wbg.__wbg_getUniformLocation_688976233799a45a = function (arg0, arg1, arg2, arg3) { + const ret = getObject(arg0).getUniformLocation(getObject(arg1), getStringFromWasm0(arg2, arg3)); + return isLikeNone(ret) ? 0 : addHeapObject(ret); + }; + imports.wbg.__wbg_linkProgram_9a2d12d120d99917 = function (arg0, arg1) { + getObject(arg0).linkProgram(getObject(arg1)); + }; + imports.wbg.__wbg_shaderSource_f435f9b74440bb54 = function (arg0, arg1, arg2, arg3) { + getObject(arg0).shaderSource(getObject(arg1), getStringFromWasm0(arg2, arg3)); + }; + imports.wbg.__wbg_texParameteri_1f17358e51eb8069 = function (arg0, arg1, arg2, arg3) { + getObject(arg0).texParameteri(arg1 >>> 0, arg2 >>> 0, arg3); + }; + imports.wbg.__wbg_uniform1i_9f94ef0ba6b3cc66 = function (arg0, arg1, arg2) { + getObject(arg0).uniform1i(getObject(arg1), arg2); + }; + imports.wbg.__wbg_uniform3f_c682f4b32f713d1a = function (arg0, arg1, arg2, arg3, arg4) { + getObject(arg0).uniform3f(getObject(arg1), arg2, arg3, arg4); + }; + imports.wbg.__wbg_useProgram_019eb6df066fabf5 = function (arg0, arg1) { + getObject(arg0).useProgram(getObject(arg1)); + }; + imports.wbg.__wbg_vertexAttribPointer_ca11984ee8843c0a = function (arg0, arg1, arg2, arg3, arg4, arg5, arg6) { + getObject(arg0).vertexAttribPointer(arg1 >>> 0, arg2, arg3 >>> 0, arg4 !== 0, arg5, arg6); + }; + imports.wbg.__wbg_bindVertexArrayOES_b7d9da7e073aa6b5 = function (arg0, arg1) { + getObject(arg0).bindVertexArrayOES(getObject(arg1)); + }; + imports.wbg.__wbg_createVertexArrayOES_6a3c3a5a68201f8f = function (arg0) { + const ret = getObject(arg0).createVertexArrayOES(); + return isLikeNone(ret) ? 0 : addHeapObject(ret); + }; + imports.wbg.__wbg_newnoargs_581967eacc0e2604 = function (arg0, arg1) { + const ret = new Function(getStringFromWasm0(arg0, arg1)); + return addHeapObject(ret); + }; + imports.wbg.__wbg_get_97b561fb56f034b5 = function () { + return handleError(function (arg0, arg1) { + const ret = Reflect.get(getObject(arg0), getObject(arg1)); + return addHeapObject(ret); + }, arguments) + }; + imports.wbg.__wbg_call_cb65541d95d71282 = function () { + return handleError(function (arg0, arg1) { + const ret = getObject(arg0).call(getObject(arg1)); + return addHeapObject(ret); + }, arguments) + }; + imports.wbg.__wbg_self_1ff1d729e9aae938 = function () { + return handleError(function () { + const ret = self.self; + return addHeapObject(ret); + }, arguments) + }; + imports.wbg.__wbg_window_5f4faef6c12b79ec = function () { + return handleError(function () { + const ret = window.window; + return addHeapObject(ret); + }, arguments) + }; + imports.wbg.__wbg_globalThis_1d39714405582d3c = function () { + return handleError(function () { + const ret = globalThis.globalThis; + return addHeapObject(ret); + }, arguments) + }; + imports.wbg.__wbg_global_651f05c6a0944d1c = function () { + return handleError(function () { + const ret = global.global; + return addHeapObject(ret); + }, arguments) + }; + imports.wbg.__wbg_now_9c5990bda04c7e53 = function () { + const ret = Date.now(); + return ret; + }; + imports.wbg.__wbg_buffer_085ec1f694018c4f = function (arg0) { + const ret = getObject(arg0).buffer; + return addHeapObject(ret); + }; + imports.wbg.__wbg_newwithbyteoffsetandlength_828b952f0e692245 = function (arg0, arg1, arg2) { + const ret = new Int8Array(getObject(arg0), arg1 >>> 0, arg2 >>> 0); + return addHeapObject(ret); + }; + imports.wbg.__wbg_newwithbyteoffsetandlength_735ed5ea2ae07fe9 = function (arg0, arg1, arg2) { + const ret = new Int16Array(getObject(arg0), arg1 >>> 0, arg2 >>> 0); + return addHeapObject(ret); + }; + imports.wbg.__wbg_newwithbyteoffsetandlength_9f43b22ab631d1d6 = function (arg0, arg1, arg2) { + const ret = new Int32Array(getObject(arg0), arg1 >>> 0, arg2 >>> 0); + return addHeapObject(ret); + }; + imports.wbg.__wbg_newwithbyteoffsetandlength_6da8e527659b86aa = function (arg0, arg1, arg2) { + const ret = new Uint8Array(getObject(arg0), arg1 >>> 0, arg2 >>> 0); + return addHeapObject(ret); + }; + imports.wbg.__wbg_new_8125e318e6245eed = function (arg0) { + const ret = new Uint8Array(getObject(arg0)); + return addHeapObject(ret); + }; + imports.wbg.__wbg_set_5cf90238115182c3 = function (arg0, arg1, arg2) { + getObject(arg0).set(getObject(arg1), arg2 >>> 0); + }; + imports.wbg.__wbg_length_72e2208bbc0efc61 = function (arg0) { + const ret = getObject(arg0).length; + return ret; + }; + imports.wbg.__wbg_newwithbyteoffsetandlength_31ff1024ef0c63c7 = function (arg0, arg1, arg2) { + const ret = new Uint16Array(getObject(arg0), arg1 >>> 0, arg2 >>> 0); + return addHeapObject(ret); + }; + imports.wbg.__wbg_newwithbyteoffsetandlength_6df0e8c3efd2a5d3 = function (arg0, arg1, arg2) { + const ret = new Uint32Array(getObject(arg0), arg1 >>> 0, arg2 >>> 0); + return addHeapObject(ret); + }; + imports.wbg.__wbg_newwithbyteoffsetandlength_69193e31c844b792 = function (arg0, arg1, arg2) { + const ret = new Float32Array(getObject(arg0), arg1 >>> 0, arg2 >>> 0); + return addHeapObject(ret); + }; + imports.wbg.__wbg_newwithlength_e5d69174d6984cd7 = function (arg0) { + const ret = new Uint8Array(arg0 >>> 0); + return addHeapObject(ret); + }; + imports.wbg.__wbg_subarray_13db269f57aa838d = function (arg0, arg1, arg2) { + const ret = getObject(arg0).subarray(arg1 >>> 0, arg2 >>> 0); + return addHeapObject(ret); + }; + imports.wbg.__wbindgen_debug_string = function (arg0, arg1) { + const ret = debugString(getObject(arg1)); + const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); + const len1 = WASM_VECTOR_LEN; + getInt32Memory0()[arg0 / 4 + 1] = len1; + getInt32Memory0()[arg0 / 4 + 0] = ptr1; + }; + imports.wbg.__wbindgen_throw = function (arg0, arg1) { + throw new Error(getStringFromWasm0(arg0, arg1)); + }; + imports.wbg.__wbindgen_memory = function () { + const ret = wasm.memory; + return addHeapObject(ret); + }; + imports.wbg.__wbindgen_closure_wrapper694 = function (arg0, arg1, arg2) { + const ret = makeMutClosure(arg0, arg1, 124, __wbg_adapter_20); + return addHeapObject(ret); + }; + imports.wbg.__wbindgen_closure_wrapper2716 = function (arg0, arg1, arg2) { + const ret = makeMutClosure(arg0, arg1, 518, __wbg_adapter_23); + return addHeapObject(ret); + }; + imports.wbg.__wbindgen_closure_wrapper2718 = function (arg0, arg1, arg2) { + const ret = makeMutClosure(arg0, arg1, 518, __wbg_adapter_23); + return addHeapObject(ret); + }; - return imports; -} - -function __wbg_init_memory(imports, maybe_memory) { - -} - -function __wbg_finalize_init(instance, module) { - wasm = instance.exports; - __wbg_init.__wbindgen_wasm_module = module; - cachedInt32Memory0 = null; - cachedUint8Memory0 = null; - - wasm.__wbindgen_start(); - return wasm; -} - -function initSync(module) { - if (wasm !== undefined) return wasm; - - const imports = __wbg_get_imports(); - - __wbg_init_memory(imports); - - if (!(module instanceof WebAssembly.Module)) { - module = new WebAssembly.Module(module); + return imports; } - const instance = new WebAssembly.Instance(module, imports); + function __wbg_init_memory(imports, maybe_memory) { - return __wbg_finalize_init(instance, module); -} - -async function __wbg_init(input) { - if (wasm !== undefined) return wasm; - - if (typeof input === 'undefined' && script_src !== 'undefined') { - input = script_src.replace(/\.js$/, '_bg.wasm'); - } - const imports = __wbg_get_imports(); - - if (typeof input === 'string' || (typeof Request === 'function' && input instanceof Request) || (typeof URL === 'function' && input instanceof URL)) { - input = fetch(input); } - __wbg_init_memory(imports); + function __wbg_finalize_init(instance, module) { + wasm = instance.exports; + __wbg_init.__wbindgen_wasm_module = module; + cachedInt32Memory0 = null; + cachedUint8Memory0 = null; - const { instance, module } = await __wbg_load(await input, imports); + wasm.__wbindgen_start(); + return wasm; + } - return __wbg_finalize_init(instance, module); -} + function initSync(module) { + if (wasm !== undefined) return wasm; -wasm_bindgen = Object.assign(__wbg_init, { initSync }, __exports); + const imports = __wbg_get_imports(); + + __wbg_init_memory(imports); + + if (!(module instanceof WebAssembly.Module)) { + module = new WebAssembly.Module(module); + } + + const instance = new WebAssembly.Instance(module, imports); + + return __wbg_finalize_init(instance, module); + } + + async function __wbg_init(input) { + if (wasm !== undefined) return wasm; + + if (typeof input === 'undefined' && script_src !== 'undefined') { + input = script_src.replace(/\.js$/, '_bg.wasm'); + } + const imports = __wbg_get_imports(); + + if (typeof input === 'string' || (typeof Request === 'function' && input instanceof Request) || (typeof URL === 'function' && input instanceof URL)) { + input = fetch(input); + } + + __wbg_init_memory(imports); + + const { instance, module } = await __wbg_load(await input, imports); + + return __wbg_finalize_init(instance, module); + } + + wasm_bindgen = Object.assign(__wbg_init, { initSync }, __exports); })();