aboutsummaryrefslogtreecommitdiff
path: root/engines/sword25/util/lua/scummvm_file.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'engines/sword25/util/lua/scummvm_file.cpp')
-rw-r--r--engines/sword25/util/lua/scummvm_file.cpp48
1 files changed, 35 insertions, 13 deletions
diff --git a/engines/sword25/util/lua/scummvm_file.cpp b/engines/sword25/util/lua/scummvm_file.cpp
index 3c0377d0ee..33053a71cb 100644
--- a/engines/sword25/util/lua/scummvm_file.cpp
+++ b/engines/sword25/util/lua/scummvm_file.cpp
@@ -32,11 +32,30 @@ Sword25FileProxy::Sword25FileProxy(const Common::String &filename, const Common:
setupConfigFile();
}
+Common::String Sword25FileProxy::formatDouble(double value) {
+ // This is a bit hackish. The point of it is that it's important that
+ // we ignore the locale decimal mark and force it to be a point. If it
+ // would happen to be a comma instead, it seems that it's seen as two
+ // comma-separated integers rather than one floating-point value. Or
+ // something like that.
+
+ bool negative = value < 0.0;
+ value = fabs(value);
+ double integerPart = floor(value);
+ double fractionalPart = (value - integerPart) * 1000000.0;
+
+ Common::String out = Common::String::format("%.0f.%.0f", integerPart, fractionalPart);
+ if (negative)
+ out = "-" + out;
+
+ return out;
+}
+
void Sword25FileProxy::setupConfigFile() {
- double sfxVolume = ConfMan.hasKey("sfx_volume") ? 1.0 : 1.0 * ConfMan.getInt("sfx_volume") / 255.0;
- double musicVolume = ConfMan.hasKey("music_volume") ? 0.5 : 1.0 * ConfMan.getInt("music_volume") / 255.0;
- double speechVolume = ConfMan.hasKey("speech_volume") ? 1.0 : 1.0 * ConfMan.getInt("speech_volume") / 255.0;
- bool subtitles = ConfMan.hasKey("subtitles") ? true : ConfMan.getBool("subtitles");
+ double sfxVolume = !ConfMan.hasKey("sfx_volume") ? 1.0 : 1.0 * ConfMan.getInt("sfx_volume") / 255.0;
+ double musicVolume = !ConfMan.hasKey("music_volume") ? 0.5 : 1.0 * ConfMan.getInt("music_volume") / 255.0;
+ double speechVolume = !ConfMan.hasKey("speech_volume") ? 1.0 : 1.0 * ConfMan.getInt("speech_volume") / 255.0;
+ bool subtitles = !ConfMan.hasKey("subtitles") ? true : ConfMan.getBool("subtitles");
_readData = Common::String::format(
"GAME_LANGUAGE = \"%s\"\r\n\
@@ -45,10 +64,13 @@ MAX_MEMORY_USAGE = 256000000\r\n\
GFX_VSYNC_ACTIVE = true\r\n\
SFX_SAMPLING_RATE = 44100\r\n\
SFX_CHANNEL_COUNT = 32\r\n\
-SFX_SOUND_VOLUME = %f\r\n\
-SFX_MUSIC_VOLUME = %f\r\n\
-SFX_SPEECH_VOLUME = %f\r\n",
- getLanguage().c_str(), subtitles ? "true" : "false", sfxVolume, musicVolume, speechVolume);
+SFX_SOUND_VOLUME = %s\r\n\
+SFX_MUSIC_VOLUME = %s\r\n\
+SFX_SPEECH_VOLUME = %s\r\n",
+ getLanguage().c_str(), subtitles ? "true" : "false",
+ formatDouble(sfxVolume).c_str(),
+ formatDouble(musicVolume).c_str(),
+ formatDouble(speechVolume).c_str());
_readPos = 0;
}
@@ -76,14 +98,14 @@ size_t Sword25FileProxy::write(const char *ptr, size_t count) {
// Legitimate data
const char *p = strchr(ptr, '\n');
if (!p) p = ptr + strlen(ptr);
- while ((*p == '\r') || (*p == '\n'))
+ while ((*p == '\r') || (*p == '\n'))
++p;
_settings += Common::String(ptr, p - ptr);
ptr = p;
}
- while ((*ptr == '\r') || (*ptr == '\n'))
+ while ((*ptr == '\r') || (*ptr == '\n'))
++ptr;
}
@@ -97,7 +119,7 @@ void Sword25FileProxy::writeSettings() {
if ((*pSrc != '\r') && (*pSrc != '\n')) {
const char *p = strchr(pSrc, '=');
assert(p);
-
+
// Get the setting name
const char *pEnd = p - 1;
while (*pEnd == ' ')
@@ -110,10 +132,10 @@ void Sword25FileProxy::writeSettings() {
++pStart;
pEnd = pStart + 1;
- while ((*pEnd != '\r') && (*pEnd != '\n') && (*pEnd != '\0'))
+ while ((*pEnd != '\r') && (*pEnd != '\n') && (*pEnd != '\0'))
++pEnd;
Common::String value(pStart + (*pStart == '"' ? 1 : 0), pEnd - pStart - (*pStart == '"' ? 2 : 0));
-
+
// Update the setting
updateSetting(settingName, value);
pSrc = pEnd;