예제 #1
0
    public static void UnitTest()
    {
        TSVLookup tsv = new TSVLookup("UnitTests/TSVLookup");

        Debug.Log(String.Join("\n*", tsv.Lookup("VictoriaStreet", "Examine").ToArray()));
        Debug.Log(String.Join("\n*", tsv.Lookup("VictoriaStreet", "Examine", "Baton").ToArray()));
        Debug.Log(String.Join("\n*", tsv.Lookup("VictoriaStreet", "Examine", "Scissors").ToArray()));
        Debug.Log(String.Join("\n*", tsv.Lookup("VictoriaStreet", "Talk", "Daligmata", "!A").ToArray()));
        try
        {
            Debug.Log(String.Join("\n*", tsv.Lookup("VictoriaStreet", "Talk", "Daligmata", "!A", "something").ToArray()));  // exception
        }
        catch (Exception e)
        {
            Debug.Log(e.ToString());
        }
        Debug.Log(String.Join("\n*", tsv.Lookup("VictoriaStreet", "Talker", "Daligmata", "!A").ToArray()));         // returns empty list
        Debug.Log(String.Join("\n*", tsv.Lookup("VictoriaStreet", "Talk", "Daligmata", "anotherthing").ToArray())); // returns empty list
    }
예제 #2
0
    private void Start()
    {
        gameState = GameObject.Find("GameState").GetComponent <GameStateBehaviour>();
        TSVLookup tsv = null;

        try
        {
            tsv = new TSVLookup("Cards/" + cardName);
        }
        catch (NullReferenceException)
        {
            if (previousCardName != null)
            {
                transform.GetChild(0).GetChild(0).gameObject.name = previousCardName;
            }
        }

        if (previousCardName == null)
        {
            startTime = 0;
        }

        Sprite background = Resources.Load <Sprite>("Cards/" + cardName);
        Sprite buttons    = Resources.Load <Sprite>("Cards/" + cardName + "-buttons");

        if (buttons == null)
        {
            buttons = background;
        }
        transform.GetChild(0).GetComponent <UnityEngine.UI.Image>().overrideSprite = background;
        transform.GetChild(0).GetChild(0).GetChild(0).GetComponent <UnityEngine.UI.Image>().overrideSprite = buttons;

        if (tsv != null)
        {
            int count = 0;
            foreach (string card in tsv.Lookup())
            {
                foreach (string condition in tsv.Lookup(card))
                {
                    string flags     = condition;
                    string newStatus = null;
                    if (condition.IndexOf('#') != -1)
                    {
                        flags     = condition.Substring(0, condition.IndexOf('#'));
                        newStatus = condition.Substring(condition.IndexOf('#') + 1);
                    }
                    if (gameState.EvaluateFlags(flags))
                    {
                        if (newStatus != null && status != newStatus)
                        {
                            status    = newStatus;
                            startTime = 0;
                        }

                        if (count > 0)
                        {
                            Instantiate(transform.GetChild(0).GetChild(0), transform.GetChild(0));
                        }

                        Transform t = transform.GetChild(0).GetChild(count);
                        t.gameObject.name = card;
                        int[] coords
                            = Array.ConvertAll <string, int>(tsv.Lookup(card, condition)[0].Split(','), int.Parse);
                        t.GetComponent <RectTransform>().anchoredPosition
                            = new Vector2(coords[0], 512 - coords[1] - coords[3]);
                        t.GetComponent <RectTransform>().sizeDelta
                            = new Vector2(coords[2], coords[3]);
                        t.GetChild(0).GetComponent <RectTransform>().anchoredPosition
                            = new Vector2(-coords[0], -(512 - coords[1] - coords[3]));
                        if (coords.Length > 4 && (coords[4] & 1) == 0)
                        {
                            t.GetChild(0).GetComponent <UnityEngine.UI.Image>().overrideSprite = background;
                        }
                        else
                        {
                            t.GetChild(0).GetComponent <UnityEngine.UI.Image>().overrideSprite = buttons;
                        }
                        if (coords.Length > 4 && (coords[4] & 2) != 0)
                        {
                            t.GetChild(0).gameObject.name = "Glow";
                        }
                        count++;
                        break;
                    }
                }
            }
        }
    }
