/// <summary> /// Looks up a port type (name) from the port dictionary from the specified sceneID and orderID. /// </summary> /// <param name="sceneID"></param> /// <param name="orderID"></param> /// <returns></returns> public static DockingPortType GetDockingPortType(StructureSceneID sceneID, int orderID) { // Attempt to locate the correct port Dictionary by sceneID. if (DockingPortHints.TryGetValue(sceneID, out Dictionary <int, DockingPortType> portDictionary)) { // We should have a Dictionary object containing the structure's port OrderIDs and Names (aka types). if (portDictionary.TryGetValue(orderID, out DockingPortType portType)) { return(portType); } } return(DockingPortType.Unspecified); }
/// <summary> /// Looks up the orderID from the port dictionary for the specified sceneID and portType. /// </summary> /// <param name="sceneID"></param> /// <param name="portType"></param> /// <returns></returns> public static int?GetOrderID(StructureSceneID sceneID, DockingPortType portType) { // Attempt to locate the correct port Dictionary by sceneID. if (DockingPortHints.TryGetValue(sceneID, out Dictionary <int, DockingPortType> portDictionary)) { // We should have a Dictionary object containing the structure's port OrderIDs and Names (aka types). // Look up the keys of ports with matching name (type). IEnumerable <int> results = portDictionary.Keys.Where(k => portDictionary[k] == portType); // There should only be one result otherwise there's a duplicate name in the definitions. if (results.Count() < 1 || results.Count() > 1) { return(null); } return(results.Single()); } return(null); }
/// <summary> /// Generates a list of BlueprintDockingPort objects appropriate to the specified sceneID (module type). /// </summary> /// <param name="sceneID"></param> /// <returns></returns> public static List <BlueprintDockingPort> GenerateBlueprintDockingPorts(StructureSceneID sceneID) { List <BlueprintDockingPort> results = new List <BlueprintDockingPort>(); // Attempt to locate the correct port Dictionary by sceneID. if (DockingPortHints.TryGetValue(sceneID, out Dictionary <int, DockingPortType> portDictionary)) { // We should have a Dictionary object containing the structure's port OrderIDs and Names (aka types). foreach (KeyValuePair <int, DockingPortType> item in portDictionary) { // Create a new BlueprintDockingPort. BlueprintDockingPort newPort = new BlueprintDockingPort() { PortName = item.Value, OrderID = item.Key, }; // Add it to the results list. results.Add(newPort); } } return(results); }
public void BuildStationBlueprintFromJData() { Debug.Print("------------------------------------------------------------"); Debug.Print("BuildStationBlueprintFromJData: Starting."); //// Check it's for the correct __ObjectType. //JToken testToken = JData["__ObjectType"]; //if (testToken == null || (string)testToken != "StationBlueprint") //{ // Debug.Print("BuildStationBlueprintFromJData: ObjectType not StationBlueprint"); // return; //} JToken testToken; // Create a new StationBlueprint. BlueprintObject = new StationBlueprint { OwnerObject = this, // __ObjectType = BlueprintObjectType.StationBlueprint }; // Set the blueprint name; testToken = JData["Name"]; if (testToken != null) { BlueprintObject.Name = (string)testToken; } // Set the blueprint Link Uri; testToken = JData["LinkURI"]; if (testToken != null) { BlueprintObject.LinkURI = (Uri)testToken; } // Set blueprint level properties. testToken = JData["Invulnerable"]; if (testToken != null) { BlueprintObject.Invulnerable = (bool)testToken; } testToken = JData["SystemsOnline"]; if (testToken != null) { BlueprintObject.SystemsOnline = (bool)testToken; } testToken = JData["DoorsLocked"]; if (testToken != null) { BlueprintObject.DoorsLocked = (bool)testToken; } Debug.Print("------------------------------------------------------------"); Debug.Print("Creating new blueprint structures (" + JData["Structures"].Count() + ")"); foreach (JObject structure in JData["Structures"]) { Debug.Print("------------------------------"); StructureSceneID sceneID = StructureSceneID.Unspecified; int structureID = (int)structure["StructureID"]; Debug.Print("structureID " + structureID); // Attempt to get a StructureType - this is a mix between the in-game three letter // names and the SceneNames. testToken = structure["StructureType"]; if (testToken != null) { string parsedStructureType = (string)structure["StructureType"]; Debug.Print("parsedStructureType " + parsedStructureType); sceneID = parsedStructureType.ParseToEnumDescriptionOrEnumerator <StructureSceneID>(); Debug.Print("sceneID " + sceneID); } //// Attempt to get a SceneID - this is for newer format blueprints. //testToken = structure["SceneID"]; //if (testToken != null) //{ // int parsedSceneID = (int)structure["SceneID"]; // sceneID = parsedSceneID.ParseToEnumDescriptionOrEnumerator<StructureSceneID>(); //} // Call the BlueprintObject's AddStructure method with the sceneID and structureID. BlueprintStructure newStructure = BlueprintObject.AddStructure(sceneID, structureID); // A StationBlueprint file should have only one docking tree and StructureID=0 is the root. if (newStructure.StructureID != 0) { newStructure.IsStructureHierarchyRoot = false; } Debug.Print(" newStructure ports (" + newStructure.DockingPorts.Count + ")"); foreach (BlueprintDockingPort tmpPort in newStructure.DockingPorts) { Debug.Print(" PortName " + tmpPort.PortName); Debug.Print(" OrderID " + tmpPort.OrderID); Debug.Print(" Locked " + tmpPort.Locked); } } Debug.Print("------------------------------------------------------------"); Debug.Print("Setting docking port data from loaded data."); foreach (JObject structure in JData["Structures"]) { Debug.Print("------------------------------"); int structureID = (int)structure["StructureID"]; Debug.Print("structureID " + structureID); BlueprintStructure newStructure = BlueprintObject.GetStructure(structureID); if (newStructure == null) { throw new Exception(); } foreach (JObject dockingPort in structure["DockingPorts"]) { Debug.Print("-------------------------"); Debug.Print(" DockingPort"); int orderID = (int)dockingPort["OrderID"]; Debug.Print(" orderID " + orderID); int?dockedStructureID = (int?)dockingPort["DockedStructureID"]; Debug.Print(" dockedStructureID " + dockedStructureID); bool locked = dockingPort["Locked"] != null ? (bool)dockingPort["Locked"] : false; Debug.Print(" locked " + locked); BlueprintDockingPort newPort = newStructure.GetDockingPortByOrderID(orderID); if (newPort == null) { throw new Exception(); } // If we got here we should have the port in the new structure that corresponds // to the port in this JObject. newPort.DockedStructureID = dockedStructureID; newPort.Locked = locked; } } }
/// <summary> /// Returns the ImageIndex for a particular blueprint structure type. /// </summary> /// <param name="sceneID"></param> /// <returns></returns> public static int GetStructureImageIndexBySceneID(StructureSceneID sceneID) { switch (sceneID) { case StructureSceneID.AltCorp_CorridorModule: return((int)HEStructuresImageNames.STRUCT_CIM); case StructureSceneID.AltCorp_CorridorIntersectionModule: return((int)HEStructuresImageNames.STRUCT_CTM); case StructureSceneID.AltCorp_Corridor45TurnModule: return((int)HEStructuresImageNames.STRUCT_CLM); case StructureSceneID.AltCorp_Shuttle_SARA: return((int)HEStructuresImageNames.STRUCT_ARG); case StructureSceneID.ALtCorp_PowerSupply_Module: return((int)HEStructuresImageNames.STRUCT_PSM); case StructureSceneID.AltCorp_LifeSupportModule: return((int)HEStructuresImageNames.STRUCT_LSM); case StructureSceneID.AltCorp_Cargo_Module: return((int)HEStructuresImageNames.STRUCT_CBM); case StructureSceneID.AltCorp_CorridorVertical: return((int)HEStructuresImageNames.STRUCT_CSM); case StructureSceneID.AltCorp_Command_Module: return((int)HEStructuresImageNames.STRUCT_CM); case StructureSceneID.AltCorp_Corridor45TurnRightModule: return((int)HEStructuresImageNames.STRUCT_CRM); case StructureSceneID.AltCorp_StartingModule: return((int)HEStructuresImageNames.STRUCT_OUTPOST); case StructureSceneID.AltCorp_AirLock: return((int)HEStructuresImageNames.STRUCT_AM); case StructureSceneID.Generic_Debris_JuncRoom001: case StructureSceneID.Generic_Debris_JuncRoom002: case StructureSceneID.Generic_Debris_Corridor001: case StructureSceneID.Generic_Debris_Corridor002: return((int)HEStructuresImageNames.STRUCT_Unspecified); case StructureSceneID.AltCorp_DockableContainer: return((int)HEStructuresImageNames.STRUCT_IC); case StructureSceneID.AltCorp_CrewQuarters_Module: return((int)HEStructuresImageNames.STRUCT_CQM); case StructureSceneID.AltCorp_SolarPowerModule: return((int)HEStructuresImageNames.STRUCT_SPM); case StructureSceneID.AltCorp_Shuttle_CECA: return((int)HEStructuresImageNames.STRUCT_Unspecified); case StructureSceneID.AltCorp_FabricatorModule: return((int)HEStructuresImageNames.STRUCT_FM); case StructureSceneID.Unspecified: default: return((int)HEStructuresImageNames.STRUCT_Unspecified); } }
/// <summary> /// The type of parent structure this docking port is part of. /// </summary> /// <remarks> /// Used to assist in lookup of OrderID to PortName and vice versa. /// </remarks> /// <param name="parentType"></param> public BlueprintDockingPort(StructureSceneID parentType) : this() { RootNode.AutoGenerateName = true; StructureSceneID = parentType; }