Example #1
0
    private void UIRobotCommand_OnReleaseRobotCommand(ShiftCommand command, ShiftCommand insertBefore)
    {
        if (!robotAlive || reachedGoal)
        {
            return;
        }

        if (!heldCard.SameAs(command))
        {
            Debug.LogWarning(string.Format("Trying to insert card {0} that doesn't match what is held {1}.", command, heldCard));
            return;
        }
        bool         inserted  = false;
        ShiftCommand insertion = ShiftCommand.NothingHeld;
        int          position  = 0;

        for (int i = 0, l = instructionsFeed.Count; i < l; i++)
        {
            if (inserted)
            {
                instructionsFeed[i] = ShiftCommand.JumpRight(instructionsFeed[i]);
            }
            else
            {
                if (instructionsFeed[i].SameAs(insertBefore))
                {
                    insertion = ShiftCommand.Insert(instructionsFeed[i], command.command);
                    inserted  = true;
                    position  = i;
                }
            }
        }
        if (inserted)
        {
            instructionsFeed.Insert(position, insertion);
        }
        else
        {
            instructionsFeed.Add(ShiftCommand.MoveLeftFrom(command.command, instructionsFeed.Count));
        }

        heldCard = ShiftCommand.NothingHeld;
        OnSyncCommands?.Invoke(instructionsFeed, heldCard);
    }
Example #2
0
 private void UIRobotCommand_OnGrabRobotCommand(ShiftCommand command, ShiftCommand insertBefore)
 {
     if (reachedGoal || !robotAlive || !insertBefore.Held)
     {
         return;
     }
     for (int i = 0, l = instructionsFeed.Count; i < l; i++)
     {
         ShiftCommand card = instructionsFeed[i];
         if (card.SameAs(command))
         {
             instructionsFeed.RemoveAt(i);
             if (!heldCard.Empty)
             {
                 Debug.LogWarning(string.Format("Picking up a second card {0} while holding {1}", card, heldCard));
                 trashDeck.Add(heldCard.command);
             }
             heldCard = ShiftCommand.Pickup(card);
             SendSynchFeed();
             return;
         }
     }
     Debug.LogWarning(string.Format("Tried to pickup card {0}, but couldn't find it", command));
 }
Example #3
0
    private void RemoteController_OnSyncCommands(List <ShiftCommand> commands, ShiftCommand held)
    {
        int idC = 0;
        int lC  = commands.Count;

        for (int idF = 0, lF = feed.Count; idF < lF; idF++)
        {
            var command = commands[idC];
            var card    = feed[idF];
            // Card is where it should be, nothing to do
            if (card.shiftCommand.SameAs(command))
            {
                idC++;
                continue;
            }

            // Card has moved leftward
            if (card.shiftCommand.SameButShiftedLeft(command))
            {
                card.ShiftLeft(command);
                idC++;
                continue;
            }

            // Card needs to shift rightward
            if (card.shiftCommand.SameButShiftedRight(command))
            {
                card.ShiftRight(command);
                idC++;
                continue;
            }

            // Card is picked up
            if (card.shiftCommand.SameButPickedUp(held))
            {
                if (heldCard != null)
                {
                    cardsNotInPlay.Add(heldCard);
                    heldCard.NotInPlay();
                }

                heldCard = card;
                feed.RemoveAt(idF);
                idF--;
                lF--;
                idC++;
                continue;
            }

            // Actually previously held card is now here
            if (heldCard != null && command.command == heldCard.shiftCommand.command)
            {
                heldCard.SetInPlay(command);
                feed.Insert(idF, heldCard);
                heldCard = null;
                lF++;
                continue;
            }

            // Remove card because not in play
            if (idF > 0)
            {
                Debug.LogWarning(string.Format("Lost track of UI Card {0}, this should not happen", card));
            }
            card.NotInPlay();
            cardsNotInPlay.Add(card);
            feed.RemoveAt(idF);
            idF--;
            lF--;
            continue;
        }

        if (idC != feed.Count)
        {
            Debug.LogWarning(string.Format("We have a gap in the feed, it should be {0} long, but is {1}", idC, feed.Count));
        }

        // Fillout new cards
        while (idC < lC)
        {
            ShiftCommand command = commands[(int)idC];
            if (!command.Empty)
            {
                var card = GetInactiveOrSpawn();
                card.SetInPlay(command, cardSprites[(int)command.command]);
                feed.Add(card);
            }
            idC++;
        }

        //Deal with held card
        if (held.Empty && heldCard != null)
        {
            heldCard.NotInPlay();
            cardsNotInPlay.Add(heldCard);
            heldCard = null;
        }
        else if (!held.Empty && heldCard != null && !held.SameAs(heldCard.shiftCommand))
        {
            Debug.LogWarning(string.Format("Held card is wrong, this should not happen, expected {0}, but found {1} (updating)", held, heldCard.shiftCommand));
            heldCard.SetInPlay(held, cardSprites[(int)held.command]);
        }
    }