#pragma once
#include "shared.h"
#include <enginend/engine.h>
#include "cheats.h"
enum CURSORMODES {
	MAINMENU=0,
	COMPUTER=1,
	LEFT=2,RIGHT=3,UP=4,DOWN=5,
	FLASHLIGHT=6,INTERACT=7
};
#define LOADMAP LoadTexture(newpath.c_str());
struct entity {
	char pos;
	char dir;
};



extern std::vector<std::vector<char>> map;
extern std::vector<char> opposites;
char moveentity(char pos,char dir,bool backwards);
char rotateentity(char pos,char dir, bool clockwise);
bool ifforward();bool ifbackward();bool ifleft();bool ifright();
bool ifinteract();bool ifflashlight();
bool cansee(char dest,char pos, char dir);
extern std::vector<char> sides;
extern std::vector<std::string> lightlevel;

struct game:public enginend::scene {
	// dir 1
	
	int lightmode:2=1; // off, on, urcooked
	std::string mappath;
	// this is for quick loading but without weighting ram..
	// yea the assets are small but i like optimization
	float stamina=0.0;
	entity uycatroz{6,3};
	entity skaile{10,3};
	entity player{0,1};
	Texture2D current;
	bool canseeuycatroz=false;
	bool canseeskaile=false;
	float crystallyprogress=1.;
	void boot() final {
		mappath=AT("res/map");
		this->nodes={
			new enginend::nodes::twod::relative::textured()
		};
		std::string newpath=AT((mappath+"/"+lightlevel[lightmode]+"/"+sides[player.dir]+"/"+std::to_string(player.pos)+".jpg"));
		
		current=LOADMAP
	}
	void tick() final {
		bool changed=false;
		bool updateview=false;
		if (stamina>=1.){
			if (ifforward()){player.pos=moveentity(player.pos,player.dir,false);changed=true;}
			if (ifbackward()){player.pos=moveentity(player.pos,player.dir,true);changed=true;}
			if (ifleft()){player.dir=rotateentity(player.pos,player.dir,false);changed=true;}
			if (ifright()){player.dir=rotateentity(player.pos,player.dir,true);changed=true;}
			if (changed) {
				UnloadTexture(current);
				std::string newpath=AT((mappath+"/"+lightlevel[lightmode]+"/"+sides[player.dir]+"/"+std::to_string(player.pos)+".jpg"));
				current=LOADMAP
				//tiny::success((char*)newpath.c_str());
				updateview=true;
			}
			if (updateview) {
				canseeuycatroz=cansee(uycatroz.pos,player.pos,player.dir);
				canseeskaile=cansee(skaile.pos,player.pos,player.dir);
			}
			if (ifinteract()) {
				if (player.pos==0&&player.dir==0)changeto=0;
				
			}
		}else stamina+=.01;
		
		
	}
	void draw() final {
		float screenw=(float)GetScreenWidth();float screenh=(float)GetScreenHeight();
		BeginDrawing();
		ClearBackground(rl::WHITE);
		DrawTexturePro(current,{0,0,480,280},{0,0,screenw,screenh},{0,0},0,rl::WHITE);
		if (canseeuycatroz)DrawRectangle(
			screenw/10.,screenh/10.,screenw/12,screenh/1.5,rl::BLUE);
		if (canseeskaile)DrawRectangle(
			screenw/2.,screenh/10.,screenw/12,screenh/1.5,rl::RED);
		DrawText(("pos: "+std::to_string(player.pos)+" dir:"+std::to_string(player.dir)).c_str(),0,0,64,rl::WHITE);
		DrawText(("uypos: "+std::to_string(uycatroz.pos)+" uydir:"+std::to_string(uycatroz.dir)).c_str(),0,64,64,rl::SKYBLUE);
		DrawText(("skpos: "+std::to_string(skaile.pos)+" skdir:"+std::to_string(skaile.dir)).c_str(),0,128,64,rl::RED);
		DrawText(("crystally: "+std::to_string(crystallyprogress)).c_str(),0,196,64,rl::LIME);
		
		
		EndDrawing();
		
	}
};