public CBlockView(InvokationBlock model, BlockAttributes attribute, List<ContentView> contents, IEnumerable<BlockStackView> scripts, CBlockImgParts parts, List<ArgumentPartition> argPartitions) { this.model = model; this.attribute = attribute; Contents.AddRange(contents); Scripts.AddRange(scripts); this.ArgPartitions = argPartitions; int si = 0; foreach (ArgumentPartition p in argPartitions) { if (p.Type == ArgViewType.Script) scriptIndexes.Add(si); si += p.N; } this.parts = parts; Changed += delegate(object sender) { }; foreach (ContentView cv in contents) { cv.Parent = this; cv.Changed += new ViewChangedEvent(subView_Changed); } foreach (BlockStackView sv in scripts) { sv.Parent = this; sv.Changed += new ViewChangedEvent(subView_Changed); } Reassemble(); }
public BlockInfo(string methodName, BlockAttributes attribute, DataType returnType, DataType[] argTypes) { this.Text = methodName; this.Attribute = attribute; this.ReturnType = returnType; this.ArgTypes = argTypes; }
public Block(BlockAttributes atts) { Name = atts.name; IsSolid = atts.IsSolid; TexturePos = atts.TexturePos; IsEmpty = atts.IsEmpty; //Color = atts.Color; }
public static Block Empty(Vector3 pos, World world, Chunk owner) { BlockAttributes scr = ScriptableObject.CreateInstance <BlockAttributes>(); scr.name = "Empty"; scr.IsEmpty = true; scr.IsSolid = false; return(new Block(scr, pos, world, owner)); }
public bool RegisteredMethodAttribute(string invokation, out BlockAttributes attr) { if (blockInfos.ContainsKey(invokation)) { attr = blockInfos[invokation].Attribute; return(true); } attr = BlockAttributes.Stack; return(false); }
public void RegisterMethod(string methodName, BlockAttributes attribute, DataType returnType, DataType[] argTypes, bool system) { BlockInfo bi = new BlockInfo(methodName, attribute, returnType, argTypes); blockInfos[methodName] = bi; if (system) { systemBlockInfos[methodName] = bi; } }
public InvokationBlock(string text, BlockAttributes Attributes, IEnumerable<DataType> ArgTypes, DataType returnType) { this.Text = text; this.Attributes = Attributes; this.ArgTypes = new List<DataType>(); this.ArgTypes.AddRange(ArgTypes); this.ReturnType = returnType; this.Args = new ArgList(this); this.ParentRelationship = new ParentRelationship(); this.OnArgChanged += delegate(object sender, int arg, IBlock _old, IBlock _new) { }; }
public InvokationBlock(string text, BlockAttributes Attributes, IEnumerable <DataType> ArgTypes, DataType returnType) { this.Text = text; this.Attributes = Attributes; this.ArgTypes = new List <DataType>(); this.ArgTypes.AddRange(ArgTypes); this.ReturnType = returnType; this.Args = new ArgList(this); this.ParentRelationship = new ParentRelationship(); this.OnArgChanged += delegate(object sender, int arg, IBlock _old, IBlock _new) { }; }
public InvokationBlockView(InvokationBlock model, BlockAttributes attribute, ContentView content) { this.model = model; this.content = content; this.attribute = attribute; Changed += delegate(object sender) { }; content.Changed += new ViewChangedEvent(content_Changed); content.Parent = this; content.RelativePos = new Point(0, 0); Reassemble(); }
internal bool IsCompatible(DataType bType, BlockAttributes droppedAttr) { switch (DropType) { case DropType.Above: return droppedAttr == BlockAttributes.Hat || droppedAttr == BlockAttributes.Stack; case DropType.Below: return droppedAttr == BlockAttributes.Cap || droppedAttr == BlockAttributes.Stack; case DropType.Between: return droppedAttr == BlockAttributes.Stack; case DropType.AsArgument: return IsAssignableFrom(this.ArgType, bType); default: return false; } }
public IBlockView ViewFromBlock(IBlock block) { if (blockViews.ContainsKey(block)) { return(blockViews[block]); } if (block is BlockStack) { IBlockView ret = ViewFromBlockStack((BlockStack)block);; blockViews[block] = ret; return(ret); } if (block is VarAccessBlock || block is VarDefBlock) { IBlockView ret = new VariableView((IVarBlock)block, varb_parts, textMetrics, textFont); blockViews[block] = ret; return(ret); } if (block is TextBlock) { IBlockView ret = new TextView((TextBlock)block, ib_parts, textMetrics, textFont); blockViews[block] = ret; return(ret); } if (block is InvokationBlock) { InvokationBlock b = (InvokationBlock)block; BlockAttributes attr = blockSpace.AttributeOf(b); IBlockView r = ViewFromInvokationBlock(b, attr); blockViews[block] = r; return(r); } if (block is ProcDefBlock) { ProcDefBlock b = (ProcDefBlock)block; BlockAttributes attr = blockSpace.AttributeOf(b); IBlockView r = ViewFromProcDefBlock(b); blockViews[block] = r; return(r); } throw new ArgumentException(); }
internal bool IsCompatible(DataType bType, BlockAttributes droppedAttr) { switch (DropType) { case DropType.Above: return(droppedAttr == BlockAttributes.Hat || droppedAttr == BlockAttributes.Stack); case DropType.Below: return(droppedAttr == BlockAttributes.Cap || droppedAttr == BlockAttributes.Stack); case DropType.Between: return(droppedAttr == BlockAttributes.Stack); case DropType.AsArgument: return(IsAssignableFrom(this.ArgType, bType)); default: return(false); } }
public static IEnumerable <DropRegion> EdgeDropRegions( this IInvokationBlockView view, Point origin, Size size) { BlockAttributes Attribute = view.Attribute; int Width = size.Width; int Height = size.Height; if (Attribute == BlockAttributes.Stack) { yield return(new DropRegion(DropType.Above, new Rectangle(origin.Offseted(0, -2), new Size(Width, 5)), view)); yield return(new DropRegion(DropType.Below, new Rectangle(origin.Offseted(0, Height - 2), new Size(Width, 5)), view)); } else if (Attribute == BlockAttributes.Hat) { yield return(new DropRegion(DropType.Below, new Rectangle(origin.Offseted(0, Height - 2), new Size(Width, 5)), view)); } else if (Attribute == BlockAttributes.Cap) { yield return(new DropRegion(DropType.Above, new Rectangle(origin.Offseted(0, -2), new Size(Width, 5)), view)); } }
public CBlockView(InvokationBlock model, BlockAttributes attribute, List <ContentView> contents, IEnumerable <BlockStackView> scripts, CBlockImgParts parts, List <ArgumentPartition> argPartitions) { this.model = model; this.attribute = attribute; Contents.AddRange(contents); Scripts.AddRange(scripts); this.ArgPartitions = argPartitions; int si = 0; foreach (ArgumentPartition p in argPartitions) { if (p.Type == ArgViewType.Script) { scriptIndexes.Add(si); } si += p.N; } this.parts = parts; Changed += delegate(object sender) { }; foreach (ContentView cv in contents) { cv.Parent = this; cv.Changed += new ViewChangedEvent(subView_Changed); } foreach (BlockStackView sv in scripts) { sv.Parent = this; sv.Changed += new ViewChangedEvent(subView_Changed); } Reassemble(); }
public bool RegisteredMethodAttribute(string invokation, out BlockAttributes attr) { if (blockInfos.ContainsKey(invokation)) { attr = blockInfos[invokation].Attribute; return true; } attr = BlockAttributes.Stack; return false; }
public IBlockView ViewFromInvokationBlock(InvokationBlock b, BlockAttributes attribute) { string[] textParts = b.Text.SplitFuncArgs(); Bitmap[] textBitmaps = RenderTextBits(textParts); if (b.ArgTypes.All(t => t != DataType.Script)) { // it ain't a C block List<IBlockView> subContent = new List<IBlockView>(); int i = 0; int currentArg = 0; BitArray trueArgs = new BitArray(textParts.Length); foreach (string s in textParts) { if (s == "%") { subContent.Add(ViewFromBlock(b.Args[currentArg++])); trueArgs[i] = true; } else { subContent.Add(new LabelView(textBitmaps[i])); trueArgs[i] = false; } ++i; } NineContent imageParts = sb_parts; // dummy initial val switch (attribute) { case BlockAttributes.Stack: imageParts = sb_parts; break; case BlockAttributes.Report: if (b.ReturnType == DataType.Boolean) imageParts = bool_parts; else imageParts = fib_parts; break; case BlockAttributes.Cap: imageParts = capb_parts; break; case BlockAttributes.Hat: imageParts = hatb_parts; break; } ContentView content = new ContentView(subContent.ToArray(), b.ArgTypes.ToArray(), trueArgs, imageParts); InvokationBlockView ib = new InvokationBlockView(b, attribute, content); b.OnArgChanged += new InvokationBlockArgChangeEvent(InvokationBlock_ArgChanged); return ib; } else { // it's a C block, yappari List<ContentView> contents = new List<ContentView>(); List<IBlockView> subContent = new List<IBlockView>(); List<DataType> subArgTypes = new List<DataType>(); List<BlockStackView> scripts = new List<BlockStackView>(); List<ArgumentPartition> argPartitions = new List<ArgumentPartition>(); List<bool> trueArgs = new List<bool>(); int currentArg = 0; int currentPartitionCount = 0; int i = 0; bool head = true; foreach (string s in textParts) { if (s != "%") { LabelView lv = new LabelView(textBitmaps[i]); subContent.Add(lv); trueArgs.Add(false); } else { // It's an arg. Script or normal? DataType type = b.ArgTypes[currentArg]; IBlock arg = b.Args[currentArg]; if (type != DataType.Script) { // Oh it's just a normal argument IBlockView bv = ViewFromBlock(arg); subContent.Add(bv); subArgTypes.Add(type); trueArgs.Add(true); currentPartitionCount++; } else { // We need to split a new head or waist in the C block NineContent nc; if (head) { nc = cb_parts.Head; head = false; } else { nc = cb_parts.Waist; } ContentView cv = new ContentView(subContent.ToArray(), subArgTypes.ToArray(), new BitArray(trueArgs.ToArray()), nc); contents.Add(cv); ArgumentPartition ap = new ArgumentPartition(currentPartitionCount, ArgViewType.Content); argPartitions.Add(ap); currentPartitionCount = 0; BlockStackView side = (BlockStackView)ViewFromBlock((BlockStack)arg); scripts.Add(side); ap = new ArgumentPartition(1, ArgViewType.Script); argPartitions.Add(ap); subContent = new List<IBlockView>(); subArgTypes = new List<DataType>(); trueArgs = new List<bool>(); } currentArg++; } i++; } b.OnArgChanged +=new InvokationBlockArgChangeEvent(InvokationBlock_ArgChanged); CBlockView cb = new CBlockView(b, attribute, contents, scripts, cb_parts, argPartitions); return cb; } }
public void RegisterSystemMethod(string methodName, BlockAttributes attribute, DataType returnType, DataType[] argTypes) { blockSpace.RegisterMethod(methodName, attribute, returnType, argTypes, true); }
/// <summary> /// /// </summary> /// <param name="atts"></param> /// <param name="pos">Position in the chunk.</param> /// <param name="world"></param> /// <param name="owner"></param> public Block(BlockAttributes atts, Vector3 pos, World world, Chunk owner) : this(atts) { m_world = world; m_owner = owner; Position = pos; }
public IBlockView ViewFromInvokationBlock(InvokationBlock b, BlockAttributes attribute) { string[] textParts = b.Text.SplitFuncArgs(); Bitmap[] textBitmaps = RenderTextBits(textParts); if (b.ArgTypes.All(t => t != DataType.Script)) { // it ain't a C block List <IBlockView> subContent = new List <IBlockView>(); int i = 0; int currentArg = 0; BitArray trueArgs = new BitArray(textParts.Length); foreach (string s in textParts) { if (s == "%") { subContent.Add(ViewFromBlock(b.Args[currentArg++])); trueArgs[i] = true; } else { subContent.Add(new LabelView(textBitmaps[i])); trueArgs[i] = false; } ++i; } NineContent imageParts = sb_parts; // dummy initial val switch (attribute) { case BlockAttributes.Stack: imageParts = sb_parts; break; case BlockAttributes.Report: if (b.ReturnType == DataType.Boolean) { imageParts = bool_parts; } else { imageParts = fib_parts; } break; case BlockAttributes.Cap: imageParts = capb_parts; break; case BlockAttributes.Hat: imageParts = hatb_parts; break; } ContentView content = new ContentView(subContent.ToArray(), b.ArgTypes.ToArray(), trueArgs, imageParts); InvokationBlockView ib = new InvokationBlockView(b, attribute, content); b.OnArgChanged += new InvokationBlockArgChangeEvent(InvokationBlock_ArgChanged); return(ib); } else { // it's a C block, yappari List <ContentView> contents = new List <ContentView>(); List <IBlockView> subContent = new List <IBlockView>(); List <DataType> subArgTypes = new List <DataType>(); List <BlockStackView> scripts = new List <BlockStackView>(); List <ArgumentPartition> argPartitions = new List <ArgumentPartition>(); List <bool> trueArgs = new List <bool>(); int currentArg = 0; int currentPartitionCount = 0; int i = 0; bool head = true; foreach (string s in textParts) { if (s != "%") { LabelView lv = new LabelView(textBitmaps[i]); subContent.Add(lv); trueArgs.Add(false); } else { // It's an arg. Script or normal? DataType type = b.ArgTypes[currentArg]; IBlock arg = b.Args[currentArg]; if (type != DataType.Script) { // Oh it's just a normal argument IBlockView bv = ViewFromBlock(arg); subContent.Add(bv); subArgTypes.Add(type); trueArgs.Add(true); currentPartitionCount++; } else { // We need to split a new head or waist in the C block NineContent nc; if (head) { nc = cb_parts.Head; head = false; } else { nc = cb_parts.Waist; } ContentView cv = new ContentView(subContent.ToArray(), subArgTypes.ToArray(), new BitArray(trueArgs.ToArray()), nc); contents.Add(cv); ArgumentPartition ap = new ArgumentPartition(currentPartitionCount, ArgViewType.Content); argPartitions.Add(ap); currentPartitionCount = 0; BlockStackView side = (BlockStackView)ViewFromBlock((BlockStack)arg); scripts.Add(side); ap = new ArgumentPartition(1, ArgViewType.Script); argPartitions.Add(ap); subContent = new List <IBlockView>(); subArgTypes = new List <DataType>(); trueArgs = new List <bool>(); } currentArg++; } i++; } b.OnArgChanged += new InvokationBlockArgChangeEvent(InvokationBlock_ArgChanged); CBlockView cb = new CBlockView(b, attribute, contents, scripts, cb_parts, argPartitions); return(cb); } }