Beispiel #1
0
        private void Move(Draggable.Slot slot)
        {
            Divider targetDivider = (Divider)slot;

            int oldLineNumber = label.val;
            int newLineNumber = targetDivider.lineNumber;

            label.val = newLineNumber;

            // Remove old entry
            codeList.Program.branchLabelList.Remove(label);

            // Find new entry
            int insertionIndex = 0;

            for (int i = 0; i < codeList.Program.branchLabelList.Count; ++i)
            {
                Label l = codeList.Program.branchLabelList[i];
                if (l.val > label.val)
                {
                    break;
                }
                else if (l.val < label.val)
                {
                    insertionIndex = i + 1;
                }
                else if (l.val == label.val)
                {
                    if (l == targetDivider.label)
                    {
                        insertionIndex = i;
                        break;
                    }
                    else
                    {
                        insertionIndex = i + 1;
                    }
                }
            }

            codeList.Program.branchLabelList.Insert(insertionIndex, label);
            codeList.Program.BroadcastBranchLabelChange();

            // Reset frontend
            Destroy(gameObject);
        }
        private void Insert(Draggable.Slot slot)
        {
            Divider targetDivider = (Divider)slot;
            int     newLineNumber = targetDivider.lineNumber;
            int     adjustedNewLineNumber;

            if (lineNumber != -1)
            {
                // Remove old instruction
                Remove();

                adjustedNewLineNumber = newLineNumber > lineNumber ? newLineNumber - 1 : newLineNumber;
            }
            else
            {
                adjustedNewLineNumber = newLineNumber;
            }

            // Insert new instruction
            Globals.program.instructions.Insert(adjustedNewLineNumber, instruction);

            // Adjust labels
            bool crossed = false;

            foreach (Label label in Globals.program.branchLabelList)
            {
                if (targetDivider.label == label)
                {
                    crossed = true;
                }
                if (crossed || adjustedNewLineNumber < label.val)
                {
                    ++label.val; // TODO: This will need to be variable when we add dragging selected blocks
                }
            }
        }