/// <summary> /// Finds the part by name. /// </summary> /// <param name="inPartName">The parts name to find</param> private Part findPartByName(string inPartName) { // Written, 10.09.2021 Part part = ModClient.parts.Find(_part => _part.name == inPartName); if (!part) { ModApiInterface.print("Could not find the part by name."); } else { ModApiInterface.print("Found part: {0}", part.name); } return(part); }
/// <summary> /// Represents the main entry for the command. /// </summary> /// <param name="args">arguments passed to command</param> public override void Run(string[] args) { // Written, 10.09.2021 if (args.Length == 0) { ModApiInterface.print(Help); } else if (args.Length > 0) { switch (args[0]) { case "help": case "?": case "": if (args.Length > 1) { switch (args[1]) { case "debug": case "db": if (args.Length > 2) { switch (args[2]) { case "tpp": case "tppart": case "teleportpart": ModApiInterface.print(helpListTeleportPart); break; case "epit": case "editpart": case "editpartinstalltransform": ModApiInterface.print(helpListEditInstallTransformPart); break; } } else { ModApiInterface.print(helpListDebug); } break; default: ModApiInterface.print("unknown command"); ModApiInterface.print(helpListGeneral); break; } } else { ModApiInterface.print(helpListGeneral); } break; case "version": case "ver": case "v": ModApiInterface.print("version:{0}\nplatform:{1}\nconfiguration:{2}", ModClient.version, ModClient.IS_X64 ? "x64" : "x86", ModClient.IS_DEBUG_CONFIG ? "debug" : "release"); break; case "debug": case "db": if (args.Length > 1) { switch (args[1]) { case "lp": case "lparts": case "listparts": if (ModClient.parts.Count > 0) { foreach (var item in ModClient.parts) { ModApiInterface.print("{0}", item.gameObject.name); } } else { ModApiInterface.print("No parts found :("); } break; case "epit": case "editpart": case "editpartinstalltransform": if (args.Length > 2) { switch (args[2]) { case "-r": if (!_startedInspectingPart) { if (args.Length == 3) { ModApiInterface.print("Edit part install transform by raycast (-r)"); RaycastHit hitInfo; bool hasHit = Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hitInfo); if (hasHit) { Part _part = hitInfo.collider.GetComponent <Part>(); if (_part) { ModApiInterface.print("found {0} by raycast!", _part.name); _inspectingPart = _part; } else { ModApiInterface.print("Could not find a part by raycast :( reason: raycast hit returned true but no part behaviour was found."); } } else { ModApiInterface.print("Could not find a part by raycast :( reason: raycast hit returned false."); } } else { ModApiInterface.print("command, \"modapi debug editpartinstalltransform -r\" expects 0 arguments."); } } else { ModApiInterface.print("Stop inspecting part prior to looking for another part."); } break; case "-n": if (!_startedInspectingPart) { if (args.Length == 4) { ModApiInterface.print("Edit part install transform by name (-n)"); Part _part = findPartByName(args[3]); if (_part) { ModApiInterface.print("found {0} by name!", _part.name); _inspectingPart = _part; } else { ModApiInterface.print("Use \"modapi listparts\" to see all vaild parameters."); } } else { ModApiInterface.print("command, \"modapi debug editpartinstalltransform -n\" expects 1 argument, the parts name. Use \"modapi listparts\" to see all vaild parameters."); } } else { ModApiInterface.print("Stop inspecting part prior to looking for another part."); } break; case "start": if (!_inspectingPart) { ModApiInterface.print("Find part prior to starting."); return; } if (_startedInspectingPart) { ModApiInterface.print("Already inspecting part."); return; } _startedInspectingPart = true; _inspectingPart.StartCoroutine(movePartCoroutine()); ModApiInterface.print("Started inspecting {0}..", _inspectingPart.name); break; case "stop": if (!_inspectingPart) { ModApiInterface.print("Find part prior to stopping."); return; } if (!_startedInspectingPart) { ModApiInterface.print("You need to start inspecting a part prior to stopping.."); return; } _startedInspectingPart = false; ModApiInterface.print("Stopped inspecting {0}..", _inspectingPart.name); break; case "print": if (!_inspectingPart) { ModApiInterface.print("Find part prior to printing transform info."); return; } ModApiInterface.print("{0} Transform info:\nposition: {1}\nrotation: {2}", _inspectingPart.name, _inspectingPart.transform.localPosition, _inspectingPart.transform.localEulerAngles); break; default: ModApiInterface.print("unknown command"); ModApiInterface.print(helpListEditInstallTransformPart); break; } } else { ModApiInterface.print("command, \"modapi debug editpartinstalltransform\" expects atleast 1 argument, a sub command. Use \"modapi help debug editpartinstalltransform\" to see all vaild parameters."); } break; case "tpp": case "tppart": case "teleportpart": if (args.Length >= 3) { Part part = findPartByName(args[2]); if (part) { if (part.installed && args.Length == 3 && args[3] != "-f") { ModApiInterface.print("cannot teleport part while it's installed... use \"-f\" to force an uninstall and teleport."); } else { if (part.installed && args.Length == 3 && args[3] == "-f") { part.disassemble(); } Rigidbody rb = part.GetComponent <Rigidbody>(); if (rb) { if (!rb.isKinematic) { rb = null; } else { rb.isKinematic = true; } } part.transform.position = Camera.main.transform.position; if (rb) { rb.isKinematic = false; } } } else { ModApiInterface.print("Use \"modapi listparts\" to see all vaild parameters."); } } else { ModApiInterface.print("command, \"modapi debug teleportpart\" expects atleast 1 argument, the parts name. Use \"modapi listparts\" to see all vaild parameters."); } break; default: ModApiInterface.print("unknown command"); ModApiInterface.print(helpListDebug); break; } } else { ModApiInterface.print("command, \"modapi debug\" expects atleast 1 argument, a sub command. Use \"modapi help debug\" to see all vaild parameters."); } break; default: ModApiInterface.print("unknown command"); ModApiInterface.print(helpListGeneral); break; } } }