fix: Fixes allocating CompactInfo when changing the weight of an item (#2282)
### Summary * Fixes extra allocations and computing weight values when changing the weight of an item.
This commit is contained in:
parent
5fb0e806c5
commit
6a7d49b679
1 changed files with 19 additions and 17 deletions
|
|
@ -474,25 +474,27 @@ public partial class Item : IHued, IComparable<Item>, ISpawnable, IObjectPropert
|
||||||
}
|
}
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (Weight != value)
|
var defaultWeight = DefaultWeight;
|
||||||
|
var info = LookupCompactInfo();
|
||||||
|
var oldWeight = info is { m_Weight: >= 0 } ? info.m_Weight : defaultWeight;
|
||||||
|
|
||||||
|
if (oldWeight == value)
|
||||||
{
|
{
|
||||||
var info = AcquireCompactInfo();
|
return;
|
||||||
|
|
||||||
var oldPileWeight = PileWeight;
|
|
||||||
|
|
||||||
info.m_Weight = value;
|
|
||||||
|
|
||||||
if (info.m_Weight < 0)
|
|
||||||
{
|
|
||||||
VerifyCompactInfo();
|
|
||||||
}
|
|
||||||
|
|
||||||
var newPileWeight = PileWeight;
|
|
||||||
|
|
||||||
UpdateTotal(this, TotalType.Weight, newPileWeight - oldPileWeight);
|
|
||||||
|
|
||||||
InvalidateProperties();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (value < 0 || defaultWeight == value)
|
||||||
|
{
|
||||||
|
info?.m_Weight = -1;
|
||||||
|
VerifyCompactInfo();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
(info ?? AcquireCompactInfo()).m_Weight = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
UpdateTotal(this, TotalType.Weight, PileWeight - (int)Math.Ceiling(oldWeight * Amount));
|
||||||
|
InvalidateProperties();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue