mirror of
https://github.com/bdunderscore/modular-avatar.git
synced 2025-02-07 06:12:47 +08:00
fix: incorrect default value for single menu item with automatic value (#1147)
This commit is contained in:
parent
3b28ea2b14
commit
b83b89ce38
@ -96,10 +96,10 @@ namespace nadena.dev.modular_avatar.core.editor
|
|||||||
{
|
{
|
||||||
defaultValue = list.FirstOrDefault(m => m.isDefault && !m.automaticValue)?.Control?.value ?? 0;
|
defaultValue = list.FirstOrDefault(m => m.isDefault && !m.automaticValue)?.Control?.value ?? 0;
|
||||||
|
|
||||||
if (list.Count == 1)
|
if (list.Count == 1 && list[0].isDefault && list[0].automaticValue)
|
||||||
// If we have only a single entry, it's probably an on-off toggle, so we'll implicitly let 0
|
// If we have only a single entry, it's probably an on-off toggle, so we'll implicitly let 1
|
||||||
// be the 'unselected' default value (if this is not default)
|
// be the 'selected' default value (if this is default and automatic value)
|
||||||
defaultValue = 0;
|
defaultValue = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
HashSet<int> usedValues = new();
|
HashSet<int> usedValues = new();
|
||||||
@ -124,11 +124,7 @@ namespace nadena.dev.modular_avatar.core.editor
|
|||||||
{
|
{
|
||||||
if (mami.automaticValue)
|
if (mami.automaticValue)
|
||||||
{
|
{
|
||||||
if (list.Count == 1)
|
if (mami.isDefault)
|
||||||
{
|
|
||||||
mami.Control.value = 1;
|
|
||||||
}
|
|
||||||
else if (mami.isDefault)
|
|
||||||
{
|
{
|
||||||
mami.Control.value = defaultValue;
|
mami.Control.value = defaultValue;
|
||||||
}
|
}
|
||||||
|
@ -16,10 +16,14 @@ namespace UnitTests.ReactiveComponent.ParameterAssignment
|
|||||||
[Test]
|
[Test]
|
||||||
public void ManuallyAssignedParametersAreNotReplaced()
|
public void ManuallyAssignedParametersAreNotReplaced()
|
||||||
{
|
{
|
||||||
TestAssignments(
|
TestAssignments(new[] { (false, 1.0f) }, new[] { 1.0f });
|
||||||
new[] { (false, 1.0f), (false, 4.0f) },
|
TestAssignments(new[] { (false, 1.0f) }, new[] { 1.0f }, 0);
|
||||||
new[] { 1.0f, 4.0f }
|
|
||||||
);
|
TestAssignments(new[] { (false, 4.0f) }, new[] { 4.0f });
|
||||||
|
TestAssignments(new[] { (false, 4.0f) }, new[] { 4.0f }, 0);
|
||||||
|
|
||||||
|
TestAssignments(new[] { (false, 1.0f), (false, 4.0f) }, new[] { 1.0f, 4.0f });
|
||||||
|
TestAssignments(new[] { (false, 1.0f), (false, 4.0f) }, new[] { 1.0f, 4.0f }, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@ -98,6 +102,9 @@ namespace UnitTests.ReactiveComponent.ParameterAssignment
|
|||||||
{
|
{
|
||||||
Assert.AreEqual(expected, mami.Control.value);
|
Assert.AreEqual(expected, mami.Control.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var expectedDefaultValue = defaultIndex.HasValue ? expectedAssignments[defaultIndex.Value] : 0;
|
||||||
|
Assert.AreEqual(expectedDefaultValue, avDesc.expressionParameters.parameters.Single().defaultValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user