Exemple #1
0
    // Applies all options from the saved file to the locally created variables.
    public static void Load()
    {
        // Make sure all the strings for conversations are loaded.
        ConversationsDB.LoadConversationsFromFiles();

        if (File.Exists(WhereIsData()))
        {
            // Prepare for data IO.
            BinaryFormatter bf   = new BinaryFormatter();
            FileStream      file = File.Open(WhereIsData(), FileMode.Open);

            // Deserialize the data.
            SaveContainer data = (SaveContainer)bf.Deserialize(file);
            file.Close();

            //! Fields go here.
            ConversationTrigger.tokens = new HashSet <string>(data.tokens);

            // Read inventory-related tokens.
            InventoryController.ConvertTokensToInventory();
            BatterySystem.TokensToPower();

            Debug.Log("Loaded all options successfully.");
        }
        else
        {
            // No file exists? We should make the default one!
            Debug.Log("No save found, creating default file.");
            Save();
        }
    }
    // Enable the text box, supplying a trigger. This is generally better when possible, since it will set name / escape rule.
    public static void Enable(ConversationTrigger trigger)
    {
        // Make sure we didn't lose our ref somehow...
        if (textBox == null || textBox.isActiveAndEnabled == false)
        {
            textBox         = thisObject.GetComponentInChildren <ScrollingText>();
            textBox.enabled = true;
        }

        // Make sure the dictionary is prepped if a "bad" key is given.
        if (!ConversationsDB.convos.ContainsKey(trigger.conversationName))
        {
            ConversationsDB.LoadConversationsFromFiles();
        }
        textBox.ApplyConversation(ConversationsDB.convos[trigger.conversationName]);
        currentConversationName = trigger.conversationName;
        currentEscRule          = trigger.allowEscape;
        if (trigger.conversationName == "nowhere")
        {
            SoftDisable();
            return;
        }
        SetStarterName(trigger.nameOfStarter);
        FakeActive(thisObject, true);
        currentlyEnabled = true;
        AllowMouse();

        // Oneshot destroys the trigger and marks it with a token so it never comes back again. Ever.
        // You'll have to delete the save file to have it trigger again.
        if (trigger.oneShot)
        {
            Destroy(trigger);
            ConversationTrigger.AddToken("oneShot_" + trigger.conversationName);
        }
    }