diff --git a/Source code/MscModApi/Caching/Cache.cs b/Source code/MscModApi/Caching/Cache.cs index c1c1bc0..7e27d15 100644 --- a/Source code/MscModApi/Caching/Cache.cs +++ b/Source code/MscModApi/Caching/Cache.cs @@ -19,8 +19,7 @@ public static GameObject Find(string name, bool findEvenIfInactive = true) return gameObject; } } - catch - { + catch { // ignored. Continues below } @@ -28,8 +27,7 @@ public static GameObject Find(string name, bool findEvenIfInactive = true) GameObject foundObject = GameObject.Find(name); - if (!foundObject && findEvenIfInactive) - { + if (!foundObject && findEvenIfInactive) { foundObject = FindInGlobal(name); } @@ -39,29 +37,25 @@ public static GameObject Find(string name, bool findEvenIfInactive = true) private static GameObject FindInGlobal(string name) { - if (globalCache == null) - { + if (globalCache == null) { globalCache = Resources.FindObjectsOfTypeAll(); } - foreach(var gameObject in globalCache) - { + foreach (var gameObject in globalCache) { string nameToCompareTo = gameObject.name; - if (gameObject.name.Contains("OptionsMenu")) - { - + if (gameObject.name.Contains("OptionsMenu")) { } - if (name.Contains("/")) - { + if (name.Contains("/")) { nameToCompareTo = GetObjectPath(gameObject); } - if (nameToCompareTo == name) - { + + if (nameToCompareTo == name) { return gameObject; } } + return null; } @@ -75,8 +69,7 @@ private static string GetObjectPath(GameObject gameObject) Transform currentTransform = gameObject.transform; string path = currentTransform.name; - while (currentTransform.parent != null) - { + while (currentTransform.parent != null) { currentTransform = currentTransform.parent; path = currentTransform.name + "/" + path; } diff --git a/Source code/MscModApi/Caching/CarH.cs b/Source code/MscModApi/Caching/CarH.cs index 14e3f28..e6ceb7e 100644 --- a/Source code/MscModApi/Caching/CarH.cs +++ b/Source code/MscModApi/Caching/CarH.cs @@ -28,7 +28,8 @@ public static string playerCurrentVehicle } } - public static GameObject electricity { + public static GameObject electricity + { get { if (_electricity != null) return _electricity; @@ -38,7 +39,8 @@ public static GameObject electricity { } } - public static bool hasPower { + public static bool hasPower + { get { if (_electricsOk != null) return _electricsOk.Value; @@ -48,7 +50,8 @@ public static bool hasPower { } } - public static CarController carController { + public static CarController carController + { get { if (_carController != null) return _carController; @@ -58,7 +61,8 @@ public static CarController carController { } } - public static AxisCarController axisCarController { + public static AxisCarController axisCarController + { get { if (_axisController != null) return _axisController; @@ -68,7 +72,8 @@ public static AxisCarController axisCarController { } } - public static Drivetrain drivetrain { + public static Drivetrain drivetrain + { get { if (_drivetrain != null) return _drivetrain; @@ -78,7 +83,8 @@ public static Drivetrain drivetrain { } } - public static GameObject satsuma { + public static GameObject satsuma + { get { if (_satsuma != null) return _satsuma; diff --git a/Source code/MscModApi/Caching/Game.cs b/Source code/MscModApi/Caching/Game.cs index 4ec54d2..bd474c5 100644 --- a/Source code/MscModApi/Caching/Game.cs +++ b/Source code/MscModApi/Caching/Game.cs @@ -14,7 +14,7 @@ public static float money { if (_money != null) return _money.Value; _money = PlayMakerGlobals.Instance.Variables.FindFsmFloat("PlayerMoney"); - return (float) Math.Round(_money.Value, 1); + return (float)Math.Round(_money.Value, 1); } set { diff --git a/Source code/MscModApi/Commands/ScrewPlacementModCommand.cs b/Source code/MscModApi/Commands/ScrewPlacementModCommand.cs index 1c8d6c2..7286d79 100644 --- a/Source code/MscModApi/Commands/ScrewPlacementModCommand.cs +++ b/Source code/MscModApi/Commands/ScrewPlacementModCommand.cs @@ -18,23 +18,15 @@ class ScrewPlacementModCommand : ConsoleCommand private readonly Command enableCommand; private readonly Command disableCommand; private readonly Command listCommand; + protected class Command { - public string name - { - get; - } + public string name { get; } - public string help - { - get; - } + public string help { get; } - public string parameterCallExample - { - get; - } + public string parameterCallExample { get; } public Command(string name, string help, string parameterCallExample = "") { @@ -49,8 +41,12 @@ public ScrewPlacementModCommand(MscModApi mod, Dictionary'"); - + helpCommand = new Command( + "help", + "This help", + "Escape further command arguments with spaces, with two '" + ); + enableCommand = new Command( "enable", "Enable screw placement mode for a part", @@ -69,7 +65,7 @@ public ScrewPlacementModCommand(MscModApi mod, Dictionary'" ); - availableCommands.AddRange(new [] + availableCommands.AddRange(new[] { helpCommand, listCommand, @@ -77,13 +73,12 @@ public ScrewPlacementModCommand(MscModApi mod, Dictionary{command.name}: {command.help}"); - if (command.parameterCallExample != "") - { + if (command.parameterCallExample != "") { ModConsole.Print($"=> {command.parameterCallExample}"); } } + break; case Command cmd1 when cmd1 == enableCommand: case Command cmd2 when cmd2 == disableCommand: modId = args.ElementAtOrDefault(1); partId = args.ElementAtOrDefault(2); - if (string.IsNullOrEmpty(modId) || string.IsNullOrEmpty(partId)) - { + if (string.IsNullOrEmpty(modId) || string.IsNullOrEmpty(partId)) { goto default; } @@ -117,22 +109,20 @@ public override void Run(string[] args) modId = modId.Replace("'", ""); partId = partId.Replace("'", ""); - if (!ScrewPlacementAssist.IsScrewPlacementModeEnabled(modId)) - { + if (!ScrewPlacementAssist.IsScrewPlacementModeEnabled(modId)) { ModConsole.Print($"ScrewPlacementMode not enabled for mod with id '{modId}'"); break; } - if (!modsParts.ContainsKey(modId)) - { + if (!modsParts.ContainsKey(modId)) { ModConsole.Error($"No mod with id {modId} found that has added parts"); break; } - if (!modsParts[modId].ContainsKey(partId)) - { - ModConsole.Error($"No part with id {partId} found for mod with id {modId}"); + if (!modsParts[modId].ContainsKey(partId)) { + ModConsole.Error( + $"No part with id {partId} found for mod with id {modId}"); break; } @@ -142,30 +132,27 @@ public override void Run(string[] args) case Command cmd2 when cmd2 == listCommand: modId = args.ElementAtOrDefault(1); - if (string.IsNullOrEmpty(modId)) - { + if (string.IsNullOrEmpty(modId)) { goto default; } //Removing potential '' modId = modId.Replace("'", ""); - if (!ScrewPlacementAssist.IsScrewPlacementModeEnabled(modId)) - { + if (!ScrewPlacementAssist.IsScrewPlacementModeEnabled(modId)) { ModConsole.Print($"ScrewPlacementMode not enabled for mod with id '{modId}'"); break; } - if (!modsParts.ContainsKey(modId)) - { + if (!modsParts.ContainsKey(modId)) { ModConsole.Error($"No mod with id {modId} found that has added parts"); break; } - foreach (var partDict in modsParts[modId]) - { + foreach (var partDict in modsParts[modId]) { part = partDict.Value; - ModConsole.Print($"{part.id} => {(part.screwPlacementMode ? "Enabled" : "Disabled")}"); + ModConsole.Print( + $"{part.id} => {(part.screwPlacementMode ? "Enabled" : "Disabled")}"); } break; @@ -180,4 +167,4 @@ public override void Run(string[] args) public override string Help => "Run mod-api-screw help for a list of commands and arguments"; } -} +} \ No newline at end of file diff --git a/Source code/MscModApi/MscModApi.cs b/Source code/MscModApi/MscModApi.cs index f86c292..ef3f9ea 100644 --- a/Source code/MscModApi/MscModApi.cs +++ b/Source code/MscModApi/MscModApi.cs @@ -31,6 +31,7 @@ public class MscModApi : Mod private static Settings enableInstantInstall = new Settings("enableInstantInstall", "Enable Instant Part install", false); + private const string assetsFile = "msc-mod-api.unity3d"; private Tool tool; @@ -48,7 +49,8 @@ public class MscModApi : Mod /// Enables the screw placement for all parts. /// The mod. - [Obsolete("Only kept for compatibility, use part.screwPlacementMode = true/false instead. Won't do anything!", true)] + [Obsolete("Only kept for compatibility, use part.screwPlacementMode = true/false instead. Won't do anything!", + true)] public static void EnableScrewPlacementForAllParts(Mod mod) { //Don't do anything @@ -70,7 +72,8 @@ public override void ModSettings() Settings.AddCheckBox(this, showBoltSizeSetting); Keybind.AddHeader(this, "Developer area - Screw placement mode"); #if DEBUG - instantInstallKeybind = Keybind.Add(this, "instant-install", "Instant install part looking at", KeyCode.UpArrow); + instantInstallKeybind = + Keybind.Add(this, "instant-install", "Instant install part looking at", KeyCode.UpArrow); Settings.AddCheckBox(this, enableInstantInstall); #endif ScrewPlacementAssist.ModSettings(this); @@ -80,16 +83,18 @@ public void OnGui() { ScrewPlacementAssist.OnGui(); } - + public static void NewGameCleanUp(Mod mod, string saveFileName = "parts_saveFile.json") { SaveLoad.SerializeSaveFile(mod, new Dictionary(), saveFileName); - SaveLoad.SerializeSaveFile(mod, new Dictionary(), "paintingSystem_saveFile.json"); + SaveLoad.SerializeSaveFile(mod, new Dictionary(), + "paintingSystem_saveFile.json"); } private void MenuLoad() { - ModConsole.Print($"You are running {Name} [v{Version}]"); + ModConsole.Print( + $"You are running {Name} [v{Version}]"); //Do cleanup of static fields to avoid problems with reloading (going/getting to menu and then going back into game) LoadCleanup(); @@ -107,7 +112,6 @@ private void MenuLoad() Logger.InitLogger(this); LoadAssets(); ConsoleCommand.Add(new ScrewPlacementModCommand(this, modsParts)); - } private void Load() @@ -120,35 +124,29 @@ private void Load() private void Save() { - foreach (PartBox partBox in partBoxes) - { + foreach (PartBox partBox in partBoxes) { partBox.CheckUnpackedOnSave(); } PaintingSystem.PaintingSystem.Save(); - foreach (var modParts in modsParts) - { + foreach (var modParts in modsParts) { var mod = ModLoader.GetMod(modParts.Key); - if (!modSaveFileMapping.TryGetValue(mod.ID, out var saveFileName)) - { + if (!modSaveFileMapping.TryGetValue(mod.ID, out var saveFileName)) { //save file for mod can't be found, skip the whole mod. continue; } var modPartSaves = new Dictionary(); - foreach (var partData in modParts.Value) - { + foreach (var partData in modParts.Value) { var id = partData.Key; var part = partData.Value; - try - { + try { part.CustomSaveSaving(mod, $"{id}_saveFile.json"); } - catch - { + catch { // ignored } @@ -167,20 +165,18 @@ private void Save() private new void Update() { - if (updateLocked) - { + if (updateLocked) { return; } + Shop.Handle(); #if DEBUG InstantInstallDebug(); #endif var toolInHand = tool.GetToolInHand(); - if (toolInHand == Tool.ToolType.None) - { - if (previousScrew != null) - { + if (toolInHand == Tool.ToolType.None) { + if (previousScrew != null) { previousScrew.Highlight(false); previousScrew = null; } @@ -192,13 +188,11 @@ private void Save() if (screw == null) return; - if (screw.part.screwPlacementMode) - { + if (screw.part.screwPlacementMode) { return; } - if (ShowScrewSize && screw.showSize) - { + if (ShowScrewSize && screw.showSize) { UserInteraction.GuiInteraction($"Screw size: {screw.size.ToString("#.#").Replace(".00", "")}mm"); } @@ -208,10 +202,8 @@ private void Save() if (!tool.CheckBoltingSpeed()) return; - if (UserInteraction.MouseScrollWheel.Up) - { - switch (toolInHand) - { + if (UserInteraction.MouseScrollWheel.Up) { + switch (toolInHand) { case Tool.ToolType.RatchetTighten: screw.In(); break; @@ -223,10 +215,8 @@ private void Save() break; } } - else if (UserInteraction.MouseScrollWheel.Down) - { - switch (toolInHand) - { + else if (UserInteraction.MouseScrollWheel.Down) { + switch (toolInHand) { case Tool.ToolType.RatchetTighten: screw.In(); break; @@ -242,8 +232,7 @@ private void Save() #if DEBUG private void InstantInstallDebug() { - if (!(bool)enableInstantInstall.Value) - { + if (!(bool)enableInstantInstall.Value) { return; } @@ -253,13 +242,10 @@ private void InstantInstallDebug() if (hit.collider == null) return; var gameObject = hit.collider.gameObject; Part part = null; - foreach (var modParts in modsParts) - { - foreach (var partData in modParts.Value) - { + foreach (var modParts in modsParts) { + foreach (var partData in modParts.Value) { var partName = partData.Value.gameObject.name; - if (partName == gameObject.name) - { + if (partName == gameObject.name) { part = partData.Value; break; } @@ -268,46 +254,37 @@ private void InstantInstallDebug() if (part != null) break; } - if (part == null || !part.hasParent || part.screwPlacementMode) - { + if (part == null || !part.hasParent || part.screwPlacementMode) { return; } - if (part.installBlocked) - { + if (part.installBlocked) { UserInteraction.GuiInteraction("Installation is blocked"); return; } - if (!part.bolted) - { - if (part.installed) - { + if (!part.bolted) { + if (part.installed) { UserInteraction.GuiInteraction("Tighten all screws"); - if (instantInstallKeybind.GetKeybindDown()) - { + if (instantInstallKeybind.GetKeybindDown()) { part.partSave.screws.ForEach(delegate(Screw screw) { screw.InBy(Screw.maxTightness - screw.tightness); }); } } - else - { + else { UserInteraction.GuiInteraction("Fully install part"); - if (instantInstallKeybind.GetKeybindDown()) - { + if (instantInstallKeybind.GetKeybindDown()) { part.Install(); part.partSave.screws.ForEach(delegate(Screw screw) { screw.InBy(Screw.maxTightness); }); } } } - else - { + else { UserInteraction.GuiInteraction("Loosen all screws"); - if (instantInstallKeybind.GetKeybindDown()) - { + if (instantInstallKeybind.GetKeybindDown()) { part.partSave.screws.ForEach(delegate(Screw screw) { screw.OutBy(Screw.maxTightness); }); } } @@ -315,25 +292,21 @@ private void InstantInstallDebug() #endif private Screw DetectScrew() { - if (previousScrew != null) - { + if (previousScrew != null) { previousScrew.Highlight(false); previousScrew = null; } - if (Camera.main == null) - { + if (Camera.main == null) { return null; } if (!Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out var hit, 1f, - 1 << LayerMask.NameToLayer("DontCollide"))) - { + 1 << LayerMask.NameToLayer("DontCollide"))) { return null; } - if (!hit.collider) - { + if (!hit.collider) { return null; } diff --git a/Source code/MscModApi/PaintingSystem/PaintingStorage.cs b/Source code/MscModApi/PaintingSystem/PaintingStorage.cs index 3bd4890..cb15869 100644 --- a/Source code/MscModApi/PaintingSystem/PaintingStorage.cs +++ b/Source code/MscModApi/PaintingSystem/PaintingStorage.cs @@ -53,10 +53,8 @@ internal Color GetColorOfMaterial(Material material) public PaintingStorage SetMetallic(float metallic, float glossiness) { - foreach (var pair in paintMaterialConfig) - { - foreach (Material material in pair.Value) - { + foreach (var pair in paintMaterialConfig) { + foreach (Material material in pair.Value) { material.SetFloat("_Metallic", metallic); material.SetFloat("_Glossiness", glossiness); } @@ -67,10 +65,8 @@ public PaintingStorage SetMetallic(float metallic, float glossiness) public PaintingStorage SetColor(Color color) { - foreach (var pair in paintMaterialConfig) - { - foreach (Material material in pair.Value) - { + foreach (var pair in paintMaterialConfig) { + foreach (Material material in pair.Value) { SetColorOfMaterial(material, color); } } @@ -80,10 +76,8 @@ public PaintingStorage SetColor(Color color) public PaintingStorage SetColor(Color color, Color emisionColor, Color specColor) { - foreach (var pair in paintMaterialConfig) - { - foreach (Material material in pair.Value) - { + foreach (var pair in paintMaterialConfig) { + foreach (Material material in pair.Value) { SetColorOfMaterial(material, color); material.SetColor("_EmissionColor", emisionColor); material.SetColor("_SpecColor", specColor); @@ -98,33 +92,29 @@ public PaintingStorage ApplyMaterial(string materialName, bool withColor = false return ApplyMaterial(PaintingSystem.FindMaterial(materialName), withColor); } - public PaintingStorage ApplyMaterial(Material materialToApply, bool withColor = false, bool withMainTexture = false) + public PaintingStorage ApplyMaterial(Material materialToApply, bool withColor = false, + bool withMainTexture = false) { - if (materialToApply == null) - { + if (materialToApply == null) { return this; } - foreach (var pair in paintMaterialConfig) - { + foreach (var pair in paintMaterialConfig) { pair.Value.Clear(); - foreach (Renderer renderer in pair.Key.GetComponentsInChildren(true)) - { + foreach (Renderer renderer in pair.Key.GetComponentsInChildren(true)) { Texture oldMainTexture = renderer.material.GetTexture("_MainTex"); Color oldColor = GetColorOfMaterial(renderer.material); renderer.material = materialToApply; - if (!withColor) - { + if (!withColor) { SetColorOfMaterial(renderer.material, oldColor); } - if (!withMainTexture) - { + if (!withMainTexture) { renderer.material.SetTexture("_MainTex", oldMainTexture); } - + pair.Value.Add(renderer.material); } diff --git a/Source code/MscModApi/PaintingSystem/PaintingSystem.cs b/Source code/MscModApi/PaintingSystem/PaintingSystem.cs index 2e2b93b..a83559a 100644 --- a/Source code/MscModApi/PaintingSystem/PaintingSystem.cs +++ b/Source code/MscModApi/PaintingSystem/PaintingSystem.cs @@ -28,22 +28,20 @@ private enum State private static Dictionary> modSave; - public static PaintingStorage Setup(Mod mod, string id, GameObject paintDetector, Dictionary> paintConfig) + public static PaintingStorage Setup(Mod mod, string id, GameObject paintDetector, + Dictionary> paintConfig) { - if (!storage.ContainsKey(mod)) - { + if (!storage.ContainsKey(mod)) { storage.Add(mod, new List()); } Dictionary colorSave = new Dictionary(); - if (!modSave.ContainsKey(mod)) - { + if (!modSave.ContainsKey(mod)) { colorSave = Helper.LoadSaveOrReturnNew>(mod, "paintingSystem_saveFile.json"); modSave.Add(mod, colorSave); } - else - { + else { colorSave = modSave[mod]; } @@ -53,22 +51,18 @@ public static PaintingStorage Setup(Mod mod, string id, GameObject paintDetector Dictionary> collectedPaintMaterialConfig = new Dictionary>(); - foreach (var pair in paintConfig) - { + foreach (var pair in paintConfig) { List rebuildMaterialList = new List(); - foreach (var materialName in pair.Value) - { + foreach (var materialName in pair.Value) { rebuildMaterialList.Add(materialName); rebuildMaterialList.Add(materialName + " (Instance)"); } List materialsToPaint = new List(); - foreach (Renderer renderer in pair.Key.GetComponentsInChildren(true)) - { - if (rebuildMaterialList.Contains(renderer.material.name) || pair.Value.Count == 0) - { + foreach (Renderer renderer in pair.Key.GetComponentsInChildren(true)) { + if (rebuildMaterialList.Contains(renderer.material.name) || pair.Value.Count == 0) { materialsToPaint.Add(renderer.material); } /* @@ -88,8 +82,7 @@ public static PaintingStorage Setup(Mod mod, string id, GameObject paintDetector PaintingStorage paintingStorage = new PaintingStorage(mod, id, collectedPaintMaterialConfig); - if (colorSave.ContainsKey(id)) - { + if (colorSave.ContainsKey(id)) { paintingStorage.SetColor(colorSave[id]); } @@ -173,10 +166,8 @@ internal static Color GetCurrentColor() internal static Material FindMaterial(string name) { - foreach (Material material in availableMaterials) - { - if (material.name == name) - { + foreach (Material material in availableMaterials) { + if (material.name == name) { return material; } } @@ -186,11 +177,9 @@ internal static Material FindMaterial(string name) public static void Save() { - foreach (var modPaintData in storage) - { + foreach (var modPaintData in storage) { Dictionary colorSave = new Dictionary(); - foreach (PaintingStorage paintingData in modPaintData.Value) - { + foreach (PaintingStorage paintingData in modPaintData.Value) { colorSave.Add(paintingData.GetPaintingId(), paintingData.GetCurrentColor()); } diff --git a/Source code/MscModApi/PaintingSystem/PaintingSystemLogic.cs b/Source code/MscModApi/PaintingSystem/PaintingSystemLogic.cs index 2b73a01..5b575e4 100644 --- a/Source code/MscModApi/PaintingSystem/PaintingSystemLogic.cs +++ b/Source code/MscModApi/PaintingSystem/PaintingSystemLogic.cs @@ -14,17 +14,14 @@ public class PaintingSystemLogic : MonoBehaviour void Update() { - if (!PaintingSystem.IsPainting() || !gameObject.IsLookingAt()) - { + if (!PaintingSystem.IsPainting() || !gameObject.IsLookingAt()) { return; } Color color = PaintingSystem.GetCurrentColor(); - foreach (var pair in paintingStorage.GetGameObjectMaterialConfig()) - { - foreach (Material material in pair.Value) - { + foreach (var pair in paintingStorage.GetGameObjectMaterialConfig()) { + foreach (Material material in pair.Value) { paintingStorage.SetColorOfMaterial(material, color); } } diff --git a/Source code/MscModApi/Parts/BasicPart.cs b/Source code/MscModApi/Parts/BasicPart.cs index 516fc66..95de35c 100644 --- a/Source code/MscModApi/Parts/BasicPart.cs +++ b/Source code/MscModApi/Parts/BasicPart.cs @@ -53,21 +53,15 @@ public abstract class BasicPart /// Returns if the player is currently looking at this part /// public abstract bool isLookingAt { get; } - + /// /// Returns if the player is currently holding this part /// public abstract bool isHolding { get; } - public abstract bool installed - { - get; - } + public abstract bool installed { get; } - public abstract bool bolted - { - get; - } + public abstract bool bolted { get; } /// /// Resets the part to its defaultPosition & defaultRotation diff --git a/Source code/MscModApi/Parts/Box.cs b/Source code/MscModApi/Parts/Box.cs index 01a46d0..13c4e17 100644 --- a/Source code/MscModApi/Parts/Box.cs +++ b/Source code/MscModApi/Parts/Box.cs @@ -110,8 +110,7 @@ protected void Setup(string boxName, string partId, string partName, GameObject PartBaseInfo partBaseInfo = parent.partBaseInfo; - for (int i = 0; i < numberOfParts; i++) - { + for (int i = 0; i < numberOfParts; i++) { int iOffset = i + 1; Part part = new Part( @@ -119,8 +118,7 @@ protected void Setup(string boxName, string partId, string partName, GameObject parent, installLocations[i], installRotations[i], partBaseInfo, uninstallWhenParentUninstalls, disableCollisionWhenInstalled); part.defaultPosition = defaultPosition; - if (!part.bought) - { + if (!part.bought) { part.Uninstall(); part.active = false; } @@ -141,8 +139,7 @@ protected void Setup(string boxName, string partId, string partName, GameObject /// protected void AddScrews(Screw[] screws, float overrideScale = 0f, float overrideSize = 0f) { - foreach (Part part in parts) - { + foreach (Part part in parts) { part.AddScrews(screws.CloneToNew(), overrideScale, overrideSize); } } diff --git a/Source code/MscModApi/Parts/BoxLogic.cs b/Source code/MscModApi/Parts/BoxLogic.cs index 1e17042..c6505a9 100644 --- a/Source code/MscModApi/Parts/BoxLogic.cs +++ b/Source code/MscModApi/Parts/BoxLogic.cs @@ -12,20 +12,17 @@ public class BoxLogic : MonoBehaviour void Update() { - if (box.hasPartsToUnpack && box.isLookingAt) - { + if (box.hasPartsToUnpack && box.isLookingAt) { Part nextPart = box.parts[box.partsUnpackedCount]; - UserInteraction.GuiInteraction($"Press [{cInput.GetText("Use")}] to Unpack {nextPart.cleanName}" ); - if (UserInteraction.UseButtonDown) - { + UserInteraction.GuiInteraction($"Press [{cInput.GetText("Use")}] to Unpack {nextPart.cleanName}"); + if (UserInteraction.UseButtonDown) { nextPart.position = gameObject.transform.position + gameObject.transform.up * 0.3f; nextPart.active = true; box.IncrementUnpackedCount(); } } - if (!box.hasPartsToUnpack) - { + if (!box.hasPartsToUnpack) { box.active = false; } } diff --git a/Source code/MscModApi/Parts/Kit.cs b/Source code/MscModApi/Parts/Kit.cs index 221a6a6..9e86039 100644 --- a/Source code/MscModApi/Parts/Kit.cs +++ b/Source code/MscModApi/Parts/Kit.cs @@ -35,10 +35,8 @@ private void Setup(string name, GameObject boxModel, Part[] parts) AddParts(parts); - if (!bought) - { - foreach (Part part in this.parts) - { + if (!bought) { + foreach (Part part in this.parts) { part.Uninstall(); part.active = false; } diff --git a/Source code/MscModApi/Parts/Part.cs b/Source code/MscModApi/Parts/Part.cs index aa7cb04..45ef921 100644 --- a/Source code/MscModApi/Parts/Part.cs +++ b/Source code/MscModApi/Parts/Part.cs @@ -9,8 +9,6 @@ namespace MscModApi.Parts { - - public class Part : BasicPart, SupportsPartEvents { protected static GameObject clampModel; @@ -31,37 +29,17 @@ public class Part : BasicPart, SupportsPartEvents public bool uninstallWhenParentUninstalls { get; protected set; } - public GameObject parentGameObject - { - get; - protected set; - } - public Part parentPart - { - get; - protected set; - } + public GameObject parentGameObject { get; protected set; } + public Part parentPart { get; protected set; } protected List savedScrews; - public Collider collider - { - get; - protected set; - } + public Collider collider { get; protected set; } - public TriggerWrapper trigger - { - get; - protected set; - } + public TriggerWrapper trigger { get; protected set; } public Transform transform => gameObject.transform; - - public GameObject gameObjectUsedForInstantiation - { - get; - protected set; - } + + public GameObject gameObjectUsedForInstantiation { get; protected set; } public bool usingPartParent => parentPart != null; protected Dictionary preScrewPlacementModeEnableTightnessMap = new Dictionary(); @@ -81,26 +59,18 @@ public bool screwPlacementMode get => _screwPlacementMode; set { - if (!installed) - { + if (!installed) { return; } - if (!injectedScrewPlacementDisablePreUninstall) - { + if (!injectedScrewPlacementDisablePreUninstall) { injectedScrewPlacementDisablePreUninstall = true; - AddEventListener(EventTime.Pre, EventType.Uninstall, () => - { - this.screwPlacementMode = false; - }); + AddEventListener(EventTime.Pre, EventType.Uninstall, () => { this.screwPlacementMode = false; }); } - foreach (Screw screw in screws) - { - if (!value) - { - if (!preScrewPlacementModeEnableTightnessMap.TryGetValue(screw, out int preEnableTightness)) - { + foreach (Screw screw in screws) { + if (!value) { + if (!preScrewPlacementModeEnableTightnessMap.TryGetValue(screw, out int preEnableTightness)) { continue; } @@ -111,17 +81,16 @@ public bool screwPlacementMode continue; } - if (preScrewPlacementModeEnableTightnessMap.ContainsKey(screw)) - { + if (preScrewPlacementModeEnableTightnessMap.ContainsKey(screw)) { continue; } + preScrewPlacementModeEnableTightnessMap.Add(screw, screw.tightness); screw.InBy(Screw.maxTightness); screw.tightness = 0; } - if (!value && ScrewPlacementAssist.selectedPart == this) - { + if (!value && ScrewPlacementAssist.selectedPart == this) { ScrewPlacementAssist.HidePartInteraction(); } @@ -193,11 +162,8 @@ protected void Setup(string id, string name, GameObject parentGameObject, Vector this.installRotation = installRotation; this.parentGameObject = parentGameObject; - if (!usingPartParent) - { - try - { - + if (!usingPartParent) { + try { PlayMakerFSM parentRemovalFsm = parentGameObject.FindFsm("Removal"); /* @@ -206,8 +172,7 @@ protected void Setup(string id, string name, GameObject parentGameObject, Vector removalFsm.InitializeFSM(); } */ - if (!parentRemovalFsm.Fsm.Initialized) - { + if (!parentRemovalFsm.Fsm.Initialized) { parentRemovalFsm.InitializeFSM(); } @@ -215,33 +180,27 @@ protected void Setup(string id, string name, GameObject parentGameObject, Vector PlayMakerFSM fsmPartDataFsm = fsmPartGameObject.FindFsm("Data"); parentGameObjectBolted = fsmPartDataFsm.FsmVariables.FindFsmBool("Bolted"); } - catch (Exception) - { + catch (Exception) { // ignored } } - if (gameObjectUsedForInstantiation != null) - { + if (gameObjectUsedForInstantiation != null) { gameObject = GameObject.Instantiate(gameObjectUsedForInstantiation); gameObject.SetNameLayerTag(name + "(Clone)", "PART", "Parts"); } - else - { + else { gameObject = Helper.LoadPartAndSetName(partBaseInfo.assetBundle, prefabName ?? id, name); } - if (!partBaseInfo.partsSave.TryGetValue(id, out partSave)) - { + if (!partBaseInfo.partsSave.TryGetValue(id, out partSave)) { partSave = new PartSave(); } - try - { + try { CustomSaveLoading(partBaseInfo.mod, $"{id}_saveFile.json"); } - catch - { + catch { // ignored } @@ -250,29 +209,24 @@ protected void Setup(string id, string name, GameObject parentGameObject, Vector collider = gameObject.GetComponent(); - if (parentGameObject != null) - { + if (parentGameObject != null) { trigger = new TriggerWrapper(this, parentGameObject, disableCollisionWhenInstalled); } - if (partSave.installed) - { + if (partSave.installed) { Install(); } LoadPartPositionAndRotation(gameObject, partSave); - if (!MscModApi.modSaveFileMapping.ContainsKey(partBaseInfo.mod.ID)) - { + if (!MscModApi.modSaveFileMapping.ContainsKey(partBaseInfo.mod.ID)) { MscModApi.modSaveFileMapping.Add(partBaseInfo.mod.ID, partBaseInfo.saveFilePath); } - if (MscModApi.modsParts.TryGetValue(partBaseInfo.mod.ID, out var modParts)) - { + if (MscModApi.modsParts.TryGetValue(partBaseInfo.mod.ID, out var modParts)) { modParts.Add(id, this); } - else - { + else { MscModApi.modsParts.Add(partBaseInfo.mod.ID, new Dictionary { { id, this } @@ -284,12 +238,10 @@ protected void Setup(string id, string name, GameObject parentGameObject, Vector protected void InitEventStorage() { - foreach (EventTime eventTime in Enum.GetValues(typeof(EventTime))) - { + foreach (EventTime eventTime in Enum.GetValues(typeof(EventTime))) { Dictionary> eventTypeDict = new Dictionary>(); - foreach (EventType eventType in Enum.GetValues(typeof(EventType))) - { + foreach (EventType eventType in Enum.GetValues(typeof(EventType))) { eventTypeDict.Add(eventType, new List()); } @@ -314,12 +266,10 @@ public bool parentInstalled { get { - if (usingPartParent) - { + if (usingPartParent) { return parentPart.installed; } - else - { + else { return parentGameObject.transform.parent != null; } } @@ -329,12 +279,10 @@ public bool parentBolted { get { - if (usingPartParent) - { + if (usingPartParent) { return parentPart.bolted; } - else - { + else { return parentGameObjectBolted.Value; } } @@ -353,8 +301,7 @@ public override Vector3 position get => gameObject.transform.position; set { - if (!installed) - { + if (!installed) { gameObject.transform.position = value; } } @@ -366,8 +313,7 @@ public override Vector3 rotation get => gameObject.transform.rotation.eulerAngles; set { - if (!installed) - { + if (!installed) { gameObject.transform.rotation = Quaternion.Euler(value); } } @@ -382,8 +328,7 @@ public override bool active internal void ResetScrews() { - foreach (var screw in partSave.screws) - { + foreach (var screw in partSave.screws) { screw.OutBy(screw.tightness); } } @@ -398,7 +343,7 @@ internal void SetScrewsActive(bool active) { partSave.screws.ForEach(delegate(Screw screw) { screw.gameObject.SetActive(active); }); } - + public void Install() { trigger?.Install(); @@ -418,17 +363,14 @@ public bool IsFixed(bool ignoreUnsetScrews = true) public override bool bolted { - get - { - return screws.Count > 0 && screws.All(screw => screw.tightness == Screw.maxTightness) && installed; - } + get { return screws.Count > 0 && screws.All(screw => screw.tightness == Screw.maxTightness) && installed; } } public void Uninstall() { trigger?.Uninstall(); } - + public void AddClampModel(Vector3 position, Vector3 rotation, Vector3 scale) { var clamp = GameObject.Instantiate(clampModel); @@ -486,15 +428,12 @@ internal static void LoadAssets(AssetBundle assetBundle) public void AddScrews(Screw[] screws, float overrideScale = 0f, float overrideSize = 0f) { - foreach (var screw in screws) - { - if (overrideScale != 0f) - { + foreach (var screw in screws) { + if (overrideScale != 0f) { screw.scale = overrideScale; } - if (overrideSize != 0f) - { + if (overrideSize != 0f) { screw.size = overrideSize; } @@ -595,34 +534,32 @@ public void AddEventListener(EventTime eventTime, EventType eventType, Action ac { events[eventTime][eventType].Add(action); - if (eventTime == EventTime.Post) - { - switch (eventType) - { + if (eventTime == EventTime.Post) { + switch (eventType) { //ToDo: check if invoking just the newly added action is enough of if all have to be invoked case EventType.Install: - if (installed) - { + if (installed) { action.Invoke(); } + break; case EventType.Uninstall: - if (!installed) - { + if (!installed) { action.Invoke(); } + break; case EventType.Bolted: - if (bolted) - { + if (bolted) { action.Invoke(); } + break; case EventType.Unbolted: - if (!bolted) - { + if (!bolted) { action.Invoke(); } + break; } } @@ -640,8 +577,7 @@ public List GetEvents(EventTime eventTime, EventType eventType) /// public override void ResetToDefault(bool uninstall = false) { - if (uninstall && installed) - { + if (uninstall && installed) { Uninstall(); } diff --git a/Source code/MscModApi/Parts/PartBaseInfo.cs b/Source code/MscModApi/Parts/PartBaseInfo.cs index 01a812d..d704c79 100644 --- a/Source code/MscModApi/Parts/PartBaseInfo.cs +++ b/Source code/MscModApi/Parts/PartBaseInfo.cs @@ -14,7 +14,8 @@ public class PartBaseInfo private List partsList; internal Dictionary partsSave; - public PartBaseInfo(Mod mod, AssetBundle assetBundle, List partsList = null, string saveFilePath = "parts_saveFile.json") + public PartBaseInfo(Mod mod, AssetBundle assetBundle, List partsList = null, + string saveFilePath = "parts_saveFile.json") { this.mod = mod; this.assetBundle = assetBundle; diff --git a/Source code/MscModApi/Parts/PartBox.cs b/Source code/MscModApi/Parts/PartBox.cs index 8343a0f..68fc373 100644 --- a/Source code/MscModApi/Parts/PartBox.cs +++ b/Source code/MscModApi/Parts/PartBox.cs @@ -33,8 +33,7 @@ public abstract class PartBox : BasicPart internal void IncrementUnpackedCount() { - if (!hasPartsToUnpack) - { + if (!hasPartsToUnpack) { return; } @@ -87,8 +86,7 @@ public override bool bought get { return parts.Any(part => part.bought); } set { - foreach (Part part in parts) - { + foreach (Part part in parts) { part.bought = value; } } @@ -121,15 +119,12 @@ public override bool active /// public void CheckUnpackedOnSave() { - if (!bought) - { + if (!bought) { return; } - if (hasPartsToUnpack) - { - foreach (var part in parts.Where(part => !part.installed && !part.gameObject.activeSelf)) - { + if (hasPartsToUnpack) { + foreach (var part in parts.Where(part => !part.installed && !part.gameObject.activeSelf)) { part.position = boxModel.transform.position; part.active = active; } @@ -146,16 +141,13 @@ public void CheckUnpackedOnSave() /// Should an installed part be uninstalled prior to resetting public override void ResetToDefault(bool uninstall = false) { - if (active) - { + if (active) { position = defaultPosition; rotation = defaultRotation; } - foreach (Part part in parts) - { - if (uninstall && part.installed) - { + foreach (Part part in parts) { + if (uninstall && part.installed) { part.Uninstall(); } @@ -179,8 +171,7 @@ protected void AddPart(Part part) /// protected void AddParts(IEnumerable parts) { - foreach (Part part in parts) - { + foreach (Part part in parts) { AddPart(part); } } diff --git a/Source code/MscModApi/Parts/ReplacePart/GamePart.cs b/Source code/MscModApi/Parts/ReplacePart/GamePart.cs index 18c2136..348fb0c 100644 --- a/Source code/MscModApi/Parts/ReplacePart/GamePart.cs +++ b/Source code/MscModApi/Parts/ReplacePart/GamePart.cs @@ -25,7 +25,7 @@ public class GamePart : BasicPart, SupportsPartEvents /// Flag used to avoid calling the pre bolted event multiple times /// protected bool alreadyCalledPreBolted; - + /// /// Flag used to avoid calling the post bolted event multiple times /// @@ -57,27 +57,25 @@ public GamePart(string mainFsmPartName, bool simpleBoltedStateDetection = true) InitEventStorage(); this.simpleBoltedStateDetection = simpleBoltedStateDetection; mainFsmGameObject = Cache.Find(mainFsmPartName); - if (!mainFsmGameObject) - { + if (!mainFsmGameObject) { throw new Exception($"Unable to find main fsm part GameObject using '{mainFsmPartName}'"); } dataFsm = mainFsmGameObject.FindFsm("Data"); - if (!dataFsm) - { + if (!dataFsm) { throw new Exception($"Unable to find data fsm on GameObject with name '{mainFsmGameObject.name}'"); } triggerFsmGameObject = dataFsm.FsmVariables.FindFsmGameObject("Trigger").Value; - if (!triggerFsmGameObject) - { - throw new Exception($"Unable to find trigger GameObject on GameObject with name '{mainFsmGameObject.name}'"); + if (!triggerFsmGameObject) { + throw new Exception( + $"Unable to find trigger GameObject on GameObject with name '{mainFsmGameObject.name}'"); } partFsmGameObject = dataFsm.FsmVariables.FindFsmGameObject("ThisPart").Value; - if (!partFsmGameObject) - { - throw new Exception($"Unable to find part GameObject on GameObject with name '{mainFsmGameObject.name}'"); + if (!partFsmGameObject) { + throw new Exception( + $"Unable to find part GameObject on GameObject with name '{mainFsmGameObject.name}'"); } boltedState = dataFsm.FsmVariables.FindFsmBool("Bolted"); @@ -89,60 +87,44 @@ public GamePart(string mainFsmPartName, bool simpleBoltedStateDetection = true) removalFsm = partFsmGameObject.FindFsm("Removal"); boltCheckFsm = partFsmGameObject.FindFsm("BoltCheck"); - if (!assemblyFsm.Fsm.Initialized) - { + if (!assemblyFsm.Fsm.Initialized) { assemblyFsm.InitializeFSM(); } - if (!removalFsm.Fsm.Initialized) - { + if (!removalFsm.Fsm.Initialized) { removalFsm.InitializeFSM(); } - if (!boltCheckFsm.Fsm.Initialized) - { + if (!boltCheckFsm.Fsm.Initialized) { boltCheckFsm.InitializeFSM(); } tightness = boltCheckFsm.FsmVariables.FindFsmFloat("Tightness"); - AddActionAsFirst(assemblyFsm.FindState("Assemble"), () => - { - GetEvents(EventTime.Pre, EventType.Install).InvokeAll(); - }); + AddActionAsFirst(assemblyFsm.FindState("Assemble"), + () => { GetEvents(EventTime.Pre, EventType.Install).InvokeAll(); }); - AddActionAsLast(assemblyFsm.FindState("End"), () => - { - GetEvents(EventTime.Post, EventType.Install).InvokeAll(); - }); + AddActionAsLast(assemblyFsm.FindState("End"), + () => { GetEvents(EventTime.Post, EventType.Install).InvokeAll(); }); - AddActionAsFirst(removalFsm.FindState("Remove part"), () => - { - GetEvents(EventTime.Pre, EventType.Uninstall).InvokeAll(); - }); - AddActionAsLast(removalFsm.FindState("Remove part"), () => - { - GetEvents(EventTime.Post, EventType.Uninstall).InvokeAll(); - }); + AddActionAsFirst(removalFsm.FindState("Remove part"), + () => { GetEvents(EventTime.Pre, EventType.Uninstall).InvokeAll(); }); + AddActionAsLast(removalFsm.FindState("Remove part"), + () => { GetEvents(EventTime.Post, EventType.Uninstall).InvokeAll(); }); - if (tightness == null) - { + if (tightness == null) { throw new Exception($"Unable to find tightness on bolt check fsm of part '{partFsmGameObject.name}'"); } - if (boltedState != null) - { - if (simpleBoltedStateDetection) - { + if (boltedState != null) { + if (simpleBoltedStateDetection) { SetupSimpleBoltedStateDetection(); } - else - { + else { SetupAdvancedBoltedStateDetection(); } } - else - { + else { boltedState = new FsmBool(); //Avoiding null } } @@ -153,30 +135,25 @@ public GamePart(string mainFsmPartName, bool simpleBoltedStateDetection = true) protected void SetupAdvancedBoltedStateDetection() { GameObject boltsGameObject = partFsmGameObject.FindChild("Bolts"); - if (!boltsGameObject) - { - ModConsole.Print($"GamePart: Unable to find 'Bolts' child of '{partFsmGameObject.name}'. Bolted event listening not possible"); + if (!boltsGameObject) { + ModConsole.Print( + $"GamePart: Unable to find 'Bolts' child of '{partFsmGameObject.name}'. Bolted event listening not possible"); } - for (int i = 0; i < boltsGameObject.transform.childCount; i++) - { + for (int i = 0; i < boltsGameObject.transform.childCount; i++) { GameObject boltGameObject; - try - { + try { boltGameObject = boltsGameObject.transform.GetChild(i).gameObject; - if (!boltGameObject) - { + if (!boltGameObject) { throw new Exception("Null GameObject"); } } - catch (Exception) - { + catch (Exception) { continue; } PlayMakerFSM boltFsm = boltGameObject.FindFsm("Screw"); - if (!boltFsm) - { + if (!boltFsm) { continue; } @@ -184,13 +161,11 @@ protected void SetupAdvancedBoltedStateDetection() FsmState tightState = boltFsm.FindState("8 2"); FsmState unscrewPreState = boltFsm.FindState("Unscrew 2"); FsmState unscrewPostState = boltFsm.FindState("Wait 4"); - if (tightState == null || unscrewPreState == null || unscrewPostState == null) - { + if (tightState == null || unscrewPreState == null || unscrewPostState == null) { return; } - if (!boltFsm.Fsm.Initialized) - { + if (!boltFsm.Fsm.Initialized) { boltFsm.InitializeFSM(); } @@ -213,10 +188,10 @@ protected void SetupSimpleBoltedStateDetection() { alreadyCalledPreBolted = false; - if (alreadyCalledPreUnbolted) - { + if (alreadyCalledPreUnbolted) { return; } + GetEvents(EventTime.Pre, EventType.Uninstall).InvokeAll(); }); AddActionAsLast(boltCheckFsm.FindState("Bolts OFF"), () => @@ -224,10 +199,10 @@ protected void SetupSimpleBoltedStateDetection() alreadyCalledPostBolted = false; - if (alreadyCalledPostUnbolted) - { + if (alreadyCalledPostUnbolted) { return; } + GetEvents(EventTime.Post, EventType.Uninstall).InvokeAll(); }); @@ -236,10 +211,10 @@ protected void SetupSimpleBoltedStateDetection() { alreadyCalledPreUnbolted = false; - if (alreadyCalledPreBolted) - { + if (alreadyCalledPreBolted) { return; } + GetEvents(EventTime.Pre, EventType.Install).InvokeAll(); }); AddActionAsLast(boltCheckFsm.FindState("Bolts ON"), () => @@ -247,10 +222,10 @@ protected void SetupSimpleBoltedStateDetection() alreadyCalledPostUnbolted = false; - if (alreadyCalledPostBolted) - { + if (alreadyCalledPostBolted) { return; } + GetEvents(EventTime.Post, EventType.Install).InvokeAll(); }); } @@ -260,12 +235,10 @@ protected void SetupSimpleBoltedStateDetection() /// protected void InitEventStorage() { - foreach (EventTime eventTime in Enum.GetValues(typeof(EventTime))) - { + foreach (EventTime eventTime in Enum.GetValues(typeof(EventTime))) { Dictionary> eventTypeDict = new Dictionary>(); - foreach (EventType eventType in Enum.GetValues(typeof(EventType))) - { + foreach (EventType eventType in Enum.GetValues(typeof(EventType))) { eventTypeDict.Add(eventType, new List()); } @@ -276,7 +249,11 @@ protected void InitEventStorage() /// /// Block installation of the part by disabling the trigger object /// - public bool installBlocked { get => triggerFsmGameObject.activeSelf; set => triggerFsmGameObject.SetActive(!value); } + public bool installBlocked + { + get => triggerFsmGameObject.activeSelf; + set => triggerFsmGameObject.SetActive(!value); + } /// /// The parts tightness (sum of all screw tightness (8 x screw count = all bolted)) @@ -363,8 +340,7 @@ public override Vector3 position get => partFsmGameObject.transform.position; set { - if (!installed) - { + if (!installed) { partFsmGameObject.transform.position = value; } } @@ -376,8 +352,7 @@ public override Vector3 rotation get => partFsmGameObject.transform.rotation.eulerAngles; set { - if (!installed) - { + if (!installed) { partFsmGameObject.transform.rotation = Quaternion.Euler(value); } } @@ -395,8 +370,7 @@ public override bool bolted { get { - if (simpleBoltedStateDetection) - { + if (simpleBoltedStateDetection) { return boltedState.Value; } @@ -430,8 +404,7 @@ public void Uninstall() public override void ResetToDefault(bool uninstall = false) { - if (uninstall && installed) - { + if (uninstall && installed) { Uninstall(); } @@ -444,8 +417,7 @@ public override void ResetToDefault(bool uninstall = false) /// protected void AddActionAsFirst(FsmState fsmState, Action action) { - if (fsmState == null) - { + if (fsmState == null) { return; } @@ -459,8 +431,7 @@ protected void AddActionAsFirst(FsmState fsmState, Action action) /// protected void AddActionAsLast(FsmState fsmState, Action action) { - if (fsmState == null) - { + if (fsmState == null) { return; } @@ -477,11 +448,9 @@ protected void OnUnscrew(EventTime eventTime) alreadyCalledPreBolted = false; alreadyCalledPostBolted = false; - switch (eventTime) - { + switch (eventTime) { case EventTime.Pre: - if (alreadyCalledPreUnbolted) - { + if (alreadyCalledPreUnbolted) { return; } @@ -489,8 +458,7 @@ protected void OnUnscrew(EventTime eventTime) GetEvents(EventTime.Pre, EventType.Unbolted).InvokeAll(); break; case EventTime.Post: - if (alreadyCalledPostUnbolted) - { + if (alreadyCalledPostUnbolted) { return; } @@ -506,20 +474,17 @@ protected void OnUnscrew(EventTime eventTime) /// protected void OnTight(EventTime eventTime) { - if (tightness.Value < maxTightness) - { + if (tightness.Value < maxTightness) { return; //Wait for all screws to be tight } - + alreadyCalledPreUnbolted = false; alreadyCalledPostUnbolted = false; - switch (eventTime) - { + switch (eventTime) { case EventTime.Pre: - if (alreadyCalledPreBolted) - { + if (alreadyCalledPreBolted) { return; } @@ -527,8 +492,7 @@ protected void OnTight(EventTime eventTime) GetEvents(EventTime.Pre, EventType.Bolted).InvokeAll(); break; case EventTime.Post: - if (alreadyCalledPostBolted) - { + if (alreadyCalledPostBolted) { return; } @@ -554,36 +518,34 @@ public void AddEventListener(EventTime eventTime, EventType eventType, Action ac { events[eventTime][eventType].Add(action); - if (eventTime == EventTime.Post) - { - switch (eventType) - { + if (eventTime == EventTime.Post) { + switch (eventType) { //ToDo: check if invoking just the newly added action is enough of if all have to be invoked case EventType.Install: - if (installed) - { + if (installed) { action.Invoke(); } + break; case EventType.Uninstall: - if (!installed) - { + if (!installed) { action.Invoke(); } + break; case EventType.Bolted: - if (bolted) - { + if (bolted) { //ToDo: bolted state should only be true if maxTightness is also reached action.Invoke(); } + break; case EventType.Unbolted: - if (!bolted) - { + if (!bolted) { //ToDo: bolted state should only be true if maxTightness is also reached action.Invoke(); } + break; } } diff --git a/Source code/MscModApi/Parts/ReplacePart/NewPart.cs b/Source code/MscModApi/Parts/ReplacePart/NewPart.cs index 72ab8f4..62cd1a2 100644 --- a/Source code/MscModApi/Parts/ReplacePart/NewPart.cs +++ b/Source code/MscModApi/Parts/ReplacePart/NewPart.cs @@ -70,8 +70,7 @@ public bool installBlocked get => part.installBlocked; set { - if (!canBeInstalledWithoutReplacing) - { + if (!canBeInstalledWithoutReplacing) { part.installBlocked = value; } } diff --git a/Source code/MscModApi/Parts/ReplacePart/OldPart.cs b/Source code/MscModApi/Parts/ReplacePart/OldPart.cs index ccd9770..c5f120b 100644 --- a/Source code/MscModApi/Parts/ReplacePart/OldPart.cs +++ b/Source code/MscModApi/Parts/ReplacePart/OldPart.cs @@ -35,13 +35,11 @@ public OldPart(GameObject oldFsmGameObject, bool allowSettingFakedStatus = true) assembleFsm = GetFsmByName(trigger, "Assembly"); removalFsm = GetFsmByName(gameObject, "Removal"); - if (!assembleFsm.Fsm.Initialized) - { + if (!assembleFsm.Fsm.Initialized) { assembleFsm.InitializeFSM(); } - if (!removalFsm.Fsm.Initialized) - { + if (!removalFsm.Fsm.Initialized) { removalFsm.InitializeFSM(); } } @@ -65,8 +63,7 @@ public override bool installed { get { - if (justUninstalled) - { + if (justUninstalled) { justUninstalled = false; return false; } @@ -77,8 +74,7 @@ public override bool installed public void Install(bool install) { - if (!allowSettingFakedStatus) - { + if (!allowSettingFakedStatus) { return; } diff --git a/Source code/MscModApi/Parts/ReplacePart/ReplacementPart.cs b/Source code/MscModApi/Parts/ReplacePart/ReplacementPart.cs index 4337103..fa0a0cc 100644 --- a/Source code/MscModApi/Parts/ReplacePart/ReplacementPart.cs +++ b/Source code/MscModApi/Parts/ReplacePart/ReplacementPart.cs @@ -107,48 +107,43 @@ public ReplacementPart(OldPart oldPart, NewPart[] newParts) : this(new[] { oldPa /// Multiple NewPart's public ReplacementPart(OldPart[] oldParts, NewPart[] newParts) { - foreach (var newPart in newParts) - { + foreach (var newPart in newParts) { this.newParts.Add(newPart); } - foreach (var oldPart in oldParts) - { + foreach (var oldPart in oldParts) { oldPart.SetInstallAction(OldPartInstalled); oldPart.SetUninstallAction(OldPartUninstalled); oldPart.Setup(this); this.oldParts.Add(oldPart); } - if (AreAnyOldInstalled()) - { + if (AreAnyOldInstalled()) { OldPartInstalled(); } - foreach (var newPart in newParts) - { - newPart.part.AddEventListener(EventTime.Post, EventType.Install, delegate { NewPartInstalled(newPart); }); - newPart.part.AddEventListener(EventTime.Post, EventType.Uninstall, delegate { NewPartUninstalled(newPart); }); + foreach (var newPart in newParts) { + newPart.part.AddEventListener(EventTime.Post, EventType.Install, + delegate { NewPartInstalled(newPart); }); + newPart.part.AddEventListener(EventTime.Post, EventType.Uninstall, + delegate { NewPartUninstalled(newPart); }); newPart.part.AddEventListener(EventTime.Post, EventType.Bolted, NewPartFixed); newPart.part.AddEventListener(EventTime.Post, EventType.Unbolted, NewPartUnfixed); - if (newPart.installed) - { + if (newPart.installed) { NewPartInstalled(newPart); } } - if (AreAnyNewFixed()) - { + if (AreAnyNewFixed()) { NewPartFixed(); } } internal void OnOldSave() { - if (AreAnyOldInstalled()) - { + if (AreAnyOldInstalled()) { SetFakedInstallStatus(false); } } @@ -179,8 +174,7 @@ public bool AreAnyNewFixed(bool ignoreUnsetScrews = true) /// if set to true [status]. public void SetFakedInstallStatus(bool status) { - foreach (var oldPart in oldParts) - { + foreach (var oldPart in oldParts) { oldPart.Install(status); } } @@ -256,8 +250,7 @@ public void AddAction(ActionType actionType, PartType partType, Action action) var actions = new Actions(); var actionList = new List(); bool invokeActionsNow = false; - switch (partType) - { + switch (partType) { case PartType.NewPart: actions = newPartActions; break; @@ -266,40 +259,33 @@ public void AddAction(ActionType actionType, PartType partType, Action action) break; } - switch (actionType) - { + switch (actionType) { case ActionType.AllInstalled: actionList = actions.allInstalled; - if (partType == PartType.NewPart) - { + if (partType == PartType.NewPart) { invokeActionsNow = AreAllNewInstalled(); } - else - { + else { invokeActionsNow = AreAllOldInstalled(); } break; case ActionType.AllUninstalled: actionList = actions.allUninstalled; - if (partType == PartType.NewPart) - { + if (partType == PartType.NewPart) { invokeActionsNow = AreAllNewUninstalled(); } - else - { + else { invokeActionsNow = AreAllOldUninstalled(); } break; case ActionType.AllFixed: actionList = actions.allFixed; - if (partType == PartType.NewPart) - { + if (partType == PartType.NewPart) { invokeActionsNow = AreAllNewFixed(); } - else - { + else { invokeActionsNow = AreAllOldFixed(); } @@ -309,36 +295,30 @@ public void AddAction(ActionType actionType, PartType partType, Action action) break; case ActionType.AnyInstalled: actionList = actions.anyInstalled; - if (partType == PartType.NewPart) - { + if (partType == PartType.NewPart) { invokeActionsNow = AreAnyNewInstalled(); } - else - { + else { invokeActionsNow = AreAnyOldInstalled(); } break; case ActionType.AnyUninstalled: actionList = actions.anyUninstalled; - if (partType == PartType.NewPart) - { + if (partType == PartType.NewPart) { invokeActionsNow = AreAnyNewUninstalled(); } - else - { + else { invokeActionsNow = AreAnyOldUninstalled(); } break; case ActionType.AnyFixed: actionList = actions.anyFixed; - if (partType == PartType.NewPart) - { + if (partType == PartType.NewPart) { invokeActionsNow = AreAnyNewFixed(); } - else - { + else { invokeActionsNow = AreAnyOldFixed(); } @@ -349,27 +329,22 @@ public void AddAction(ActionType actionType, PartType partType, Action action) } actionList.Add(action); - if (invokeActionsNow) - { + if (invokeActionsNow) { actionList.InvokeAll(); } } internal void NewPartInstalled(NewPart installedNewPart) { - if (!installedNewPart.canBeInstalledWithoutReplacing) - { - foreach (var oldPart in oldParts) - { + if (!installedNewPart.canBeInstalledWithoutReplacing) { + foreach (var oldPart in oldParts) { oldPart.installBlocked = true; } } if (newPartActions.anyInstalled.Count > 0) newPartActions.anyInstalled.InvokeAll(); - if (AreAllNewInstalled()) - { - if (newPartActions.allInstalled.Count > 0) - { + if (AreAllNewInstalled()) { + if (newPartActions.allInstalled.Count > 0) { newPartActions.allInstalled.InvokeAll(); } } @@ -378,12 +353,10 @@ internal void NewPartInstalled(NewPart installedNewPart) internal void NewPartFixed() { if (newPartActions.anyFixed.Count > 0) newPartActions.anyFixed.InvokeAll(); - if (AreAllNewFixed()) - { + if (AreAllNewFixed()) { SetFakedInstallStatus(true); - if (newPartActions.allFixed.Count > 0) - { + if (newPartActions.allFixed.Count > 0) { newPartActions.allFixed.InvokeAll(); } } @@ -391,11 +364,9 @@ internal void NewPartFixed() internal void NewPartUnfixed() { - if (AreAnyNewFixed()) - { + if (AreAnyNewFixed()) { SetFakedInstallStatus(false); - if (newPartActions.anyUnfixed.Count > 0) - { + if (newPartActions.anyUnfixed.Count > 0) { newPartActions.anyUnfixed.InvokeAll(); } } @@ -404,18 +375,14 @@ internal void NewPartUnfixed() internal void NewPartUninstalled(NewPart uninstalledNewPart) { var allNewUninstalled = AreAllNewUninstalled(); - if (!uninstalledNewPart.canBeInstalledWithoutReplacing) - { - foreach (var oldPart in oldParts) - { + if (!uninstalledNewPart.canBeInstalledWithoutReplacing) { + foreach (var oldPart in oldParts) { oldPart.installBlocked = !allNewUninstalled; } } - if (AreAnyNewUninstalled()) - { - if (newPartActions.anyUninstalled.Count > 0) - { + if (AreAnyNewUninstalled()) { + if (newPartActions.anyUninstalled.Count > 0) { newPartActions.anyUninstalled.InvokeAll(); } } @@ -426,8 +393,7 @@ internal void NewPartUninstalled(NewPart uninstalledNewPart) internal void OldPartInstalled() { - foreach (var newPart in newParts) - { + foreach (var newPart in newParts) { newPart.installBlocked = true; } @@ -438,8 +404,7 @@ internal void OldPartInstalled() internal void OldPartUninstalled() { var allOldUninstalled = AreAllOldUninstalled(); - foreach (var newPart in newParts) - { + foreach (var newPart in newParts) { newPart.installBlocked = !allOldUninstalled; } diff --git a/Source code/MscModApi/Parts/Screw.cs b/Source code/MscModApi/Parts/Screw.cs index 21da290..8173630 100644 --- a/Source code/MscModApi/Parts/Screw.cs +++ b/Source code/MscModApi/Parts/Screw.cs @@ -34,8 +34,7 @@ public enum Type internal GameObject gameObject; private MeshRenderer renderer; - [JsonProperty] - internal int tightness; + [JsonProperty] internal int tightness; internal bool showSize; private Collider collider; @@ -148,30 +147,23 @@ public void In(bool useAudio = true) gameObject.transform.Translate(0f, 0f, -transformStep); bool changingToFixedState = false; - if (tightness + 1 == maxTightness) - { + if (tightness + 1 == maxTightness) { int screwCount = part.screws.Count; int totalTightness = 0; - part.screws.ForEach((Screw screw) => - { - totalTightness += screw.tightness; - }); + part.screws.ForEach((Screw screw) => { totalTightness += screw.tightness; }); - if (totalTightness + 1 == screwCount * maxTightness) - { + if (totalTightness + 1 == screwCount * maxTightness) { changingToFixedState = true; } } - if (changingToFixedState) - { + if (changingToFixedState) { part.GetEvents(EventTime.Pre, EventType.Bolted).InvokeAll(); } tightness++; - - if (changingToFixedState) - { + + if (changingToFixedState) { part.GetEvents(EventTime.Post, EventType.Bolted).InvokeAll(); } } @@ -188,16 +180,14 @@ public void Out(bool useAudio = true) gameObject.transform.Translate(0f, 0f, transformStep); bool changingToUnfixed = part.bolted; - - if (changingToUnfixed) - { + + if (changingToUnfixed) { part.GetEvents(EventTime.Pre, EventType.Unbolted).InvokeAll(); } tightness--; - if (changingToUnfixed) - { + if (changingToUnfixed) { part.GetEvents(EventTime.Post, EventType.Unbolted).InvokeAll(); } } @@ -229,7 +219,8 @@ internal void Highlight(bool highlight) if (highlight) { renderer.material.shader = textShader; renderer.material.SetColor(color1, Color.green); - } else { + } + else { renderer.material = material; } } diff --git a/Source code/MscModApi/Shopping/ModItem.cs b/Source code/MscModApi/Shopping/ModItem.cs index aa26da4..5b5702d 100644 --- a/Source code/MscModApi/Shopping/ModItem.cs +++ b/Source code/MscModApi/Shopping/ModItem.cs @@ -29,10 +29,7 @@ internal ModItem(ShopLocation shopLocation, ShopInterface shopInterface, Mod mod modImage.enabled = false; //Tmp until solution is found //modImage.sprite = Helper.LoadNewSprite(modImage.sprite, mod.Icon); var btnOpenShop = gameObject.FindChild("panel/mod_open_shop").GetComponent