Example #1
0
    public int count = 1; //at least 1

    public override bool Evaluate(ShapeProfile shapeProfile)
    {
        int equalCount = 0;

        var sides = shapeProfile.sideLengths;

        //need at least 4 even sides for this to make sense
        if (sides.Length < 4 && sides.Length % 2 != 0)
        {
            return(false);
        }

        int hCount = sides.Length / 2;

        //compare opposite sides
        for (int i = 0; i < hCount; i++)
        {
            var sideA = Mathf.RoundToInt(sides[i]);
            var sideB = Mathf.RoundToInt(sides[i + hCount]);

            if (sideA == sideB)
            {
                equalCount++;
            }
        }

        return(equalCount >= count);
    }
Example #2
0
    public bool exclusive; //if true, ensure match count is exactly equal to count

    public override bool Evaluate(ShapeProfile shapeProfile)
    {
        int parallelCount = 0;

        var sideDirs = shapeProfile.sideDirs;

        //need at least 4 even sides for this to make sense
        if (sideDirs.Length < 4 && sideDirs.Length % 2 != 0)
        {
            return(false);
        }

        int hCount = sideDirs.Length / 2;

        //compare opposite sides
        for (int i = 0; i < hCount; i++)
        {
            var dirA = sideDirs[i];
            var dirB = sideDirs[i + hCount];

            var angle  = Vector2.Angle(dirA, dirB);
            var iAngle = Mathf.RoundToInt(angle);
            if (iAngle == 0 || iAngle == 180)
            {
                parallelCount++;
            }
        }

        if (exclusive)
        {
            return(parallelCount == count);
        }

        return(parallelCount >= count);
    }
Example #3
0
    void OnShapeCollected(ShapeProfile shape)
    {
        var ind = LevelController.instance.shapesCollected.Count - 1;

        if (ind < mCollectItems.Count)
        {
            mCollectItems[ind].activeGO.SetActive(true);
        }
    }
Example #4
0
    public override bool Evaluate(ShapeProfile shapeProfile)
    {
        var equalCount = 0;

        var sides = shapeProfile.sideLengths;

        if (sides.Length % 2 != 0)
        {
            return(false);
        }

        var hSideCount = sides.Length / 2;

        if (mPairs == null || mPairs.Count != hSideCount)
        {
            mPairs = new M8.CacheList <Pair>(hSideCount);
        }
        else
        {
            mPairs.Clear();
        }

        for (int i = 0; i < sides.Length; i++)
        {
            //make sure these are not already paired
            var indA = i;
            if (IsPaired(indA))
            {
                continue;
            }

            var indB = i < sides.Length - 1 ? i + 1 : 0;
            if (IsPaired(indB))
            {
                continue;
            }



            var sideLenA = Mathf.RoundToInt(sides[indA]);
            var sideLenB = Mathf.RoundToInt(sides[indB]);

            if (sideLenA == sideLenB)
            {
                mPairs.Add(new Pair {
                    indA = indA, indB = indB
                });
                equalCount++;
            }
        }

        return(equalCount >= count);
    }
Example #5
0
    public override bool Evaluate(ShapeProfile shapeProfile)
    {
        int matchCount = 0;

        for (int i = 0; i < shapeProfile.angles.Length; i++)
        {
            var iAngle = Mathf.RoundToInt(shapeProfile.angles[i]);
            if (iAngle == angle)
            {
                matchCount++;
            }
        }

        return(matchCount >= count);
    }
Example #6
0
    public void CollectShape(ShapeProfile shapeProfile)
    {
        if (shapeProfile.isCollected) //fail-safe
        {
            return;
        }

        shapeProfile.Collect();

        shapesCollected.Add(shapeProfile);

        shapeCollectedCallback?.Invoke(shapeProfile);

        actionMode = ActionMode.Collect;
    }
Example #7
0
    public int count = 1; //at least 1

    public override bool Evaluate(ShapeProfile shapeProfile)
    {
        int equalCount = 0;

        var angles = shapeProfile.angles;
        int hCount = angles.Length / 2;

        //compare opposite sides
        for (int i = 0; i < hCount; i++)
        {
            var angleA = Mathf.RoundToInt(angles[i]);
            var angleB = Mathf.RoundToInt(angles[i + hCount]);

            if (angleA == angleB)
            {
                equalCount++;
            }
        }

        return(equalCount >= count);
    }
