Ejemplo n.º 1
0
        public void OnBeginDrag(PointerEventData eventData)
        {
            if (!IsMovable)
            {
                return;
            }

            CodeUIElement.Instance.DraggedBlock = this;

            placeHolder = new GameObject();
            var placeHolderTransform = placeHolder.AddComponent <RectTransform>();

            placeHolderTransform.SetParent(transform.parent);
            placeHolderTransform.SetSiblingIndex(transform.GetSiblingIndex());
            placeHolderTransform.anchorMin = new Vector2(0, 1);
            placeHolderTransform.anchorMax = new Vector2(0, 1);
            LayoutElement layoutElement = placeHolder.AddComponent <LayoutElement>();

            layoutElement.minWidth  = OriginalWidth;
            layoutElement.minHeight = OriginalHeight;

            OriginalPosition     = transform.position;
            OriginalParent       = transform.parent;
            OriginalSiblingIndex = transform.GetSiblingIndex();

            IsInSlot = false;

            transform.SetParent(CodeUIElement.Instance.transform);
            canvasGroup.blocksRaycasts = false;

            if (ContainedSlot != null)
            {
                ContainedSlot.Filled = false;
                ContainedSlot        = null;
            }
            if (ContainedScopedBlock != null)
            {
                ContainedScopedBlock.UpdateBlocks();
                ContainedScopedBlock = null;
            }
        }
Ejemplo n.º 2
0
        public void FindWhereYouBelong()
        {
            Transform parent = transform.parent;

            while (parent != null)
            {
                ScopedBlock scopedBlock = parent.GetComponent <ScopedBlock>();
                if (scopedBlock != null)
                {
                    ContainedScopedBlock = scopedBlock;
                    break;
                }
                ExprSlot exprSlot = parent.GetComponent <ExprSlot>();
                if (exprSlot != null)
                {
                    ContainedSlot = exprSlot;
                    break;
                }
                parent = parent.parent;
            }
        }
Ejemplo n.º 3
0
 private static Interpreter.Stmt CompileStmt(StmtBlock stmtBlock)
 {
     if (stmtBlock is ScopedBlock)
     {
         ScopedBlock scopedBlock = (ScopedBlock)stmtBlock;
         if (scopedBlock is RepeatBlock)
         {
             RepeatBlock repeatBlock = (RepeatBlock)scopedBlock;
             return(new Interpreter.Repeat
             {
                 Body = new Interpreter.Block
                 {
                     Statements = repeatBlock.StatementBlocks
                                  .Select(CompileStmt).ToList()
                 }
             });
         }
         if (scopedBlock is IfBlock)
         {
             IfBlock ifBlock = (IfBlock)scopedBlock;
             if (ifBlock.EntityToCheck == null)
             {
                 throw new CompilerException($"Missing arugment in if block.");
             }
             return(new Interpreter.If
             {
                 Cond = new Interpreter.BoolExpr {
                     type = ifBlock.EntityToCheck.Value, Value = ifBlock.Not
                 },
                 Then = new Interpreter.Block
                 {
                     Statements = ifBlock.StatementBlocks.Select(CompileStmt).ToList()
                 },
                 Else = null
             });
         }
         if (scopedBlock is StmtListBlock)
         {
             StmtListBlock stmtListBlock = (StmtListBlock)scopedBlock;
             return(new Interpreter.Block
             {
                 Statements = stmtListBlock.StatementBlocks
                              .Select(CompileStmt).ToList()
             });
         }
         throw new CompilerException($"Scoped block {scopedBlock.GetType().Name} is not supported.");
     }
     if (stmtBlock is ConjureBlock)
     {
         ConjureBlock conjureBlock = (ConjureBlock)stmtBlock;
         if (conjureBlock.EntityToConjure == null)
         {
             throw new CompilerException($"Missing argument in statement Conjure.");
         }
         return(new Interpreter.Conjure
         {
             Entity = conjureBlock.EntityToConjure.Value
         });
     }
     if (stmtBlock is ChangeBlock)
     {
         ChangeBlock changeBlock = (ChangeBlock)stmtBlock;
         if (changeBlock.Adjective == null)
         {
             throw new CompilerException($"Missing argument in statement Change.");
         }
         return(new Interpreter.Change
         {
             Adjective = changeBlock.Adjective.Value
         });
     }
     if (stmtBlock is MoveBlock)
     {
         MoveBlock moveBlock = (MoveBlock)stmtBlock;
         if (moveBlock.Dir == null)
         {
             throw new CompilerException($"Missing direction argument in statement Move.");
         }
         if (moveBlock.Distance == null || moveBlock.Distance <= 0 || moveBlock.Distance > 3)
         {
             throw new CompilerException($"Missing distance argument in statement Move.");
         }
         return(new Interpreter.Move {
             Dir = moveBlock.Dir.Value, Distance = moveBlock.Distance.Value
         });
     }
     if (stmtBlock is BreakBlock)
     {
         return(new Interpreter.Break());
     }
     throw new CompilerException($"Statement block {stmtBlock.GetType().Name} is not supported.");
 }