示例#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
    // ********************************************************************
    // Function:	DisplayFrame()
    // Purpose:		Removes current text on frame and shows new frame
    // ********************************************************************
    private void DisplayFrame()
    {
        // Initialize stuff for new frame
        m_sectionIndex            = 0;
        m_numCharSinceLastNewline = 0;
        m_textObject.text         = "";
        m_currentDisplayString    = new StringBuilder();
        ++m_frameCount;

        // Load correct portrait
        int side = -1;
        DialoguePortraitSettings portraitSettings = m_currentFrame.portraitSettings;

        if (portraitSettings != null && portraitSettings.active)
        {
            // TODO: Small portraits
            side = (int)portraitSettings.position;
            Debug.Log("Setting portrait to: " + m_portraitPathLarge + portraitSettings.image);
            m_largePortrait[side].SetBool("Shown", true);
            m_characterAnimator[side].sprite = Resources.Load <Sprite>(m_portraitPathLarge + portraitSettings.image);
        }
        for (int i = 0; i < 2; ++i)
        {
            if (i != side)
            {
                m_largePortrait[i].SetBool("Shown", false);
            }
        }
        StartCoroutine(DisplaySection());
    }
示例#3
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);
    }
示例#4
0
    static public DialoguePortraitSettings Load(Dictionary <string, object> JSON, DialoguePortraitSettings defaults = null)
    {
        DialoguePortraitSettings newObject;

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

        // Display Info
        if (JSON.ContainsKey("active"))
        {
            newObject.active = bool.Parse(JSON["active"].ToString());
        }
        if (JSON.ContainsKey("image"))
        {
            newObject.image = JSON["image"] as string;
        }
        if (JSON.ContainsKey("displayName"))
        {
            newObject.displayName = JSON["displayName"] as string;
        }
        if (JSON.ContainsKey("position"))
        {
            newObject.position = JSON["position"] as string == "left" ? PortraitPosition.left : PortraitPosition.right;
        }
        if (JSON.ContainsKey("large"))
        {
            newObject.large = bool.Parse(JSON["large"].ToString());
        }

        // Animations
        if (JSON.ContainsKey("idleAnimation"))
        {
            newObject.idleAnimation = JSON["idleAnimation"] as string;
        }
        if (JSON.ContainsKey("talkAnimation"))
        {
            newObject.talkAnimation = JSON["talkAnimation"] as string;
        }

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