Reorganize data file specs and implement custom operator syntax
Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
This commit is contained in:
		
							parent
							
								
									f7f29196c5
								
							
						
					
					
						commit
						11aa50105c
					
				| @ -21,12 +21,13 @@ INCLUDE_EMITTER_LIST | ||||
| //#define DEBUG_POS //Shows player position.
 | ||||
| 
 | ||||
| //192x192
 | ||||
| const vi2d WINDOW_SIZE={24*15,24*10}; | ||||
| vi2d WINDOW_SIZE={24*15,24*10}; | ||||
| std::map<AnimationState,Animate2D::FrameSequence>ANIMATION_DATA; | ||||
| std::vector<Monster>MONSTER_LIST; | ||||
| std::vector<MonsterSpawner>SPAWNER_LIST; | ||||
| std::vector<std::shared_ptr<DamageNumber>>DAMAGENUMBER_LIST; | ||||
| std::vector<std::unique_ptr<Bullet>>BULLET_LIST; | ||||
| utils::datafile DATA; | ||||
| Crawler*game; | ||||
| 
 | ||||
| Key Crawler::KEY_ABILITY1=Q; | ||||
| @ -38,18 +39,17 @@ Crawler::Crawler() | ||||
| { | ||||
| 	sAppName = "Crawler Concept"; | ||||
| 	game=this; | ||||
| } | ||||
| 
 | ||||
| bool Crawler::OnUserCreate(){ | ||||
| 
 | ||||
| 	utils::datafile::Read(DATA,"assets/config/configuration.txt"); | ||||
| 
 | ||||
| 	std::string CONFIG_PATH = GetString("config_path"); | ||||
| 
 | ||||
| 	std::string GFX_CONFIG = CONFIG_PATH + GetString("gfx_config"); | ||||
| 	std::string CONFIG_PATH = "config_path"S; | ||||
| 
 | ||||
| 	std::string GFX_CONFIG = CONFIG_PATH + "gfx_config"S; | ||||
| 	utils::datafile::Read(DATA,GFX_CONFIG); | ||||
| 	WINDOW_SIZE={"WINDOW_SIZE"i[0],"WINDOW_SIZE"i[1]}; | ||||
| } | ||||
| 
 | ||||
| bool Crawler::OnUserCreate(){ | ||||
| 	InitializeLevel("assets/Campaigns/1_1.tmx",CAMPAIGN_1_1); | ||||
| 
 | ||||
| 	player=std::make_unique<Warrior>(); | ||||
| @ -1100,18 +1100,35 @@ std::string Crawler::GetString(std::string key){ | ||||
| 	return DATA.GetProperty(key).GetString(); | ||||
| } | ||||
| 
 | ||||
| datafilestringdata Crawler::GetStringList(std::string key){ | ||||
| 	return {DATA,key}; | ||||
| } | ||||
| 
 | ||||
| int Crawler::GetInt(std::string key){ | ||||
| 	return DATA.GetProperty(key).GetInt(); | ||||
| } | ||||
| 
 | ||||
| datafileintdata Crawler::GetIntList(std::string key){ | ||||
| 	return {DATA,key}; | ||||
| } | ||||
| 
 | ||||
| float Crawler::GetFloat(std::string key){ | ||||
| 	return DATA.GetProperty(key).GetReal(); | ||||
| } | ||||
| 
 | ||||
| datafilefloatdata Crawler::GetFloatList(std::string key){ | ||||
| 	return {DATA,key}; | ||||
| } | ||||
| 
 | ||||
| double Crawler::GetDouble(std::string key){ | ||||
| 	return DATA.GetProperty(key).GetReal(); | ||||
| } | ||||
| 
 | ||||
| datafiledoubledata Crawler::GetDoubleList(std::string key){ | ||||
| 	return {DATA,key}; | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| int main() | ||||
| { | ||||
| 	Crawler demo; | ||||
| @ -1119,4 +1136,36 @@ int main() | ||||
| 		demo.Start(); | ||||
| 
 | ||||
| 	return 0; | ||||
| } | ||||
| 
 | ||||
| datafilestringdata operator ""s(const char*key,std::size_t len){ | ||||
| 	return {DATA,std::string(key,len)}; | ||||
| } | ||||
| 
 | ||||
| datafileintdata operator ""i(const char*key,std::size_t len){ | ||||
| 	return {DATA,std::string(key,len)}; | ||||
| } | ||||
| 
 | ||||
| datafilefloatdata operator ""f(const char*key,std::size_t len){ | ||||
| 	return {DATA,std::string(key,len)}; | ||||
| } | ||||
| 
 | ||||
| datafiledoubledata operator ""d(const char*key,std::size_t len){ | ||||
| 	return {DATA,std::string(key,len)}; | ||||
| } | ||||
| 
 | ||||
| std::string operator ""S(const char*key,std::size_t len){ | ||||
| 	return DATA.GetProperty(std::string(key,len)).GetString(); | ||||
| } | ||||
| 
 | ||||
| int operator ""I(const char*key,std::size_t len){ | ||||
| 	return DATA.GetProperty(std::string(key,len)).GetInt(); | ||||
| } | ||||
| 
 | ||||
| float operator ""F(const char*key,std::size_t len){ | ||||
| 	return DATA.GetProperty(std::string(key,len)).GetReal(); | ||||
| } | ||||
| 
 | ||||
| double operator ""D(const char*key,std::size_t len){ | ||||
| 	return DATA.GetProperty(std::string(key,len)).GetReal(); | ||||
| } | ||||
| @ -52,7 +52,6 @@ private: | ||||
| 	int bridgeLayerIndex=-1; | ||||
| 	float bridgeFadeFactor=0.f; | ||||
| 	void InitializeClassAbilities(); | ||||
| 	utils::datafile DATA; | ||||
| public: | ||||
| 	Crawler(); | ||||
| 	bool OnUserCreate() override; | ||||
| @ -101,7 +100,28 @@ public: | ||||
| 	void PopulateRenderLists(std::vector<Monster*>&monstersBeforeLower,std::vector<Monster*>&monstersBeforeUpper,std::vector<Monster*>&monstersAfterLower,std::vector<Monster*>&monstersAfterUpper,std::vector<Bullet*>&bulletsLower,std::vector<Bullet*>&bulletsUpper,std::vector<Effect*>&backgroundEffectsLower,std::vector<Effect*>&backgroundEffectsUpper,std::vector<Effect*>&foregroundEffectsLower,std::vector<Effect*>&foregroundEffectsUpper); | ||||
| 	void ChangePlayerClass(Class cl); | ||||
| 	std::string GetString(std::string key); | ||||
| 	datafilestringdata GetStringList(std::string key); | ||||
| 	int GetInt(std::string key); | ||||
| 	datafileintdata GetIntList(std::string key); | ||||
| 	float GetFloat(std::string key); | ||||
| 	datafilefloatdata GetFloatList(std::string key); | ||||
| 	double GetDouble(std::string key); | ||||
| }; | ||||
| 	datafiledoubledata GetDoubleList(std::string key); | ||||
| }; | ||||
| 
 | ||||
