Example #1
0
    private void LoadFile(string loadedFileName)
    {
        Debug.Log("THIS FIRES WHEN!?");
        //This is fired when we change the current File from a dropdown
        //So we need to run the dirt test here too
        if (RunDirtTest())
        {
            return;
        }

        //If we have a graph loaded, deconstruct it
        if (graph != null)
        {
            DeconstructGraph();
        }

        Debug.Log("Attempting to Load File " + loadedFileName);
        currentFile = Resources.Load <SpeakEasyFile>(conversationFolder + "/" + loadedFileName);
        if (currentFile == null)
        {
            EditorUtility.DisplayDialog("ERROR!", "Unable to find the file at " + pathToResources + conversationFolder, "Ok.");
        }

        else
        {
            fileNameLabel.SetValueWithoutNotify(loadedFileName);
            loadButton.SetEnabled(true);
        }
    }
Example #2
0
    public void DeactivateScreen()
    {
        ClearScreen();

        uiInstance.SetActive(false);
        GameplayManager.gm.popupNumber--;
        GameplayManager.gm.ToggleFocus(false);

        currentFile = null;
        locale      = null;
    }
    public void LoadData(SpeakEasyFile file)
    {
        //Now we transfer the saved data onto the graph

        //Debug.Log("Found " + file.connectionData.Count + " edges in the Saved File");
        Debug.Log("Found " + file.nodeData.Count + " nodes in the Saved File");
        Debug.Log("Loading Nodes");
        //Create a temporary list

        //Assign the localization data
        localText = Locale.Load(file.localePath);

        foreach (SpeakEasyFile_NodeData n in file.nodeData)
        {
            LoadNode(n); //We load the node Data and initalize the nodes back into place.
        }
        Debug.Log("Loading Connections");
        List <SpeakEasyNode> nodeList = nodes.ToList().Cast <SpeakEasyNode>().ToList(); //At this stage we should have the nodes in place

        //Now we need to retrieve a reference of the string list for the connections.

        foreach (SpeakEasyFile_NodeData n in file.nodeData)
        {
            string originID = n.nodeID; //Grab the origin node's ID
            foreach (string e in n.connectionData)
            {
                //iterate through the list of connections
                string targetID = e;
                //Now we need to grab the nodes
                foreach (SpeakEasyNode nS in nodeList)
                {
                    if (originID == nS.nodeID)
                    {
                        foreach (SpeakEasyNode nE in nodeList)
                        {
                            if (targetID == nE.nodeID)
                            {
                                Edge tempEdge = nS.outputConnection.ConnectTo(nE.inputConnection);
                                Add(tempEdge);
                                Debug.Log("Successfully added an edge");
                            }
                        }
                    }
                }
            }
        }
    }
