Beispiel #1
0
        public void MoveToTree(Wrap what, Wrap anchor, MoveDestination dst)
        {
            var resp = GetWhereAndBeforeOf(what, anchor, dst);

            Wrap where = resp.Item1;
            Wrap beforeOf = resp.Item2;


            if (where == null)
            {
                return;
            }
            if (!CheckMoveConsistancy(what, where))
            {
                return;
            }

            if (what.Parent != null)
            {
                Remove(what);
            }
            if (UnassignedVideos.Contains(what))
            {
                UnassignedVideos.Remove(what as VideoWrap);
            }


            Insert(what, where, beforeOf);
        }
Beispiel #2
0
        Tuple<Wrap, Wrap> GetWhereAndBeforeOf(Wrap what, Wrap anchor, MoveDestination dst)
        {

            if (dst == MoveDestination.Into)
            {
                if (what is VideoWrap && anchor is VideoWrap)
                    return GetWhereAndBeforeOf(what, anchor, MoveDestination.After);
                return new Tuple<Wrap, Wrap>(anchor, null);
            }

            if (dst == MoveDestination.Before)
            {
                return Tuple.Create(anchor.Parent, anchor);
            }

            if (dst == MoveDestination.After)
            {
                if (anchor.Items.Count == 0)
                {
                    if (anchor.Parent == null) return new Tuple<Wrap, Wrap>(null, null);
                    var index = anchor.Parent.Items.IndexOf(anchor);
                    if (index == anchor.Parent.Items.Count - 1)
                        return new Tuple<Wrap, Wrap>(anchor.Parent, null);
                    return
                        Tuple.Create(anchor.Parent, anchor.Parent.Items[index + 1]);
                }
                return Tuple.Create(anchor, anchor.Items[0]);
            }

            throw new Exception("Cannot fall here");
        }
    /*public void deleteItem(GameObject item)
    {
        MovableItemOnStage mItem = item.GetComponent<MovableItemOnStage>();

        int lineNo = mItem.getLineNo();
        int index = mItem.getIndex();

        lines[lineNo, index] = 0;
        lineObjects[lineNo, index] = null;

        GameObject.DestroyImmediate(item);
    }*/

    public bool checkMove(int lineNo, int pos, MoveDestination dir)
    {
        if (lineObjects[lineNo, pos] == null)
        {
            Debug.Log("checkMove: " + lineNo + "," + pos + ". 參數位置上找不到任何物件!");
            return false;
        }
        //Debug.Log("checkMove: " + lineNo + "," + pos + ".  " + dir);
        MovableItemOnStage mItem = lineObjects[lineNo, pos].GetComponent<MovableItemOnStage>();

        int startIndex = pos;
        int checkLength = 0;

        switch (dir)
        {
            case MoveDestination.FORWARD:
                startIndex += mItem.needBlocks;
                checkLength = 1;
                break;

            case MoveDestination.BACKWARD:
                startIndex -= 1;
                checkLength = 1;
                break;

            case MoveDestination.EASTLINE:
                lineNo = 0;
                checkLength = mItem.needBlocks;
                Debug.Log("checkNext: " + lineNo + "," + checkLength);
                break;

            case MoveDestination.SOUTHLINE:
                lineNo = 1;
                checkLength = mItem.needBlocks;
                Debug.Log("checkNext: " + lineNo + "," + checkLength);
                break;

            case MoveDestination.WESTLINE:
                lineNo = 2;
                checkLength = mItem.needBlocks;
                break;


            case MoveDestination.NORTHLINE:
                lineNo = 3;
                checkLength = mItem.needBlocks;
                break;


            case MoveDestination.MIDLINE:
                lineNo = 4;
                checkLength = mItem.needBlocks;
                break;
        }

        return checkLineHasSpace(lineNo, startIndex, checkLength);
    }
    public void moveItemByDirection(int lineNo, int pos, MoveDestination dir, int blockLength)
    {
        int nextLineNo = 0;
        int nextPos = 0;

        switch (dir)
        {
            case MoveDestination.FORWARD:
                nextLineNo = lineNo;
                nextPos = pos + 1;
                break;

            case MoveDestination.BACKWARD:
                nextLineNo = lineNo;
                nextPos = pos - 1;
                break;

            case MoveDestination.EASTLINE:
                nextLineNo = 0;
                nextPos = pos;
                break;

            case MoveDestination.SOUTHLINE:
                nextLineNo = 1;
                nextPos = pos;
                break;


            case MoveDestination.WESTLINE:
                nextLineNo = 2;
                nextPos = pos;
                break;

            case MoveDestination.NORTHLINE:
                nextLineNo = 3;
                nextPos = pos;
                break;


            case MoveDestination.MIDLINE:
                nextLineNo = 4;
                nextPos = pos;
                break;
        }

        lines[lineNo, pos] = 0;
        lines[nextLineNo, nextPos] = blockLength;

        GameObject tmp = new GameObject();
        lineObjects[nextLineNo, nextPos] = lineObjects[lineNo, pos];
        lineObjects[lineNo, pos] = tmp;
        GameObject.DestroyImmediate(tmp);

        MovableItemOnStage mItem = lineObjects[nextLineNo, nextPos].GetComponent<MovableItemOnStage>();
        mItem.setPos(nextLineNo, nextPos);
    }
