Ejemplo n.º 1
0
    private void Start()
    {
        DraggableHolder dh = GetComponentInParent <DraggableHolder>();

        if (dh)
        {
            myDraggableType = GetComponentInParent <DraggableHolder>().myType;
        }
        else
        {
            myDraggableType = DraggableHolder.DraggableType.NoDragging;
        }

        rt = GetComponent <RectTransform>();
        gr = GetComponentInParent <GraphicRaycaster>();
        es = GetComponentInParent <EventSystem>();

        StartCoroutine(calcVel());

        if (false && myDraggableType != DraggableHolder.DraggableType.RedundantParens)
        {
            onApply.AddRemovableListener(_ => { enabled = false; }, this);
            onUnapply.AddRemovableListener(_ => { enabled = true; }, this);
        }
    }
Ejemplo n.º 2
0
    private Sum <Action, PreviewInfo> MakeDrop(SpawnTarget spawnTarget, Transform target) //left is on failure, right is on success
    {
        var parenTracker = target.GetComponent <LayoutTracker>();

        List <int> index = parenTracker.index;

        var my_term = myCombinator == null
            ? Shrub <Sum <Combinator, Variable> > .Node(new List <Shrub <Sum <Combinator, Variable> > >())
            : Shrub <Sum <Combinator, Variable> > .Leaf(Sum <Combinator, Variable> .Inl(myCombinator));

        if (!target.GetComponentInParent <DraggableHolder>())
        {
            return(Sum <Action, PreviewInfo> .Inl(DestroyMe));
        }

        if (spawnTarget && !spawnTarget.NoBackApplication.val) //Back application
        {
            if (myCombinator == null)
            { //You are a parenthesis
                int my_index;
                for (my_index = 0; my_index < target.childCount; my_index++)
                {
                    if (transform.position.x < target.GetChild(my_index).position.x - target.GetChild(my_index).localScale.x / 4f)
                    {
                        break;
                    }
                }


                if (true /*my_index != target.childCount*/)
                {
                    return(Util.BackApplyParen(spawnTarget.goal, index.Skip(1).ToList(), my_index).Match(t =>
                    {
                        List <IHighlightable> selected = new List <IHighlightable>();
                        for (int i = 0; i < my_index; i++)
                        {
                            selected = selected.Concat(target.GetChild(i).GetComponentsInChildren <IHighlightable>()).ToList();
                        }
                        PreviewRedundantParenInfo prp = new PreviewRedundantParenInfo(index, my_index, () =>
                        {
                            spawnTarget.addParens(index.Skip(1).ToList(), my_index, GetComponent <LayoutTracker>(), t);

                            foreach (IHighlightable highlightable in selected)
                            {
                                highlightable.unselect();
                            }
                            PlaceMe();
                            myDraggableType = DraggableHolder.DraggableType.RedundantParens;
                        }, () =>
                        {
                            foreach (IHighlightable highlightable in selected)
                            {
                                highlightable.select();
                            }
                        }, () =>
                        {
                            foreach (IHighlightable highlightable in selected)
                            {
                                highlightable.unselect();
                            }
                        });
                        return Sum <Action, PreviewInfo> .Inr(PreviewInfo.In2(prp));
                    }, _ =>
                    {
                        return Sum <Action, PreviewInfo> .Inl(DestroyMe);
                    }));
                }
                else
                {
                    return(Sum <Action, PreviewInfo> .Inl(DestroyMe));
                }
            }
            else
            { //You not are a parenthesis
                HighlightParen hightligher = parenTracker.GetComponent <HighlightParen>();
                return(Util.BackApply(spawnTarget.goal, myCombinator, index.Skip(1).ToList()).Match(t =>

                                                                                                    Sum <Action, PreviewInfo> .Inr(PreviewInfo.In1(new PreviewBackCombinatorInfo(spawnTarget, parenTracker, index, () => {
                    pushUndoGoalTerm.Invoke(spawnTarget.goal);


                    spawnTarget.unApply(t, GetComponent <LayoutTracker>(), myCombinator, index.Skip(1).ToList());

                    PlaceMe();
                    hightligher.unselect();
                    myDraggableType = DraggableHolder.DraggableType.NoDragging;
                }, hightligher.select, hightligher.unselect)))

                                                                                                    , _ => Sum <Action, PreviewInfo> .Inl(DestroyMe)));
            }
        }
        else if (!spawnTarget && !NoForwardMode.val && target.GetComponentInParent <DraggableHolder>() && target.GetComponentInParent <DraggableHolder>().myType == DraggableHolder.DraggableType.Proposal) //forward application
        {
            if (evaluationMode.val)
            {
                return(Sum <Action, PreviewInfo> .Inl(DestroyMe));
            }

            int my_index;
            for (my_index = 0; my_index < target.childCount; my_index++)
            {
                if (transform.position.x < target.GetChild(my_index).position.x)
                {
                    break;
                }
            }
            var sm = target.GetComponentInParent <SymbolManager>();
            return(Sum <Action, PreviewInfo> .Inr(
                       PreviewInfo.In0(new PreviewForwardInfo(sm, index, target, my_index, () => {
                //if (pushUndoProposalTerm) {
                //	pushUndoProposalTerm.Invoke(sm.readTerm());
                //} else {
                //	Debug.LogError("pushUndoProposalTerm is null in DraggableSpell: " + this);
                //}
                sm.Insert(index.Skip(1).Append(my_index).ToList(), my_term);

                // paren = AccessTransfrom(topTracker, paren_index);

                transform.SetParent(target, true);
                transform.SetSiblingIndex(my_index);
                PlaceMe();
                myDraggableType = DraggableHolder.DraggableType.Proposal;
            }, UnPlace))
                       ));
        }
        return(Sum <Action, PreviewInfo> .Inl(DestroyMe));
    }