This repository has been archived by the owner on Nov 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from Lohkdesgds/Snapshots
V1.0.3 (V1.1.0C)
- Loading branch information
Showing
18 changed files
with
878 additions
and
435 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,172 @@ | ||
#include "..\all\enable_all.h" | ||
|
||
namespace LSW { | ||
namespace v2 { | ||
namespace Config { | ||
|
||
ALLEGRO_CONFIG* config::c = nullptr; | ||
std::mutex config::m; | ||
|
||
config::config() | ||
{ | ||
logg << Log::START << "[CONF:CONST][INFO] Registered spawn of config ID#" + std::to_string((size_t)this) << Log::ENDL; | ||
m.lock(); | ||
if (!c) { | ||
Safer::safe_string temporary = Defaults::Config::config_file; | ||
Tools::interpret_path(temporary); | ||
Tools::createPath(temporary); | ||
|
||
logg << Log::NEEDED_START << "[CONF:CONST][INFO] Registered loading of Config file (global)" << Log::NEEDED_ENDL; | ||
if (!(c = al_load_config_file(temporary.g().c_str()))) | ||
{ | ||
c = al_create_config(); | ||
if (!c) throw "at config::config [#" + std::to_string((size_t)this) + "]: Cannot load/create config file!"; | ||
logg << Log::NEEDED_START << "[CONF:CONST][INFO] Is this the first time you're opening this game? Registered first Config load." << Log::NEEDED_ENDL; | ||
|
||
// set or load first values | ||
set(Config::HAD_ERROR, true); // then texture download starts // USED | ||
set(Config::WAS_OSD_ON, false); // USED | ||
set(Config::WAS_FULLSCREEN, true); // USED | ||
set(Config::LAST_VOLUME, 0.5); | ||
set(Config::LAST_VERSION, Defaults::version_app); // nah | ||
set(Config::LAST_PLAYERNAME, "Player"); | ||
set(Config::LAST_COLOR, "GREEN"); | ||
set(Config::SCREEN_X, Defaults::Config::screen_siz[0]); | ||
set(Config::SCREEN_Y, Defaults::Config::screen_siz[1]); | ||
set(Config::_TIMES_LIT, 0LL); | ||
|
||
if (!al_save_config_file(temporary.g().c_str(), c)) { | ||
throw "at config::config [#" + std::to_string((size_t)this) + "]: Cannot save config file!"; | ||
} | ||
} | ||
else { | ||
long long ll; | ||
get(Config::_TIMES_LIT, ll, 0LL); | ||
ll++; | ||
set(Config::_TIMES_LIT, ll); | ||
} | ||
} | ||
m.unlock(); | ||
} | ||
config::~config() | ||
{ | ||
logg << Log::START << "[CONF:DESTR][INFO] Registered despawn of config ID#" + std::to_string((size_t)this) << Log::ENDL; | ||
if (c) { | ||
m.lock(); | ||
Safer::safe_string temporary = Defaults::Config::config_file; | ||
Tools::interpret_path(temporary); | ||
Tools::createPath(temporary); | ||
al_save_config_file(temporary.g().c_str(), c); | ||
m.unlock(); | ||
} | ||
} | ||
|
||
void config::set(const Safer::safe_string e, const Safer::safe_string v) | ||
{ | ||
if (!c) throw "at config::set [#" + std::to_string((size_t)this) + "]: Cannot set \"" + e.g() + "\" as \"" + v.g() + "\"."; | ||
al_set_config_value(c, Defaults::Config::strt_txt.g().c_str(), e.g().c_str(), v.g().c_str()); | ||
} | ||
void config::set(const conf_b e, const bool v) | ||
{ | ||
set(conf_b_str[e].g(), bool_s[(int)v]); | ||
} | ||
void config::set(const conf_f e, const float v) | ||
{ | ||
set(conf_f_str[e].g(), std::to_string(v)); | ||
} | ||
void config::set(const conf_i e, const int v) | ||
{ | ||
set(conf_i_str[e].g(), std::to_string(v)); | ||
} | ||
void config::set(const conf_ll e, const long long v) | ||
{ | ||
set(conf_ll_str[e].g(), std::to_string(v)); | ||
} | ||
void config::set(const conf_s e, const Safer::safe_string v) | ||
{ | ||
set(conf_s_str[e].g(), v); | ||
} | ||
|
||
void config::get(const Safer::safe_string e, Safer::safe_string& v, const Safer::safe_string defaul) | ||
{ | ||
if (!c) throw "at config::get [#" + std::to_string((size_t)this) + "]: Cannot get \"" + e.g() + "\" as \"" + v.g() + "\"."; | ||
const char* chh = al_get_config_value(c, Defaults::Config::strt_txt.g().c_str(), e.g().c_str()); | ||
if (!chh) { | ||
logg << Log::NEEDED_START << "[CONF:GET()][WARN] There was no value to " << e << ", so the default value was set (" << defaul << ")." << Log::NEEDED_ENDL; | ||
set(e, defaul); | ||
v = defaul; | ||
return; | ||
} | ||
v = chh; | ||
} | ||
void config::get(const conf_b e, bool& v, const bool defaul) | ||
{ | ||
Safer::safe_string output; | ||
get(conf_b_str[e], output, bool_s[(int)defaul]); | ||
v = (output == bool_s[1 /*true*/]); | ||
} | ||
void config::get(const conf_f e, float& v, const float defaul) | ||
{ | ||
Safer::safe_string output; | ||
get(conf_f_str[e], output, std::to_string(defaul)); | ||
v = atof(output.g().c_str()); | ||
} | ||
void config::get(const conf_i e, int& v, const int defaul) | ||
{ | ||
Safer::safe_string output; | ||
get(conf_i_str[e], output, std::to_string(defaul)); | ||
v = atoi(output.g().c_str()); | ||
} | ||
void config::get(const conf_ll e, long long& v, const long long defaul) | ||
{ | ||
Safer::safe_string output; | ||
get(conf_ll_str[e], output, std::to_string(defaul)); | ||
v = atoll(output.g().c_str()); | ||
} | ||
void config::get(const conf_s e, Safer::safe_string& v, const Safer::safe_string defaul) | ||
{ | ||
Safer::safe_string output; | ||
get(conf_s_str[e], output, defaul); | ||
v = output; | ||
} | ||
|
||
|
||
const bool config::isEq(const Safer::safe_string e, const Safer::safe_string v) | ||
{ | ||
Safer::safe_string oth; | ||
get(e, oth, v); // meh | ||
return oth == v; | ||
} | ||
const bool config::isEq(const conf_b e, const bool v) | ||
{ | ||
bool oth; | ||
get(e, oth, v); // meh | ||
return oth == v; | ||
} | ||
const bool config::isEq(const conf_f e, const float v) | ||
{ | ||
float oth; | ||
get(e, oth, v); // meh | ||
return oth == v; | ||
} | ||
const bool config::isEq(const conf_i e, const int v) | ||
{ | ||
int oth; | ||
get(e, oth, v); // meh | ||
return oth == v; | ||
} | ||
const bool config::isEq(const conf_ll e, const long long v) | ||
{ | ||
long long oth; | ||
get(e, oth, v); // meh | ||
return oth == v; | ||
} | ||
const bool config::isEq(const conf_s e, const Safer::safe_string v) | ||
{ | ||
Safer::safe_string oth; | ||
get(e, oth, v); // meh | ||
return oth == v; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#pragma once | ||
|
||
#include "..\all\enable_all.h" | ||
|
||
namespace LSW { | ||
namespace v2 { | ||
namespace Config { | ||
|
||
enum conf_b{HAD_ERROR,WAS_OSD_ON,WAS_FULLSCREEN}; | ||
enum conf_f{LAST_VOLUME}; | ||
enum conf_i{SCREEN_X,SCREEN_Y}; | ||
enum conf_ll{_TIMES_LIT}; | ||
enum conf_s{LAST_VERSION,LAST_PLAYERNAME,LAST_COLOR}; | ||
|
||
const Safer::safe_string conf_b_str[] = { "had_error", "was_osd_on", "fullscreen" }; | ||
const Safer::safe_string conf_f_str[] = { "last_volume" }; | ||
const Safer::safe_string conf_i_str[] = { "screen_width","screen_height" }; | ||
const Safer::safe_string conf_ll_str[] = { "times_open" }; | ||
const Safer::safe_string conf_s_str[] = { "last_version","playername","playercolor" }; | ||
|
||
// tool | ||
const Safer::safe_string bool_s[] = { "false", "true" }; | ||
|
||
class config { | ||
static ALLEGRO_CONFIG* c; | ||
static std::mutex m; | ||
Log::gfile logg; | ||
public: | ||
config(); | ||
~config(); | ||
|
||
void set(const Safer::safe_string, const Safer::safe_string); | ||
void set(const conf_b, const bool); | ||
void set(const conf_f, const float); | ||
void set(const conf_i, const int); | ||
void set(const conf_ll, const long long); | ||
void set(const conf_s, const Safer::safe_string); | ||
|
||
void get(const Safer::safe_string, Safer::safe_string&, const Safer::safe_string); | ||
void get(const conf_b, bool&, const bool); | ||
void get(const conf_f, float&, const float); | ||
void get(const conf_i, int&, const int); | ||
void get(const conf_ll, long long&, const long long); | ||
void get(const conf_s, Safer::safe_string&, const Safer::safe_string); | ||
|
||
const bool isEq(const Safer::safe_string, const Safer::safe_string); | ||
const bool isEq(const conf_b, const bool); | ||
const bool isEq(const conf_f, const float); | ||
const bool isEq(const conf_i, const int); | ||
const bool isEq(const conf_ll, const long long); | ||
const bool isEq(const conf_s, const Safer::safe_string); | ||
}; | ||
} | ||
} | ||
} |
Oops, something went wrong.