예제 #3
0
    public void ButtonPress()
    {
        GameObject obj = EventSystem.current.currentSelectedGameObject;

        if (obj == null)
        {
            return;
        }
        string nextCard = obj.name;

        buttonCanvas.HideOverlay();
        try
        {
            TSVLookup tsv = new TSVLookup("Cards/" + cardName);
            foreach (string condition in tsv.Lookup(nextCard))
            {
                string flags = condition;
                if (condition.IndexOf('#') != -1)
                {
                    flags = condition.Substring(0, condition.IndexOf('#'));
                }

                if (gameState.EvaluateFlags(flags))
                {
                    string coords  = tsv.Lookup(nextCard, condition)[0];
                    string message = tsv.Lookup(nextCard, condition, coords)[0];

                    if (nextCard.Contains("%"))
                    {
                        // this card loads a level
                        gameState.SetFlag("Global%LeaveMapOption", int.Parse(message));
                        if (!gameState.GetFlag(nextCard + "%End"))
                        {
                            gameState.EncodeAnalyticsLeaveMap(int.Parse(message));
                        }
                        gameState.LoadARScene(nextCard);
                    }
                    else
                    {
                        // this card displays a dialogue and (potentially) resets to a module
                        message = message.Replace("\\n", "\n");
                        while (message.IndexOf('{') != -1)
                        {
                            int i = message.IndexOf('{');
                            int j = i + 1;
                            while (j < message.Length && message[j] != '}')
                            {
                                j++;
                            }
                            string variableName = message.Substring(i + 1, j - i - 1);
                            string variableValue;
                            if (variableName == "SERIAL")
                            {
                                variableValue = DeviceInput.HumanReadableEncoding(DeviceInput.deviceSerial);
                            }
                            else
                            {
                                variableValue = "" + gameState.GetFlagIntValue(variableName);
                            }
                            if (j != message.Length)
                            {
                                j++;
                            }
                            message = message.Substring(0, i) + variableValue + message.Substring(j);
                        }
                        buttonCanvas.ShowQuestionOverlay(
                            message,
                            nextCard[0] >= '0' && nextCard[0] <= '9' ? "Proceed" : "OK",
                            nextCard[0] >= '0' && nextCard[0] <= '9' ? "Don't Proceed" : null,
                            delegate(string pressedButton)
                        {
                            buttonCanvas.HideOverlay();
                            if (pressedButton == "Proceed")
                            {
                                gameState.AppendToAnalyticsString("_" + nextCard[0]);
                                gameState.ResetFlags(gameState.GetFlagsStartingWith("M"));
                                gameState.SetFlag("Global%Module", int.Parse(nextCard));
                                gameState.SetFlag("Global%ReplayModule", int.Parse(nextCard));
                                gameState.SetFlag("Global%GameEnd", true);
                            }
                            else
                            {
                                buttonCanvas.ShowCardOverlay(cardName, previousCardName);
                            }
                        }
                            );
                    }
                    return;
                }
            }
        }
        catch (NullReferenceException)
        {
        }
        catch (UnityException)
        {
        }

        if (nextCard == "Options")
        {
            buttonCanvas.ShowOptionsOverlay(delegate()
            {
                startTime = 0;
                buttonCanvas.ShowCardOverlay(cardName, previousCardName);
            });
        }
        else if (nextCard == "Exit")
        {
            buttonCanvas.ShowQuestionOverlay("Are you sure you want to exit?",
                                             "Exit game",
                                             "Continue playing",
                                             delegate(string pressedButton)
            {
                buttonCanvas.HideOverlay();
                if (pressedButton == "Exit game")
                {
                    DeviceInput.ExitGame(buttonCanvas);
                }
                else
                {
                    startTime = 0;
                    buttonCanvas.ShowCardOverlay(cardName, previousCardName);
                }
            });
        }
        else if (nextCard != "Close")
        {
            buttonCanvas.ShowCardOverlay(nextCard, cardName);
        }
    }