public static Direction GetLinkDirection(Serialization.Node node, string name) { if (node.nodeType == NodeType.Variable && (name == Runtime.Variable.ValueLinkName || name == string.Empty)) { return(Direction.InOut); } string fieldName = FieldName(name); VariableAttribute variable = GetVariableAttribute(node.RuntimeType, fieldName); if (variable != null) { return(variable.Direction); } // test for trigger TriggerAttribute trigger = GetTriggerAttribute(node.RuntimeType, fieldName); if (trigger != null) { return(Direction.Out); } // entry EntryAttribute entry = GetEntryAttribute(node.RuntimeType, fieldName); if (entry != null) { return(Direction.In); } return(Direction.InOut); }
public static bool ValidateEntry(Serialization.Node node, string name) { EntryAttribute entry = GetEntryAttribute(node.RuntimeType, name); if (entry != null) { return(true); } return(false); }
public static bool ValidateTrigger(Serialization.Node node, string name) { FieldInfo field = node.RuntimeType.GetField(FieldName(name)); if (field != null) { return(IsCompatableType(field.FieldType, typeof(Runtime.Trigger))); } return(false); }
public static void SetProperyValue(Serialization.Node node, string name, object value) { foreach (Property prop in node.properties) { if (prop.name == name) { prop.Value = value; } } }
public static Serialization.Node CreateSerializationNode(System.Type runtimeType, int id) { Serialization.Node node = new Serialization.Node(); node.nodeType = GetNodeType(runtimeType); node.id = id; node.RuntimeType = runtimeType; UpdateSerializationNode(node); return(node); }
public void RemoveNode(int nodeId) { Serialization.Node node = FindById(nodeId); if (node != null) { Nodes.Remove(node); // remove all links Links.RemoveAll(new LinkFinder(nodeId).Find); } }
public static bool ValidateVariable(Serialization.Node node, string name) { FieldInfo field = node.RuntimeType.GetField(FieldName(name)); if (field != null) { return(IsCompatableType(field.FieldType, typeof(Runtime.Variable))); } else if (node.nodeType == NodeType.Variable && name == Runtime.Variable.ValueLinkName) { return(true); } return(false); }
public static ValidateLinkResult ValidateLink(Serialization.Node outNode, string outName, Serialization.Node inNode, string inName) { LinkType linkOut = GetLinkType(outNode, outName); LinkType linkIn = GetLinkType(inNode, inName); EB.Debug.Log(string.Format("ValidateLink: ({0}:{1} => {2}:{3})", linkOut, outName, linkIn, inName)); switch (linkOut) { case LinkType.Trigger: { if (ValidateTrigger(outNode, outName)) { if (linkIn == Utils.LinkType.Entry && ValidateEntry(inNode, inName)) { return(ValidateLinkResult.Ok); } } } break; case LinkType.Variable: { if (ValidateVariable(outNode, outName)) { if (linkIn == Utils.LinkType.Variable && ValidateVariable(inNode, inName)) { if (ValidateVariableTypes(outNode, outName, inNode, inName)) { return(ValidateLinkResult.Ok); } else { EB.Debug.LogWarning("Invalid Variable Type: " + inName); return(ValidateLinkResult.InvalidType); } } } } break; } return(ValidateLinkResult.InvalidLink); }
public static bool ValidateVariableTypes(Serialization.Node outNode, string outName, Serialization.Node inNode, string inName) { bool acceptAnyOut = false; System.Type outType = GetVariableType(outNode, outName, out acceptAnyOut); bool acceptAnyIn = false; System.Type inType = GetVariableType(inNode, inName, out acceptAnyIn); if ((acceptAnyOut == true) || (acceptAnyIn == true)) { return(true); } if ((outType != null) && (inType != null)) { return(IsCompatableType(outType, inType)); } return(false); }
public static System.Type GetVariableType(Serialization.Node node, string feildName, out bool anyType) { System.Type variableType = null; anyType = false; switch (node.nodeType) { case NodeType.Variable: { MenuItemAttribute menuAttribute = GetMenuAttribute(node.RuntimeType); if (menuAttribute != null) { variableType = menuAttribute.VariableType; if (variableType == null) { anyType = true; } } break; } default: { VariableAttribute varAttribute = GetVariableAttribute(node.RuntimeType, FieldName(feildName)); if (varAttribute != null) { variableType = varAttribute.ExpectedType; if (variableType == null) { anyType = true; } } break; } } return(variableType); }
public Serialization.Node AddNode(Serialization.Node node) { node.id = NextId++; Nodes.Add(node); return(node); }
// checks for invalid nodes public static bool InvalidNode(EB.Sequence.Serialization.Node node) { return(node.RuntimeType == null); }
public static void UpdateSerializationNode(Serialization.Node node) { var type = node.RuntimeType; if (type != null) { var obj = System.Activator.CreateInstance(type); foreach (var field in type.GetFields()) { PropertyAttribute[] attributes = (PropertyAttribute[])field.GetCustomAttributes(typeof(PropertyAttribute), true); if (attributes.Length > 0) { if (field.FieldType.IsArray) { var array = node.GetPropertyArray(field.Name); if (array == null) { array = new PropertyArray(); array.name = field.Name; array.type = GetPropertyType(field.FieldType.GetElementType()); node.propertyArrays.Add(array); } foreach (var property in array.items) { property.Value = property.Value; } } else { var property = node.GetProperty(field.Name); if (property == null) { property = new Property(); property.name = field.Name; property.type = GetPropertyType(field.FieldType); property.Value = field.GetValue(obj); node.properties.Add(property); } property.Value = property.Value; } } } // remove old properties foreach (var property in node.properties.ToArray()) { var field = type.GetField(property.name); if (field == null || field.GetCustomAttributes(typeof(PropertyAttribute), true).Length == 0) { node.properties.Remove(property); } } // remove old arrays foreach (var array in node.propertyArrays.ToArray()) { var field = type.GetField(array.name); if (field == null || field.GetCustomAttributes(typeof(PropertyAttribute), true).Length == 0) { node.propertyArrays.Remove(array); } } } }