Skip to content

Commit

Permalink
Merge pull request #32 from MarvinBeym/develop
Browse files Browse the repository at this point in the history
develop => master
  • Loading branch information
Marvin Beym authored Sep 2, 2023
2 parents ad3fdd6 + c5a3559 commit 24bb81e
Show file tree
Hide file tree
Showing 29 changed files with 1,499 additions and 1,103 deletions.
20 changes: 14 additions & 6 deletions Source code/MscModApi/Caching/Cache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,22 @@

namespace MscModApi.Caching
{
/// <summary>
/// Cached GameObject.Find implementation for improved performance
/// </summary>
public static class Cache
{
public static Dictionary<string, GameObject> cachedGameObjects;
private static Dictionary<string, GameObject> cachedGameObjects;

private static GameObject[] globalCache;

/// <summary>
/// Works similar to GameObject.Find except that objects are cached once they are found, further "Cache.Find" calls will result in a quicker value return.
/// Also supports path search like 'Car/Engine/MyCoolPart/MyInnerPart/ThePart'
/// </summary>
/// <param name="name">The name or path of the gameobject.</param>
/// <param name="findEvenIfInactive">Uses an alternative way to find the object, if the part is not active when the .Find happens, without this, 'null' would be returned. Should rarely be disabled</param>
/// <returns></returns>
public static GameObject Find(string name, bool findEvenIfInactive = true)
{
try {
Expand Down Expand Up @@ -59,11 +69,6 @@ private static GameObject FindInGlobal(string name)
return null;
}

public static void Clear()
{
cachedGameObjects = new Dictionary<string, GameObject>();
}

private static string GetObjectPath(GameObject gameObject)
{
Transform currentTransform = gameObject.transform;
Expand All @@ -77,6 +82,9 @@ private static string GetObjectPath(GameObject gameObject)
return path;
}

/// <summary>
/// Called when the MscModApi mod loads to cleanup static data
/// </summary>
public static void LoadCleanup()
{
cachedGameObjects = new Dictionary<string, GameObject>();
Expand Down
33 changes: 33 additions & 0 deletions Source code/MscModApi/Caching/CarH.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

namespace MscModApi.Caching
{
/// <summary>
/// Utility class for everything related to the car, all cached for high performance.
/// </summary>
public class CarH
{
private static GameObject _satsuma;
Expand All @@ -14,9 +17,18 @@ public class CarH
private static GameObject _electricity;
private static FsmString _playerCurrentVehicle;

/// <summary>
/// Returns if the car is currently running (rpm above 20).
/// </summary>
public static bool running => drivetrain.rpm > 20;
/// <summary>
/// Returns if the player is currently sitting in the car (drive mode).
/// </summary>
public static bool playerInCar => playerCurrentVehicle == "Satsuma";

/// <summary>
/// Returns the current vehicle the player is in (drive mode).
/// </summary>
public static string playerCurrentVehicle
{
get
Expand All @@ -28,6 +40,9 @@ public static string playerCurrentVehicle
}
}

/// <summary>
/// Returns the cars electricity object.
/// </summary>
public static GameObject electricity
{
get
Expand All @@ -39,6 +54,9 @@ public static GameObject electricity
}
}

/// <summary>
/// Returns if the cars power is currently on.
/// </summary>
public static bool hasPower
{
get
Expand All @@ -50,6 +68,9 @@ public static bool hasPower
}
}

/// <summary>
/// Returns the UnityCar CarController object of the satsuma.
/// </summary>
public static CarController carController
{
get
Expand All @@ -61,6 +82,9 @@ public static CarController carController
}
}

/// <summary>
/// Returns the UnityCar AxisCarController object of the satsuma.
/// </summary>
public static AxisCarController axisCarController
{
get
Expand All @@ -72,6 +96,9 @@ public static AxisCarController axisCarController
}
}

/// <summary>
/// Returns the UnityCar Drivetrain object of the satsuma.
/// </summary>
public static Drivetrain drivetrain
{
get
Expand All @@ -83,6 +110,9 @@ public static Drivetrain drivetrain
}
}

/// <summary>
/// Returns the satsuma GameObject object.
/// </summary>
public static GameObject satsuma
{
get
Expand All @@ -94,6 +124,9 @@ public static GameObject satsuma
}
}

