summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes E. Krause <j.k@eclipso.de>2019-03-22 04:37:53 +0100
committerCharles Pigott <charlespigott@googlemail.com>2020-02-06 21:00:30 +0000
commit107283748ab599a1ae8a01f91c09e9f9a3e4bd06 (patch)
tree0ca588130d5c00d1fb0473c9cf04e4a19b6c5bbd
parentf389d66e36ceda578d30bde5f8ae94fdf2103704 (diff)
downloadopenttd-107283748ab599a1ae8a01f91c09e9f9a3e4bd06.tar.xz
Feature: SLF_HEX to print hexadecimal numbers in the config file
-rw-r--r--src/saveload/saveload.h3
-rw-r--r--src/settings.cpp14
2 files changed, 12 insertions, 5 deletions
diff --git a/src/saveload/saveload.h b/src/saveload/saveload.h
index c06e8fdda..14c8c3231 100644
--- a/src/saveload/saveload.h
+++ b/src/saveload/saveload.h
@@ -471,7 +471,8 @@ enum VarTypes {
SLF_NO_NETWORK_SYNC = 1 << 10, ///< do not synchronize over network (but it is saved if SLF_NOT_IN_SAVE is not set)
SLF_ALLOW_CONTROL = 1 << 11, ///< allow control codes in the strings
SLF_ALLOW_NEWLINE = 1 << 12, ///< allow new lines in the strings
- /* 3 more possible flags */
+ SLF_HEX = 1 << 13, ///< print numbers as hex in the config file (only useful for unsigned)
+ /* 2 more possible flags */
};
typedef uint32 VarType;
diff --git a/src/settings.cpp b/src/settings.cpp
index e6fbbfcf2..7fb2e7249 100644
--- a/src/settings.cpp
+++ b/src/settings.cpp
@@ -268,7 +268,7 @@ static void MakeIntList(char *buf, const char *last, const void *array, int nele
const byte *p = (const byte *)array;
for (i = 0; i != nelems; i++) {
- switch (type) {
+ switch (GetVarMemType(type)) {
case SLE_VAR_BL:
case SLE_VAR_I8: v = *(const int8 *)p; p += 1; break;
case SLE_VAR_U8: v = *(const uint8 *)p; p += 1; break;
@@ -278,7 +278,13 @@ static void MakeIntList(char *buf, const char *last, const void *array, int nele
case SLE_VAR_U32: v = *(const uint32 *)p; p += 4; break;
default: NOT_REACHED();
}
- buf += seprintf(buf, last, IsSignedVarMemType(type) ? ((i == 0) ? "%d" : ",%d") : ((i == 0) ? "%u" : ",%u"), v);
+ if (IsSignedVarMemType(type)) {
+ buf += seprintf(buf, last, (i == 0) ? "%d" : ",%d", v);
+ } else if (type & SLF_HEX) {
+ buf += seprintf(buf, last, (i == 0) ? "0x%X" : ",0x%X", v);
+ } else {
+ buf += seprintf(buf, last, (i == 0) ? "%u" : ",%u", v);
+ }
}
}
@@ -673,7 +679,7 @@ static void IniSaveSettings(IniFile *ini, const SettingDesc *sd, const char *grp
switch (sdb->cmd) {
case SDT_BOOLX: strecpy(buf, (i != 0) ? "true" : "false", lastof(buf)); break;
- case SDT_NUMX: seprintf(buf, lastof(buf), IsSignedVarMemType(sld->conv) ? "%d" : "%u", i); break;
+ case SDT_NUMX: seprintf(buf, lastof(buf), IsSignedVarMemType(sld->conv) ? "%d" : (sld->conv & SLF_HEX) ? "%X" : "%u", i); break;
case SDT_ONEOFMANY: MakeOneOfMany(buf, lastof(buf), sdb->many, i); break;
case SDT_MANYOFMANY: MakeManyOfMany(buf, lastof(buf), sdb->many, i); break;
default: NOT_REACHED();
@@ -701,7 +707,7 @@ static void IniSaveSettings(IniFile *ini, const SettingDesc *sd, const char *grp
break;
case SDT_INTLIST:
- MakeIntList(buf, lastof(buf), ptr, sld->length, GetVarMemType(sld->conv));
+ MakeIntList(buf, lastof(buf), ptr, sld->length, sld->conv);
break;
default: NOT_REACHED();