mirror of
https://github.com/luanti-org/luanti.git
synced 2025-12-30 01:55:22 +01:00
Implement player attribute backend (#4155)
* This backend permit mods to store extra players attributes to a common interface.
* Add the obj:set_attribute(attr, value) Lua call
* Add the obj:get_attribute(attr) Lua call
Examples:
* player:set_attribute("home:home", "10,25,-78")
* player:get_attribute("default:mana")
Attributes are saved as a json in the player file in extended_attributes
key
They are saved only if a modification on the attributes occurs and loaded
when emergePlayer is called (they are attached to PlayerSAO).
This commit is contained in:
@@ -180,6 +180,7 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
typedef UNORDERED_MAP<std::string, std::string> PlayerAttributes;
|
||||
class RemotePlayer;
|
||||
|
||||
class PlayerSAO : public UnitSAO
|
||||
@@ -249,6 +250,39 @@ public:
|
||||
int getWieldIndex() const;
|
||||
void setWieldIndex(int i);
|
||||
|
||||
/*
|
||||
Modding interface
|
||||
*/
|
||||
inline void setExtendedAttribute(const std::string &attr, const std::string &value)
|
||||
{
|
||||
m_extra_attributes[attr] = value;
|
||||
m_extended_attributes_modified = true;
|
||||
}
|
||||
|
||||
inline bool getExtendedAttribute(const std::string &attr, std::string *value)
|
||||
{
|
||||
if (m_extra_attributes.find(attr) == m_extra_attributes.end())
|
||||
return false;
|
||||
|
||||
*value = m_extra_attributes[attr];
|
||||
return true;
|
||||
}
|
||||
|
||||
inline const PlayerAttributes &getExtendedAttributes()
|
||||
{
|
||||
return m_extra_attributes;
|
||||
}
|
||||
|
||||
inline bool extendedAttributesModified() const
|
||||
{
|
||||
return m_extended_attributes_modified;
|
||||
}
|
||||
|
||||
inline void setExtendedAttributeModified(bool v)
|
||||
{
|
||||
m_extended_attributes_modified = v;
|
||||
}
|
||||
|
||||
/*
|
||||
PlayerSAO-specific
|
||||
*/
|
||||
@@ -343,6 +377,9 @@ private:
|
||||
f32 m_pitch;
|
||||
f32 m_fov;
|
||||
s16 m_wanted_range;
|
||||
|
||||
PlayerAttributes m_extra_attributes;
|
||||
bool m_extended_attributes_modified;
|
||||
public:
|
||||
float m_physics_override_speed;
|
||||
float m_physics_override_jump;
|
||||
|
||||
Reference in New Issue
Block a user