Exemple #1
0
 public void AssertValid()
 {
     if (this.data == null)
     {
         return;
     }
     if (this.data.GetType() != PropUtil.GetExpectedType(this.propType))
     {
         throw new System.Exception($"For prop {this.labelForDisplay}, the type of the data ({this.data.GetType()}) did not match the expected ({PropUtil.GetDefaultValue(this.propType).GetType()})");
     }
 }
Exemple #2
0
 public PropEditor(PropDef propOptions, Behaviors.PropertyAssignment?assignment, AssignedBehavior assigned)
 {
     this.propDef = propOptions;
     if (assignment != null)
     {
         this.__data = PropUtil.GetPropertyValue(assignment.Value, this.propType);
     }
     else
     {
         this.__data = PropUtil.ParsePropertyInitialValueOrDefault(this.propType, propOptions.defaultValueString);
     }
     this.assigned = assigned;
 }
Exemple #3
0
 public void SetData(object newData)
 {
     Debug.Assert(newData == null || newData.GetType() == PropUtil.GetExpectedType(this.propType));
     if (System.Object.Equals(__data, newData)) // Object.equals supports nulls
     {
         return;
     }
     __data = newData;
     if (this.assigned == null)
     {
         // Util.LogWarning("This PropEditor is not meant to be changed! It did not come from an AssignedBehavior, but probably an UnassignedBehavior!");
     }
     else
     {
         this.assigned.SetProperty(this.propDef.variableName, this);
     }
 }
Exemple #4
0
 public void SetProperty(string propertyName, PropEditor value)
 {
     using (this.assignedBrain.StartUndo($"Set {propertyName}"))
     {
         var assigns = GetUse().propertyAssignments.DeepClone();
         int i       = assigns.IndexOfWhere(pa => pa.propertyName == propertyName);
         if (i == -1)
         {
             // Add new prop
             i = assigns.Length;
             var assignList = assigns.ToList();
             assignList.Add(new PropertyAssignment());
             assigns = assignList.ToArray();
         }
         assigns[i] = PropUtil.ToAssignment(value);
         Debug.Assert(assigns[i].propertyName == propertyName);
         assignedBrain.SetProperties(this, assigns);
     }
 }
Exemple #5
0
    public void SetProperties(PropEditor[] props)
    {
        var assigns = PropUtil.SerializeProps(props);

        assignedBrain.SetProperties(this, assigns);
    }