mod furniture;
mod grid;
mod player;
mod room;

use self::{grid::Grid, player::Player, room::Room};
use crate::State;
use comfy::{error, EngineContext};

#[derive(Debug)]
pub struct HouseState {
	room: Room,
	//grid: Grid,
	player: Player
}

impl HouseState {
	pub fn generate_new_house(ctx: &mut EngineContext<'_>) -> Self {
		let room = Room::new(ctx);
		let player = Player::new(&room);
		HouseState { room, player }
	}
}

pub fn draw(state: &State, _ctx: &comfy::EngineContext<'_>) {
	let Some(house) = state.house() else {
		error!("How can I render a house when I'm not in one?!?");
		return;
	};

	//Draw House
	house.room.draw();

	//Draw Grid
	//state.house.grid.draw();

	//Draw Player
	house.player.draw();
}

pub fn update(state: &mut State, ctx: &mut comfy::EngineContext<'_>) {
	let house = state.house_mut(ctx);
	house.player.update(&house.room.grid);

	if house.player.is_moving_to_right_room(&house.room) {
		house.room = Room::new(ctx);
		house.player.reset_on_room(&house.room, true);
	} else if house.player.is_moving_to_left_room(&house.room) {
		house.room = Room::new(ctx);
		house.player.reset_on_room(&house.room, false);
	}
}
