Exemple #1
0
    static public DialogueRequirement Load(Dictionary <string, object> JSON, DialogueRequirement defaults = null)
    {
        DialogueRequirement newObject;

        if (defaults == null)
        {
            newObject = new DialogueRequirement();
        }
        else
        {
            newObject = defaults.MemberwiseClone() as DialogueRequirement;
        }

        if (JSON.ContainsKey("questComplete"))
        {
            newObject.requirementType = RequirementType.QUEST_COMPLETE;
            newObject.compareID       = JSON["questComplete"] as string;
        }
        else if (JSON.ContainsKey("questNotComplete"))
        {
            newObject.requirementType = RequirementType.QUEST_NOT_COMPLETE;
            newObject.compareID       = JSON["questNotComplete"] as string;
        }
        else if (JSON.ContainsKey("conversationSeen"))
        {
            newObject.requirementType = RequirementType.CONVERSATION_SEEN;
            newObject.compareID       = JSON["conversationSeen"] as string;
        }
        else if (JSON.ContainsKey("conversationNotSeen"))
        {
            newObject.requirementType = RequirementType.CONVERSATION_NOT_SEEN;
            newObject.compareID       = JSON["conversationNotSeen"] as string;
        }
        else if (JSON.ContainsKey("choiceMade"))
        {
            newObject.requirementType = RequirementType.CHOICE_MADE;
            newObject.compareID       = JSON["choiceMade"] as string;
        }
        else if (JSON.ContainsKey("choiceNotMade"))
        {
            newObject.requirementType = RequirementType.CHOICE_NOT_MADE;
            newObject.compareID       = JSON["choiceNotMade"] as string;
        }

        return(newObject);
    }
Exemple #2
0
    static public DialogueLink Load(Dictionary <string, object> JSON, DialogueLink defaults = null)
    {
        DialogueLink newObject;

        if (defaults == null)
        {
            newObject = new DialogueLink();
        }
        else
        {
            newObject = defaults.MemberwiseClone() as DialogueLink;
        }

        if (JSON.ContainsKey("linkedFrame"))
        {
            newObject.linkedFrame = JSON["linkedFrame"] as string;
        }
        if (JSON.ContainsKey("linkedConversation"))
        {
            newObject.linkedConversation = JSON["linkedConversation"] as string;
        }
        if (JSON.ContainsKey("text"))
        {
            newObject.text = JSON["text"] as string;
        }
        if (JSON.ContainsKey("saveChoice"))
        {
            newObject.saveChoice = bool.Parse(JSON["saveChoice"].ToString());
        }
        if (JSON.ContainsKey("requirements"))
        {
            newObject.requirements = new List <DialogueRequirement>();
            List <object> rList = JSON["requirements"] as List <object>;
            foreach (object rEntry in rList)
            {
                DialogueRequirement newRequirement = DialogueRequirement.Load(rEntry as Dictionary <string, object>);
                newObject.requirements.Add(newRequirement);
            }
        }

        return(newObject);
    }
Exemple #3
0
    public static DialogueConversation Load(Dictionary <string, object> JSON, DialogueConversation defaults = null)
    {
        DialogueConversation newObject;

        if (defaults == null)
        {
            newObject = new DialogueConversation();
        }
        else
        {
            newObject = defaults.MemberwiseClone() as DialogueConversation;
        }

        if (JSON.ContainsKey("id"))
        {
            newObject.id = JSON["id"] as string;
        }
        if (JSON.ContainsKey("autoload"))
        {
            newObject.autoload = bool.Parse(JSON["autoload"].ToString());
        }

        // Defaults
        if (JSON.ContainsKey("allowSkip"))
        {
            newObject.allowSkip = bool.Parse(JSON["allowSkip"].ToString());
        }
        if (JSON.ContainsKey("waitForInput"))
        {
            newObject.waitForInput = bool.Parse(JSON["waitForInput"].ToString());
        }
        if (JSON.ContainsKey("portraitSettings"))
        {
            newObject.portraitSettings = DialoguePortraitSettings.Load(JSON["portraitSettings"] as Dictionary <string, object>, newObject.portraitSettings);
        }
        if (JSON.ContainsKey("textSettings"))
        {
            newObject.textSettings = DialogueTextSettings.Load(JSON["textSettings"] as Dictionary <string, object>, newObject.textSettings);
        }

        // Requirements
        if (JSON.ContainsKey("requirements"))
        {
            newObject.requirements = new List <DialogueRequirement>();
            List <object> rList = JSON["requirements"] as List <object>;
            foreach (object rEntry in rList)
            {
                DialogueRequirement newRequirement = DialogueRequirement.Load(rEntry as Dictionary <string, object>);
                newObject.requirements.Add(newRequirement);
            }
        }

        // Frames
        if (JSON.ContainsKey("startingFrame"))
        {
            newObject.startingFrame = JSON["startingFrame"] as string;
        }
        if (JSON.ContainsKey("frames"))
        {
            newObject.frames = new Dictionary <string, DialogueFrame>();

            DialogueFrame defaultFrame = new DialogueFrame();
            defaultFrame.portraitSettings = newObject.portraitSettings;
            defaultFrame.textSettings     = newObject.textSettings;
            defaultFrame.allowSkip        = newObject.allowSkip;
            defaultFrame.waitForInput     = newObject.waitForInput;

            DialogueFrame lastFrame           = null;
            bool          lastFrameLinkNeeded = false;

            List <object> fList = JSON["frames"] as List <object>;
            foreach (object fEntry in fList)
            {
                DialogueFrame newFrame = DialogueFrame.Load(fEntry as Dictionary <string, object>, defaultFrame);
                newObject.frames[newFrame.id] = newFrame;

                if (lastFrameLinkNeeded)
                {
                    DialogueLink link = new DialogueLink();
                    link.linkedFrame = newFrame.id;
                    lastFrame.links  = new List <DialogueLink>();
                    lastFrame.links.Add(link);
                    Debug.Log("Frame " + lastFrame.id + " linked to frame " + newFrame.id);
                }

                lastFrameLinkNeeded = (!newFrame.endOnThisFrame && (newFrame.links == null || newFrame.links.Count == 0));
                lastFrame           = newFrame;

                if (newObject.startingFrame == null || newObject.startingFrame == "")
                {
                    newObject.startingFrame = newFrame.id;
                }
            }

            if (lastFrameLinkNeeded)
            {
                lastFrame.endOnThisFrame = true;
            }
            Debug.Log("Conversation " + newObject.id + " loaded " + newObject.frames.Count + " frames");
            Debug.Log("Starting frame: " + newObject.startingFrame);
        }

        if (newObject.portraitSettings == null)
        {
            Debug.LogError("portraitSettings is null in DialogueConversation");
        }
        if (newObject.textSettings == null)
        {
            Debug.LogError("textSettings is null in DialogueConversation");
        }

        return(newObject);
    }