Example #4
0
    public void ActivateScreen(SpeakEasyFile file)
    {
        GameplayManager.gm.ToggleFocus(true);
        GameplayManager.gm.popupNumber++;
        uiInstance.SetActive(true);

        currentFile = file;
        if (currentFile == null)
        {
            DeactivateScreen();
            Debug.Log("One of the required references is not made.");
            return;
        }

        locale = Locale.Load(file.localePath);
        if (locale == null)
        {
            Debug.Log("Unable to find the localization for this conversation.");
        }

        EnterConversation();
    }
    public bool GraphIsDirty(SpeakEasyFile file)
    {
        bool isDirty = false;

        //Compare data, returning a "isDirty" state.
        //We need a copy of the Nodes and Edges

        Debug.Log("Checking lenghts...");


        List <SpeakEasyNode> nodeList = nodes.ToList().Cast <SpeakEasyNode>().ToList();

        foreach (SpeakEasyNode n in nodeList)
        {
            Debug.Log(n.nodeID);
        }

        Debug.Log(nodeList.Count);
        Debug.Log(file.nodeData.Count);

        if (file.nodeData.Count == nodeList.Count)
        {
            //The length of the file's nodeData and nodeList in the graph are the same, keep going.
            //Now we need to compare individual node's data

            Debug.Log("Saved Data and NodeList appear to be of the same length");

            List <SpeakEasyFile_NodeData> data = file.nodeData;
            for (int i = 0; i < nodeList.Count; i++)
            {
                //Iterate through the graph's nodeList.
                if (nodeList[i].nodeType == data[i].nodeType &&
                    nodeList[i].nodeID == data[i].nodeID &&
                    nodeList[i].stringReference == data[i].stringReference &&
                    nodeList[i].isEntryPoint == data[i].isEntryPoint &&
                    nodeList[i].priority == data[i].nodePriority &&
                    nodeList[i].scriptTest == data[i].scriptTestRef &&
                    nodeList[i].scriptEvent == data[i].scriptEventRef &&
                    nodeList[i].GetPosition().position == data[i].nodePosition
                    )
                {
                    //Now we need to iterate through this node's outputs
                    Debug.Log("The Data in this node appears to be match the Data in the saved file.");

                    List <string> connectedNodes = new List <string>();
                    foreach (Edge e in nodeList[i].outputConnection.connections)
                    {
                        //Retrieve the guid of each node.
                        SpeakEasyNode input = (e.input.node as SpeakEasyNode);
                        connectedNodes.Add(input.nodeID);
                    }

                    //And run compare it to the saved data
                    if (connectedNodes.Count == file.nodeData[i].connectionData.Count)
                    {
                        Debug.Log("The connection data in this node has the same amount of connections as the saved file for this node.");

                        for (int j = 0; j < connectedNodes.Count; j++)
                        {
                            if (connectedNodes[j] == file.nodeData[i].connectionData[j])
                            {
                                Debug.Log("The connection data in this node matches the connection data in the saved file.");
                                Debug.Log("This file appears to be clean.");
                            }

                            else
                            {
                                isDirty = true;
                            }
                        }
                    }

                    else
                    {
                        isDirty = true;
                    }
                }

                else
                {
                    isDirty = true;  //If any of the above isn't matching, then we made a change to the nodeList.
                }
            }
        }

        else
        {
            isDirty = true;
        }

        return(isDirty);
    }
    public void SaveData(SpeakEasyFile file)
    {
        if (file != null)
        {
            List <Edge>          edgeList = edges.ToList();
            List <SpeakEasyNode> nodeList = nodes.ToList().Cast <SpeakEasyNode>().ToList();

            Debug.Log("Found " + edgeList.Count + " edges in the Graph");
            Debug.Log("Found " + nodeList.Count + " nodes in the Graph");

            //Clear the list in the file
            file.nodeData.Clear();

            EditorUtility.SetDirty(file);

            foreach (SpeakEasyNode n in nodeList)
            {
                //We need to grab our connections first.
                List <string> savedConnectionData = new List <string>();
                foreach (Edge e in n.outputConnection.connections)
                {
                    //Retrieve the guid of each node.
                    SpeakEasyNode input = (e.input.node as SpeakEasyNode);
                    savedConnectionData.Add(input.nodeID);
                    Debug.Log("Saved connection starting at " + n.nodeID + " node and ending with " + input.nodeID + " node.");
                }


                file.nodeData.Add(new SpeakEasyFile_NodeData
                {
                    nodeType        = n.nodeType,
                    nodeID          = n.nodeID,
                    stringReference = n.stringReference,
                    isEntryPoint    = n.isEntryPoint,
                    nodePriority    = n.priority,
                    scriptTestRef   = n.scriptTest,
                    scriptEventRef  = n.scriptEvent,
                    nodePosition    = n.GetPosition().position,
                    connectionData  = savedConnectionData
                });
                Debug.Log("Saved node " + n.nodeID);
            }

            //We need to re-save the list
            localText.Save(file.localePath);

            /*
             * foreach(Edge e in edgeList)
             * {
             *  SpeakEasyNode input = (e.input.node as SpeakEasyNode);
             *  SpeakEasyNode output = (e.output.node as SpeakEasyNode);
             *  string startingPoint = output.nodeID;
             *  string endingPoint = input.nodeID;
             *  file.connectionData.Add(new SpeakEasyFile_ConnectionData
             *  {
             *      originNodeID = startingPoint,
             *      targetNodeID = endingPoint
             *  });
             *
             *  Debug.Log("Saved connection starting at " + startingPoint + " node and ending with " + endingPoint + " node.");
             * }
             */
        }
    }