/// <summary> /// Normal constructor - requires the owner object. /// </summary> /// <param name="ownerObject"></param> /// <param name="nodeType"></param> /// <param name="nodeName"></param> public Base_TN(IParent_Base_TN ownerObject, Base_TN_NodeType nodeType = Base_TN_NodeType.Unknown, string nodeName = null) : this(ownerObject) { NodeType = nodeType; if (nodeName != null && nodeName != string.Empty) { // A value for the name was supplied - no auto-generation. Name = nodeName; } else { AutoGenerateName = true; if (ownerObject != null) { RefreshName(); } } }
/// <summary> /// Adds Solar System nodes of the specified type to the RootNode, generated from the /// Game Data nodes. /// </summary> /// <param name="nodeType"></param> public void AddSolarSystemObjectsByType(Base_TN_NodeType nodeType) { switch (nodeType) { case Base_TN_NodeType.Star: case Base_TN_NodeType.Planet: case Base_TN_NodeType.Moon: // These come from the Static Data - handled by the CelestialBodies.json member of the DataDictionary if (!GameData.StaticData.DataDictionary.TryGetValue("CelestialBodies.json", out Json_File_UI celestialBodiesJsonBaseFile)) { throw new InvalidOperationException ("AddSolarSystemObjectsByType: Unable to access the CelestialBodies.json from the Static Data Dictionary."); } else { // We're expecting the Array or Object nodes as the parent token. if (celestialBodiesJsonBaseFile.RootNode.Nodes.Count != 1) { throw new InvalidOperationException ("AddSolarSystemObjectsByType: celestialBodiesJsonBaseFile.RootNode.Nodes.Count != 1"); } foreach (Json_TN node in celestialBodiesJsonBaseFile.RootNode.FirstNode.Nodes) { Base_TN_NodeType newNodeType = Base_TN_NodeType.Unknown; JObject obj = (JObject)node.JData; if (obj == null) { throw new NullReferenceException ("Adding CelestialBodies - obj was null."); } // If the node doesn't have a parent guid set it to -1000. long newNodeParentGUID = obj["ParentGUID"] != null ? (long)obj["ParentGUID"] : -1000L; switch (newNodeParentGUID) { case 0: case -1000: throw new InvalidOperationException ("AddSolarSystemObjectsByType: Failed to read ParentGUID for node " + node.Name); case -1: // It's the star, Hellion. newNodeType = Base_TN_NodeType.Star; break; case 1: // It's a planet, orbiting the star. newNodeType = Base_TN_NodeType.Planet; break; default: // It's a moon, not a space station! newNodeType = Base_TN_NodeType.Moon; break; } SolarSystem_TN newNode = node.CreateLinkedSolarSystemNode(newNodeType); RootNode.Nodes.Insert(0, newNode); } } break; case Base_TN_NodeType.Asteroid: case Base_TN_NodeType.Ship: case Base_TN_NodeType.Player: // Set up the find key that's used to locate the TreeNode representing // the Ships, Asteroids and Players collections in the .save file. string findKey = string.Empty; switch (nodeType) { case Base_TN_NodeType.Asteroid: findKey = "Asteroids"; break; case Base_TN_NodeType.Ship: findKey = "Ships"; break; case Base_TN_NodeType.Player: findKey = "Players"; break; } if (findKey == string.Empty) { throw new InvalidOperationException ("AddSolarSystemObjectsByType: findKey was empty."); } TreeNode[] tmpMatches = GameData.SaveFile.RootNode.FirstNode.Nodes.Find(findKey, searchAllChildren: false); Json_TN sectionRootNode = null; if (tmpMatches.Count() > 0) { // Grab the first match - there shouldn't be more then one anyway. sectionRootNode = (Json_TN)tmpMatches?[0]; } else { Debug.Print("AddSolarSystemObjectsByType({0}) - sectionRootNode was null.", nodeType); } // The nodes of interest are children of the node representing the JArray. Json_TN arrayRootNode = null; if (sectionRootNode?.Nodes.Count > 0) { arrayRootNode = (Json_TN)sectionRootNode?.Nodes[0]; foreach (Json_TN node in arrayRootNode.Nodes) { Debug.Print("Node Name: " + node.Name); JObject obj = (JObject)node.JData; long newNodeParentGUID; if (nodeType == Base_TN_NodeType.Player) { newNodeParentGUID = (long)obj["ParentGUID"]; } else { newNodeParentGUID = (long)obj["OrbitData"]["ParentGUID"]; } long?newNodeGUID = (long?)obj["GUID"]; Debug.Print("ParentGUID: " + newNodeParentGUID); Debug.Print("GUID: " + newNodeGUID); SolarSystem_TN newNode = node.CreateLinkedSolarSystemNode(nodeType); if (nodeType == Base_TN_NodeType.Player) { if (newNodeParentGUID == newNodeGUID) { // Player is ALIVE and in space newNode.ParentGUID = -1; // Needs to be greater than zero to place players below the star node. newNode.OrbitData.SemiMajorAxis = 1; } else { // Player is dead, display below alive players. newNode.OrbitData.SemiMajorAxis = 10; } } RootNode.Nodes.Insert(0, newNode); } } else { Debug.Print("AddSolarSystemObjectsByType({0}) - subRootNode was null.", nodeType); } break; } }
/// <summary> /// Constructor that takes a link to an Json_TN and an Base_TN_NodeType. /// </summary> /// <param name="gameDataNodeToLink">The node to link to.</param> /// <param name="nodeType">The node Type for the new linked node.</param> public SolarSystem_TN(Json_TN gameDataNodeToLink, Base_TN_NodeType nodeType) : base(gameDataNodeToLink, nodeType: nodeType) { // Set up this end of the cross-link. LinkedGameDataNode = gameDataNodeToLink ?? throw new NullReferenceException("gameDataNodeToLink was null."); // Cast the LinkedGameDataNode.JData field in to a JObject. JObject _linkedGameDataJson = (JObject)LinkedGameDataNode.JData ?? throw new NullReferenceException("_linkedGameDataJson was null."); // If we're working with a linked blueprint node, translate the StructureID to GUID JToken tmpTkn = _linkedGameDataJson["StructureID"]; if (tmpTkn != null) { Debug.Print("Got here for some reason!"); // Set the node's Name to the StructureID of the object. Name = (string)_linkedGameDataJson["StructureID"]; // Set the GUID to the StructureID GUID = (long)_linkedGameDataJson["StructureID"]; throw new Exception("Got here for some reason!"); } else { switch (nodeType) { case Base_TN_NodeType.Ship: if (string.IsNullOrEmpty((string)_linkedGameDataJson["Name"])) { // The ship has no name - most non-player vessels fall in to this category. Name = (string)_linkedGameDataJson["Registration"]; } else { // The ship has a name, append it on to the end of the registration Name = (string)_linkedGameDataJson["Registration"] + " " + (string)_linkedGameDataJson["Name"]; } break; default: Name = ((string)_linkedGameDataJson["Name"]).Trim(); break; } // Can't use these presently as it messes with the TreeView's Path system, // which annoyingly uses the TreeNode's Text field rather than the Name field // in path generation, which would have allowed the Text property to be used like // a DisplayName property. // Text_Prefix = ((string)_linkedGameDataJson["Name"]).Trim(); // Text_Suffix = ((string)_linkedGameDataJson["GUID"]).Trim(); // Set the GUID GUID = (long)_linkedGameDataJson["GUID"]; } JToken tempToken = null; switch (nodeType) { case Base_TN_NodeType.Star: case Base_TN_NodeType.Planet: case Base_TN_NodeType.Moon: // It's a Celestial Body - the orbital data is not in an OrbitalData sub-object, but directly // as properties of this JObject. OrbitData = new OrbitalData(_linkedGameDataJson); break; case Base_TN_NodeType.Player: // It's a player - doesn't have orbital data but may have a parent GUID if in a ship/module. // Ensure OrbitData is null. // OrbitData = new OrbitalData(); tempToken = _linkedGameDataJson["ParentGUID"]; if (tempToken != null) { OrbitData.ParentGUID = (long)_linkedGameDataJson["ParentGUID"]; } else { // Set the parent GUID to -1 (the Solar System) as we currently can't place players who // are outside ships or modules. OrbitData.ParentGUID = -1; } break; case Base_TN_NodeType.Ship: // Ships also need to set the docking info if present. OrbitData = new OrbitalData((JObject)_linkedGameDataJson["OrbitData"]); DockedToShipGUID = (long?)_linkedGameDataJson["DockedToShipGUID"]; DockedPortID = (int?)_linkedGameDataJson["DockedPortID"]; DockedToPortID = (int?)_linkedGameDataJson["DockedToPortID"]; break; default: // It's a regular orbital object with it's parameters in an OrbitData sub-object. OrbitData = new OrbitalData((JObject)_linkedGameDataJson["OrbitData"]); break; } }
/// <summary> /// Constructor that takes a minimum of an Owner, but also optionally a name and type. /// </summary> /// <param name="nodeName">Name for the new node; required;</param> /// <param name="nodeType">Base_TN_NodeType of the new node; defaults to Unknown.</param> public SolarSystem_TN(IParent_Base_TN passedOwner, string nodeName = null, Base_TN_NodeType nodeType = Base_TN_NodeType.Unknown) : base(passedOwner, nodeType, nodeName) { }
public HierarchyView_TN(IParent_Base_TN passedOwner = null, string nodeName = null, Base_TN_NodeType newNodeType = Base_TN_NodeType.BlueprintHierarchyView) : base(passedOwner, newNodeType, nodeName) { }
/// <summary> /// Constructor that takes a minimum of a name, but also optionally a type and text (display name). /// </summary> /// <param name="nodeName">Name of the new node.</param> /// <param name="nodeType">Type of the new node (Base_TN_NodeType enum)</param> /// <param name="nodeText">Text of the new node (Display Name). If not specified this defaults to the node's name.</param> /// <param name="nodeToolTipText">Tool tip text of the new node. If not specified this defaults to the node's text.</param> public Json_TN(IParent_Base_TN ownerObject, Base_TN_NodeType newNodeType = Base_TN_NodeType.Unknown, string nodeName = null) : base(ownerObject, newNodeType, nodeName) { }
public Blueprint_TN(IParent_Base_TN passedOwner = null, Base_TN_NodeType newNodeType = Base_TN_NodeType.StationBlueprintFile, string nodeName = null) : base(passedOwner, newNodeType, nodeName) { }
/// <summary> /// Constructor that takes a minimum of a parent SearchHandler and a name, /// but also optionally a type and text (display name). /// </summary> /// <param name="passedParentSearchHandler"></param> /// <param name="nodeName"></param> /// <param name="newNodeType"></param> /// <param name="nodeText"></param> /// <param name="nodeToolTipText"></param> public SearchHandler_TN(SearchHandler.HESearchOperator passedParentSearchOperator, string nodeName, IParent_Base_TN passedOwner = null, Base_TN_NodeType newNodeType = Base_TN_NodeType.Unknown) : base(passedOwner, newNodeType, nodeName) { ParentSearchOperator = passedParentSearchOperator ?? throw new NullReferenceException("passedParentSearchOperator was null."); }
public SearchHandler_TN(string nodeName, IParent_Base_TN passedOwner = null, Base_TN_NodeType newNodeType = Base_TN_NodeType.Unknown) : base(passedOwner, newNodeType, nodeName) { }
/// <summary> /// Returns the defined image list index for the node type. /// </summary> /// <param name="NodeType">Specifies the HETreeNode type to get the image index of.</param> /// <returns>Returns an integer representing the image index.</returns> public static int GetIconImageIndexByNodeType(Base_TN_NodeType NodeType) { switch (NodeType) { case Base_TN_NodeType.SolarSystemView: return((int)HEIconsImageNames.Share_16x); case Base_TN_NodeType.DataView: return((int)HEIconsImageNames.ListFolder_16x); case Base_TN_NodeType.SearchResultsView: case Base_TN_NodeType.SearchHandler: case Base_TN_NodeType.SearchResultsSet: return((int)HEIconsImageNames.FindResults_16x); //case Base_TN_NodeType.CelestialBody: //case Base_TN_NodeType.DefCelestialBody: // return (int)HEIconsImageNames.Shader_16x; case Base_TN_NodeType.Star: return((int)HEIconsImageNames.Brightness_16x); case Base_TN_NodeType.Planet: return((int)HEIconsImageNames.Contrast_16x); case Base_TN_NodeType.Moon: return((int)HEIconsImageNames.DarkTheme_16x); case Base_TN_NodeType.Asteroid: //case Base_TN_NodeType.DefAsteroid: return((int)HEIconsImageNames.CheckDot_16x); case Base_TN_NodeType.Ship: return((int)HEIconsImageNames.AzureLogicApp_16x); case Base_TN_NodeType.Player: return((int)HEIconsImageNames.Actor_16x); //case Base_TN_NodeType.DynamicObject: //case Base_TN_NodeType.DefDynamicObject: // return (int)HEIconsImageNames.Driver_16x; //case Base_TN_NodeType.Scene: // return (int)HEIconsImageNames.a3DScene_16x; //case Base_TN_NodeType.DefStructure: // return (int)HEIconsImageNames.Component_16x; //case Base_TN_NodeType.SpawnPoint: //case Base_TN_NodeType.DoomControllerData: //case Base_TN_NodeType.SpawnManagerData: // return (int)HEIconsImageNames.a3DCameraOrbit_16x; case Base_TN_NodeType.JsonArray: return((int)HEIconsImageNames.Assembly_16x); case Base_TN_NodeType.JsonObject: return((int)HEIconsImageNames.Settings_16x); case Base_TN_NodeType.JsonProperty: return((int)HEIconsImageNames.Property_16x); case Base_TN_NodeType.JsonValue: return((int)HEIconsImageNames.DomainType_16x); case Base_TN_NodeType.JsonBoolean: return((int)HEIconsImageNames.CheckDot_16x); case Base_TN_NodeType.JsonBytes: return((int)HEIconsImageNames.Binary_16x); case Base_TN_NodeType.JsonString: case Base_TN_NodeType.JsonUri: case Base_TN_NodeType.JsonComment: return((int)HEIconsImageNames.String_16x); case Base_TN_NodeType.JsonInteger: case Base_TN_NodeType.JsonFloat: case Base_TN_NodeType.JsonGuid: return((int)HEIconsImageNames.DomainType_16x); case Base_TN_NodeType.JsonDate: case Base_TN_NodeType.JsonTimeSpan: return((int)HEIconsImageNames.DateTimeAxis_16x); case Base_TN_NodeType.JsonNull: return((int)HEIconsImageNames.Checkerboard_16x); case Base_TN_NodeType.SaveFile: case Base_TN_NodeType.DataFile: return((int)HEIconsImageNames.Document_16x); case Base_TN_NodeType.SaveFileError: case Base_TN_NodeType.DataFileError: return((int)HEIconsImageNames.FileError_16x); case Base_TN_NodeType.DataFolder: return((int)HEIconsImageNames.ListFolder_16x); // Folder_16x; case Base_TN_NodeType.DataFolderError: return((int)HEIconsImageNames.FolderError_16x); case Base_TN_NodeType.CollisionDataFolder: return((int)HEIconsImageNames.DocumentLibraryFolder_16x); case Base_TN_NodeType.StationBlueprintFile: return((int)HEIconsImageNames.CordovaMultidevice_16x); //return (int)HEIconsImageNames.CSWorkflowDiagram_16x; case Base_TN_NodeType.BlueprintCollection: return((int)HEIconsImageNames.BlueprintFolder_16x); case Base_TN_NodeType.BlueprintHierarchyView: return((int)HEIconsImageNames.TreeView_16x); case Base_TN_NodeType.BlueprintDataView: return((int)HEIconsImageNames.BalanceBrace_16x); case Base_TN_NodeType.BlueprintStructureDefinitionView: return((int)HEIconsImageNames.Bios_16x); case Base_TN_NodeType.BlueprintStructure: case Base_TN_NodeType.BlueprintStructureDefinition: return((int)HEIconsImageNames.Component_16x); case Base_TN_NodeType.BlueprintRootStructure: return((int)HEIconsImageNames.Hub_16x); case Base_TN_NodeType.BlueprintDockingPort: case Base_TN_NodeType.BlueprintDockingPortDefinition: return((int)HEIconsImageNames.Bolt_16x); case Base_TN_NodeType.LocalServer: return((int)HEIconsImageNames.LocalServer_16x); default: return((int)HEIconsImageNames.Checkerboard_16x); } }