Example #8
0
    public bool Evaluate(ShapeProfile shapeProfile)
    {
        if (parentCategory)
        {
            if (!parentCategory.Evaluate(shapeProfile))
            {
                return(false);
            }
        }

        for (int i = 0; i < attributes.Length; i++)
        {
            var attr = attributes[i];
            if (!attr.Evaluate(shapeProfile))
            {
                return(false);
            }
        }

        return(true);
    }
Example #9
0
    public bool isExplicit; //if true, matches must equal count

    public override bool Evaluate(ShapeProfile shapeProfile)
    {
        int maxEqualCount = 0;

        var sides = shapeProfile.sideLengths;

        for (int i = 0; i < sides.Length; i++)
        {
            var _count = 1;

            var sideCheckA = Mathf.RoundToInt(sides[i]);

            for (int j = 0; j < sides.Length; j++)
            {
                if (j == i)
                {
                    continue;
                }

                var sideCheckB = Mathf.RoundToInt(sides[j]);

                if (sideCheckA == sideCheckB)
                {
                    _count++;
                }
            }

            if (_count > maxEqualCount)
            {
                maxEqualCount = _count;
            }
        }

        if (isAll)
        {
            return(maxEqualCount == sides.Length);
        }

        return(isExplicit ? maxEqualCount == count : maxEqualCount >= count);
    }
Example #10
0
    IEnumerator DoCollect()
    {
        if (animator && !string.IsNullOrEmpty(takeIdle))
        {
            animator.Play(takeIdle);
        }

        if (mShapeCollect)
        {
            //move towards collection
            var easeFunc = DG.Tweening.Core.Easing.EaseManager.ToEaseFunction(moveEase);

            var startPos = root.position;

            Vector2 collectPos = startPos;
            Vector2 destPos    = startPos;

            var curTime = 0f;
            while (curTime < moveDelay)
            {
                yield return(null);

                collectPos = mShapeCollect.transform.position;
                destPos    = new Vector2(collectPos.x, startPos.y);

                curTime += Time.deltaTime;

                var t = easeFunc(curTime, moveDelay, 0f, 0f);

                root.position = Vector2.Lerp(startPos, destPos, t);
            }

            //setup beam size, assume pivot is top
            var beamPos  = beamRender.transform.position;
            var beamLen  = Mathf.Abs(collectPos.y - beamPos.y) + beamLengthOfs;
            var beamSize = beamRender.size;
            beamSize.y      = beamLen;
            beamRender.size = beamSize;

            //setup collect
            if (animator && !string.IsNullOrEmpty(takeCollect))
            {
                animator.ResetTake(takeCollect);
            }

            var collectRender = mShapeCollect.shape.GetComponent <SpriteRenderer>();
            collectRender.sortingLayerName = collectSortLayer;

            collectRoot.position = collectPos;
            collectRoot.gameObject.SetActive(true);

            mShapeCollect.transform.SetParent(collectShapeAnchor, true);

            M8.SoundPlaylist.instance.Play(sfxCollect, false);

            //play collect
            if (animator && !string.IsNullOrEmpty(takeCollect))
            {
                yield return(animator.PlayWait(takeCollect));
            }

            //hide collect
            collectRoot.gameObject.SetActive(false);

            mShapeCollect.transform.SetParent(null, false);
            mShapeCollect.gameObject.SetActive(false);
            mShapeCollect = null;

            if (animator && !string.IsNullOrEmpty(takeExit))
            {
                yield return(animator.PlayWait(takeExit));
            }

            displayGO.SetActive(false);
        }

        mRout = null;
    }
Example #11
0
 void OnCollect(ShapeProfile shapeProfile)
 {
     mShapeCollect = shapeProfile;
 }
Example #12
0
 public abstract bool Evaluate(ShapeProfile shapeProfile);
