public static void Assign(ActionSet actionSet, Var var) { // Get the initial value. IWorkshopTree initialValue = new V_Number(0); if (var.InitialValue != null) { initialValue = var.InitialValue.Parse(actionSet); } // Add the variable to the assigner. actionSet.IndexAssigner.Add(actionSet.VarCollection, var, actionSet.IsGlobal, initialValue); // Set the initial value. if (var.Settable()) { IndexReference reference = (IndexReference)actionSet.IndexAssigner[var]; if (reference is RecursiveIndexReference recursive) { actionSet.InitialSet().AddAction(recursive.Reset()); actionSet.AddAction(recursive.Push((Element)initialValue)); } else { actionSet.AddAction(reference.SetVariable((Element)initialValue)); } } }
public IGettable Add(VarCollection varCollection, Var var, bool isGlobal, IWorkshopTree referenceValue, bool recursive = false) { if (varCollection == null) { throw new ArgumentNullException(nameof(varCollection)); } if (var == null) { throw new ArgumentNullException(nameof(var)); } if (references.ContainsKey(var)) { throw new Exception(var.Name + " was already added into the variable index assigner."); } IGettable assigned; // A gettable/settable variable if (var.Settable()) { assigned = varCollection.Assign(var, isGlobal); if (recursive) { assigned = new RecursiveIndexReference((IndexReference)assigned); } references.Add(var, assigned); } // Element reference else if (var.VariableType == VariableType.ElementReference) { if (referenceValue == null) { throw new ArgumentNullException(nameof(referenceValue)); } assigned = new WorkshopElementReference(referenceValue); references.Add(var, assigned); } else { throw new NotImplementedException(); } return(assigned); }
public static void Assign(ActionSet actionSet, Var var) { // Get the initial value. IWorkshopTree initialValue = new V_Number(0); if (var.InitialValue != null) { initialValue = var.InitialValue.Parse(actionSet); } // Add the variable to the assigner. actionSet.IndexAssigner.Add(actionSet.VarCollection, var, actionSet.IsGlobal, initialValue); // Set the initial value. if (var.Settable()) { actionSet.AddAction( ((IndexReference)actionSet.IndexAssigner[var]).SetVariable( (Element)initialValue ) ); } }
public void Add(VarCollection varCollection, Var var, bool isGlobal, IWorkshopTree referenceValue, bool recursive = false) { if (varCollection == null) { throw new ArgumentNullException(nameof(varCollection)); } if (var == null) { throw new ArgumentNullException(nameof(var)); } // A gettable/settable variable if (var.Settable()) { var assigned = varCollection.Assign(var, isGlobal); if (recursive) { assigned = new RecursiveIndexReference(assigned); } references.Add(var, assigned); } // Element reference else if (var.VariableType == VariableType.ElementReference) { if (referenceValue == null) { throw new ArgumentNullException(nameof(referenceValue)); } references.Add(var, new WorkshopElementReference(referenceValue)); } else { throw new NotImplementedException(); } }