| //Read a string array from the config.
 | ||||
| datafilestringdata operator ""s(const char*key,std::size_t len); | ||||
| //Read an int array from the config.
 | ||||
| datafileintdata operator ""i(const char*key,std::size_t len); | ||||
| //Read a float array from the config.
 | ||||
| datafilefloatdata operator ""f(const char*key,std::size_t len); | ||||
| //Read a double array from the config.
 | ||||
| datafiledoubledata operator ""d(const char*key,std::size_t len); | ||||
| //Read a string key from the config.
 | ||||
| std::string operator ""S(const char*key,std::size_t len); | ||||
| //Read an integer key from the config.
 | ||||
| int operator ""I(const char*key,std::size_t len); | ||||
| //Read a float key from the config.
 | ||||
| float operator ""F(const char*key,std::size_t len); | ||||
| //Read a double key from the config.
 | ||||
| double operator ""D(const char*key,std::size_t len); | ||||
| @ -1,2 +1,7 @@ | ||||
| config_path = assets/config/ | ||||
| 
 | ||||
| # 360x240 is 15x10 tiles of visibility. | ||||
| WINDOW_SIZE = 360,240 | ||||
| 
 | ||||
| # Graphics Loading Config | ||||
| gfx_config = gfx/gfx.txt | ||||
| @ -64,6 +64,42 @@ David Barr, aka javidx9, <20>OneLoneCoder 2019, 2020, 2021, 2022 | ||||
| 
 | ||||
| namespace olc::utils | ||||
| { | ||||
| 	class datafilestringdata | ||||
| 	{ | ||||
| 		std::reference_wrapper<datafile>data; | ||||
| 		std::string key; | ||||
| 		public: | ||||
| 		inline datafilestringdata(datafile&dat,std::string key) | ||||
| 		:data(dat),key(key){}; | ||||
| 		std::string operator[](int index){data.get().GetIndexedProperty(key,index).GetString();}; | ||||
| 	}; | ||||
| 	class datafileintdata | ||||
| 	{ | ||||
| 		std::reference_wrapper<datafile>data; | ||||
| 		std::string key; | ||||
| 		public: | ||||
| 		inline datafileintdata(datafile&dat,std::string key) | ||||
| 		:data(dat),key(key){}; | ||||
| 		int operator[](int index){data.get().GetIndexedProperty(key,index).GetInt();}; | ||||
| 	}; | ||||
| 	class datafilefloatdata | ||||
| 	{ | ||||
| 		std::reference_wrapper<datafile>data; | ||||
| 		std::string key; | ||||
| 		public: | ||||
| 		inline datafilefloatdata(datafile&dat,std::string key) | ||||
| 		:data(dat),key(key){}; | ||||
| 		float operator[](int index){data.get().GetIndexedProperty(key,index).GetReal();}; | ||||
| 	}; | ||||
| 	class datafiledoubledata | ||||
| 	{ | ||||
| 		std::reference_wrapper<datafile>data; | ||||
| 		std::string key; | ||||
| 		public: | ||||
| 		inline datafiledoubledata(datafile&dat,std::string key) | ||||
| 		:data(dat),key(key){}; | ||||
| 		double operator[](int index){data.get().GetIndexedProperty(key,index).GetReal();}; | ||||
| 	}; | ||||
| 	class datafile | ||||
| 	{ | ||||
| 	public: | ||||
| @ -118,6 +154,11 @@ namespace olc::utils | ||||
| 			return m_vContent.size(); | ||||
| 		} | ||||
| 
 | ||||
| 		inline std::vector<std::string> GetValues() const | ||||
| 		{ | ||||
| 			return m_vContent; | ||||
| 		} | ||||
| 
 | ||||
| 		// Checks if a property exists - useful to avoid creating properties
 | ||||
| 		// via reading them, though non-essential
 | ||||
| 		inline bool HasProperty(const std::string& sName) const | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user