11#ifndef LUX_SELF_SETUP_H
12#define LUX_SELF_SETUP_H
20inline bool LuxSetupSetCfgValue(std::string& asText,
const std::string& asKey,
const std::string& asValue)
23 while((lPos = asText.find(asKey, lPos)) != std::string::npos)
25 bool bWordStart = lPos == 0 || !(isalnum((
unsigned char)asText[lPos - 1]) || asText[lPos - 1] ==
'_');
26 size_t i = lPos + asKey.size();
27 while(i < asText.size() && (asText[i] ==
' ' || asText[i] ==
'\t')) ++i;
28 if(bWordStart && i < asText.size() && asText[i] ==
'=')
31 while(i < asText.size() && (asText[i] ==
' ' || asText[i] ==
'\t')) ++i;
32 if(i < asText.size() && asText[i] ==
'"')
34 size_t lEnd = asText.find(
'"', i + 1);
35 if(lEnd == std::string::npos)
return false;
36 asText.replace(i + 1, lEnd - i - 1, asValue);
48 const std::string sDir = std::string(
kLuxSetupDir) +
"/";
49 const char* vKeys[][2] = {
50 {
"Resources",
"resources.cfg" }, {
"Game",
"game.cfg" },
51 {
"DefaultMainSettingsSDL2",
"default_main_settings_sdl2.cfg" },
52 {
"DefaultUserKeysSDL2",
"default_user_keys_sdl2.cfg" },
53 {
"BaseLanguageFolder",
"lang/" }, {
"GameLanguageFolder",
"lang_main/" },
55 for(
size_t i = 0; i <
sizeof(vKeys) /
sizeof(vKeys[0]); ++i)
62inline bool LuxSetupSetBinding(std::string& asText,
const std::string& asAction,
const std::string& asSecondary)
64 size_t lTag = asText.find(
"<" + asAction +
" ");
65 if(lTag == std::string::npos)
return false;
66 size_t lClose = asText.find(
'>', lTag);
67 size_t lSec = asText.find(
"Secondary=\"", lTag);
68 if(lSec == std::string::npos || lSec > lClose)
return false;
70 size_t lEnd = asText.find(
'"', lSec);
71 if(lEnd == std::string::npos)
return false;
72 asText.replace(lSec, lEnd - lSec, asSecondary);
84inline void LuxSetupSetAttr(std::string& asText,
const std::string& asElement,
const std::string& asAttr,
const std::string& asValue)
86 size_t lTag = std::string::npos, lFrom = 0;
87 while((lFrom = asText.find(
"<" + asElement, lFrom)) != std::string::npos)
89 char c = lFrom + 1 + asElement.size() < asText.size() ? asText[lFrom + 1 + asElement.size()] :
'>';
90 if(c ==
' ' || c ==
'/' || c ==
'>' || c ==
'\t' || c ==
'\r' || c ==
'\n') { lTag = lFrom;
break; }
93 if(lTag == std::string::npos)
95 while(!asText.empty() && (asText[asText.size() - 1] ==
'\n' || asText[asText.size() - 1] ==
'\r')) asText.erase(asText.size() - 1);
96 asText +=
"\n<" + asElement +
" " + asAttr +
"=\"" + asValue +
"\" />\n";
99 size_t lEndTag = asText.find(
'>', lTag);
100 std::string sNeedle =
" " + asAttr +
"=\"";
101 size_t lAttr = asText.find(sNeedle, lTag);
102 if(lAttr != std::string::npos && lAttr < lEndTag)
104 size_t lVal = lAttr + sNeedle.size();
105 size_t lValEnd = asText.find(
'"', lVal);
106 asText.replace(lVal, lValEnd - lVal, asValue);
109 asText.insert(lTag + 1 + asElement.size(),
" " + asAttr +
"=\"" + asValue +
"\"");
115 const char* v[][2] = { {
"TextureFilter",
"2" }, {
"TextureAnisotropy",
"16.000000" }, {
"ShadowQuality",
"2" },
116 {
"ParallaxQuality",
"1" }, {
"SSAOSamples",
"16" }, {
"SmoothShadows",
"true" }, {
"HDShadows",
"true" },
117 {
"FogAmount",
"0.350000" }, {
"FogColor",
"0.000000" } };
118 for(
size_t i = 0; i <
sizeof(v) /
sizeof(v[0]); ++i)
LuxSetupSetAttr(asText,
"Graphics", v[i][0], v[i][1]);
133 if(asText.find(
"/amfp_enhanced/override") != std::string::npos)
return true;
134 size_t lPos = asText.find(
"<Resources>");
135 if(lPos == std::string::npos)
return false;
137 const char* sNl = asText.find(
"\r\n") != std::string::npos ?
"\r\n" :
"\n";
138 asText.insert(lPos, std::string(sNl) +
" <Directory Path=\"/amfp_enhanced/override\" AddSubDirs=\"true\" />");
bool LuxSetupUserKeys(std::string &asText)
Latest hint on D-pad right, last note on D-pad left (stock: hint on L3, note unbound).
bool LuxSetupResources(std::string &asText)
resources.cfg: our override folder first, so our files win bare-name lookups.
static const char *const kLuxSetupDir
bool LuxSetupMainInit(std::string &asText)
main_init.cfg for the fork: our resources, game.cfg, key / settings defaults and language folders.
void LuxSetupSetAttr(std::string &asText, const std::string &asElement, const std::string &asAttr, const std::string &asValue)
Sets attr="value" on the first <Element ...> tag, adding the attribute (or the element).
void LuxSetupUserSettings(std::string &asText)
default_user_settings: the Modern preset for new profiles (LuxPresets.h).
bool LuxSetupSetBinding(std::string &asText, const std::string &asAction, const std::string &asSecondary)
The Secondary binding of <Action Primary="..." Secondary="..." />; false if the action is missing.
bool LuxSetupSetCfgValue(std::string &asText, const std::string &asKey, const std::string &asValue)
Replaces the quoted value of Key = "..." (any spacing); false if the key is missing.
void LuxSetupMainSettings(std::string &asText)
default_main_settings: the graphics defaults of the Modern preset.