Reorganize data file specs and implement custom operator syntax
Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
This commit is contained in:
parent
c17ff42a23
commit
460ea2d0c2
@ -21,12 +21,13 @@ INCLUDE_EMITTER_LIST
|
|||||||
//#define DEBUG_POS //Shows player position.
|
//#define DEBUG_POS //Shows player position.
|
||||||
|
|
||||||
//192x192
|
//192x192
|
||||||
const vi2d WINDOW_SIZE={24*15,24*10};
|
vi2d WINDOW_SIZE={24*15,24*10};
|
||||||
std::map<AnimationState,Animate2D::FrameSequence>ANIMATION_DATA;
|
std::map<AnimationState,Animate2D::FrameSequence>ANIMATION_DATA;
|
||||||
std::vector<Monster>MONSTER_LIST;
|
std::vector<Monster>MONSTER_LIST;
|
||||||
std::vector<MonsterSpawner>SPAWNER_LIST;
|
std::vector<MonsterSpawner>SPAWNER_LIST;
|
||||||
std::vector<std::shared_ptr<DamageNumber>>DAMAGENUMBER_LIST;
|
std::vector<std::shared_ptr<DamageNumber>>DAMAGENUMBER_LIST;
|
||||||
std::vector<std::unique_ptr<Bullet>>BULLET_LIST;
|
std::vector<std::unique_ptr<Bullet>>BULLET_LIST;
|
||||||
|
utils::datafile DATA;
|
||||||
Crawler*game;
|
Crawler*game;
|
||||||
|
|
||||||
Key Crawler::KEY_ABILITY1=Q;
|
Key Crawler::KEY_ABILITY1=Q;
|
||||||
@ -38,18 +39,17 @@ Crawler::Crawler()
|
|||||||
{
|
{
|
||||||
sAppName = "Crawler Concept";
|
sAppName = "Crawler Concept";
|
||||||
game=this;
|
game=this;
|
||||||
}
|
|
||||||
|
|
||||||
bool Crawler::OnUserCreate(){
|
|
||||||
|
|
||||||
utils::datafile::Read(DATA,"assets/config/configuration.txt");
|
utils::datafile::Read(DATA,"assets/config/configuration.txt");
|
||||||
|
|
||||||
std::string CONFIG_PATH = GetString("config_path");
|
std::string CONFIG_PATH = "config_path"S;
|
||||||
|
|
||||||
std::string GFX_CONFIG = CONFIG_PATH + GetString("gfx_config");
|
|
||||||
|
|
||||||
|
std::string GFX_CONFIG = CONFIG_PATH + "gfx_config"S;
|
||||||
utils::datafile::Read(DATA,GFX_CONFIG);
|
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);
|
InitializeLevel("assets/Campaigns/1_1.tmx",CAMPAIGN_1_1);
|
||||||
|
|
||||||
player=std::make_unique<Warrior>();
|
player=std::make_unique<Warrior>();
|
||||||
@ -1100,18 +1100,35 @@ std::string Crawler::GetString(std::string key){
|
|||||||
return DATA.GetProperty(key).GetString();
|
return DATA.GetProperty(key).GetString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
datafilestringdata Crawler::GetStringList(std::string key){
|
||||||
|
return {DATA,key};
|
||||||
|
}
|
||||||
|
|
||||||
int Crawler::GetInt(std::string key){
|
int Crawler::GetInt(std::string key){
|
||||||
return DATA.GetProperty(key).GetInt();
|
return DATA.GetProperty(key).GetInt();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
datafileintdata Crawler::GetIntList(std::string key){
|
||||||
|
return {DATA,key};
|
||||||
|
}
|
||||||
|
|
||||||
float Crawler::GetFloat(std::string key){
|
float Crawler::GetFloat(std::string key){
|
||||||
return DATA.GetProperty(key).GetReal();
|
return DATA.GetProperty(key).GetReal();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
datafilefloatdata Crawler::GetFloatList(std::string key){
|
||||||
|
return {DATA,key};
|
||||||
|
}
|
||||||
|
|
||||||
double Crawler::GetDouble(std::string key){
|
double Crawler::GetDouble(std::string key){
|
||||||
return DATA.GetProperty(key).GetReal();
|
return DATA.GetProperty(key).GetReal();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
datafiledoubledata Crawler::GetDoubleList(std::string key){
|
||||||
|
return {DATA,key};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
Crawler demo;
|
Crawler demo;
|
||||||
@ -1120,3 +1137,35 @@ int main()
|
|||||||
|
|
||||||
return 0;
|
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;
|
int bridgeLayerIndex=-1;
|
||||||
float bridgeFadeFactor=0.f;
|
float bridgeFadeFactor=0.f;
|
||||||
void InitializeClassAbilities();
|
void InitializeClassAbilities();
|
||||||
utils::datafile DATA;
|
|
||||||
public:
|
public:
|
||||||
Crawler();
|
Crawler();
|
||||||
bool OnUserCreate() override;
|
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 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);
|
void ChangePlayerClass(Class cl);
|
||||||
std::string GetString(std::string key);
|
std::string GetString(std::string key);
|
||||||
|
datafilestringdata GetStringList(std::string key);
|
||||||
int GetInt(std::string key);
|
int GetInt(std::string key);
|
||||||
|
datafileintdata GetIntList(std::string key);
|
||||||
float GetFloat(std::string key);
|
float GetFloat(std::string key);
|
||||||
|
datafilefloatdata GetFloatList(std::string key);
|
||||||
double GetDouble(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/
|
config_path = assets/config/
|
||||||
|
|
||||||
|
# 360x240 is 15x10 tiles of visibility.
|
||||||
|
WINDOW_SIZE = 360,240
|
||||||
|
|
||||||
|
# Graphics Loading Config
|
||||||
gfx_config = gfx/gfx.txt
|
gfx_config = gfx/gfx.txt
|
@ -64,6 +64,42 @@ David Barr, aka javidx9, <20>OneLoneCoder 2019, 2020, 2021, 2022
|
|||||||
|
|
||||||
namespace olc::utils
|
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
|
class datafile
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -118,6 +154,11 @@ namespace olc::utils
|
|||||||
return m_vContent.size();
|
return m_vContent.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline std::vector<std::string> GetValues() const
|
||||||
|
{
|
||||||
|
return m_vContent;
|
||||||
|
}
|
||||||
|
|
||||||
// Checks if a property exists - useful to avoid creating properties
|
// Checks if a property exists - useful to avoid creating properties
|
||||||
// via reading them, though non-essential
|
// via reading them, though non-essential
|
||||||
inline bool HasProperty(const std::string& sName) const
|
inline bool HasProperty(const std::string& sName) const
|
||||||
|
Loading…
x
Reference in New Issue
Block a user