Example #13
0
    void M8.IModalPush.Push(M8.GenericParams parms)
    {
        mShapeUseSolid       = false;
        mMeasureDisplayFlags = MeasureDisplayFlag.None;
        mShapeProfile        = null;

        mIsDragInstruct = false;

        bool showHierarchy = false;

        mShapeCategories.Clear();
        mShapeAttributes.Clear();

        //clear placements
        ClearCategoryPicks();
        ClearMeasureDisplays();
        ClearCategoryPlaced();

        ShapeCategoryData[] shapes = null;

        if (parms != null)
        {
            if (parms.ContainsKey(parmUseSolid))
            {
                mShapeUseSolid = parms.GetValue <bool>(parmUseSolid);
            }

            if (parms.ContainsKey(parmMeasureDisplayFlags))
            {
                mMeasureDisplayFlags = parms.GetValue <MeasureDisplayFlag>(parmMeasureDisplayFlags);
            }

            if (!mIsDragInstructApplied)  //only show drag instruction once
            {
                if (parms.ContainsKey(parmIsDragInstruct))
                {
                    mIsDragInstruct = parms.GetValue <bool>(parmIsDragInstruct);
                }
            }

            if (parms.ContainsKey(parmShapeProfile))
            {
                mShapeProfile = parms.GetValue <ShapeProfile>(parmShapeProfile);
            }

            if (parms.ContainsKey(parmShapes))
            {
                shapes = parms.GetValue <ShapeCategoryData[]>(parmShapes);
            }

            if (parms.ContainsKey(parmShowHierarchy))
            {
                showHierarchy = parms.GetValue <bool>(parmShowHierarchy);
            }
        }

        //determine which categories fit the shape profile
        if (mShapeProfile != null && shapes != null)
        {
            for (int i = 0; i < shapes.Length; i++)
            {
                if (shapes[i].Evaluate(mShapeProfile))
                {
                    mShapeCategories.Add(shapes[i]);
                }
            }
        }

        //generate categories
        if (shapes != null)
        {
            for (int i = 0; i < shapes.Length; i++)
            {
                var category = shapes[i];

                //add category to pick area
                if (mShapeCategoryWidgetCache.Count > 0)
                {
                    var widget = mShapeCategoryWidgetCache.RemoveLast();

                    widget.Setup(category);
                    widget.isDragEnabled = true;

                    widget.transform.SetParent(categoryPickContainer, false);

                    mShapeCategoryWidgetActivePicks.Add(widget);

                    //pick a target for drag instruct
                    if (mIsDragInstruct && !mDragInstructTarget)
                    {
                        if (mShapeCategories.Exists(category))
                        {
                            mDragInstructTarget = widget;
                        }
                    }
                }
            }
        }

        //fill up attributes
        for (int i = 0; i < mShapeCategories.Count; i++)
        {
            var category = mShapeCategories[i];

            for (int j = 0; j < category.attributes.Length; j++)
            {
                var attr = category.attributes[j];

                if (!mShapeAttributes.Exists(attr))
                {
                    mShapeAttributes.Add(attr);
                }
            }
        }

        //generate description
        mDescStrBuff.Clear();

        for (int i = 0; i < mShapeAttributes.Count; i++)
        {
            var attr = mShapeAttributes[i];

            mDescStrBuff.Append("ยท ");
            mDescStrBuff.Append(M8.Localize.Get(attr.textRef));

            if (i < mShapeAttributes.Count - 1)
            {
                mDescStrBuff.Append('\n');
            }
        }

        descText.text = mDescStrBuff.ToString();

        DefaultActiveDisplay();

        ApplyShape();

        categoryPickBase.gameObject.SetActive(true);
        categoryPickBase.PlayEnter();

        hierarchyGO.SetActive(showHierarchy);

        mCurMode = Mode.PickCategories;

        M8.SoundPlaylist.instance.Play(sfxEnter, false);
    }
Example #14
0
 public override bool Evaluate(ShapeProfile shapeProfile)
 {
     return(shapeProfile.sideLengths.Length == count);
 }
Example #15
0
 void Awake()
 {
     mShapeProfile = GetComponent <ShapeProfile>();
     mColl         = GetComponent <Collider2D>();
 }