diff options
author | Fedja Beader <fedja@protonmail.ch> | 2024-09-08 18:43:05 +0000 |
---|---|---|
committer | Fedja Beader <fedja@protonmail.ch> | 2024-09-08 18:43:05 +0000 |
commit | 08c37fd2f0d7508d9d3016382747a9722fe0564d (patch) | |
tree | 2da8fd5ae19e4892eb8dc26e1001118c7d73fa87 | |
parent | db452921bafb2dd322b52c1e5d03e5e713849dd0 (diff) | |
download | mv-08c37fd2f0d7508d9d3016382747a9722fe0564d.tar.gz mv-08c37fd2f0d7508d9d3016382747a9722fe0564d.tar.bz2 mv-08c37fd2f0d7508d9d3016382747a9722fe0564d.tar.xz mv-08c37fd2f0d7508d9d3016382747a9722fe0564d.zip |
Refactor outfit saving logic
Shaves some bytes from exe, too
****
mana/plus!102
-rw-r--r-- | src/gui/windows/outfitwindow.cpp | 36 |
1 files changed, 23 insertions, 13 deletions
diff --git a/src/gui/windows/outfitwindow.cpp b/src/gui/windows/outfitwindow.cpp index cd015a114..390f31525 100644 --- a/src/gui/windows/outfitwindow.cpp +++ b/src/gui/windows/outfitwindow.cpp @@ -181,31 +181,41 @@ void OutfitWindow::save() const std::string outfitColorsStr; for (unsigned o = 0; o < OUTFITS_COUNT; o++) { - bool good = false; + bool isEmpty = true; for (unsigned i = 0; i < OUTFIT_ITEM_COUNT; i++) { const int val = mItems[o][i]; - const int res = val != 0 ? val : -1; - if (res != -1) - good = true; + // Not sure why, but "empty" is stored as -1 instead of 0. + int res; + if (val == 0) + res = -1; + else + { + isEmpty = false; + res = val; + } + outfitStr.append(toString(res)); + outfitColorsStr.append(toString(CAST_S32(mItemColors[o][i]))); + if (i < OUTFIT_ITEM_COUNT - 1) + { outfitStr.append(" "); - outfitColorsStr.append(toString(CAST_S32( - toInt(mItemColors[o][i], int)))); - if (i < OUTFIT_ITEM_COUNT - 1) outfitColorsStr.append(" "); + } } - if (good) + + if (isEmpty) { - serverConfig.setValue("Outfit" + toString(o), outfitStr); - serverConfig.setValue("OutfitColor" + toString(o), - outfitColorsStr); + serverConfig.deleteKey("Outfit" + toString(o)); + serverConfig.deleteKey("OutfitColor" + toString(o)); } else { - serverConfig.deleteKey("Outfit" + toString(o)); - serverConfig.deleteKey("OutfitColor" + toString(o)); + serverConfig.setValue("Outfit" + toString(o), + outfitStr); + serverConfig.setValue("OutfitColor" + toString(o), + outfitColorsStr); } if (mItemsUnequip[o]) |