UDMF: fixed an issue where user variables with default values were not saved when their value was equal to the type's default value. Fixes #709

This commit is contained in:
biwa 2022-02-26 16:21:59 +01:00
parent c62b8315c4
commit 2dfe043e1e
2 changed files with 8 additions and 4 deletions

View file

@ -417,7 +417,7 @@ namespace CodeImp.DoomBuilder.Controls
}
//mxd
public void ApplyUserVars(Dictionary<string, UniversalType> vars, UniFields tofields)
public void ApplyUserVars(Dictionary<string, UniversalType> vars, Dictionary<string, object> vardefaults, UniFields tofields)
{
// Apply user variables when target map element contains user var definition and the value is not default
foreach(DataGridViewRow row in fieldslist.Rows)
@ -434,8 +434,11 @@ namespace CodeImp.DoomBuilder.Controls
// Skip field when mixed values
if(newvalue == null) continue;
// Remove field
if(newvalue.Equals(frow.TypeHandler.GetDefaultValue()))
object typedefault = frow.TypeHandler.GetDefaultValue();
object userdefault = vardefaults.ContainsKey(frow.Name) ? vardefaults[frow.Name] : typedefault;
// Remove field, but only if the type's default value is the same as the user var's default value
if (newvalue.Equals(typedefault) && typedefault.Equals(userdefault))
{
if(tofields.ContainsKey(frow.Name)) tofields.Remove(frow.Name);
}

View file

@ -584,9 +584,10 @@ namespace CodeImp.DoomBuilder.Windows
if (ti != null && ti.Actor != null)
{
Dictionary<string, UniversalType> uservars = ti.Actor.GetAllUserVars();
Dictionary<string, object> uservardefaults = ti.Actor.GetAllUserVarDefaults();
if(uservars.Count > 0)
fieldslist.ApplyUserVars(uservars, t.Fields);
fieldslist.ApplyUserVars(uservars, uservardefaults, t.Fields);
}
color.ApplyTo(t.Fields, t.Fields.GetValue("fillcolor", 0));