Beispiel #1
0
        private void ParseNodeGraph(string moduleName, string folderPath)
        {
            List <string> nodeFiles = new List <string>();

            SearchForFileType(folderPath, "*.json", nodeFiles);
            Dictionary <string, GameMasterNode> addedNodes = new Dictionary <string, GameMasterNode>();

            foreach (string filepath in nodeFiles)
            {
                GameMasterNode file = new GameMasterNode(moduleName, filepath);
                addedNodes.Add(file.Path, file);
            }

            foreach (GameMasterNode node in addedNodes.Values)
            {
                node.Load(addedNodes);
            }

            CampaignNodeData currentCampaignData = null;

            foreach (GameMasterNode node in addedNodes.Values)
            {
                if (node.NodeType == GameMasterNodeType.CAMPAIGN)
                {
                    currentCampaignData = node.NodeData as CampaignNodeData;
                    mCampaignNodes.Add(node);
                }
                else if (node.Owner == null)
                {
                    currentCampaignData.OrphanedNodes.Add(node);
                }
            }

            mGameMasterNodes = mGameMasterNodes.Concat(addedNodes).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
        }
        public bool CloneNode(IGraphOwner graphOwner, GameMasterNode original, string cloneName)
        {
            GameMasterNode newNode = original.Clone(cloneName);

            mGameMasterNodes.Add(newNode.Path, newNode);

            if (newNode.Owner == null)
            {
                CampaignNodeData campaignNodeData = mCurrentGraphRoot.NodeData as CampaignNodeData;
                campaignNodeData.OrphanedNodes.Add(newNode);
                newNode.Owner = mCurrentGraphRoot;
            }

            RefreshGraph(graphOwner);
            return(false);
        }
        public bool AddNewGenericScriptNode(IGraphOwner owner, string scriptNodeName, string filePath)
        {
            if (mCurrentGraphRoot == null)
            {
                return(false);
            }

            EncounterScriptFile scriptFile = mGenericScriptNodes[scriptNodeName];

            scriptFile.WriteDefaultToFile(filePath);
            GameMasterNode newNode = new GameMasterNode(mCurrentGraphRoot.Module, filePath);

            mGameMasterNodes.Add(newNode.Path, newNode);
            newNode.Load(mGameMasterNodes);

            string           nodeName         = Path.GetFileNameWithoutExtension(filePath);
            CampaignNodeData campaignNodeData = mCurrentGraphRoot.NodeData as CampaignNodeData;
            string           arcsDir          = Path.GetFullPath(Path.Combine(campaignNodeData.NodeFile.Path, "..", "arcs")).ToUpperInvariant();
            string           filePathUpper    = Path.GetFullPath(filePath).ToUpperInvariant();

            bool foundMatchingArc = false;

            foreach (var arcNode in campaignNodeData.GetAllArcs())
            {
                string arcDir = Path.GetFullPath(Path.Combine(arcNode.Path, "..")).ToUpperInvariant();
                if (filePathUpper.StartsWith(arcDir))
                {
                    // Add new node to arc's index file (ex. game_events_arc) using nodeName as the key
                    (arcNode.NodeData as ArcNodeData).AddEncounter(newNode.NodeData as EncounterNodeData);
                    newNode.Owner    = arcNode;
                    foundMatchingArc = true;
                    break;
                }
            }

            if (!foundMatchingArc)
            {
                (mCurrentGraphRoot.NodeData as CampaignNodeData).OrphanedNodes.Add(newNode);
                newNode.Owner = mCurrentGraphRoot;
            }

            newNode.IsModified = true;
            newNode.SaveIfNecessary();
            RefreshGraph(owner);
            return(true);
        }