예제 #1
0
    IEnumerator CreateGfxsSlowly()
    {
        for (int i = 0; i < allBelts.Count; i++)
        {
            BeltObject belt = allBelts[i];

            belt.GetComponent <BeltGfx>().UpdateGraphics(belt.beltInputs, belt.beltOutputs);

            if (i % 10 == 0)
            {
                yield return(null);
            }
        }

        yield return(null);
    }
예제 #2
0
    public void SetupBeltSystem()
    {
        allBelts = new List <BeltObject>(FindObjectsOfType <BeltObject>());

        for (int i = 0; i < allBelts.Count; i++)
        {
            BeltObject belt = allBelts[i];
            belt.SetPosBasedOnWorlPos();
            allBeltsCoords[belt.pos] = belt;
        }

        beltPreProc = new BeltPreProcessor(beltGroups, allBeltItems, GetBeltAtLocation);

        beltPreProc.PrepassBelts(allBelts);

        beltItemSlotProc = new BeltItemSlotUpdateProcessor(itemPool, beltGroups);
    }
예제 #3
0
    List <BeltGroup> GetNearbyBeltGroups(BeltObject belt)
    {
        List <BeltGroup> nearbyBeltGroups = new List <BeltGroup>();

        for (int i = 0; i < 4; i++)
        {
            if (belt.beltInputs[i] || belt.beltOutputs[i])
            {
                BeltObject neighborBelt = GetBeltAtLocation(belt.pos + IndexToXY(i));
                if (BeltObject.CanConnectBelts(belt, neighborBelt))
                {
                    nearbyBeltGroups.Add(allBeltGroups[neighborBelt.beltGroup]);
                }
            }
        }

        return(nearbyBeltGroups);
    }
예제 #4
0
    public void ProcessOneBeltChange(BeltObject belt)
    {
        belt.RemoveOldItemSlots(allBeltGroups[belt.beltGroup].beltItemSlotGroups);
        belt.CreateBeltItemSlots();
        List <BeltItemSlot> targetBeltSlots = belt.allBeltItemSlots;

        List <BeltGroup> myNearbyBeltGroups = GetNearbyBeltGroups(belt);


        BeltGroup targetBeltGroup;

        // If there is no nearby belt group, create a new one with this in it
        if (myNearbyBeltGroups.Count == 0)
        {
            targetBeltGroup       = new BeltGroup();
            targetBeltGroup.belts = new List <BeltObject>();
            allBeltGroups.Add(targetBeltGroup);
        }
        else
        {
            targetBeltGroup = myNearbyBeltGroups[0];
            targetBeltGroup.belts.Add(belt);
            foreach (BeltGroup group in myNearbyBeltGroups)
            {
                foreach (List <BeltItemSlot> belItemSlotList in group.beltItemSlotGroups)
                {
                    targetBeltSlots.AddRange(belItemSlotList);
                }
            }

            for (int i = 1; i < myNearbyBeltGroups.Count; i++)
            {
                allBeltGroups.Remove(myNearbyBeltGroups[i]);
            }
        }



        targetBeltGroup.belts.Add(belt);
        targetBeltGroup.beltItemSlotGroups.Add(targetBeltSlots);

        ProcessBeltGroupItemSlots(targetBeltGroup, targetBeltSlots);
    }
예제 #5
0
    public static void ConnectBelts(BeltObject from, BeltObject to, int connectionSide)
    {
        if (from == null || to == null)
        {
            return;
        }

        switch (connectionSide)
        {
        case 0:
            for (int x = 1; x < 3; x++)
            {
                BeltItemSlot.ConnectBeltItemSlots(from.myBeltItemSlots[x, 0], to.myBeltItemSlots[x, 3]);
                BeltItemSlot.ConnectBeltItemSlots(from.myBeltItemSlots[x, 0], to.myBeltItemSlots[x, 3]);
            }
            break;

        case 1:
            for (int y = 1; y < 3; y++)
            {
                BeltItemSlot.ConnectBeltItemSlots(from.myBeltItemSlots[3, y], to.myBeltItemSlots[0, y]);
                BeltItemSlot.ConnectBeltItemSlots(from.myBeltItemSlots[3, y], to.myBeltItemSlots[0, y]);
            }
            break;

        case 2:
            for (int x = 1; x < 3; x++)
            {
                BeltItemSlot.ConnectBeltItemSlots(from.myBeltItemSlots[x, 3], to.myBeltItemSlots[x, 0]);
                BeltItemSlot.ConnectBeltItemSlots(from.myBeltItemSlots[x, 3], to.myBeltItemSlots[x, 0]);
            }
            break;

        case 3:
            for (int y = 1; y < 3; y++)
            {
                BeltItemSlot.ConnectBeltItemSlots(from.myBeltItemSlots[0, y], to.myBeltItemSlots[3, y]);
                BeltItemSlot.ConnectBeltItemSlots(from.myBeltItemSlots[0, y], to.myBeltItemSlots[3, y]);
            }
            break;
        }
    }
