i/o stuff: skeleton framework for morgue files, and a config.toml file

This commit is contained in:
Llywelwyn 2023-08-24 22:34:05 +01:00
parent b2010958e7
commit 3023a33cc5
17 changed files with 209 additions and 56 deletions

View file

@ -1,4 +1,4 @@
use crate::{ gamelog, raws, spawner, Clock, Map, RandomNumberGenerator, TakingTurn, LOG_SPAWNING };
use crate::{ config::CONFIG, gamelog, raws, spawner, Clock, Map, RandomNumberGenerator, TakingTurn };
use specs::prelude::*;
const TRY_SPAWN_CHANCE: i32 = 70;
@ -22,7 +22,7 @@ pub fn try_spawn_interval(ecs: &mut World) {
}
}
if try_spawn {
if LOG_SPAWNING {
if CONFIG.logging.log_spawning {
rltk::console::log("SPAWNINFO: Trying spawn.");
}
spawn_random_mob_in_free_nonvisible_tile(ecs);
@ -36,7 +36,7 @@ fn spawn_random_mob_in_free_nonvisible_tile(ecs: &mut World) {
rltk::console::log(player_level);
let difficulty = (map.difficulty + player_level) / 2;
if available_tiles.len() == 0 {
if LOG_SPAWNING {
if CONFIG.logging.log_spawning {
rltk::console::log("SPAWNINFO: No free tiles; not spawning anything..");
}
return;
@ -55,7 +55,7 @@ fn spawn_random_mob_in_free_nonvisible_tile(ecs: &mut World) {
std::mem::drop(rng);
// For every idx in the spawn list, spawn mob.
for idx in spawn_locations {
if LOG_SPAWNING {
if CONFIG.logging.log_spawning {
rltk::console::log(format!("SPAWNINFO: Spawning {} at {}, {}.", key, idx.0, idx.1));
}
raws::spawn_named_entity(

View file

@ -1,6 +1,7 @@
use super::{ Map, Point, TileType };
use crate::config::glyphs::*;
use crate::config::visuals::*;
use crate::config::CONFIG;
use rltk::prelude::*;
use std::ops::{ Add, Mul };
@ -19,13 +20,17 @@ pub fn get_tile_renderables_for_id(idx: usize, map: &Map, other_pos: Option<Poin
fg = fg.add(map.additional_fg_offset);
(fg, bg) = apply_colour_offset(fg, bg, map, idx);
if WITH_SCANLINES && WITH_SCANLINES_BRIGHTEN_AMOUNT > 0.0 {
if CONFIG.visuals.with_scanlines && WITH_SCANLINES_BRIGHTEN_AMOUNT > 0.0 {
(fg, bg) = brighten_by(fg, bg, WITH_SCANLINES_BRIGHTEN_AMOUNT);
}
bg = apply_bloodstain_if_necessary(bg, map, idx);
let (mut multiplier, mut nonvisible, mut darken) = (1.0, false, false);
if !map.visible_tiles[idx] {
multiplier = if WITH_SCANLINES { NON_VISIBLE_MULTIPLIER_IF_SCANLINES } else { NON_VISIBLE_MULTIPLIER };
multiplier = if CONFIG.visuals.with_scanlines {
NON_VISIBLE_MULTIPLIER_IF_SCANLINES
} else {
NON_VISIBLE_MULTIPLIER
};
nonvisible = true;
}
if other_pos.is_some() && WITH_DARKEN_BY_DISTANCE && !nonvisible {
@ -34,7 +39,7 @@ pub fn get_tile_renderables_for_id(idx: usize, map: &Map, other_pos: Option<Poin
other_pos.unwrap()
);
multiplier = distance.clamp(
if WITH_SCANLINES {
if CONFIG.visuals.with_scanlines {
NON_VISIBLE_MULTIPLIER_IF_SCANLINES
} else {
NON_VISIBLE_MULTIPLIER
@ -266,7 +271,10 @@ fn darken_by_distance(pos: Point, other_pos: Point) -> f32 {
(distance - START_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 - (if WITH_SCANLINES { MAX_DARKENING_IF_SCANLINES } else { MAX_DARKENING }));
return (
1.0 -
interp_factor * (1.0 - (if CONFIG.visuals.with_scanlines { MAX_DARKENING_IF_SCANLINES } else { MAX_DARKENING }))
);
}
fn brighten_by(mut fg: RGB, mut bg: RGB, amount: f32) -> (RGB, RGB) {