Ejemplo n.º 1
0
    public void LoadNextNode(string node)
    {
        _currNode = node;
        _node     = NodeUtil.GetNodeData <StoryNode>(node);
        _isAnyKey = false;
        foreach (var keys in _node.nodes.Select(n => n.keys))
        {
            if (keys.Any() && !keys.Contains("*"))
            {
                continue;
            }

            _isAnyKey = true;
            break;
        }

        if (!_node.nodes.Any())
        {
            _isAnyKey = true;
        }

        _terminalManager.AppendHistory("\n> " + _input);
        _terminalManager.AppendHistory(TerminalHistory.Separator);
        _terminalManager.AppendHistory(_node.text);
    }
Ejemplo n.º 2
0
    public void LoadExistingNode(string file)
    {
        var node = NodeUtil.GetNodeData <StoryNode>(file);

        _isExistingNode = true;
        SetActiveStatuses();
        Reset();

        var nameOfNode = NodeUtil.StripFileExtension(file);

        deleteNode.interactable = !string.Equals(nameOfNode, "default") && !string.Equals(nameOfNode, "entry");

        nodeName.text         = nameOfNode;
        nodeName.interactable = false;
        text.text             = node.text;
        inputGroups.LoadExistingNode(node);
    }
Ejemplo n.º 3
0
    public void PopulateNodes()
    {
        _nodesWithLinksFrom = new Dictionary <string, HashSet <string> >();
        _nodesWithLinksTo   = new Dictionary <string, HashSet <string> >();
        if (_lines != null && _lines.Any())
        {
            Debug.Log("Deleting lines");
            foreach (var line in _lines.Values)
            {
                line.Destroy();
                Destroy(line.gameObject);
            }
        }

        if (_nodeButtons != null && _nodeButtons.Any())
        {
            Debug.Log("Deleting buttons");
            foreach (var button in _nodeButtons.Values)
            {
                Destroy(button.gameObject);
            }
        }

        if (_floatingNodeButtons != null && _floatingNodeButtons.Any())
        {
            Debug.Log("Deleting floating buttons");
            foreach (var floatingButton in _floatingNodeButtons.Values)
            {
                Destroy(floatingButton.gameObject);
            }
        }
        _nodeButtons = new Dictionary <string, Button>();
        _lines       = new Dictionary <string, LineHolder>();

        var files     = NodeUtil.GetAvailableNodes();
        var nodes     = new List <Tuple <string, StoryNode> >();
        var nodeNames = new HashSet <string>();

        foreach (var file in files)
        {
            var nName = NodeUtil.StripFileExtension(file);
            nodes.Add(new Tuple <string, StoryNode>(nName, NodeUtil.GetNodeData <StoryNode>(file)));
            if (!nodeNames.Contains(nName))
            {
                nodeNames.Add(nName);
            }
        }

        // Gets the dictionary of nodes with the nodes that link to it
        foreach (var(key, node) in nodes)
        {
            foreach (var nodeLink in node.nodes)
            {
                var link = NodeUtil.StripFileExtension(nodeLink.link);
                if (!nodeNames.Contains(link))
                {
                    continue;
                }

                if (!_nodesWithLinksFrom.ContainsKey(link))
                {
                    _nodesWithLinksFrom.Add(link, new HashSet <string>());
                }

                if (!_nodesWithLinksFrom[link].Contains(key))
                {
                    _nodesWithLinksFrom[link].Add(key);
                }
            }
        }

        // Gets the dictionary of nodes with the nodes that it links to
        foreach (var(key, node) in nodes)
        {
            if (!_nodesWithLinksTo.ContainsKey(key))
            {
                _nodesWithLinksTo.Add(key, new HashSet <string>());
            }

            var linksToDelete = new List <string>();
            foreach (var nodeLink in node.nodes)
            {
                var link = NodeUtil.StripFileExtension(nodeLink.link);
                if (!_nodesWithLinksFrom.ContainsKey(link))
                {
                    linksToDelete.Add(link);
                    continue;
                }

                if (!_nodesWithLinksTo[key].Contains(link))
                {
                    _nodesWithLinksTo[key].Add(link);
                }
            }

            // if there are any non-existing links, then update the node data
            if (linksToDelete.Any())
            {
                var correctedNode = new Node
                {
                    text  = node.text,
                    nodes = node.nodes.Where(n => !linksToDelete.Contains(NodeUtil.StripFileExtension(n.link))).ToArray()
                };

                NodeUtil.WriteNodeData(key, correctedNode);
            }
        }

        _connectedNodes      = new HashSet <string>();
        _floatingNodeButtons = new Dictionary <string, Button>();

        // if there is no entry node then make one
        if (!_nodesWithLinksTo.ContainsKey("entry"))
        {
            _nodesWithLinksTo.Add("entry", new HashSet <string>());
            NodeUtil.WriteNodeData("entry", new Node());
        }

        // This part creates all of the buttons for the tree starting from 'entry'
        AddNode("entry");

        // Construct the floating nodes list
        BuildFloatingNodesList(nodes);

        // This parts sets up the lines between nodes and the indicators for them
        BuildGraphButtonLinks();
    }
Ejemplo n.º 4
0
 void Start()
 {
     _node            = NodeUtil.GetNodeData <StoryNode>("entry.json");
     _terminalManager = FindObjectOfType <TerminalManager>();
     _currNode        = "entry.json";
 }