/// <summary>
/// Called when the MscModApi mod loads to cleanup static data
/// </summary>
public static void LoadCleanup()
{
_satsuma = null;
Expand Down
9 changes: 9 additions & 0 deletions Source code/MscModApi/Caching/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,16 @@

namespace MscModApi.Caching
{
/// <summary>
/// Utility class for everything related to the game.
/// </summary>
public class Game
{
private static FsmFloat _money;

/// <summary>
/// Returns the current amount of money the player has.
/// </summary>
public static float money
{
get
Expand All @@ -24,6 +30,9 @@ public static float money
}
}

/// <summary>
/// Called when the MscModApi mod loads to cleanup static data
/// </summary>
public static void LoadCleanup()
{
_money = null;
Expand Down
38 changes: 14 additions & 24 deletions Source code/MscModApi/MscModApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
using MscModApi.Caching;
using MscModApi.Commands;
using MscModApi.PaintingSystem;
using MscModApi.Parts.ReplacePart;
using UnityEngine;
using EventType = MscModApi.Parts.EventType;

namespace MscModApi
{
Expand All @@ -21,16 +21,15 @@ public class MscModApi : Mod
public override string ID => "MscModApi";
public override string Name => "MscModApi";
public override string Author => "DonnerPlays";
public override string Version => "1.2";
public override string Version => "1.3";

public override string Description =>
"This allows developers to make their parts installable on the car. Also adds screws";
"A general modding 'help' featuring things like installable/boltable parts, shop, part boxing, utility tools & more.";

public override bool UseAssetsFolder => true;
private static Settings showBoltSizeSetting = new Settings("showBoltSizeSetting", "Show screw size", false);
private static SettingsCheckBox showBoltSizeSetting;

private static Settings enableInstantInstall =
new Settings("enableInstantInstall", "Enable Instant Part install", false);
private static SettingsCheckBox enableInstantInstall;

private const string assetsFile = "msc-mod-api.unity3d";
private Tool tool;
Expand All @@ -47,16 +46,7 @@ public class MscModApi : Mod

private bool updateLocked = true;

/// <summary>Enables the screw placement for all parts.</summary>
/// <param name="mod">The mod.</param>
[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
}

internal static bool ShowScrewSize => (bool)showBoltSizeSetting.Value;
internal static bool ShowScrewSize => (bool)showBoltSizeSetting.GetValue();

public override void ModSetup()
{
Expand All @@ -69,12 +59,11 @@ public override void ModSetup()

public override void ModSettings()
{
Settings.AddCheckBox(this, showBoltSizeSetting);
Keybind.AddHeader(this, "Developer area - Screw placement mode");
showBoltSizeSetting = Settings.AddCheckBox(this, "showBoltSizeSetting", "Show screw size", false);
Keybind.AddHeader(this, "Developer Area");
#if DEBUG
instantInstallKeybind =
Keybind.Add(this, "instant-install", "Instant install part looking at", KeyCode.UpArrow);
Settings.AddCheckBox(this, enableInstantInstall);
instantInstallKeybind = Keybind.Add(this, "instant-install", "Instant install part looking at", KeyCode.UpArrow);
enableInstantInstall = Settings.AddCheckBox(this, "enableInstantInstall", "Enable Instant Part install", false);
#endif
ScrewPlacementAssist.ModSettings(this);
}
Expand Down Expand Up @@ -108,6 +97,7 @@ private void MenuLoad()
ScrewPlacementAssist.LoadCleanup();
UserInteraction.LoadCleanup();
Tool.LoadCleanup();
SatsumaGamePart.LoadCleanup();

Logger.InitLogger(this);
LoadAssets();
Expand Down Expand Up @@ -146,11 +136,11 @@ private void Save()
try {
part.CustomSaveSaving(mod, $"{id}_saveFile.json");
}
catch {
catch (Exception) {
// ignored
}

part.GetEvents(EventTime.Pre, EventType.Save).InvokeAll();
part.GetEvents(PartEvent.Time.Pre, PartEvent.Type.Save).InvokeAll();

var partSave = part.partSave;
partSave.position = part.gameObject.transform.position;
Expand Down Expand Up @@ -232,7 +222,7 @@ private void Save()
#if DEBUG
private void InstantInstallDebug()
{
if (!(bool)enableInstantInstall.Value) {
if (!enableInstantInstall.GetValue()) {
return;
}

Expand Down
64 changes: 30 additions & 34 deletions Source code/MscModApi/MscModApi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,27 @@
<DocumentationFile>bin\Release\MscModApi.xml</DocumentationFile>
</PropertyGroup>
<ItemGroup>
<Reference Include="Assembly-CSharp">
<HintPath>S:\Spiele\Steam\steamapps\common\My Summer Car\mysummercar_Data\Managed\Assembly-CSharp.dll</HintPath>
<Reference Include="0Harmony">
<HintPath>..\..\..\..\..\Spiele\Steam\steamapps\common\My Summer Car\mysummercar_Data\Managed\0Harmony.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<Reference Include="Assembly-CSharp, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>S:\Spiele\Steam\steamapps\common\My Summer Car\mysummercar_Data\Managed\Newtonsoft.Json.dll</HintPath>
<Private>False</Private>
<HintPath>..\..\..\..\..\Spiele\Steam\steamapps\common\My Summer Car\mysummercar_Data\Managed\Assembly-CSharp.dll</HintPath>
</Reference>
<Reference Include="Assembly-CSharp-firstpass">
<HintPath>..\..\..\..\..\Spiele\Steam\steamapps\common\My Summer Car\mysummercar_Data\Managed\Assembly-CSharp-firstpass.dll</HintPath>
</Reference>
<Reference Include="cInput">
<HintPath>..\..\..\..\..\Spiele\Steam\steamapps\common\My Summer Car\mysummercar_Data\Managed\cInput.dll</HintPath>
</Reference>
<Reference Include="MSCLoader">
<HintPath>..\..\..\..\..\Spiele\Steam\steamapps\common\My Summer Car\mysummercar_Data\Managed\MSCLoader.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json">
<HintPath>..\..\..\..\..\Spiele\Steam\steamapps\common\My Summer Car\mysummercar_Data\Managed\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="PlayMaker">
<HintPath>..\..\..\..\..\Spiele\Steam\steamapps\common\My Summer Car\mysummercar_Data\Managed\PlayMaker.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
Expand All @@ -48,32 +62,11 @@
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="UnityEngine">
<HintPath>S:\Spiele\Steam\steamapps\common\My Summer Car\mysummercar_Data\Managed\UnityEngine.dll</HintPath>
<Private>False</Private>
<HintPath>..\..\..\..\..\Spiele\Steam\steamapps\common\My Summer Car\mysummercar_Data\Managed\UnityEngine.dll</HintPath>
</Reference>
<Reference Include="MSCLoader">
<HintPath>S:\Spiele\Steam\steamapps\common\My Summer Car\mysummercar_Data\Managed\MSCLoader.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Assembly-CSharp-firstpass">
<HintPath>S:\Spiele\Steam\steamapps\common\My Summer Car\mysummercar_Data\Managed\Assembly-CSharp-firstpass.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="cInput">
<HintPath>S:\Spiele\Steam\steamapps\common\My Summer Car\mysummercar_Data\Managed\cInput.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="PlayMaker">
<HintPath>S:\Spiele\Steam\steamapps\common\My Summer Car\mysummercar_Data\Managed\PlayMaker.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="0Harmony">
<HintPath>S:\Spiele\Steam\steamapps\common\My Summer Car\mysummercar_Data\Managed\0Harmony.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="UnityEngine.UI">
<HintPath>S:\Spiele\Steam\steamapps\common\My Summer Car\mysummercar_Data\Managed\UnityEngine.UI.dll</HintPath>
<Aliases>global</Aliases>
<Reference Include="UnityEngine.UI, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\..\Spiele\Steam\steamapps\common\My Summer Car\mysummercar_Data\Managed\UnityEngine.UI.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
Expand All @@ -87,13 +80,16 @@
<Compile Include="PaintingSystem\SerializableColor.cs" />
<Compile Include="Parts\BasicPart.cs" />
<Compile Include="Parts\DerivablePart.cs" />
<Compile Include="Parts\PartEvent.cs" />
<Compile Include="Parts\ReplacePart\GamePart.cs" />
<Compile Include="Parts\ReplacePart\NewPart.cs" />
<Compile Include="Parts\ReplacePart\OldPart.cs" />
<Compile Include="Parts\ReplacePart\ReplacementPart.cs" />
<Compile Include="Parts\Box.cs" />
<Compile Include="Parts\BoxLogic.cs" />
<Compile Include="Parts\Kit.cs" />
<Compile Include="Parts\ReplacePart\SatsumaGamePart.cs" />
<Compile Include="Parts\SupportsPartBehaviourEvents.cs" />
<Compile Include="Parts\SupportsPartEvents.cs" />
<Compile Include="Shopping\ModItem.cs" />
<Compile Include="Parts\PartBox.cs" />
Expand Down Expand Up @@ -127,13 +123,13 @@
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>if "$(ConfigurationName)" == "Debug" (
copy "$(TargetPath)" "S:\Spiele\Steam\steamapps\common\My Summer Car\Mods" /y
copy "$(TargetPath)" "D:\Spiele\Steam\steamapps\common\My Summer Car\Mods" /y
copy "$(TargetDir)$(TargetName).pdb" "S:\Spiele\Steam\steamapps\common\My Summer Car\Mods" /y
cd "S:\Spiele\Steam\steamapps\common\My Summer Car\Mods"
call "S:\Spiele\Steam\steamapps\common\My Summer Car\Mods\debug.bat"
cd "D:\Spiele\Steam\steamapps\common\My Summer Car\Mods"
call "D:\Spiele\Steam\steamapps\common\My Summer Car\Mods\debug.bat"
) ELSE (
copy "$(TargetPath)" "D:\Programmierung\My Summer Car Modding\MscModApi\project files\Current version" /y
copy "$(TargetPath)" "S:\Spiele\Steam\steamapps\common\My Summer Car\Mods" /y
copy "$(TargetPath)" "D:\Spiele\Steam\steamapps\common\My Summer Car\Mods" /y
)</PostBuildEvent>
</PropertyGroup>
</Project>
Loading

0 comments on commit 24bb81e

Please sign in to comment.