private List <MethodDef> getMethods() { List <MethodDef> methods = new List <MethodDef>(); if (typeComboBox.SelectedIndex > -1) { Nodes.Behavior behavior = GetBehavior(); AgentType agentType = Plugin.GetInstanceAgentType(_currentNames[typeComboBox.SelectedIndex], behavior, _agentType); if (agentType != null) { // get the linked method to filter MethodDef linkedMethod = null; bool linkBroken; DesignerPropertyInfo linkedProp = _property.Attribute.GetLinkedProperty(_object, out linkBroken); object prop = linkedProp.GetValue(_object); if (prop != null && prop is MethodDef) { linkedMethod = prop as MethodDef; } DesignerMethodEnum attrMethod = _property.Attribute as DesignerMethodEnum; #if USE_NOOP IList <MethodDef> methods = new List <MethodDef>(); methods.Add(MethodDef.Noop); IList <MethodDef> agentMethods = agentType.GetMethods(attrMethod.MethodType, ValueTypes.All, linkedMethod); foreach (MethodDef m in agentMethods) { methods.Add(m); } #else if (attrMethod != null) { methods.AddRange(agentType.GetMethods(attrMethod.MethodType, attrMethod.MethodReturnType, linkedMethod)); } else { DesignerRightValueEnum attrMethodRV = _property.Attribute as DesignerRightValueEnum; if (attrMethodRV != null) { methods.AddRange(agentType.GetMethods(attrMethodRV.MethodType, ValueTypes.All, linkedMethod)); } } #endif//#if USE_NOOP } } return(methods); }
private List <MethodDef> getMethods() { List <MethodDef> methods = new List <MethodDef>(); Behaviac.Design.Attachments.Attach evt = _object as Behaviac.Design.Attachments.Attach; Behaviac.Design.Nodes.BaseNode baseNode = (evt != null) ? evt.Node : _object as Behaviac.Design.Nodes.BaseNode; if (baseNode == null) { baseNode = this._root; } Behaviac.Design.Nodes.Behavior behavior = null; if (baseNode != null) { behavior = baseNode.Behavior as Behaviac.Design.Nodes.Behavior; } AgentType agentType = null; if (behavior != null && behavior.AgentType != null) { agentType = behavior.AgentType; } object action = _property.Property.GetValue(_object, null); RightValueDef varRV = action as RightValueDef; if (varRV != null && Plugin.IsInstanceName(varRV.ValueClassReal)) { agentType = Plugin.GetInstanceAgentType(varRV.ValueClassReal); } if (agentType != null) { DesignerRightValueEnum enumAttRV = _property.Attribute as DesignerRightValueEnum; DesignerMethodEnum attrMethod = _property.Attribute as DesignerMethodEnum; MethodType methodType = attrMethod != null ? attrMethod.MethodType : MethodType.Getter; if (enumAttRV != null) { methodType = enumAttRV.MethodType; } IList <MethodDef> actions = agentType.GetMethods(methodType); foreach (MethodDef actionType in actions) { if (Plugin.IsCompatibleType(this.FilterType, actionType.ReturnType, false)) { methods.Add(actionType); } } } return(methods); }
private List <MethodDef> getMethods() { List <MethodDef> methods = new List <MethodDef>(); Nodes.Behavior behavior = GetBehavior(); AgentType agentType = (behavior != null) ? behavior.AgentType : null; object action = _property.Property.GetValue(_object, null); VariableDef var = action as VariableDef; Debug.Check(var == null); RightValueDef varRV = action as RightValueDef; if (varRV != null && Plugin.IsInstanceName(varRV.ValueClassReal, behavior)) { agentType = Plugin.GetInstanceAgentType(varRV.ValueClassReal, behavior, agentType); } if (agentType != null) { DesignerRightValueEnum enumAttRV = _property.Attribute as DesignerRightValueEnum; DesignerMethodEnum attrMethod = _property.Attribute as DesignerMethodEnum; MethodType methodType = attrMethod != null ? attrMethod.MethodType : MethodType.Getter; if (enumAttRV != null) { methodType = enumAttRV.MethodType; } IList <MethodDef> actions = agentType.GetMethods(true, methodType); foreach (MethodDef actionType in actions) { if (Plugin.IsCompatibleType(this.ValueType, this.FilterType, actionType.ReturnType, false)) { methods.Add(actionType); } } } return(methods); }
private void setMembers() { _methods.Clear(); _properties.Clear(); this.memberListBox.Items.Clear(); if (this.instanceComboBox.SelectedIndex > -1 && this.memberTypeComboBox.SelectedIndex > -1) { AgentType agentType = null; // self if (this.instanceComboBox.SelectedIndex == 0) { BehaviorTreeView focusedView = (BehaviorTreeViewDock.LastFocused != null) ? BehaviorTreeViewDock.LastFocused.BehaviorTreeView : null; if (focusedView != null && focusedView.RootNode != null) { agentType = focusedView.RootNode.AgentType; } } // global else { agentType = Plugin.InstanceNames[this.instanceComboBox.SelectedIndex - 1].agentType_; } if (agentType != null) { string filter = !string.IsNullOrEmpty(memberFilterTextBox.Text) ? memberFilterTextBox.Text.ToLowerInvariant() : string.Empty; // method if (this.memberTypeComboBox.SelectedIndex == 0 || this.memberTypeComboBox.SelectedIndex == 2) { IList <MethodDef> methods = agentType.GetMethods(MethodType.Method); foreach (MethodDef m in methods) { string methodName = m.DisplayName.ToLowerInvariant(); if (memberFilterCheckBox.Checked && methodName.StartsWith(filter) || !memberFilterCheckBox.Checked && methodName.Contains(filter)) { _methods.Add(m); this.memberListBox.Items.Add(m.DisplayName + "()"); } } } // property if (this.memberTypeComboBox.SelectedIndex == 1 || this.memberTypeComboBox.SelectedIndex == 2) { IList <PropertyDef> properties = agentType.GetProperties(); foreach (PropertyDef p in properties) { string propName = p.DisplayName.ToLowerInvariant(); if (memberFilterCheckBox.Checked && propName.StartsWith(filter) || !memberFilterCheckBox.Checked && propName.Contains(filter)) { _properties.Add(p); this.memberListBox.Items.Add(p.DisplayName); } } } } } this.memberCountLabel.Text = this.memberListBox.Items.Count.ToString(); }
public static MethodDef parseMethodString(NodeTag.DefaultObject node, AgentType agentType, MethodType methodType, string str) { try { if (agentType != null) { int pos = str.IndexOf('('); if (pos < 0) { return(null); } string ownerName = agentType.ToString(); int pointIndex = str.IndexOf('.'); if (pointIndex > -1 && pointIndex < pos) { ownerName = str.Substring(0, pointIndex); str = str.Substring(pointIndex + 1, str.Length - pointIndex - 1); agentType = Plugin.GetInstanceAgentType(ownerName, agentType); //if (agentType == node.Behavior.AgentType) // ownerName = VariableDef.kSelf; pos = str.IndexOf('('); } IList <MethodDef> actions = agentType.GetMethods(methodType); string actionName = str.Substring(0, pos); foreach (MethodDef actionTypeIt in actions) { if (actionTypeIt.Name == actionName #if BEHAVIAC_NAMESPACE_FIX || actionTypeIt.Name.EndsWith(actionName) #endif ) { MethodDef method = new MethodDef(actionTypeIt); method.Owner = ownerName; List <string> paras = parseParams(str.Substring(pos + 1, str.Length - pos - 2)); //Debug.Check((paras.Count == actionTypeIt.Params.Count)); //if (paras.Count == actionTypeIt.Params.Count) { for (int i = 0; i < paras.Count; ++i) { string param = paras[i]; string[] tokens = null; if (param[0] == '\"') { param = param.Substring(1, param.Length - 2); } else if (param[0] == '{') { //struct //to set it as action.Method is used in the following parsing Nodes.Action action = node as Nodes.Action; if (action != null) { action.Method = method; } } else { tokens = param.Split(' '); } if (i < method.Params.Count) { MethodDef.Param par = method.Params[i]; if (tokens != null && tokens.Length > 1) { //par VariableDef var = setParameter(node, tokens[tokens.Length - 1]); if (var != null) { par.Value = var; } //else // throw new Exception(string.Format(Resources.ExceptionDesignerAttributeIllegalFloatValue, str)); } else { bool bOk = Plugin.InvokeTypeParser(par.Type, param, (object value) => par.Value = value, node, par.Name); if (!bOk) { throw new Exception(string.Format(Resources.ExceptionDesignerAttributeIllegalFloatValue, str)); } } } else { break; } } } return(method); } } } } catch (Exception) { System.Windows.Forms.MessageBox.Show(str, Resources.LoadError, System.Windows.Forms.MessageBoxButtons.OK); } return(null); }
public static MethodDef parseMethodString(List<Nodes.Node.ErrorCheck> result, DefaultObject node, AgentType agentType, MethodType methodType, string str) { try { if (agentType != null) { int pos = str.IndexOf('('); if (pos < 0) { return null; } string ownerName = agentType.ToString(); int pointIndex = str.IndexOf('.'); if (pointIndex > -1 && pointIndex < pos) { ownerName = str.Substring(0, pointIndex); Nodes.Behavior behavior = node.Behavior as Nodes.Behavior; if (ownerName != VariableDef.kSelf && !Plugin.IsInstanceName(ownerName, behavior)) { throw new Exception("The instance does not exist."); } str = str.Substring(pointIndex + 1, str.Length - pointIndex - 1); agentType = Plugin.GetInstanceAgentType(ownerName, behavior, agentType); //if (agentType == node.Behavior.AgentType) // ownerName = VariableDef.kSelf; pos = str.IndexOf('('); } IList<MethodDef> actions = agentType.GetMethods(methodType); string actionName = str.Substring(0, pos); foreach(MethodDef actionTypeIt in actions) { if (actionTypeIt.Name == actionName #if BEHAVIAC_NAMESPACE_FIX || actionTypeIt.Name.EndsWith(actionName) #endif ) { MethodDef method = new MethodDef(actionTypeIt); method.Owner = ownerName; List<string> paras = parseParams(str.Substring(pos + 1, str.Length - pos - 2)); //Debug.Check((paras.Count == actionTypeIt.Params.Count)); //if (paras.Count == actionTypeIt.Params.Count) { for (int i = 0; i < paras.Count; ++i) { if (i >= method.Params.Count) { break; } string param = paras[i]; MethodDef.Param par = method.Params[i]; bool bOk = parseParam(result, node, method, par, param); if (!bOk) { throw new Exception(string.Format(Resources.ExceptionDesignerAttributeIllegalFloatValue, str)); } } } return method; } } } } catch (Exception) { //System.Windows.Forms.MessageBox.Show(str, Resources.LoadError, System.Windows.Forms.MessageBoxButtons.OK); if (result != null) { Nodes.Node n = node as Nodes.Node; string label = ""; if (n == null) { Attachments.Attachment a = node as Attachments.Attachment; if (a != null) { n = a.Node; label = a.Label; } } else { label = n.Label; } Nodes.Node.ErrorCheck error = new Nodes.Node.ErrorCheck(n, node.Id, label, Nodes.ErrorCheckLevel.Error, str); result.Add(error); } } return null; }
public static MethodDef parseMethodString(List <Nodes.Node.ErrorCheck> result, DefaultObject node, AgentType agentType, MethodType methodType, string str) { try { if (agentType != null) { int pos = str.IndexOf('('); if (pos < 0) { return(null); } string ownerName = agentType.ToString(); int pointIndex = str.IndexOf('.'); if (pointIndex > -1 && pointIndex < pos) { ownerName = str.Substring(0, pointIndex); if (ownerName != VariableDef.kSelf && !Plugin.IsInstanceName(ownerName)) { throw new Exception("The instance does not exist."); } str = str.Substring(pointIndex + 1, str.Length - pointIndex - 1); agentType = Plugin.GetInstanceAgentType(ownerName, agentType); //if (agentType == node.Behavior.AgentType) // ownerName = VariableDef.kSelf; pos = str.IndexOf('('); } IList <MethodDef> actions = agentType.GetMethods(methodType); string actionName = str.Substring(0, pos); foreach (MethodDef actionTypeIt in actions) { if (actionTypeIt.Name == actionName #if BEHAVIAC_NAMESPACE_FIX || actionTypeIt.Name.EndsWith(actionName) #endif ) { MethodDef method = new MethodDef(actionTypeIt); method.Owner = ownerName; List <string> paras = parseParams(str.Substring(pos + 1, str.Length - pos - 2)); //Debug.Check((paras.Count == actionTypeIt.Params.Count)); //if (paras.Count == actionTypeIt.Params.Count) { for (int i = 0; i < paras.Count; ++i) { if (i >= method.Params.Count) { break; } string param = paras[i]; MethodDef.Param par = method.Params[i]; bool bOk = parseParam(result, node, method, par, param); if (!bOk) { throw new Exception(string.Format(Resources.ExceptionDesignerAttributeIllegalFloatValue, str)); } } } return(method); } } } } catch (Exception) { //System.Windows.Forms.MessageBox.Show(str, Resources.LoadError, System.Windows.Forms.MessageBoxButtons.OK); if (result != null) { Nodes.Node n = node as Nodes.Node; string label = ""; if (n == null) { Attachments.Attachment a = node as Attachments.Attachment; if (a != null) { n = a.Node; label = a.Label; } } else { label = n.Label; } Nodes.Node.ErrorCheck error = new Nodes.Node.ErrorCheck(n, node.Id, label, Nodes.ErrorCheckLevel.Error, str); result.Add(error); } } return(null); }
public static MethodDef parseMethodString(NodeTag.DefaultObject node, AgentType agentType, MethodType methodType, string str) { try { if (agentType != null) { int pos = str.IndexOf('('); if (pos < 0) return null; string ownerName = agentType.ToString(); int pointIndex = str.IndexOf('.'); if (pointIndex > -1 && pointIndex < pos) { ownerName = str.Substring(0, pointIndex); str = str.Substring(pointIndex + 1, str.Length - pointIndex - 1); agentType = Plugin.GetInstanceAgentType(ownerName, agentType); if (agentType == node.Behavior.AgentType) ownerName = VariableDef.kSelf; pos = str.IndexOf('('); } IList<MethodDef> actions = agentType.GetMethods(methodType); string actionName = str.Substring(0, pos); foreach (MethodDef actionTypeIt in actions) { if (actionTypeIt.Name == actionName #if BEHAVIAC_NAMESPACE_FIX || actionTypeIt.Name.EndsWith(actionName) #endif ) { MethodDef method = new MethodDef(actionTypeIt); method.Owner = ownerName; List<string> paras = parseParams(str.Substring(pos + 1, str.Length - pos - 2)); //Debug.Check((paras.Count == actionTypeIt.Params.Count)); //if (paras.Count == actionTypeIt.Params.Count) { for (int i = 0; i < paras.Count; ++i) { string param = paras[i]; string[] tokens = null; if (param[0] == '\"') { param = param.Substring(1, param.Length - 2); } else if (param[0] == '{') { //struct //to set it as action.Method is used in the following parsing Nodes.Action action = node as Nodes.Action; if (action != null) { action.Method = method; } } else { tokens = param.Split(' '); } if (i < method.Params.Count) { MethodDef.Param par = method.Params[i]; if (tokens != null && tokens.Length > 1) { //par VariableDef var = setParameter(node, tokens[tokens.Length - 1]); if (var != null) par.Value = var; //else // throw new Exception(string.Format(Resources.ExceptionDesignerAttributeIllegalFloatValue, str)); } else { bool bOk = Plugin.InvokeTypeParser(par.Type, param, (object value) => par.Value = value, node, par.Name); if (!bOk) throw new Exception(string.Format(Resources.ExceptionDesignerAttributeIllegalFloatValue, str)); } } else { break; } } } return method; } } } } catch (Exception) { System.Windows.Forms.MessageBox.Show(str, Resources.LoadError, System.Windows.Forms.MessageBoxButtons.OK); } return null; }