예제 #6
0
    public static bool CanConnectBelts(BeltObject from, BeltObject to)
    {
        if (from == null || to == null)
        {
            return(false);
        }

        int xDiff = from.pos.x - to.pos.x;
        int yDiff = from.pos.y - to.pos.y;

        if (xDiff == 1 && yDiff == 0)
        {
            if ((from.beltOutputs[3] && to.beltInputs[1]) || (from.beltInputs[3] && to.beltOutputs[1]))
            {
                return(true);
            }
        }
        else if (xDiff == -1 && yDiff == 0)
        {
            if ((from.beltOutputs[1] && to.beltInputs[3]) || (from.beltInputs[1] && to.beltOutputs[3]))
            {
                return(true);
            }
        }
        else if (xDiff == 0 && yDiff == 1)
        {
            if ((from.beltOutputs[2] && to.beltInputs[0]) || (from.beltInputs[2] && to.beltOutputs[0]))
            {
                return(true);
            }
        }
        else if (xDiff == 0 && yDiff == -1)
        {
            if ((from.beltOutputs[0] && to.beltInputs[2]) || (from.beltInputs[0] && to.beltOutputs[2]))
            {
                return(true);
            }
        }
        return(false);
    }
예제 #7
0
        public void BeltCanConnectBeltsTest()
        {
            //Arrange
            GameObject belt1_obj = new GameObject();
            BeltObject belt1     = belt1_obj.AddComponent <BeltObject>();

            belt1.beltOutputs[1] = true;
            GameObject belt2_obj = new GameObject();
            BeltObject belt2     = belt2_obj.AddComponent <BeltObject>();

            belt2.pos.x         = 1;
            belt2.beltInputs[3] = true;
            GameObject belt3_obj = new GameObject();
            BeltObject belt3     = belt3_obj.AddComponent <BeltObject>();

            belt3.pos.x         = 2;
            belt3.beltInputs[3] = true;

            //Assert
            Assert.IsTrue(BeltObject.CanConnectBelts(belt1, belt2));
            Assert.IsFalse(BeltObject.CanConnectBelts(belt1, belt3));
        }
예제 #8
0
    void RecursiveGroupBelts(BeltObject currentBelt, List <BeltObject> processedBelts)
    {
        if (currentBelt.isProcessed)
        {
            return;
        }

        currentBelt.isProcessed = true;
        processedBelts.Add(currentBelt);


        for (int i = 0; i < 4; i++)
        {
            if (currentBelt.beltOutputs[i])
            {
                // Get the next belt that out output is pointing at
                BeltObject nextBelt = GetBeltAtLocation(currentBelt.pos + IndexToXY(i));
                if (nextBelt != null)
                {
                    // Check if they are getting input from our output, a requirement for us to be connected
                    if (nextBelt.beltInputs[(i + 2) % 4])
                    {
                        // Continue recursion with that next belt
                        BeltObject.ConnectBelts(currentBelt, nextBelt, i);
                        RecursiveGroupBelts(nextBelt, processedBelts);
                    }
                    else
                    {
                        currentBelt.isEndPoint = true;
                    }
                }
                else
                {
                    currentBelt.isEndPoint = true;
                }
            }
            if (currentBelt.beltInputs[i])
            {
                // Get the next belt that out output is pointing at
                BeltObject nextBelt = GetBeltAtLocation(currentBelt.pos + IndexToXY(i));
                if (nextBelt != null)
                {
                    // Check if they are getting input from our output, a requirement for us to be connected
                    if (nextBelt.beltOutputs[(i + 2) % 4])
                    {
                        // Continue recursion with that next belt
                        BeltObject.ConnectBelts(nextBelt, currentBelt, i + 2 % 4);
                        RecursiveGroupBelts(nextBelt, processedBelts);
                    }
                    else
                    {
                        currentBelt.isEndPoint = true;
                    }
                }
                else
                {
                    currentBelt.isEndPoint = true;
                }
            }
        }
    }
예제 #9
0
 public void ChangeOneBelt(BeltObject updatedBelt)
 {
     beltPreProc.ProcessOneBeltChange(updatedBelt);
 }
예제 #10
0
 public void AddOneBelt(BeltObject newBelt)
 {
     allBelts.Add(newBelt);
     ChangeOneBelt(newBelt);
 }