// Returns whether the encounter was found (and therefore removed). public bool RemoveEncounter(EncounterNodeData encounter) { GameMasterNode encounterNodeFile = encounter.NodeFile; var filePath = GetEncounterFilePath(encounter); string key = null; foreach (var pair in mEncounters) { if (pair.Value == filePath) { key = pair.Key; break; } } if (key != null) { mEncounters.Remove(key); mEncounterFiles.Remove(encounterNodeFile); (NodeFile.Json["encounters"] as JObject).Property(key).Remove(); NodeFile.IsModified = true; NodeFile.SaveIfNecessary(); return(true); } else { return(false); } }
private void UpdateSelectedNodeInfo(GameMasterNode node) { if (mSelectedNode == node) { return; } mSelectedNode = node; if (mNodePreview != null) { if (!mNodePreview.TrySetFileDataFromTextbox()) { // Don't allow switching nodes if the file is invalid. // This is terrible, but since we currently don't allow writing out invalid JSON, // switching away could cause data loss. return; } editorInfoSplitter.Panel1.Controls.Remove(mNodePreview); mNodePreview.Dispose(); mNodePreview = null; } if (node != null) { // Add a text editor. mNodePreview = new FilePreview(this, node.FileData); mNodePreview.Dock = DockStyle.Fill; editorInfoSplitter.Panel1.Controls.Add(mNodePreview); UpdateValidationSchema(); mNodePreview.OnModifiedChanged += (bool isModified) => { if (mSelectedNode?.FileData == mNodePreview.FileData) { mSelectedNode.IsModified = isModified; mSelectedNode.NodeData.UpdateGraphNode(mSelectedDNode.DrawingNode); graphViewer.Invalidate(mSelectedDNode); } }; // Add some extra labels to the text editor toolbar. var nodeNameLabel = mNodePreview.toolStrip.Items.Add(node.Name + (node.NodeType == GameMasterNodeType.ENCOUNTER ? (" (" + ((EncounterNodeData)node.NodeData).EncounterType + ")") : "")); nodeNameLabel.Margin = new Padding(24, 0, 0, 0); nodeNameLabel.Enabled = false; var nodePathLabel = mNodePreview.toolStrip.Items.Add(node.Path); nodePathLabel.Enabled = false; nodePathLabel.Alignment = ToolStripItemAlignment.Right; // Set up the details panel. PopulateFileDetails(node); editorInfoSplitter.Panel2Collapsed = fileDetailsListBox.Items.Count == 0; } else { PopulateFileDetails(null); editorInfoSplitter.Panel2Collapsed = true; } }
public void TryModifyJson(IGraphOwner graphOwner, GameMasterNode node, string newJsonString) { if (node.TryModifyJson(newJsonString)) { node.OnFileChanged(mGameMasterNodes); RefreshGraph(graphOwner); } }
protected override void UpdateOutEdges(Graph graph) { GameMasterNode arcFile = NodeFile.Owner; ArcNodeData arc = arcFile?.NodeData as ArcNodeData; if (arc != null) { foreach (string inEdgeName in mOutEdgeStrings) { List <GameMasterNode> linkedEncounters = arc.GetEncountersWithInEdge(inEdgeName); if (linkedEncounters.Count == 1 && linkedEncounters[0].Name.Equals(inEdgeName)) { if (mChoiceEdgeInfo.ContainsKey(inEdgeName)) { foreach (string choice in mChoiceEdgeInfo[inEdgeName]) { Node choiceNode = graph.AddNode(NodeFile.Id + "#" + choice); choiceNode.LabelText = '"' + choice + '"'; MakeNodePrivate(choiceNode); graph.AddEdge(NodeFile.Id, choiceNode.Id).UserData = inEdgeName; graph.AddEdge(choiceNode.Id, linkedEncounters[0].Id).UserData = inEdgeName; } } else { graph.AddEdge(NodeFile.Id, linkedEncounters[0].Id).UserData = inEdgeName; } } else { Node arcOutNode = graph.AddNode(arcFile.Id + "#" + inEdgeName); arcOutNode.LabelText = inEdgeName; MakeNodePrivate(arcOutNode); if (mChoiceEdgeInfo.ContainsKey(inEdgeName)) { foreach (string choice in mChoiceEdgeInfo[inEdgeName]) { Node choiceNode = graph.AddNode(NodeFile.Id + "#" + choice); choiceNode.LabelText = '"' + choice + '"'; MakeNodePrivate(choiceNode); graph.AddEdge(NodeFile.Id, choiceNode.Id).UserData = inEdgeName; graph.AddEdge(choiceNode.Id, arcOutNode.Id).UserData = inEdgeName; } } else { graph.AddEdge(NodeFile.Id, arcOutNode.Id).UserData = inEdgeName; } foreach (GameMasterNode linkedEncounter in linkedEncounters) { graph.AddEdge(arcOutNode.Id, linkedEncounter.Id).UserData = inEdgeName; } } } } }
private string GetEncounterFilePath(EncounterNodeData encounter) { GameMasterNode encounterNodeFile = encounter.NodeFile; string filePath = encounterNodeFile.Path; string selfPath = NodeFile.Directory + '/'; // TODO: if selfPath isn't in filePath, make path relative to mod folder. return("file(" + filePath.Replace(selfPath, "") + ")"); }
public override bool AddOutEdge(GameMasterNode nodeFile) { if (nodeFile.NodeType == GameMasterNodeType.ARC) { mArcTriggers.Add(nodeFile.Name, nodeFile); return(true); } return(false); }
public override bool AddOutEdge(GameMasterNode nodeFile) { if (nodeFile.NodeType == GameMasterNodeType.ARC) { mArcTriggers.Add(nodeFile.Name, nodeFile); return true; } return false; }
public void AddEncounter(EncounterNodeData encounter) { GameMasterNode encounterNodeFile = encounter.NodeFile; var filePath = GetEncounterFilePath(encounter); mEncounters.Add(encounterNodeFile.Name, filePath); mEncounterFiles.Add(encounterNodeFile); NodeFile.Json["encounters"][encounterNodeFile.Name] = filePath; NodeFile.IsModified = true; NodeFile.SaveIfNecessary(); }
public void SelectCampaign(IGraphOwner graphOwner, string module, string name) { foreach (GameMasterNode node in mCampaignNodes) { if (name.Equals(node.Name) && node.Module.Equals(module)) { mCurrentGraphRoot = node; RefreshGraph(graphOwner); } } }
public bool DeleteNode(string nodePath) { GameMasterNode node = GetGameMasterNode(nodePath); if (node == null) { return(false); } File.Delete(nodePath); mGameMasterNodes.Remove(nodePath); return(false); }
public void AddEncounter(EncounterNodeData encounter) { // TODO, get relative path GameMasterNode encounterNodeFile = encounter.NodeFile; string filePath = encounterNodeFile.Path; string selfPath = NodeFile.Directory + '/'; filePath = "file(" + filePath.Replace(selfPath, "") + ")"; mEncounters.Add(encounterNodeFile.Name, filePath); mEncounterFiles.Add(encounterNodeFile); NodeFile.Json["encounters"][encounterNodeFile.Name] = filePath; NodeFile.IsModified = true; NodeFile.SaveIfNecessary(); }
public override bool AddOutEdge(GameMasterNode nodeFile) { if (nodeFile.NodeType == GameMasterNodeType.ENCOUNTER) { EncounterNodeData encounterData = nodeFile.NodeData as EncounterNodeData; if (encounterData.IsStartNode && !mEncounterFiles.Contains(nodeFile)) { // can only add an edge between this and the encounter if the encounter is a start node AddEncounter(encounterData); return(true); } } return(false); }
public override bool AddOutEdge(GameMasterNode nodeFile) { if (nodeFile.NodeType == GameMasterNodeType.ENCOUNTER) { EncounterNodeData encounterData = nodeFile.NodeData as EncounterNodeData; if (encounterData.IsStartNode && !mEncounterFiles.Contains(nodeFile)) { // can only add an edge between this and the encounter if the encounter is a start node AddEncounter(encounterData); return true; } } return false; }
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); }
private void UpdateSelectedNodeInfo(GameMasterNode node) { if (node != null) { mSelectedNode = node; nodeInfoName.Text = node.Name; encounterRightSideFilePath.Text = node.Path; nodeInfoType.Text = node.NodeType.ToString(); nodePath.Text = node.Path; nodeInfoSubType.Text = node.NodeType == GameMasterNodeType.ENCOUNTER ? ((EncounterNodeData)node.NodeData).EncounterType : ""; if (mNodePreview != null) { splitContainer2.Panel1.Controls.Remove(mNodePreview); } mNodePreview = new FilePreview(this, node.FileData); mNodePreview.Dock = DockStyle.Fill; splitContainer2.Panel1.Controls.Add(mNodePreview); copyGameMasterNode.Text = "Clone " + node.Name; copyGameMasterNode.Enabled = true; openEncounterFileButton.Visible = true; deleteNodeToolStripMenuItem.Visible = true; PopulateFileDetails(node); } else { mSelectedNode = null; nodeInfoName.Text = "Select a Node"; encounterRightSideFilePath.Text = string.Empty; nodeInfoType.Text = string.Empty; nodeInfoSubType.Text = string.Empty; nodePath.Text = string.Empty; if (mNodePreview != null) { splitContainer2.Panel1.Controls.Remove(mNodePreview); } copyGameMasterNode.Text = "Clone Node"; copyGameMasterNode.Enabled = false; openEncounterFileButton.Visible = false; deleteNodeToolStripMenuItem.Visible = false; PopulateFileDetails(null); } }
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); }
private void UpdateHoveredObjects(IViewerObject hoveredObject) { // Update hovered node. var dNode = hoveredObject as DNode; if (mHoveredDNode != dNode) { if (mHoveredDNode != null) { SetBranchHighlighted(mHoveredDNode, false); mHoveredDNode = null; } if (dNode != null) { GameMasterNode nodeData = GameMasterDataManager.GetInstance().GetGameMasterNode(dNode.DrawingNode.Id); if (nodeData != null) { mHoveredDNode = dNode; SetBranchHighlighted(mHoveredDNode, true); } } } // Update hovered edge. var dEdge = hoveredObject as DEdge; if (mHoveredDEdge != dEdge) { if (mHoveredDEdge != null) { mHoveredDEdge.DrawingEdge.Attr.LineWidth -= 2; graphViewer.Invalidate(mHoveredDEdge); mHoveredDEdge = null; graphViewer.SetToolTip(mHoveredEdgeTooltip, ""); } if (dEdge != null) { dEdge.DrawingEdge.Attr.LineWidth += 2; graphViewer.Invalidate(dEdge); mHoveredDEdge = dEdge; graphViewer.SetToolTip(mHoveredEdgeTooltip, mHoveredDEdge.Edge.UserData as string); } } }
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; List <GameMasterNode> orphanedNodes = new List <GameMasterNode>(); foreach (GameMasterNode node in addedNodes.Values) { if (node.NodeType == GameMasterNodeType.CAMPAIGN) { currentCampaignData = node.NodeData as CampaignNodeData; mCampaignNodes.Add(node); } else if (node.Owner == null) { orphanedNodes.Add(node); } } if (currentCampaignData != null) { currentCampaignData.OrphanedNodes.AddRange(orphanedNodes); } else { MessageBox.Show("Could not find root campaign node in: " + folderPath); } mGameMasterNodes = mGameMasterNodes.Concat(addedNodes).ToDictionary(kvp => kvp.Key, kvp => kvp.Value); }
private void SetSelfAsOwner(Dictionary <string, string> children, Dictionary <string, GameMasterNode> toUpdate, Dictionary <string, GameMasterNode> allNodes) { int lastIndexOfSlash = NodeFile.Path.LastIndexOf('/'); string nodeFilePathWithoutFileName = NodeFile.Path.Substring(0, lastIndexOfSlash); foreach (KeyValuePair <string, string> child in children) { string absoluteFilePath = JsonHelper.GetFileFromFileJson(child.Value, nodeFilePathWithoutFileName); GameMasterNode otherFile = null; if (allNodes.TryGetValue(absoluteFilePath, out otherFile)) { // this is a proper edge otherFile.Owner = NodeFile; toUpdate.Add(child.Key, otherFile); mNumArcNodes++; } } }
private void graphViewer_MouseDown(object sender, MouseEventArgs e) { if (graphViewer.Graph != null) { object obj = graphViewer.GetObjectAt(e.X, e.Y); var dnode = obj as DNode; if (dnode != null) { Node drawingNode = dnode.DrawingNode; GameMasterNode nodeData = GameMasterDataManager.GetInstance().GetGameMasterNode(drawingNode.Id); UpdateSelectedNodeInfo(nodeData); } else { UpdateSelectedNodeInfo(null); } } }
// Returns list of out edges private List <string> GetOutEdges() { List <string> outEdges = new List <string>(); GameMasterNode arcFile = NodeFile.Owner; if (arcFile != null) { ArcNodeData arc = arcFile.NodeData as ArcNodeData; foreach (string inEdgeName in mOutEdgeStrings) { foreach (GameMasterNode linkedEncounter in arc.GetEncountersWithInEdge(inEdgeName)) { outEdges.Add(linkedEncounter.Id); } } } return(outEdges); }
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; }
public override NodeData Clone(GameMasterNode nodeFile) { EncounterNodeData newNodeData = new EncounterNodeData(); newNodeData.NodeFile = nodeFile; newNodeData.mEncounterType = mEncounterType; newNodeData.mInEdge = mInEdge; newNodeData.mOutEdgeStrings = new List <string>(); newNodeData.mIsStartNode = mIsStartNode; if (NodeFile.Owner != null && NodeFile.Owner.NodeType == GameMasterNodeType.ARC) { ArcNodeData ownerArcData = NodeFile.Owner.NodeData as ArcNodeData; ownerArcData.AddEncounter(newNodeData); nodeFile.Owner = NodeFile.Owner; } return(newNodeData); }
private void saveNewEncounterNodeDialog_FileOk(object sender, CancelEventArgs e) { string filePath = saveNewEncounterNodeDialog.FileName; if (filePath == null) { return; } filePath = JsonHelper.NormalizeSystemPath(filePath); GameMasterNode existingNode = GameMasterDataManager.GetInstance().GetGameMasterNode(filePath); if (existingNode != null) { MessageBox.Show("Cannot override an existing node. Either edit that node or create a new name."); return; } GameMasterDataManager.GetInstance().AddNewGenericScriptNode(this, mSelectedNewScriptNode, filePath); }
private void deleteNodeToolStripMenuItem_Click(object sender, EventArgs e) { if (mSelectedNode != null) { string path = mSelectedNode.Path; DialogResult result = MessageBox.Show("Are you sure you want to delete " + path + "?", "Confirm Delete", MessageBoxButtons.OKCancel); if (result == DialogResult.OK) { GameMasterNode currentCampaign = GameMasterDataManager.GetInstance().GraphRoot; string currentCampaignName = currentCampaign != null ? currentCampaign.Name : null; string currentCampaignMod = currentCampaign != null ? currentCampaign.Module : null; System.IO.File.Delete(path); Initialize(); if (currentCampaignName != null) { GameMasterDataManager.GetInstance().SelectCampaign(this, currentCampaignMod, currentCampaignName); } } } }
public override void LoadData(Dictionary <string, GameMasterNode> allNodes) { mEncounters = new Dictionary <string, string>(); mEncounterFiles = new List <GameMasterNode>(); mRarity = NodeFile.Json["rarity"].ToString(); mEncounters = JsonConvert.DeserializeObject <Dictionary <string, string> >(NodeFile.Json["encounters"].ToString()); int lastIndexOfSlash = NodeFile.Path.LastIndexOf('/'); string nodeFilePathWithoutFileName = NodeFile.Path.Substring(0, lastIndexOfSlash); foreach (string filename in mEncounters.Values) { string absoluteFilePath = JsonHelper.GetFileFromFileJson(filename, nodeFilePathWithoutFileName); GameMasterNode otherFile = null; if (allNodes.TryGetValue(absoluteFilePath, out otherFile)) { // this is a proper edge otherFile.Owner = NodeFile; mEncounterFiles.Add(otherFile); } } }
public GameMasterNode Clone(string newFileName) { try { string newPath = mDirectory + '/' + newFileName + ".json"; GameMasterNode newNode = new GameMasterNode(mModule, newPath); newNode.IsModified = true; NodeData newNodeData = NodeData.Clone(newNode); newNodeData.NodeFile = newNode; newNode.mNodeData = newNodeData; newNode.mNodeType = NodeType; newNode.mJsonFileData = new JsonFileData(newNode.Path); newNode.mJsonFileData.TrySetFlatFileData(Json.ToString()); return(newNode); } catch (Exception e) { MessageBox.Show("Unable to clone Game Master Node to " + newFileName + ". Error: " + e.Message); } return(null); }
private IEnumerable <string> GetAllNodes() { if (graphViewer.Graph == null) { yield break; } SortedSet <string> allNodes = new SortedSet <string>(); foreach (var node in graphViewer.Graph.Nodes) { GameMasterNode nodeData = GameMasterDataManager.GetInstance().GetGameMasterNode(node.Id); if (nodeData != null) { allNodes.Add(nodeData.Name); } } foreach (var node in allNodes) { yield return('"' + node + '"'); } }
private void deleteNodeToolStripMenuItem_Click(object sender, EventArgs e) { if (mSelectedNode != null) { encounterGraphContextMenu.Hide(); string path = mSelectedNode.Path; DialogResult result = MessageBox.Show("Are you sure you want to delete " + path + "?", "Confirm Delete", MessageBoxButtons.OKCancel); if (result == DialogResult.OK) { // Unparent. var encounter = mSelectedNode.NodeData as EncounterNodeData; if (encounter != null) { var owner = mSelectedNode.Owner; if (owner?.NodeData is ArcNodeData) { (owner.NodeData as ArcNodeData).RemoveEncounter(encounter); } } // Delete the actual file. System.IO.File.Delete(path); // Reinitialize. GameMasterNode currentCampaign = GameMasterDataManager.GetInstance().GraphRoot; string currentCampaignName = currentCampaign != null ? currentCampaign.Name : null; string currentCampaignMod = currentCampaign != null ? currentCampaign.Module : null; Initialize(); if (currentCampaignName != null) { GameMasterDataManager.GetInstance().SelectCampaign(this, currentCampaignMod, currentCampaignName); } GameMasterDataManager.GetInstance().RefreshGraph(this); } } }
private void graphViewer_MouseDown(object sender, MouseEventArgs e) { if (e.Button == System.Windows.Forms.MouseButtons.Middle) { mPreviousMouseX = e.X; mPreviousMouseY = e.Y; } else if (e.Button == System.Windows.Forms.MouseButtons.Left || e.Button == System.Windows.Forms.MouseButtons.Right) { if (graphViewer.Graph != null) { var dNode = graphViewer.ObjectUnderMouseCursor as DNode; if (dNode != null) { GameMasterNode nodeData = GameMasterDataManager.GetInstance().GetGameMasterNode(dNode.DrawingNode.Id); if (nodeData != null) { if (mSelectedDNode != null) { SetBranchFocused(mSelectedDNode, false); mSelectedDNode.DrawingNode.Attr.LineWidth = 1; graphViewer.Invalidate(mSelectedDNode); } mSelectedDNode = dNode; SetBranchFocused(mSelectedDNode, true); mSelectedDNode.DrawingNode.Attr.LineWidth = 5; graphViewer.Invalidate(mSelectedDNode); UpdateSelectedNodeInfo(nodeData); } } } } }
public override bool AddOutEdge(GameMasterNode nodeFile) { if (nodeFile.NodeType != GameMasterNodeType.ENCOUNTER) { return(false); } EncounterNodeData encounterData = nodeFile.NodeData as EncounterNodeData; string inEdge = encounterData.InEdge; if (encounterData.IsStartNode) { // Cannot add start nodes to an encounter. they should be added to arc return(false); } List <string> outEdges = GetOutEdges(); if (outEdges.Contains(nodeFile.Id)) { // This item is already part of the out edges return(false); } if (!mOutEdgeStrings.Contains(inEdge)) { // This out edge isn't already in the list of possible out edges, see if we can add it. switch (mEncounterType) { case "generator": // Cannot add more than one edge to generator return(false); case "random_out_edge": JObject randomOutEdgesDictionary = (JObject)NodeFile.Json["random_out_edge_info"]["out_edges"]; randomOutEdgesDictionary.Add(inEdge, JObject.Parse(@"{""weight"":1 }")); mOutEdgeStrings.Add(inEdge); break; case "collection_quest": return(false); case "dialog_tree": // We can't add to a dialog tree, you have to specify a node. return(false); case "counter": // Cannot add to a counter because it either does fail or success return(false); default: NodeFile.Json.Remove("out_edge"); mOutEdgeStrings.Add(inEdge); NodeFile.Json.Add("out_edge", JsonConvert.SerializeObject(mOutEdgeStrings)); break; } } if (nodeFile.Owner != NodeFile.Owner) { // make sure encounter is added to this tree ArcNodeData ownerArcData = NodeFile.Owner.NodeData as ArcNodeData; ownerArcData.AddEncounter(encounterData); nodeFile.Owner = NodeFile.Owner; } NodeFile.IsModified = true; return(true); }
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 void SelectCampaign(IGraphOwner graphOwner, string module, string name) { foreach (GameMasterNode node in mCampaignNodes) { if (name.Equals(node.Name) && node.Module.Equals(module)) { mCurrentGraphRoot = node; RefreshGraph(graphOwner); } } }
public CloneDialogCallback(IGraphOwner viewer, GameMasterNode node) { mViewer = viewer; mNode = node; }
public abstract NodeData Clone(GameMasterNode nodeFile);
private void PopulateFileDetails(GameMasterNode node) { fileDetailsListBox.Items.Clear(); if (node == null) { return; } Dictionary <string, float> stats = new Dictionary <string, float>(); if (node.NodeType == GameMasterNodeType.ENCOUNTER) { EncounterNodeData encounterData = node.NodeData as EncounterNodeData; if (encounterData.EncounterType == "create_mission" || encounterData.EncounterType == "city_raid") { JToken members = node.Json.SelectToken("create_mission_info.mission.members"); if (members == null) { JToken missions = node.Json.SelectToken("city_raid_info.missions"); foreach (JProperty content in missions.Children()) { // Only gets stats for the first mission of city raids members = content.Value["members"]; } } int maxEnemies = 0; float totalWeaponBaseDamage = 0; Dictionary <string, float> allStats = new Dictionary <string, float>(); foreach (string attribute in kAttributesOfInterest) { allStats[attribute] = 0; } if (members != null) { foreach (JToken member in members.Children()) { // grab name, max number of members, and tuning JProperty memberProperty = member as JProperty; if (memberProperty != null) { JValue jMax = memberProperty.Value.SelectToken("from_population.max") as JValue; int max = 0; if (jMax != null) { max = jMax.Value <int>(); maxEnemies = maxEnemies + max; } JValue tuning = memberProperty.Value.SelectToken("tuning") as JValue; if (tuning != null) { string alias = tuning.ToString(); ModuleFile tuningFile = ModuleDataManager.GetInstance().GetModuleFile(alias); if (tuningFile != null) { JsonFileData jsonFileData = tuningFile.FileData as JsonFileData; if (jsonFileData != null) { foreach (string attribute in kAttributesOfInterest) { JValue jAttribute = jsonFileData.Json.SelectToken("attributes." + attribute) as JValue; if (jAttribute != null) { allStats[attribute] = allStats[attribute] + (max * jAttribute.Value <int>()); } } JArray weapon = jsonFileData.Json.SelectToken("equipment.weapon") as JArray; if (weapon != null) { foreach (JValue weaponAlias in weapon.Children()) { ModuleFile weaponModuleFile = ModuleDataManager.GetInstance().GetModuleFile(weaponAlias.ToString()); if (weaponModuleFile != null) { JToken baseDamage = (weaponModuleFile.FileData as JsonFileData).Json.SelectToken("entity_data.stonehearth:combat:weapon_data.base_damage"); if (baseDamage != null) { totalWeaponBaseDamage = totalWeaponBaseDamage + (max * baseDamage.Value <int>()); } } } } } } } } } } fileDetailsListBox.Items.Add("max enemies : " + maxEnemies); fileDetailsListBox.Items.Add("total weapon damage : " + totalWeaponBaseDamage); foreach (string attribute in kAttributesOfInterest) { fileDetailsListBox.Items.Add("total " + attribute + " : " + allStats[attribute]); } fileDetailsListBox.Items.Add("average weapon damage : " + totalWeaponBaseDamage / maxEnemies); foreach (string attribute in kAttributesOfInterest) { fileDetailsListBox.Items.Add("average " + attribute + " : " + allStats[attribute] / maxEnemies); } } } }
private void UpdateSelectedNodeInfo(GameMasterNode node) { if (node != null) { mSelectedNode = node; nodeInfoName.Text = node.Name; encounterRightSideFilePath.Text = node.Path; nodeInfoType.Text = node.NodeType.ToString(); nodePath.Text = node.Path; nodeInfoSubType.Text = node.NodeType == GameMasterNodeType.ENCOUNTER ? ((EncounterNodeData)node.NodeData).EncounterType : ""; if (mNodePreview != null) { splitContainer2.Panel1.Controls.Remove(mNodePreview); } mNodePreview = new FilePreview(this, node.FileData); mNodePreview.Dock = DockStyle.Fill; splitContainer2.Panel1.Controls.Add(mNodePreview); copyGameMasterNode.Text = "Clone " + node.Name; copyGameMasterNode.Enabled = true; openEncounterFileButton.Visible = true; deleteNodeToolStripMenuItem.Visible = true; PopulateFileDetails(node); } else { mSelectedNode = null; nodeInfoName.Text = "Select a Node"; encounterRightSideFilePath.Text = string.Empty; nodeInfoType.Text = string.Empty; nodeInfoSubType.Text = string.Empty; nodePath.Text = string.Empty; if (mNodePreview != null) { splitContainer2.Panel1.Controls.Remove(mNodePreview); } copyGameMasterNode.Text = "Clone Node"; copyGameMasterNode.Enabled = false; openEncounterFileButton.Visible = false; deleteNodeToolStripMenuItem.Visible = false; PopulateFileDetails(null); } }
public CloneDialogCallback(IGraphOwner viewer, GameMasterNode node) { mViewer = viewer; mNode = node; }
private void PopulateFileDetails(GameMasterNode node) { fileDetailsListBox.Items.Clear(); if (node == null) { // remove details return; } Dictionary<string, float> stats = new Dictionary<string, float>(); if (node.NodeType == GameMasterNodeType.ENCOUNTER) { EncounterNodeData encounterData = node.NodeData as EncounterNodeData; if (encounterData.EncounterType == "create_mission" || encounterData.EncounterType == "city_raid") { JToken members = node.Json.SelectToken("create_mission_info.mission.members"); if (members == null) { JToken missions = node.Json.SelectToken("city_raid_info.missions"); foreach (JProperty content in missions.Children()) { // Only gets stats for the first mission of city raids members = content.Value["members"]; } } int maxEnemies = 0; float totalWeaponBaseDamage = 0; Dictionary<string, float> allStats = new Dictionary<string, float>(); foreach (string attribute in kAttributesOfInterest) { allStats[attribute] = 0; } if (members != null) { foreach (JToken member in members.Children()) { // grab name, max number of members, and tuning JProperty memberProperty = member as JProperty; if (memberProperty != null) { JValue jMax = memberProperty.Value.SelectToken("from_population.max") as JValue; int max = 0; if (jMax != null) { max = jMax.Value<int>(); maxEnemies = maxEnemies + max; } JValue tuning = memberProperty.Value.SelectToken("tuning") as JValue; if (tuning != null) { string alias = tuning.ToString(); ModuleFile tuningFile = ModuleDataManager.GetInstance().GetModuleFile(alias); if (tuningFile != null) { JsonFileData jsonFileData = tuningFile.FileData as JsonFileData; if (jsonFileData != null) { foreach (string attribute in kAttributesOfInterest) { JValue jAttribute = jsonFileData.Json.SelectToken("attributes." + attribute) as JValue; if (jAttribute != null) { allStats[attribute] = allStats[attribute] + (max * jAttribute.Value<int>()); } } JArray weapon = jsonFileData.Json.SelectToken("equipment.weapon") as JArray; if (weapon != null) { foreach (JValue weaponAlias in weapon.Children()) { ModuleFile weaponModuleFile = ModuleDataManager.GetInstance().GetModuleFile(weaponAlias.ToString()); if (weaponModuleFile != null) { JToken baseDamage = (weaponModuleFile.FileData as JsonFileData).Json.SelectToken("entity_data.stonehearth:combat:weapon_data.base_damage"); if (baseDamage != null) { totalWeaponBaseDamage = totalWeaponBaseDamage + (max * baseDamage.Value<int>()); } } } } } } } } } } fileDetailsListBox.Items.Add("max enemies : " + maxEnemies); fileDetailsListBox.Items.Add("total weapon damage : " + totalWeaponBaseDamage); foreach (string attribute in kAttributesOfInterest) { fileDetailsListBox.Items.Add("total " + attribute + " : " + allStats[attribute]); } fileDetailsListBox.Items.Add("average weapon damage : " + totalWeaponBaseDamage / maxEnemies); foreach (string attribute in kAttributesOfInterest) { fileDetailsListBox.Items.Add("average " + attribute + " : " + allStats[attribute] / maxEnemies); } } } }
public override bool AddOutEdge(GameMasterNode nodeFile) { if (nodeFile.NodeType != GameMasterNodeType.ENCOUNTER) { return false; } EncounterNodeData encounterData = nodeFile.NodeData as EncounterNodeData; string inEdge = encounterData.InEdge; if (encounterData.IsStartNode) { // Cannot add start nodes to an encounter. they should be added to arc return false; } List<string> outEdges = GetOutEdges(); if (outEdges.Contains(nodeFile.Id)) { // This item is already part of the out edges return false; } if (!mOutEdgeStrings.Contains(inEdge)) { // This out edge isn't already in the list of possible out edges, see if we can add it. switch (mEncounterType) { case "generator": // Cannot add more than one edge to generator return false; case "random_out_edge": JObject randomOutEdgesDictionary = (JObject)NodeFile.Json["random_out_edge_info"]["out_edges"]; randomOutEdgesDictionary.Add(inEdge, JObject.Parse(@"{""weight"":1 }")); mOutEdgeStrings.Add(inEdge); break; case "collection_quest": return false; case "dialog_tree": // We can't add to a dialog tree, you have to specify a node. return false; case "counter": // Cannot add to a counter because it either does fail or success return false; default: NodeFile.Json.Remove("out_edge"); mOutEdgeStrings.Add(inEdge); NodeFile.Json.Add("out_edge", JsonConvert.SerializeObject(mOutEdgeStrings)); break; } } if (nodeFile.Owner != NodeFile.Owner) { // make sure encounter is added to this tree ArcNodeData ownerArcData = NodeFile.Owner.NodeData as ArcNodeData; ownerArcData.AddEncounter(encounterData); nodeFile.Owner = NodeFile.Owner; } NodeFile.IsModified = true; return true; }
public override NodeData Clone(GameMasterNode nodeFile) { return new ArcNodeData(); }
public GameMasterNode Clone(string newFileName) { try { string newPath = mDirectory + '/' + newFileName + ".json"; GameMasterNode newNode = new GameMasterNode(mModule, newPath); newNode.IsModified = true; NodeData newNodeData = NodeData.Clone(newNode); newNodeData.NodeFile = newNode; newNode.mNodeData = newNodeData; newNode.mNodeType = NodeType; newNode.mJsonFileData = new JsonFileData(newNode.Path); newNode.mJsonFileData.TrySetFlatFileData(Json.ToString()); return newNode; } catch (Exception e) { MessageBox.Show("Unable to clone Game Master Node to " + newFileName + ". Error: " + e.Message); } return null; }
public override NodeData Clone(GameMasterNode nodeFile) { throw new NotImplementedException(); }
public void TryModifyJson(IGraphOwner graphOwner, GameMasterNode node, string newJsonString) { if (node.TryModifyJson(newJsonString)) { node.OnFileChanged(mGameMasterNodes); RefreshGraph(graphOwner); } }
public virtual bool AddOutEdge(GameMasterNode nodeFile) { return false; }
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 override NodeData Clone(GameMasterNode nodeFile) { EncounterNodeData newNodeData = new EncounterNodeData(); newNodeData.NodeFile = nodeFile; newNodeData.mEncounterType = mEncounterType; newNodeData.mInEdge = mInEdge; newNodeData.mOutEdgeStrings = new List<string>(); newNodeData.mIsStartNode = mIsStartNode; if (NodeFile.Owner != null && NodeFile.Owner.NodeType == GameMasterNodeType.ARC) { ArcNodeData ownerArcData = NodeFile.Owner.NodeData as ArcNodeData; ownerArcData.AddEncounter(newNodeData); nodeFile.Owner = NodeFile.Owner; } return newNodeData; }