diff --git a/Crawler/Crawler.cpp b/Crawler/Crawler.cpp index 93cc88ce..735c948b 100644 --- a/Crawler/Crawler.cpp +++ b/Crawler/Crawler.cpp @@ -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::mapANIMATION_DATA; std::vectorMONSTER_LIST; std::vectorSPAWNER_LIST; std::vector>DAMAGENUMBER_LIST; std::vector>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(); @@ -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(); } \ No newline at end of file diff --git a/Crawler/Crawler.h b/Crawler/Crawler.h index 727a8c1e..9adef51f 100644 --- a/Crawler/Crawler.h +++ b/Crawler/Crawler.h @@ -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&monstersBeforeLower,std::vector&monstersBeforeUpper,std::vector&monstersAfterLower,std::vector&monstersAfterUpper,std::vector&bulletsLower,std::vector&bulletsUpper,std::vector&backgroundEffectsLower,std::vector&backgroundEffectsUpper,std::vector&foregroundEffectsLower,std::vector&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); -}; \ No newline at end of file + 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); \ No newline at end of file diff --git a/Crawler/assets/config/configuration.txt b/Crawler/assets/config/configuration.txt index 7a0aad51..a9ae8ef1 100644 --- a/Crawler/assets/config/configuration.txt +++ b/Crawler/assets/config/configuration.txt @@ -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 \ No newline at end of file diff --git a/Crawler/olcUTIL_DataFile.h b/Crawler/olcUTIL_DataFile.h index 826cf15c..0d172b94 100644 --- a/Crawler/olcUTIL_DataFile.h +++ b/Crawler/olcUTIL_DataFile.h @@ -64,6 +64,42 @@ David Barr, aka javidx9, �OneLoneCoder 2019, 2020, 2021, 2022 namespace olc::utils { + class datafilestringdata + { + std::reference_wrapperdata; + 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_wrapperdata; + 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_wrapperdata; + 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_wrapperdata; + 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 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