示例#1
0
    public Sprite largePortrait; // TODO: Animation?

    public static DialogueNPCSettings Load(Dictionary <string, object> JSON, DialogueNPCSettings defaults = null)
    {
        DialogueNPCSettings newObject;

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

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

        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);
        }

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

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

        if (JSON.ContainsKey("portraitSettings"))
        {
            newObject.portraitSettings = DialoguePortraitSettings.Load(JSON["portraitSettings"] as Dictionary <string, object>, defaults.portraitSettings);
        }
        if (JSON.ContainsKey("textSettings"))
        {
            newObject.textSettings = DialogueTextSettings.Load(JSON["textSettings"] as Dictionary <string, object>, defaults.textSettings);
        }

        if (JSON.ContainsKey("triggerAnimation"))
        {
            newObject.triggerAnimation = JSON["triggerAnimation"] as string;
        }
        if (JSON.ContainsKey("triggerEffect"))
        {
            newObject.triggerEffect = JSON["triggerEffect"] as string;
        }
        if (JSON.ContainsKey("forceIdle"))
        {
            newObject.forceIdle = bool.Parse(JSON["forceIdle"] as string);
        }

        if (JSON.ContainsKey("text"))
        {
            newObject.text = new StringBuilder(JSON["text"] as string);
        }

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

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

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

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

        // Links
        if (JSON.ContainsKey("endOnThisFrame"))
        {
            newObject.endOnThisFrame = bool.Parse(JSON["endOnThisFrame"].ToString());
        }
        if (JSON.ContainsKey("displayChoices"))
        {
            newObject.displayChoices = bool.Parse(JSON["displayChoices"].ToString());
        }
        if (JSON.ContainsKey("links"))
        {
            newObject.links = new List <DialogueLink>();
            List <object> lList = JSON["links"] as List <object>;
            foreach (object lEntry in lList)
            {
                DialogueLink newLink = DialogueLink.Load(lEntry as Dictionary <string, object>);
                newObject.links.Add(newLink);
            }
        }

        // Load NPC Settings
        if (JSON.ContainsKey("npcSettings"))
        {
            DialogueNPCSettings npcSettings = DialogueManager.FetchNPCSettings(JSON["npcSettings"] as string);

            if (npcSettings != null)
            {
                Debug.Log("NPC Settings fetched for: " + JSON["npcSettings"] + " - " + npcSettings);
                if (npcSettings.portraitSettings != null)
                {
                    newObject.portraitSettings = npcSettings.portraitSettings.ShallowCopy();
                }
                if (npcSettings.textSettings != null)
                {
                    newObject.textSettings = npcSettings.textSettings.ShallowCopy();
                }
            }
            else
            {
                Debug.LogError("NPC Settings NOT FOUND for: " + JSON["npcSettings"]);
            }
        }

        // Overrides
        if (JSON.ContainsKey("allowSkip"))
        {
            newObject.allowSkip = bool.Parse(JSON["allowSkip"] as string);
        }
        if (JSON.ContainsKey("waitForInput"))
        {
            newObject.waitForInput = bool.Parse(JSON["waitForInput"] as string);
        }
        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);
        }

        // Sections
        if (JSON.ContainsKey("sections"))
        {
            newObject.sections = new List <DialogueSection>();
            DialogueSection defaultSection = new DialogueSection();
            defaultSection.portraitSettings = newObject.portraitSettings;
            defaultSection.textSettings     = newObject.textSettings;
            List <object> sList = JSON["sections"] as List <object>;
            foreach (object sEntry in sList)
            {
                DialogueSection newSection = DialogueSection.Load(sEntry as Dictionary <string, object>, defaultSection);
                newObject.sections.Add(newSection);
            }
            Debug.Log("Frame " + newObject.id + " loaded " + newObject.sections.Count + " sections");
        }

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

        return(newObject);
    }
示例#4
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);
    }