private Connection CreateConnection(Vector2 <int> location, Define.EConnection type, Workspace workspace) { return(new Connection(new Block() { Workspace = workspace }, type) { Location = location }); }
/// <summary> /// Get output, previous, next connection by connection type /// </summary> public Connection GetFirstClassConnection(Define.EConnection connectionType) { switch (connectionType) { case Define.EConnection.OutputValue: return(OutputConnection); case Define.EConnection.PrevStatement: return(PreviousConnection); case Define.EConnection.NextStatement: return(NextConnection); } throw new Exception("Block GetFirstClassConnection: Only get output, previous, next connection"); }
/// <summary> /// create input from json object /// </summary> public static Input CreateFromJson(JObject json) { string inputType = json["type"].ToString(); Define.EConnection inputTypeInt = Define.EConnection.InputValue; string inputName = json["name"] != null ? json["name"].ToString() : ""; Connection connection = null; switch (inputType) { case "input_value": inputTypeInt = Define.EConnection.InputValue; connection = new Connection(inputTypeInt); break; case "input_statement": inputTypeInt = Define.EConnection.NextStatement; connection = new Connection(inputTypeInt); break; case "input_dummy": inputTypeInt = Define.EConnection.DummyInput; break; } Input input = new Input(inputTypeInt, inputName, connection); if (json["align"] != null) { string alignText = json["align"].ToString(); Define.EAlign align = alignText.Equals("LEFT") ? Define.EAlign.Left : (alignText.Equals("RIGHT") ? Define.EAlign.Right : Define.EAlign.Center); input.SetAlign(align); } if (json["check"] != null) { JArray checkArray = json["check"] as JArray; if (checkArray != null) { List <string> checkList = checkArray.Select(token => token.ToString()).ToList(); input.SetCheck(checkList); } else { input.SetCheck(json["check"].ToString()); } } return(input); }
/// <summary> /// create input from input params /// </summary> /// <param name="type">input type</param> /// <param name="name">input name</param> /// <param name="align">input alignment</param> /// <param name="check">input type checks</param> public static Input Create(Define.EConnection type, string name, Define.EAlign align, List <string> check) { Connection connection = null; if (type == Define.EConnection.InputValue || type == Define.EConnection.NextStatement) { connection = new Connection(type); } Input input = new Input(type, name, connection); input.SetAlign(align); input.SetCheck(check); return(input); }
/// <summary> /// Class for an input with an optional field. /// </summary> /// <param name="type"> The type of the input.</param> /// <param name="name"> Language-neutral identifier which may used to find this input again</param> /// <param name="block"> The block containing this input.</param> /// <param name="connection"> Optional connection for this input</param> public Input(Define.EConnection type, string name, Block block, Connection connection = null) { if (type != Define.EConnection.DummyInput && string.IsNullOrEmpty(name)) { throw new Exception("Value inputs and statement inputs must have non-empty name."); } Type = type; Name = name; mSourceBlock = block; Connection = connection; FieldRow = new List <Field>(); Align = Define.EAlign.Left; }
/// <summary> /// Get the connection view of connectionType /// output, previous, next connection /// </summary> public ConnectionView GetConnectionView(Define.EConnection connectionType) { int i = 0; while (i < Childs.Count) { ConnectionView view = Childs[i] as ConnectionView; if (view == null) { break; } if (view.ConnectionType == connectionType) { return(view); } i++; } //Debug.LogFormat("<color=red>Can't find the {0} connection view in block view of {1}.</color>", connectionType, BlockType); return(null); }
private Connection CreateConnection(Block sourceBlock, Vector2 <int> location, Define.EConnection type) { return(new Connection(sourceBlock, type) { Location = location }); }
/// <summary> /// Class for an input with an optional field. /// </summary> public Input(Define.EConnection type, string name, Connection connection = null) : this(type, name, null, connection) { }
/// <summary> /// Class for a connection between blocks. /// </summary> /// <param name="source">The block establishing this connection.</param> /// <param name="type">The type of the connection.</param> public Connection(Block source, Define.EConnection type) { Type = type; SourceBlock = source; }
/// <summary> /// Class for a connection between blocks. /// </summary> /// <param name="type"></param> public Connection(Define.EConnection type) : this(null, type) { }