public GettableAssignerResult GetResult(GettableAssignerValueInfo info) { var inline = _attributes.StoreType == StoreType.None || info.Inline; // Get the initial value. IWorkshopTree initialValue = Element.Num(0); bool hasDefaultValue = true; // Set the initial value to the override if it exists. if (info.InitialValueOverride != null) { initialValue = info.InitialValueOverride; } // Otherwise, use the var's initial value. else if (_attributes.DefaultValue != null) { initialValue = _attributes.DefaultValue.Parse(info.ActionSet); } // No default value else { hasDefaultValue = false; } // Inline if (inline) { return(new GettableAssignerResult(new WorkshopElementReference(initialValue), initialValue)); } // Assign the index reference var value = info.IndexReferenceCreator.Create(_attributes); if (info.IsRecursive) { value = new RecursiveIndexReference(value); } // Set the initial value. if (info.SetInitialValue == SetInitialValue.SetAndFallbackTo0 || (info.SetInitialValue == SetInitialValue.SetIfExists && hasDefaultValue)) { if (value is RecursiveIndexReference recursive) { info.ActionSet.InitialSet().AddAction(recursive.Reset()); info.ActionSet.AddAction(recursive.Push((Element)initialValue)); } else { info.ActionSet.AddAction(value.SetVariable((Element)initialValue)); } } return(new GettableAssignerResult(value, initialValue)); }
public GettableAssignerResult GetResult(GettableAssignerValueInfo info) { IStructValue initialValue = null; // Set the initial value. // If an initial value is provided, use that. if (info.InitialValueOverride != null) { initialValue = ValueInArrayToWorkshop.ExtractStructValue(info.InitialValueOverride); } // Otherwise, use the default initial value if it exists. else if (_attributes.DefaultValue != null) { initialValue = ValueInArrayToWorkshop.ExtractStructValue(_attributes.DefaultValue.Parse(info.ActionSet)); } // 'initialValue' may still be null. bool inline = info.Inline || _attributes.StoreType == StoreType.None; var values = new Dictionary <string, IGettable>(); foreach (var var in _variables) { // Get the child gettable. values.Add( var.Name, var.GetAssigner(new(info.ActionSet, _attributes.Name + "_")) .GetValue(new GettableAssignerValueInfo( actionSet: info.ActionSet, setInitialValue: info.SetInitialValue, initialValue: initialValue?.GetValue(var.Name), inline: inline, indexReferenceCreator: info.IndexReferenceCreator, isGlobal: info.IsGlobal, isRecursive: info.IsRecursive))); } return(new GettableAssignerResult(new StructAssignerValue(values), null)); }