cat_cfg_rebase, cat_cfg_resetbase, cat_save_complete
This commit is contained in:
parent
0bc3451bbb
commit
e87fad18db
@ -12,6 +12,74 @@
|
||||
|
||||
int CatVar::last_id { 0 };
|
||||
|
||||
int rebased_count { 0 };
|
||||
|
||||
int GetRebasedCatVarCount() {
|
||||
return rebased_count;
|
||||
}
|
||||
|
||||
static CatCommand cfg_rebase("cfg_setbase", "Rebase config", []() {
|
||||
for (auto& cv : CatVarList()) {
|
||||
std::string value(cv->GetString());
|
||||
if (value != cv->defaults) {
|
||||
cv->current_base = value;
|
||||
rebased_count++;
|
||||
}
|
||||
}
|
||||
logging::Info("Successfully rebased %d variables", rebased_count);
|
||||
});
|
||||
|
||||
static CatCommand cfg_resetbase("cfg_resetbase", "Reset config base", []() {
|
||||
for (auto& cv : CatVarList()) {
|
||||
cv->current_base = cv->defaults;
|
||||
}
|
||||
rebased_count = 0;
|
||||
});
|
||||
|
||||
static CatCommand save_settings("save", "Save settings (optional filename)", [](const CCommand& args) {
|
||||
std::string filename("lastcfg");
|
||||
if (args.ArgC() > 1) {
|
||||
filename = std::string(args.Arg(1));
|
||||
}
|
||||
std::string path = format("tf/cfg/cat_", filename, ".cfg");
|
||||
logging::Info("Saving settings to %s", path.c_str());
|
||||
if (GetRebasedCatVarCount()) {
|
||||
logging::Info("[Warning] %d CatVars are rebased!", GetRebasedCatVarCount());
|
||||
}
|
||||
std::ofstream file(path, std::ios::out);
|
||||
if (file.bad()) {
|
||||
logging::Info("Couldn't open the file!");
|
||||
return;
|
||||
}
|
||||
for (const auto& i : CatVarList()) {
|
||||
if (i->GetBase() != std::string(i->GetString())) {
|
||||
file << CON_PREFIX << i->name << " \"" << i->GetString() << "\"\n";
|
||||
}
|
||||
}
|
||||
file.close();
|
||||
});
|
||||
|
||||
static CatCommand save_settings_complete("save_complete", "Save all settings (optional filename)", [](const CCommand& args) {
|
||||
std::string filename("lastcfg");
|
||||
if (args.ArgC() > 1) {
|
||||
filename = std::string(args.Arg(1));
|
||||
}
|
||||
std::string path = format("tf/cfg/cat_", filename, ".cfg");
|
||||
logging::Info("Saving settings to %s", path.c_str());
|
||||
if (GetRebasedCatVarCount()) {
|
||||
logging::Info("[Warning] %d CatVars are rebased!", GetRebasedCatVarCount());
|
||||
}
|
||||
std::ofstream file(path, std::ios::out);
|
||||
if (file.bad()) {
|
||||
logging::Info("Couldn't open the file!");
|
||||
return;
|
||||
}
|
||||
for (const auto& i : CatVarList()) {
|
||||
file << CON_PREFIX << i->name << " \"" << i->GetString() << "\"\n";
|
||||
}
|
||||
file.close();
|
||||
});
|
||||
|
||||
// Prevent initialization errors.
|
||||
std::vector<CatVar*>& registrationArray() {
|
||||
static std::vector<CatVar*> vector;
|
||||
@ -94,6 +162,7 @@ void CatVar::Register() {
|
||||
id = last_id++;
|
||||
convar = CreateConVar(CON_PREFIX + name, defaults, desc_short);
|
||||
convar_parent = convar->m_pParent;
|
||||
current_base = defaults;
|
||||
while (!callbacks.empty()) {
|
||||
callbacks.back()(this);
|
||||
callbacks.pop_back();
|
||||
|
@ -94,6 +94,10 @@ public:
|
||||
return g_IInputSystem->IsButtonDown(static_cast<ButtonCode_t>(static_cast<int>(*this)));
|
||||
}
|
||||
|
||||
inline const std::string& GetBase() const {
|
||||
return current_base;
|
||||
}
|
||||
|
||||
public:
|
||||
const CatVar_t type;
|
||||
const std::string name;
|
||||
@ -102,6 +106,8 @@ public:
|
||||
const std::string desc_long { "" };
|
||||
const CatEnum* const enum_type { nullptr };
|
||||
|
||||
std::string current_base { "0" };
|
||||
|
||||
bool restricted { false };
|
||||
float min { 0.0f };
|
||||
float max { 0.0f };
|
||||
@ -121,5 +127,6 @@ std::vector<CatCommand*>& commandRegistrationArray();
|
||||
|
||||
std::vector<CatVar*>& CatVarList();
|
||||
void RegisterCatVars();
|
||||
int GetRebasedCatVarCount();
|
||||
|
||||
#endif /* CVWRAPPER_H_ */
|
||||
|
@ -485,27 +485,6 @@ CatCommand name("name_set", "Immediate name change", [](const CCommand& args) {
|
||||
ch->SendNetMsg(setname, false);
|
||||
}
|
||||
});
|
||||
CatCommand save_settings("save", "Save settings (optional filename)", [](const CCommand& args) {
|
||||
std::string filename("lastcfg");
|
||||
if (args.ArgC() > 1) {
|
||||
filename = std::string(args.Arg(1));
|
||||
}
|
||||
std::string path = format("tf/cfg/cat_", filename, ".cfg");
|
||||
logging::Info("Saving settings to %s", path.c_str());
|
||||
std::ofstream file(path, std::ios::out);
|
||||
if (file.bad()) {
|
||||
logging::Info("Couldn't open the file!");
|
||||
return;
|
||||
}
|
||||
for (const auto& i : RegisteredVarsList()) {
|
||||
if (i) {
|
||||
if (strcmp(i->GetString(), i->GetDefault())) {
|
||||
file << i->GetName() << " \"" << i->GetString() << "\"\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
file.close();
|
||||
});
|
||||
CatCommand say_lines("say_lines", "Say with newlines (\\n)", [](const CCommand& args) {
|
||||
std::string message(args.ArgS());
|
||||
ReplaceString(message, "\\n", "\n");
|
||||
|
Reference in New Issue
Block a user