From dedbb0927cfa7c79f544154e1e5551af9f4de11b Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Tue, 1 Feb 2022 15:41:08 -0500 Subject: [PATCH] Update docs --- src/components.rs | 6 ++++-- src/effects.rs | 1 + src/gamesystem.rs | 1 + src/gui.rs | 1 + src/map_builders.rs | 1 + src/player.rs | 1 + src/random_table.rs | 1 + src/raws.rs | 1 + src/saveload_system.rs | 5 +++++ src/spawner.rs | 1 + src/state.rs | 3 ++- 11 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/components.rs b/src/components.rs index cd5c9f0..53803b2 100644 --- a/src/components.rs +++ b/src/components.rs @@ -1,4 +1,4 @@ -// ! The `C` in `ECS` +//! The `C` in `ECS` mod enums; mod serialize; mod tags; @@ -25,7 +25,9 @@ pub struct Position { impl From<(i32, i32)> for Position { fn from(f: (i32, i32)) -> Self { - Position { x: f.0, y: f.1 } + let (x, y) = f; + + Position { x, y } } } diff --git a/src/effects.rs b/src/effects.rs index 333971c..e41d8e6 100644 --- a/src/effects.rs +++ b/src/effects.rs @@ -1,3 +1,4 @@ +//! The effects system mod damage; mod hunger; mod movement; diff --git a/src/gamesystem.rs b/src/gamesystem.rs index 3e4648a..16cb307 100644 --- a/src/gamesystem.rs +++ b/src/gamesystem.rs @@ -1,3 +1,4 @@ +//! Miscellaneous common functions use crate::{Skill, Skills}; pub fn attr_bonus(value: i32) -> i32 { diff --git a/src/gui.rs b/src/gui.rs index 11fa7f8..3c2c89f 100644 --- a/src/gui.rs +++ b/src/gui.rs @@ -1,3 +1,4 @@ +//! Interface-building output mod enums; mod menu; mod tooltip; diff --git a/src/map_builders.rs b/src/map_builders.rs index 77a829f..2276a3a 100644 --- a/src/map_builders.rs +++ b/src/map_builders.rs @@ -1,3 +1,4 @@ +//! Procedurally generated map builders mod area_ending_point; mod area_starting_points; mod bsp_dungeon; diff --git a/src/player.rs b/src/player.rs index 0c699b3..020b0c2 100644 --- a/src/player.rs +++ b/src/player.rs @@ -1,3 +1,4 @@ +//! Player-related functionality use std::cmp::{max, min}; use rltk::{DistanceAlg, Point, RandomNumberGenerator, Rltk, VirtualKeyCode}; diff --git a/src/random_table.rs b/src/random_table.rs index a292bde..b37b100 100644 --- a/src/random_table.rs +++ b/src/random_table.rs @@ -1,3 +1,4 @@ +//! Weighted random generation of entities use ::rltk::RandomNumberGenerator; use crate::raws::{spawn_type_by_name, RawMaster, SpawnTableType}; diff --git a/src/raws.rs b/src/raws.rs index 0436e57..cfce031 100644 --- a/src/raws.rs +++ b/src/raws.rs @@ -1,3 +1,4 @@ +//! Generates entities based on spec files mod faction_structs; mod item_structs; mod loot_structs; diff --git a/src/saveload_system.rs b/src/saveload_system.rs index fe03b9d..bf04431 100644 --- a/src/saveload_system.rs +++ b/src/saveload_system.rs @@ -1,3 +1,4 @@ +//! Serializes / Deserializes game data for saving and loading use std::fs::{self, File}; use std::path::Path; @@ -29,6 +30,7 @@ macro_rules! serialize_individually { #[cfg(target_arch = "wasm32")] pub fn save_game(_ecs: &mut World) {} +/// Saves the game data to a file #[cfg(not(target_arch = "wasm32"))] pub fn save_game(ecs: &mut World) { // Create helper @@ -152,6 +154,7 @@ pub fn save_game(ecs: &mut World) { .expect("Failed to clean up savehelper2 component"); } +/// Does the save game exist? pub fn does_save_exist() -> bool { Path::new("./savegame.json").exists() } @@ -171,6 +174,7 @@ macro_rules! deserialize_individually { }; } +/// Loads the game data from a file pub fn load_game(ecs: &mut World) { { // Delete everything @@ -319,6 +323,7 @@ pub fn load_game(ecs: &mut World) { .expect("Unable to delete helper2 entity"); } +/// Deletes the save file, if it exists pub fn delete_save() { if Path::new("./savegame.json").exists() { std::fs::remove_file("./savegame.json").expect("Failed to delete save file."); diff --git a/src/spawner.rs b/src/spawner.rs index 7ade2c9..7988e04 100644 --- a/src/spawner.rs +++ b/src/spawner.rs @@ -1,3 +1,4 @@ +//! Spawns things use std::collections::HashMap; use ::rltk::{Point, RandomNumberGenerator}; diff --git a/src/state.rs b/src/state.rs index 2d2e8d1..916ecc4 100644 --- a/src/state.rs +++ b/src/state.rs @@ -1,4 +1,4 @@ -//! +//! Game state use ::rltk::{GameState, Point, Rltk}; use ::specs::prelude::*; @@ -59,6 +59,7 @@ pub enum RunState { ShowIdentify, } +/// The main wrapper around the game's state pub struct State { pub ecs: World, mapgen_next_state: Option,