fixes message log wrapping - sort of
it's an improvement - messages will wrap if the added fragment is longer than the maximum width, but it still causes issues if an *individual* fragment is longer than the width. the proper solution here, i think, is to get rid of the whole fragment system and just log words and newlines, and not have to bother with any of this.
This commit is contained in:
parent
1e25d062db
commit
650afaf821
5 changed files with 48 additions and 25 deletions
|
|
@ -19,19 +19,33 @@ pub fn clear_log() {
|
|||
LOG.lock().unwrap().clear();
|
||||
}
|
||||
|
||||
pub fn print_log(console: &mut Box<dyn Console>, pos: Point, descending: bool, len: usize) {
|
||||
pub fn print_log(console: &mut Box<dyn Console>, pos: Point, descending: bool, len: usize, maximum_len: i32) {
|
||||
let mut y = pos.y;
|
||||
let mut x = pos.x;
|
||||
LOG.lock().unwrap().iter().rev().take(len).for_each(|log| {
|
||||
let mut len_so_far: i32 = 0;
|
||||
let mut entry_len = 0;
|
||||
log.iter().for_each(|frag| {
|
||||
console.print_color(x, y, frag.colour.into(), RGB::named(rltk::BLACK).into(), &frag.text);
|
||||
entry_len += frag.text.len() as i32;
|
||||
});
|
||||
let lines = entry_len / maximum_len;
|
||||
y -= lines;
|
||||
log.iter().for_each(|frag| {
|
||||
if len_so_far + frag.text.len() as i32 > maximum_len {
|
||||
y += 1;
|
||||
x = pos.x;
|
||||
len_so_far = 0;
|
||||
}
|
||||
if y > pos.y - len as i32 {
|
||||
console.print_color(x, y, frag.colour.into(), RGB::named(rltk::BLACK).into(), &frag.text);
|
||||
}
|
||||
x += frag.text.len() as i32;
|
||||
x += 0;
|
||||
len_so_far += frag.text.len() as i32;
|
||||
});
|
||||
if descending {
|
||||
y += 1;
|
||||
} else {
|
||||
y -= 1;
|
||||
y -= 1 + lines;
|
||||
}
|
||||
x = pos.x;
|
||||
});
|
||||
|
|
@ -40,9 +54,7 @@ pub fn print_log(console: &mut Box<dyn Console>, pos: Point, descending: bool, l
|
|||
pub fn setup_log() {
|
||||
clear_log();
|
||||
events::clear_events();
|
||||
for _ in 0..5 {
|
||||
Logger::new().log();
|
||||
}
|
||||
|
||||
Logger::new()
|
||||
.append("Welcome!")
|
||||
.colour(rltk::CYAN)
|
||||
|
|
|
|||
|
|
@ -120,8 +120,8 @@ pub fn draw_ui(ecs: &World, ctx: &mut Rltk) {
|
|||
}
|
||||
}
|
||||
|
||||
// Render the message log at [1, 46], descending, with 6 lines.
|
||||
gamelog::print_log(&mut rltk::BACKEND_INTERNAL.lock().consoles[0].console, Point::new(1, 7), false, 7);
|
||||
// Render the message log at [1, 7], ascending, with 7 lines and a max width of 68.
|
||||
gamelog::print_log(&mut rltk::BACKEND_INTERNAL.lock().consoles[0].console, Point::new(1, 7), false, 7, 68);
|
||||
|
||||
// Render id
|
||||
let map = ecs.fetch::<Map>();
|
||||
|
|
@ -493,7 +493,6 @@ pub fn ranged_target(gs: &mut State, ctx: &mut Rltk, range: i32, aoe: i32) -> (I
|
|||
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 {
|
||||
rltk::console::log("yo");
|
||||
ctx.set_bg(screen_x + x_offset, screen_y + y_offset, RGB::named(rltk::BLUE));
|
||||
available_cells.push(idx);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -238,18 +238,18 @@ impl<'a> System<'a> for ItemUseSystem {
|
|||
for (item_entity, already_equipped, _name) in (&entities, &equipped, &names).join() {
|
||||
if already_equipped.owner == target && already_equipped.slot == target_slot {
|
||||
to_unequip.push(item_entity);
|
||||
/*if target == *player_entity {
|
||||
gamelog::Logger::new()
|
||||
.append("You unequip the")
|
||||
.item_name_n(&item_being_used.name)
|
||||
.period()
|
||||
.log();
|
||||
}*/
|
||||
}
|
||||
}
|
||||
for item in to_unequip.iter() {
|
||||
equipped.remove(*item);
|
||||
backpack.insert(*item, InBackpack { owner: target }).expect("Unable to insert backpack");
|
||||
if target == *player_entity {
|
||||
gamelog::Logger::new()
|
||||
.append("You remove your")
|
||||
.item_name_n(&item_being_used.name)
|
||||
.period()
|
||||
.log();
|
||||
}
|
||||
}
|
||||
|
||||
// Wield the item
|
||||
|
|
|
|||
|
|
@ -80,7 +80,7 @@ impl State {
|
|||
self.mapgen_timer = 0.0;
|
||||
self.mapgen_history.clear();
|
||||
let mut rng = self.ecs.write_resource::<rltk::RandomNumberGenerator>();
|
||||
let mut builder = map_builders::level_builder(new_id, &mut rng, 80, 50);
|
||||
let mut builder = map_builders::level_builder(new_id, &mut rng, 100, 50);
|
||||
builder.build_map(&mut rng);
|
||||
std::mem::drop(rng);
|
||||
self.mapgen_history = builder.build_data.history.clone();
|
||||
|
|
|
|||
|
|
@ -183,6 +183,15 @@ pub fn spawn_named_mob(
|
|||
) -> Option<Entity> {
|
||||
if raws.mob_index.contains_key(key) {
|
||||
let mob_template = &raws.raws.mobs[raws.mob_index[key]];
|
||||
let mut player_level = 1;
|
||||
{
|
||||
let pools = ecs.read_storage::<Pools>();
|
||||
let player_entity = ecs.fetch::<Entity>();
|
||||
let player_pool = pools.get(*player_entity);
|
||||
if let Some(pool) = player_pool {
|
||||
player_level = pool.level;
|
||||
}
|
||||
}
|
||||
|
||||
let mut eb;
|
||||
// New entity with a position, name, combatstats, and viewshed
|
||||
|
|
@ -245,16 +254,19 @@ pub fn spawn_named_mob(
|
|||
|
||||
let base_mob_level = if mob_template.level.is_some() { mob_template.level.unwrap() } else { 0 };
|
||||
let mut mob_level = base_mob_level;
|
||||
// If the level difficulty is smaller than the mob's base level, subtract 1;
|
||||
// else, if the level difficulty is larger, add one-fifth of the difference
|
||||
if base_mob_level > map_difficulty {
|
||||
mob_level -= 1;
|
||||
} else if base_mob_level < map_difficulty {
|
||||
mob_level += (map_difficulty - base_mob_level) / 5;
|
||||
|
||||
if mob_level as f32 > 1.5 * base_mob_level as f32 {
|
||||
let mob_levelf32 = (1.5 * base_mob_level as f32).trunc();
|
||||
mob_level = mob_levelf32 as i32;
|
||||
}
|
||||
}
|
||||
// If the player is a higher level than the mob, add one-fifth of the difference
|
||||
if base_mob_level < player_level {
|
||||
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);
|
||||
|
||||
// Should really use existing RNG here
|
||||
let mut rng = rltk::RandomNumberGenerator::new();
|
||||
|
|
@ -265,8 +277,8 @@ pub fn spawn_named_mob(
|
|||
|
||||
if SPAWN_LOGGING {
|
||||
rltk::console::log(format!(
|
||||
"SPAWNLOG: {} ({}HP, {}MANA, {}BAC) spawned at level {} (base level: {}, map difficulty: {})",
|
||||
&mob_template.name, mob_hp, mob_mana, mob_bac, mob_level, base_mob_level, map_difficulty
|
||||
"SPAWNLOG: {} ({}HP, {}MANA, {}BAC) spawned at level {} ({}[base], {}[map difficulty], {}[player level])",
|
||||
&mob_template.name, mob_hp, mob_mana, mob_bac, mob_level, base_mob_level, map_difficulty, player_level
|
||||
));
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue