コード例 #1
0
 public MutableFieldChange(MutableBoxBehaviour mbb, IMutableField valBefore, string valAfter)
 {
     field         = mbb.name;
     node_id       = mbb.transform.parent.parent.GetComponent <ChainNodeView>().ChainNode.JsonId;
     literalBefore = valBefore.SchemaSource == SchemaSource.Literal;
     literalAfter  = valAfter.StartsWith("Literal.");
     valueBefore   = GetUserFacingKeyFromMutableField(valBefore);
     valueAfter    = literalAfter ? valAfter.Substring(8) : valAfter;
 }
コード例 #2
0
        private void UndoLogAdd(object item, int index)
        {
            if (UndoLog != null)
            {
                // also set UndoLog property on added item, if it needs a reference to the undo logger
                IMutableField mutableValue = item as IMutableField;
                if (mutableValue != null)
                {
                    mutableValue.UndoLog = UndoLog;
                }

                UndoLog.AddUndoAction(new UndoListAdd(this, item, index));
            }
        }
コード例 #3
0
        private static string GetUserFacingKeyFromMutableField(IMutableField field)
        {
            switch (field.SchemaSource)
            {
            default:
                return(field.GetLiteralValueAsString());

            case SchemaSource.Mutable:
                return("Local Payload" + (field.AbsoluteKey != "" ? "." : "") + field.AbsoluteKey);

            case SchemaSource.Cached:
                return("Cached Data" + (field.AbsoluteKey != "" ? "." : "") + field.AbsoluteKey);

            case SchemaSource.Global:
                return("Global Data" + (field.AbsoluteKey != "" ? "." : "") + field.AbsoluteKey);
            }
        }
コード例 #4
0
        private void Set(string name, object value, bool raiseEvent, bool cloneClonableValues, bool allowUpdateSortOrder = true)
        {
            bool   changed;
            bool   added    = true;
            object oldValue = null;

            if (m_attributes.ContainsKey(name))
            {
                added    = false;
                oldValue = Get(name);
            }
            else
            {
                if (!Utility.IsValidFieldName(name))
                {
                    throw new Exception(string.Format("Invalid attribute name '{0}'", name));
                }
            }

            if (value == null)
            {
                changed = (oldValue != null);
            }
            else
            {
                changed = !value.Equals(oldValue);
            }

            if (changed && cloneClonableValues)
            {
                IMutableField mutableOldValue = oldValue as IMutableField;
                IMutableField mutableNewValue = value as IMutableField;
                if (mutableOldValue != null)
                {
                    if (m_worldModel.EditMode || mutableOldValue.RequiresCloning)
                    {
                        oldValue = mutableOldValue.Clone();
                    }
                }
                if (mutableNewValue != null)
                {
                    if (m_worldModel.EditMode || mutableNewValue.RequiresCloning)
                    {
                        value = mutableNewValue.Clone();
                    }
                    IMutableField mutableValue = (IMutableField)value;
                    mutableValue.Locked  = m_mutableFieldsLocked;
                    mutableValue.UndoLog = m_worldModel.UndoLogger;
                    mutableValue.Owner   = m_element;
                }
            }

            if (name == "name" && !(value is string))
            {
                throw new ArgumentException("Invalid data type for 'name'");
            }

            if (name == "parent" && value == m_element)
            {
                throw new ArgumentException(string.Format("Parent of element '{0}' cannot be set to itself", m_element.Name));
            }

            if (m_worldModel.Version >= WorldModelVersion.v530 && value == null)
            {
                m_attributes.Remove(name);
            }
            else
            {
                m_attributes[name] = value;
            }

            if (changed && allowUpdateSortOrder && name == "parent" && m_element.Initialised)
            {
                m_worldModel.UpdateElementSortOrder(m_element);
            }

            if (name == "name" && changed && value != null && !added && NameChanged != null)
            {
                if (!m_worldModel.EditMode)
                {
                    // Actually we could allow this I suppose but I don't think it's sensible.
                    throw new InvalidOperationException("Cannot change name of element when not in Edit mode");
                }
                NameChanged(this, new NameChangedEventArgs
                {
                    OldName = (string)oldValue,
                    Element = m_element
                });
            }

            if (raiseEvent)
            {
                if (changed)
                {
                    UndoLog(name, oldValue, value, added);
                }
                if (changed && AttributeChanged != null)
                {
                    AttributeChanged(this, new AttributeChangedEventArgs(name, value, oldValue));
                }
            }
            else
            {
                // when undoing, the editor still needs a notification of a changed field
                if (changed && AttributeChangedSilent != null)
                {
                    AttributeChangedSilent(this, new AttributeChangedEventArgs(name, value, oldValue));
                }
            }
        }