Skip to content

Commit

Permalink
Reformat Code
Browse files Browse the repository at this point in the history
  • Loading branch information
Marvin Beym authored and Marvin Beym committed Aug 13, 2023
1 parent 75eaac8 commit 5dbcc32
Show file tree
Hide file tree
Showing 35 changed files with 537 additions and 895 deletions.
27 changes: 10 additions & 17 deletions Source code/MscModApi/Caching/Cache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,15 @@ public static GameObject Find(string name, bool findEvenIfInactive = true)
return gameObject;
}
}
catch
{
catch {
// ignored. Continues below
}

GameObject.FindObjectOfType<GameObject>();

GameObject foundObject = GameObject.Find(name);

if (!foundObject && findEvenIfInactive)
{
if (!foundObject && findEvenIfInactive) {
foundObject = FindInGlobal(name);
}

Expand All @@ -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<GameObject>();
}

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;
}

Expand All @@ -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;
}
Expand Down
18 changes: 12 additions & 6 deletions Source code/MscModApi/Caching/CarH.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ public static string playerCurrentVehicle
}
}

public static GameObject electricity {
public static GameObject electricity
{
get
{
if (_electricity != null) return _electricity;
Expand All @@ -38,7 +39,8 @@ public static GameObject electricity {
}
}

public static bool hasPower {
public static bool hasPower
{
get
{
if (_electricsOk != null) return _electricsOk.Value;
Expand All @@ -48,7 +50,8 @@ public static bool hasPower {
}
}

public static CarController carController {
public static CarController carController
{
get
{
if (_carController != null) return _carController;
Expand All @@ -58,7 +61,8 @@ public static CarController carController {
}
}

public static AxisCarController axisCarController {
public static AxisCarController axisCarController
{
get
{
if (_axisController != null) return _axisController;
Expand All @@ -68,7 +72,8 @@ public static AxisCarController axisCarController {
}
}

public static Drivetrain drivetrain {
public static Drivetrain drivetrain
{
get
{
if (_drivetrain != null) return _drivetrain;
Expand All @@ -78,7 +83,8 @@ public static Drivetrain drivetrain {
}
}

public static GameObject satsuma {
public static GameObject satsuma
{
get
{
if (_satsuma != null) return _satsuma;
Expand Down
2 changes: 1 addition & 1 deletion Source code/MscModApi/Caching/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
75 changes: 31 additions & 44 deletions Source code/MscModApi/Commands/ScrewPlacementModCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "")
{
Expand All @@ -49,8 +41,12 @@ public ScrewPlacementModCommand(MscModApi mod, Dictionary<string, Dictionary<str
this.mod = mod;
this.modsParts = modsParts;

helpCommand = new Command("help", "This help", "Escape further command arguments with spaces, with two <color=blue>'</color>");

helpCommand = new Command(
"help",
"This help",
"Escape further command arguments with spaces, with two <color=blue>'</color>"
);

enableCommand = new Command(
"enable",
"Enable screw placement mode for a part",
Expand All @@ -69,70 +65,64 @@ public ScrewPlacementModCommand(MscModApi mod, Dictionary<string, Dictionary<str
"mod-api-screw list '<your-mod-id>'"
);

availableCommands.AddRange(new []
availableCommands.AddRange(new[]
{
helpCommand,
listCommand,
enableCommand,
disableCommand,
});
}

public override void Run(string[] args)
{
Command mainCommand = null;
foreach (Command command in availableCommands)
{
if (command.name == args.ElementAtOrDefault(0))
{
foreach (Command command in availableCommands) {
if (command.name == args.ElementAtOrDefault(0)) {
mainCommand = command;
}
}

string partId;
string modId;
Part part;
switch (mainCommand)
{
switch (mainCommand) {
case Command cmd when cmd == helpCommand:
foreach (Command command in availableCommands)
{
foreach (Command command in availableCommands) {
ModConsole.Print($"<color=orange>{command.name}</color>: {command.help}");
if (command.parameterCallExample != "")
{
if (command.parameterCallExample != "") {
ModConsole.Print($"<color=orange>=></color> {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;
}

//Removing potential ''
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 <color=blue>{modId}</color> found that has added parts");
break;
}

if (!modsParts[modId].ContainsKey(partId))
{
ModConsole.Error($"No part with id <color=blue>{partId}</color> found for mod with id <color=blue>{modId}</color>");
if (!modsParts[modId].ContainsKey(partId)) {
ModConsole.Error(
$"No part with id <color=blue>{partId}</color> found for mod with id <color=blue>{modId}</color>");
break;
}

Expand All @@ -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 <color=blue>{modId}</color> found that has added parts");
break;
}

foreach (var partDict in modsParts[modId])
{
foreach (var partDict in modsParts[modId]) {
part = partDict.Value;
ModConsole.Print($"<color=orange>{part.id}</color> => {(part.screwPlacementMode ? "Enabled" : "Disabled")}");
ModConsole.Print(
$"<color=orange>{part.id}</color> => {(part.screwPlacementMode ? "Enabled" : "Disabled")}");
}

break;
Expand All @@ -180,4 +167,4 @@ public override void Run(string[] args)
public override string Help =>
"Run <color=blue>mod-api-screw help</color> for a list of commands and arguments";
}
}
}
Loading

0 comments on commit 5dbcc32

Please sign in to comment.