formatted
This commit is contained in:
parent
a1ffc7b95d
commit
e68fa87fc9
@ -1,14 +1,14 @@
|
||||
use rltk::{Point, VirtualKeyCode};
|
||||
use rltk::RGB;
|
||||
use rltk::Rltk;
|
||||
use rltk::RGB;
|
||||
use rltk::{Point, VirtualKeyCode};
|
||||
use specs::prelude::*;
|
||||
|
||||
use crate::{CombatStats, InBackpack, RunState, State, Viewshed};
|
||||
use crate::gamelog::GameLog;
|
||||
use crate::Map;
|
||||
use crate::Name;
|
||||
use crate::Player;
|
||||
use crate::Position;
|
||||
use crate::{CombatStats, InBackpack, RunState, State, Viewshed};
|
||||
|
||||
pub fn draw_ui(ecs: &World, ctx: &mut Rltk) {
|
||||
ctx.draw_box(
|
||||
@ -413,7 +413,6 @@ pub fn main_menu(gs: &mut State, ctx: &mut Rltk) -> MainMenuResult {
|
||||
"Rust Roguelike Tutorial",
|
||||
);
|
||||
|
||||
|
||||
if let RunState::MainMenu {
|
||||
menu_selection: selection,
|
||||
} = *runstate
|
||||
@ -452,7 +451,6 @@ pub fn main_menu(gs: &mut State, ctx: &mut Rltk) -> MainMenuResult {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if selection == MainMenuSelection::Quit {
|
||||
ctx.print_color_centered(
|
||||
26,
|
||||
|
@ -26,9 +26,9 @@ mod melee_combat_system;
|
||||
mod monster_ai_system;
|
||||
mod player;
|
||||
mod rect;
|
||||
mod save_load_system;
|
||||
mod spawner;
|
||||
mod visibility_system;
|
||||
mod save_load_system;
|
||||
|
||||
#[derive(PartialEq, Copy, Clone)]
|
||||
pub enum RunState {
|
||||
|
@ -1,6 +1,6 @@
|
||||
use std::cmp::{max, min};
|
||||
|
||||
use rltk::{Algorithm2D, BaseMap, Point, RandomNumberGenerator, RGB, Rltk};
|
||||
use rltk::{Algorithm2D, BaseMap, Point, RandomNumberGenerator, Rltk, RGB};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use specs::prelude::*;
|
||||
|
||||
@ -65,7 +65,6 @@ impl Map {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fn is_exit_valid(&self, x: i32, y: i32) -> bool {
|
||||
if x < 1 || x > self.width - 1 || y < 1 || y > self.height - 1 {
|
||||
return false;
|
||||
|
@ -3,8 +3,8 @@ use specs::prelude::*;
|
||||
|
||||
use crate::{
|
||||
components::{Monster, Position, Viewshed, WantsToMelee},
|
||||
Confusion,
|
||||
map::Map, RunState,
|
||||
map::Map,
|
||||
Confusion, RunState,
|
||||
};
|
||||
|
||||
pub struct MonsterAI {}
|
||||
|
@ -3,12 +3,12 @@ use std::cmp::{max, min};
|
||||
use rltk::{Point, Rltk, VirtualKeyCode};
|
||||
use specs::prelude::*;
|
||||
|
||||
use crate::gamelog::GameLog;
|
||||
use crate::{
|
||||
components::{CombatStats, Player, Position, Viewshed, WantsToMelee},
|
||||
Item,
|
||||
map::Map, RunState, State, WantsToPickupItem,
|
||||
map::Map,
|
||||
Item, RunState, State, WantsToPickupItem,
|
||||
};
|
||||
use crate::gamelog::GameLog;
|
||||
|
||||
pub fn try_move_player(delta_x: i32, delta_y: i32, ecs: &mut World) {
|
||||
let mut positions = ecs.write_storage::<Position>();
|
||||
@ -22,7 +22,13 @@ pub fn try_move_player(delta_x: i32, delta_y: i32, ecs: &mut World) {
|
||||
for (entity, _player, pos, viewshed) in
|
||||
(&entities, &mut players, &mut positions, &mut viewsheds).join()
|
||||
{
|
||||
if pos.x + delta_x < 1 || pos.x + delta_x > map.width - 1 || pos.y + delta_y < 1 || pos.y + delta_y > map.height - 1 { return; }
|
||||
if pos.x + delta_x < 1
|
||||
|| pos.x + delta_x > map.width - 1
|
||||
|| pos.y + delta_y < 1
|
||||
|| pos.y + delta_y > map.height - 1
|
||||
{
|
||||
return;
|
||||
}
|
||||
let destination_idx = map.xy_idx(pos.x + delta_x, pos.y + delta_y);
|
||||
|
||||
for potential_target in map.tile_content[destination_idx].iter() {
|
||||
|
@ -4,7 +4,9 @@ use std::path::Path;
|
||||
|
||||
use specs::error::NoError;
|
||||
use specs::prelude::*;
|
||||
use specs::saveload::{DeserializeComponents, MarkedBuilder, SerializeComponents, SimpleMarker, SimpleMarkerAllocator};
|
||||
use specs::saveload::{
|
||||
DeserializeComponents, MarkedBuilder, SerializeComponents, SimpleMarker, SimpleMarkerAllocator,
|
||||
};
|
||||
|
||||
use super::components::*;
|
||||
|
||||
@ -37,14 +39,39 @@ pub fn save_game(ecs: &mut World) {
|
||||
|
||||
// Actually serialize
|
||||
{
|
||||
let data = (ecs.entities(), ecs.read_storage::<SimpleMarker<SerializeMe>>());
|
||||
let data = (
|
||||
ecs.entities(),
|
||||
ecs.read_storage::<SimpleMarker<SerializeMe>>(),
|
||||
);
|
||||
|
||||
let writer = File::create("./savegame.json").unwrap();
|
||||
let mut serializer = serde_json::Serializer::new(writer);
|
||||
serialize_individually!(ecs, serializer, data, Position, Renderable, Player, Viewshed, Monster,
|
||||
Name, BlocksTile, CombatStats, SufferDamage, WantsToMelee, Item, Consumable, Ranged, InflictsDamage,
|
||||
AreaOfEffect, Confusion, ProvidesHealing, InBackpack, WantsToPickupItem, WantsToUseItem,
|
||||
WantsToDropItem, SerializationHelper
|
||||
serialize_individually!(
|
||||
ecs,
|
||||
serializer,
|
||||
data,
|
||||
Position,
|
||||
Renderable,
|
||||
Player,
|
||||
Viewshed,
|
||||
Monster,
|
||||
Name,
|
||||
BlocksTile,
|
||||
CombatStats,
|
||||
SufferDamage,
|
||||
WantsToMelee,
|
||||
Item,
|
||||
Consumable,
|
||||
Ranged,
|
||||
InflictsDamage,
|
||||
AreaOfEffect,
|
||||
Confusion,
|
||||
ProvidesHealing,
|
||||
InBackpack,
|
||||
WantsToPickupItem,
|
||||
WantsToUseItem,
|
||||
WantsToDropItem,
|
||||
SerializationHelper
|
||||
);
|
||||
}
|
||||
|
||||
@ -87,12 +114,38 @@ pub fn load_game(ecs: &mut World) {
|
||||
let mut de = serde_json::Deserializer::from_str(&data);
|
||||
|
||||
{
|
||||
let mut d = (&mut ecs.entities(), &mut ecs.write_storage::<SimpleMarker<SerializeMe>>(), &mut ecs.write_resource::<SimpleMarkerAllocator<SerializeMe>>());
|
||||
let mut d = (
|
||||
&mut ecs.entities(),
|
||||
&mut ecs.write_storage::<SimpleMarker<SerializeMe>>(),
|
||||
&mut ecs.write_resource::<SimpleMarkerAllocator<SerializeMe>>(),
|
||||
);
|
||||
|
||||
deserialize_individually!(ecs, de, d, Position, Renderable, Player, Viewshed, Monster,
|
||||
Name, BlocksTile, CombatStats, SufferDamage, WantsToMelee, Item, Consumable, Ranged, InflictsDamage,
|
||||
AreaOfEffect, Confusion, ProvidesHealing, InBackpack, WantsToPickupItem, WantsToUseItem,
|
||||
WantsToDropItem, SerializationHelper
|
||||
deserialize_individually!(
|
||||
ecs,
|
||||
de,
|
||||
d,
|
||||
Position,
|
||||
Renderable,
|
||||
Player,
|
||||
Viewshed,
|
||||
Monster,
|
||||
Name,
|
||||
BlocksTile,
|
||||
CombatStats,
|
||||
SufferDamage,
|
||||
WantsToMelee,
|
||||
Item,
|
||||
Consumable,
|
||||
Ranged,
|
||||
InflictsDamage,
|
||||
AreaOfEffect,
|
||||
Confusion,
|
||||
ProvidesHealing,
|
||||
InBackpack,
|
||||
WantsToPickupItem,
|
||||
WantsToUseItem,
|
||||
WantsToDropItem,
|
||||
SerializationHelper
|
||||
);
|
||||
}
|
||||
|
||||
@ -115,9 +168,12 @@ pub fn load_game(ecs: &mut World) {
|
||||
*player_resource = e;
|
||||
}
|
||||
}
|
||||
ecs.delete_entity(deleteme.unwrap()).expect("Unable to delete helper");
|
||||
ecs.delete_entity(deleteme.unwrap())
|
||||
.expect("Unable to delete helper");
|
||||
}
|
||||
|
||||
pub fn delete_save() {
|
||||
if Path::new("./savegame.json").exists() { std::fs::remove_file("./savegame.json").expect("Unable to delete file"); }
|
||||
if Path::new("./savegame.json").exists() {
|
||||
std::fs::remove_file("./savegame.json").expect("Unable to delete file");
|
||||
}
|
||||
}
|
||||
|
@ -2,8 +2,12 @@ use rltk::{FontCharType, RandomNumberGenerator, RGB};
|
||||
use specs::prelude::*;
|
||||
use specs::saveload::{MarkedBuilder, SimpleMarker};
|
||||
|
||||
use crate::{AreaOfEffect, BlocksTile, CombatStats, Confusion, Consumable, InflictsDamage, Item, MAP_WIDTH, MAX_ITEMS, MAX_MONSTER, Monster, Name, Player, Position, ProvidesHealing, Ranged, Renderable, SerializeMe, Viewshed};
|
||||
use crate::rect::Rect;
|
||||
use crate::{
|
||||
AreaOfEffect, BlocksTile, CombatStats, Confusion, Consumable, InflictsDamage, Item, Monster,
|
||||
Name, Player, Position, ProvidesHealing, Ranged, Renderable, SerializeMe, Viewshed, MAP_WIDTH,
|
||||
MAX_ITEMS, MAX_MONSTER,
|
||||
};
|
||||
|
||||
pub fn player(ecs: &mut World, player_x: i32, player_y: i32) -> Entity {
|
||||
ecs.create_entity()
|
||||
|
Loading…
Reference in New Issue
Block a user