diff options
author | eriktorbjorn | 2011-06-18 18:30:04 +0200 |
---|---|---|
committer | eriktorbjorn | 2011-06-18 18:30:04 +0200 |
commit | 72aa426770af379223b1572f87c003c540f5a263 (patch) | |
tree | 1f1c2e21c0bf6dd3b71506aa3c68e68779415511 /engines/sword25/util/lua | |
parent | a7234eef817ae43a93f1e3949a238dd3a3555e10 (diff) | |
download | scummvm-rg350-72aa426770af379223b1572f87c003c540f5a263.tar.gz scummvm-rg350-72aa426770af379223b1572f87c003c540f5a263.tar.bz2 scummvm-rg350-72aa426770af379223b1572f87c003c540f5a263.zip |
SWORD25: Fix locale-related bug when reading the volume settings
I don't really like this, but I can't think of any better way. It
seems that Lua doesn't like decimal comma at all, so we have to
format the volume settings with a decimal point instead. Otherwise,
all I'll ever get is either full volume or no volume, with nothing
in between.
Diffstat (limited to 'engines/sword25/util/lua')
-rw-r--r-- | engines/sword25/util/lua/scummvm_file.cpp | 30 | ||||
-rw-r--r-- | engines/sword25/util/lua/scummvm_file.h | 1 |
2 files changed, 27 insertions, 4 deletions
diff --git a/engines/sword25/util/lua/scummvm_file.cpp b/engines/sword25/util/lua/scummvm_file.cpp index 9df090f49b..7667e19c6f 100644 --- a/engines/sword25/util/lua/scummvm_file.cpp +++ b/engines/sword25/util/lua/scummvm_file.cpp @@ -32,6 +32,25 @@ 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; @@ -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; } diff --git a/engines/sword25/util/lua/scummvm_file.h b/engines/sword25/util/lua/scummvm_file.h index a4cbd2a6cf..e8c468ee07 100644 --- a/engines/sword25/util/lua/scummvm_file.h +++ b/engines/sword25/util/lua/scummvm_file.h @@ -37,6 +37,7 @@ private: uint _readPos; Common::String _settings; + Common::String formatDouble(double value); void setupConfigFile(); Common::String getLanguage(); void setLanguage(const Common::String &lang); |