mirror of
https://github.com/OpenMW/openmw.git
synced 2025-06-21 17:41:36 +00:00
Use nil instead of -1 for default enchantment charge
This commit is contained in:
parent
66b2d428c8
commit
b1773d7e9f
2 changed files with 13 additions and 6 deletions
|
@ -1,5 +1,6 @@
|
||||||
#include <sol/sol.hpp>
|
#include <sol/sol.hpp>
|
||||||
|
|
||||||
|
#include "../../mwmechanics/spellutil.hpp"
|
||||||
#include "../../mwworld/class.hpp"
|
#include "../../mwworld/class.hpp"
|
||||||
|
|
||||||
#include "../itemdata.hpp"
|
#include "../itemdata.hpp"
|
||||||
|
@ -10,10 +11,16 @@ namespace MWLua
|
||||||
{
|
{
|
||||||
void addItemBindings(sol::table item, const Context& context)
|
void addItemBindings(sol::table item, const Context& context)
|
||||||
{
|
{
|
||||||
item["getEnchantmentCharge"]
|
item["getEnchantmentCharge"] = [](const Object& object) -> sol::optional<float> {
|
||||||
= [](const Object& object) { return object.ptr().getCellRef().getEnchantmentCharge(); };
|
float charge = object.ptr().getCellRef().getEnchantmentCharge();
|
||||||
item["setEnchantmentCharge"]
|
if (charge == -1)
|
||||||
= [](const GObject& object, float charge) { object.ptr().getCellRef().setEnchantmentCharge(charge); };
|
return sol::nullopt;
|
||||||
|
else
|
||||||
|
return charge;
|
||||||
|
};
|
||||||
|
item["setEnchantmentCharge"] = [](const GObject& object, sol::optional<float> charge) {
|
||||||
|
object.ptr().getCellRef().setEnchantmentCharge(charge.value_or(-1));
|
||||||
|
};
|
||||||
item["isRestocking"]
|
item["isRestocking"]
|
||||||
= [](const Object& object) -> bool { return object.ptr().getCellRef().getCount(false) < 0; };
|
= [](const Object& object) -> bool { return object.ptr().getCellRef().getCount(false) < 0; };
|
||||||
|
|
||||||
|
|
|
@ -652,7 +652,7 @@
|
||||||
-- Get this item's current enchantment charge.
|
-- Get this item's current enchantment charge.
|
||||||
-- @function [parent=#Item] getEnchantmentCharge
|
-- @function [parent=#Item] getEnchantmentCharge
|
||||||
-- @param openmw.core#GameObject item
|
-- @param openmw.core#GameObject item
|
||||||
-- @return #number The charge remaining. -1 if the enchantment has never been used, implying the charge is full. Unenchanted items will always return a value of -1.
|
-- @return #number The charge remaining. `nil` if the enchantment has never been used, implying the charge is full. Unenchanted items will always return a value of `nil`.
|
||||||
|
|
||||||
---
|
---
|
||||||
-- Checks if the item restocks.
|
-- Checks if the item restocks.
|
||||||
|
@ -665,7 +665,7 @@
|
||||||
-- Set this item's enchantment charge.
|
-- Set this item's enchantment charge.
|
||||||
-- @function [parent=#Item] setEnchantmentCharge
|
-- @function [parent=#Item] setEnchantmentCharge
|
||||||
-- @param openmw.core#GameObject item
|
-- @param openmw.core#GameObject item
|
||||||
-- @param #number charge
|
-- @param #number charge Can be `nil` to reset the unused state / full
|
||||||
|
|
||||||
---
|
---
|
||||||
-- Whether the object is supposed to be carriable. It is true for all items except
|
-- Whether the object is supposed to be carriable. It is true for all items except
|
||||||
|
|
Loading…
Reference in a new issue