mirror of
https://github.com/bdunderscore/modular-avatar.git
synced 2025-01-31 02:32:53 +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;
|
||||
|
||||
if (list.Count == 1)
|
||||
// If we have only a single entry, it's probably an on-off toggle, so we'll implicitly let 0
|
||||
// be the 'unselected' default value (if this is not default)
|
||||
defaultValue = 0;
|
||||
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 1
|
||||
// be the 'selected' default value (if this is default and automatic value)
|
||||
defaultValue = 1;
|
||||
}
|
||||
|
||||
HashSet<int> usedValues = new();
|
||||
@ -124,11 +124,7 @@ namespace nadena.dev.modular_avatar.core.editor
|
||||
{
|
||||
if (mami.automaticValue)
|
||||
{
|
||||
if (list.Count == 1)
|
||||
{
|
||||
mami.Control.value = 1;
|
||||
}
|
||||
else if (mami.isDefault)
|
||||
if (mami.isDefault)
|
||||
{
|
||||
mami.Control.value = defaultValue;
|
||||
}
|
||||
|
@ -16,10 +16,14 @@ namespace UnitTests.ReactiveComponent.ParameterAssignment
|
||||
[Test]
|
||||
public void ManuallyAssignedParametersAreNotReplaced()
|
||||
{
|
||||
TestAssignments(
|
||||
new[] { (false, 1.0f), (false, 4.0f) },
|
||||
new[] { 1.0f, 4.0f }
|
||||
);
|
||||
TestAssignments(new[] { (false, 1.0f) }, new[] { 1.0f });
|
||||
TestAssignments(new[] { (false, 1.0f) }, new[] { 1.0f }, 0);
|
||||
|
||||
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]
|
||||
@ -98,6 +102,9 @@ namespace UnitTests.ReactiveComponent.ParameterAssignment
|
||||
{
|
||||
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