Beispiel #5
0
        Tuple<Wrap, Wrap> GetWhereAndBeforeOf(Wrap what, Wrap anchor, MoveDestination dst)
        {
            if (dst == MoveDestination.Into)
            {
                if (what is VideoWrap && anchor is VideoWrap)
                    return GetWhereAndBeforeOf(what, anchor, MoveDestination.After);
                return new Tuple<Wrap, Wrap>(anchor, null);
            }

            if (dst == MoveDestination.Before)
            {
                return Tuple.Create(anchor.Parent, anchor);
            }

            if (dst == MoveDestination.After)
            {
                if (anchor.Items.Count == 0)
                {
                    if (anchor.Parent == null) return new Tuple<Wrap, Wrap>(null, null);
                    var index = anchor.Parent.Items.IndexOf(anchor);
                    if (index == anchor.Parent.Items.Count - 1)
                        return new Tuple<Wrap, Wrap>(anchor.Parent, null);
                    return
                        Tuple.Create(anchor.Parent, anchor.Parent.Items[index + 1]);
                }
                return Tuple.Create(anchor, anchor.Items[0]);
            }

            throw new Exception("Cannot fall here");
        }
Beispiel #6
0
        public void MoveToTree(Wrap what, Wrap anchor, MoveDestination dst)
        {
            var resp = GetWhereAndBeforeOf(what, anchor, dst);
            Wrap where = resp.Item1;
            Wrap beforeOf = resp.Item2;

            if (where == null) return;
            if (!CheckMoveConsistancy(what, where)) return;

            if (what.Parent!=null)
                Remove(what);
            if (UnassignedVideos.Contains(what))
                UnassignedVideos.Remove(what as VideoWrap);

            Insert(what, where, beforeOf);
        }
Beispiel #7
0
        protected override void Format(DeltaType type, JsonFormatContext context, JToken delta, JToken leftValue, string key, string leftKey, MoveDestination movedFrom)
        {
            switch (type)
            {
            case DeltaType.Added:
                FormatAdded(context, delta);
                break;

            case DeltaType.Node:
                FormatNode(context, delta, leftValue);
                break;

            case DeltaType.Modified:
                FormatModified(context, delta);
                break;

            case DeltaType.Deleted:
                FormatDeleted(context);
                break;

            case DeltaType.Moved:
                FormatMoved(context, delta);
                break;

            case DeltaType.Unknown:
            case DeltaType.Unchanged:
            case DeltaType.MoveDestination:
                break;

            case DeltaType.TextDiff:
                throw new InvalidOperationException("JSON RFC 6902 does not support TextDiff.");
            }
        }