mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
Add wear bar color API (#13328)
--------- Co-authored-by: Muhammad Rifqi Priyo Susanto <muhammadrifqipriyosusanto@gmail.com> Co-authored-by: Lars Müller <34514239+appgurueu@users.noreply.github.com> Co-authored-by: grorp <gregor.parzefall@posteo.de>
This commit is contained in:
parent
e10d8080ba
commit
176e674a51
19 changed files with 598 additions and 26 deletions
|
@ -21,7 +21,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
#include "itemstackmetadata.h"
|
||||
#include "util/serialize.h"
|
||||
#include "util/strfnd.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <optional>
|
||||
|
||||
#define DESERIALIZE_START '\x01'
|
||||
#define DESERIALIZE_KV_DELIM '\x02'
|
||||
|
@ -31,11 +33,13 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
#define DESERIALIZE_PAIR_DELIM_STR "\x03"
|
||||
|
||||
#define TOOLCAP_KEY "tool_capabilities"
|
||||
#define WEAR_BAR_KEY "wear_color"
|
||||
|
||||
void ItemStackMetadata::clear()
|
||||
{
|
||||
SimpleMetadata::clear();
|
||||
updateToolCapabilities();
|
||||
updateWearBarParams();
|
||||
}
|
||||
|
||||
static void sanitize_string(std::string &str)
|
||||
|
@ -55,6 +59,8 @@ bool ItemStackMetadata::setString(const std::string &name, const std::string &va
|
|||
bool result = SimpleMetadata::setString(clean_name, clean_var);
|
||||
if (clean_name == TOOLCAP_KEY)
|
||||
updateToolCapabilities();
|
||||
else if (clean_name == WEAR_BAR_KEY)
|
||||
updateWearBarParams();
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -91,6 +97,7 @@ void ItemStackMetadata::deSerialize(std::istream &is)
|
|||
}
|
||||
}
|
||||
updateToolCapabilities();
|
||||
updateWearBarParams();
|
||||
}
|
||||
|
||||
void ItemStackMetadata::updateToolCapabilities()
|
||||
|
@ -116,3 +123,25 @@ void ItemStackMetadata::clearToolCapabilities()
|
|||
{
|
||||
setString(TOOLCAP_KEY, "");
|
||||
}
|
||||
|
||||
void ItemStackMetadata::updateWearBarParams()
|
||||
{
|
||||
if (contains(WEAR_BAR_KEY)) {
|
||||
std::istringstream is(getString(WEAR_BAR_KEY));
|
||||
wear_bar_override = WearBarParams::deserializeJson(is);
|
||||
} else {
|
||||
wear_bar_override.reset();
|
||||
}
|
||||
}
|
||||
|
||||
void ItemStackMetadata::setWearBarParams(const WearBarParams ¶ms)
|
||||
{
|
||||
std::ostringstream os;
|
||||
params.serializeJson(os);
|
||||
setString(WEAR_BAR_KEY, os.str());
|
||||
}
|
||||
|
||||
void ItemStackMetadata::clearWearBarParams()
|
||||
{
|
||||
setString(WEAR_BAR_KEY, "");
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue