Quellcode durchsuchen

[MoreLights] [2.0.3.6] ScrapYard.API link

Zariteis vor 4 Jahren
Ursprung
Commit
e9a8561cb4

+ 2 - 1
MoreLights/Manifest.ini

@@ -1,3 +1,4 @@
 [Metadata]
 Name=More Lights
-Assembly=MoreLights.dll
+Assembly=MoreLights.dll
+Dependencies=Scrap Yard

+ 21 - 2
MoreLights/MoreLights.cs

@@ -1,13 +1,14 @@
 using UnityEngine;
 using GadgetCore.API;
 using GadgetCore.API.ConfigMenu;
+using ScrapYard.API;
 
 namespace MoreLights
 {
-  [Gadget("MoreLights", LoadAfter: new string[] { "ItemFrames" })]
+  [Gadget("MoreLights", LoadAfter: new string[] { "ScrapYard" }, Dependencies: new string[] { "ScrapYard" })]
   public class MoreLights : Gadget<MoreLights>
   {
-    public const string MOD_VERSION = "1.1"; // Set this to the version of your mod.
+    public const string MOD_VERSION = "1.2"; // Set this to the version of your mod.
     public const string CONFIG_VERSION = "1.0"; // Increment this whenever you change your mod's config file.
 
     public override IGadgetConfigMenu GetConfigMenu() { return null; }
@@ -27,6 +28,24 @@ namespace MoreLights
       Core.itemOrangeLampId = ItemUtil.CreatePlacableLightItem("cOrangeLamp.png", "iOrangeLamp.png", "Orange Light", new Color(0.7f, 0.15f, 0, 1));
       Core.itemPurpleLampId = ItemUtil.CreatePlacableLightItem("cPurpleLamp.png", "iPurpleLamp.png", "Purple Light", new Color(0.5f, 0, 0.6f, 1));
       Core.itemWhiteLampId = ItemUtil.CreatePlacableLightItem("cWhiteLamp.png", "iWhiteLamp.png", "White Light", new Color(0.8f, 0.8f, 0.8f, 1));
+
+      foreach (var e in ShopPlatform.DefaultObjects.GetShopPlatformEntries())
+      {
+        if(e.ItemID == 2401 || e.ItemID == 2402)
+        {
+          ShopPlatform.DefaultObjects.RemoveShopPlatformEntry(e);
+        }
+      }
+
+      var lightsPlatform = new ShopPlatform("Lights").Register();
+      lightsPlatform.AddShopPlatformEntry(new ShopPlatformEntry(Core.itemWhiteLampId, 1000));
+      lightsPlatform.AddShopPlatformEntry(new ShopPlatformEntry(Core.itemYellowLampId, 1000));
+      lightsPlatform.AddShopPlatformEntry(new ShopPlatformEntry(Core.itemOrangeLampId, 1000));
+      lightsPlatform.AddShopPlatformEntry(new ShopPlatformEntry(2402, 1000));
+      lightsPlatform.AddShopPlatformEntry(new ShopPlatformEntry(Core.itemPurpleLampId, 1000));
+      lightsPlatform.AddShopPlatformEntry(new ShopPlatformEntry(2401, 1000));
+      lightsPlatform.AddShopPlatformEntry(new ShopPlatformEntry(Core.itemGreenLampId, 1000));
+
     }
   }
 }

+ 8 - 0
MoreLights/MoreLights.csproj

@@ -46,6 +46,11 @@
       <HintPath>$(GamePath)$(ManagedFolder)GadgetCore.dll</HintPath>
       <Private>false</Private>
     </Reference>
+    <Reference Include="ScrapYard">
+      <HintPath>..\ScrapYard\Release\ScrapYard.dll</HintPath>
+      <Private>false</Private>
+      <SpecificVersion>false</SpecificVersion>
+    </Reference>
     <Reference Include="UnityEngine">
       <HintPath>$(GamePath)$(ManagedFolder)UnityEngine.dll</HintPath>
       <Private>false</Private>
@@ -224,4 +229,7 @@
       <EmbedInteropTypes>false</EmbedInteropTypes>
     </Reference>
   </ItemGroup>
+  <ItemGroup>
+    <Folder Include="Patches\" />
+  </ItemGroup>
 </Project>

+ 0 - 94
MoreLights/Patches/Patch_KylockeStand_Awake.cs

@@ -1,94 +0,0 @@
-using GadgetCore.API;
-using GadgetCore.Util;
-using HarmonyLib;
-using System.Collections;
-using System.Threading;
-using System.Windows.Threading;
-using UnityEngine;
-
-namespace MoreLights.Patches
-{
-
-  [HarmonyPatch(typeof(KylockeStand))]
-  [HarmonyPatch("Awake")]
-  [HarmonyGadget("MoreLights")]
-  public static class Patch_KylockeStand_Awake
-  {
-    [HarmonyPostfix]
-    public static void Prefix(KylockeStand __instance)
-    {
-      __instance.StartCoroutine(StartUpdateLoop(__instance));
-    }
-
-    public static IEnumerator LightColorUpdateLoop(KylockeStand instance)
-    {
-      while (!Network.isServer && !Network.isClient)
-      {
-        yield return new WaitForSeconds(0f);
-      }
-
-      if (Network.isServer)
-      {
-        while (true)
-        {
-          yield return new WaitForSeconds(1f);
-          if (instance.gameObject.activeSelf && Network.isServer)
-          {
-            instance.itemID = getItemIdFromIndex(colorIndex);
-            instance.GetComponent<NetworkView>().RPC("Set", RPCMode.All, new object[]
-            {
-              new int[]{ instance.itemID, instance.cost }
-            });
-          }
-          yield return new WaitForSeconds(9f);
-          colorIndex = (colorIndex + 1) % 6;
-        }
-      }
-    }
-
-    private static IEnumerator StartUpdateLoop(KylockeStand instance)
-    {
-
-      if (instance.itemID == 2402)
-      {
-        instance.itemID = Core.itemWhiteLampId;
-        foreach (var gadget in GadgetCore.API.Gadgets.ListAllEnabledGadgets())
-          if (gadget.Info?.ModName == "ItemFrames")
-          {
-            instance.transform.localPosition += new Vector3(4, 0, 0);
-            break;
-          }
-      }
-      else if (instance.itemID == 2401)
-      {
-        colorIndex = Random.Range(0, 6);
-        instance.StartCoroutine(LightColorUpdateLoop(instance));
-        CoroutineManager newComponent = instance.gameObject.AddComponent<CoroutineManager>();
-        newComponent.SetAction(new System.Action(() => { newComponent.StartCoroutine(LightColorUpdateLoop(instance)); }));
-      }
-      yield break;
-    }
-
-    private static int colorIndex = 0;
-
-    private static int getItemIdFromIndex(int i)
-    {
-      switch (i)
-      {
-        case 0:
-          return Core.itemYellowLampId;
-        case 1:
-          return Core.itemOrangeLampId;
-        case 2:
-          return 2402;
-        case 3:
-          return Core.itemPurpleLampId;
-        case 4:
-          return 2401;
-        case 5:
-          return Core.itemGreenLampId;
-      }
-      return 2401;
-    }
-  }
-}

+ 0 - 78
MoreLights/Patches/Patch_KylockeStand_Set.cs

@@ -1,78 +0,0 @@
-using GadgetCore.API;
-using GadgetCore.Util;
-using HarmonyLib;
-using System.Collections;
-using System.Linq;
-using UnityEngine;
-
-namespace MoreLights.Patches
-{
-
-  [HarmonyPatch(typeof(KylockeStand))]
-  [HarmonyPatch("Set")]
-  [HarmonyGadget("MoreLights")]
-  public static class Patch_KylockeStand_Set
-  {
-    [HarmonyPostfix]
-    public static void Prefix(KylockeStand __instance, int[] p)
-    {
-      __instance.StartCoroutine(DoUpdateAnimation(__instance));
-      if (new int[] { Core.itemYellowLampId, Core.itemOrangeLampId, 2402, Core.itemPurpleLampId, 2401, Core.itemGreenLampId }.Contains(p[0]))
-        __instance.StartCoroutine(DoUpdateLoadingAnimation(__instance));
-    }
-
-    private static IEnumerator DoUpdateAnimation(KylockeStand instance)
-    {
-      if (!GameScript.inInstance)
-      {
-        instance.GetComponent<AudioSource>().PlayOneShot((AudioClip)Resources.Load("Au/shipdroid" + UnityEngine.Random.Range(0, 3)), Menuu.soundLevel / 10f);
-      }
-      var scale = instance.icon.transform.localScale;
-      instance.icon.transform.localScale = new Vector3(scale.x * 0.90f, scale.y);
-      yield return new WaitForSeconds(0.05f);
-      instance.icon.transform.localScale = new Vector3(scale.x * 0.76f, scale.y);
-      yield return new WaitForSeconds(0.05f);
-      instance.icon.transform.localScale = new Vector3(scale.x * 0.70f, scale.y);
-      yield return new WaitForSeconds(0.05f);
-      instance.icon.transform.localScale = new Vector3(scale.x * 0.76f, scale.y);
-      yield return new WaitForSeconds(0.05f);
-      instance.icon.transform.localScale = new Vector3(scale.x * 0.90f, scale.y);
-      yield return new WaitForSeconds(0.05f);
-      instance.icon.transform.localScale = new Vector3(scale.y, scale.y);
-    }
-
-    private static Texture2D textureStand0 = GadgetCoreAPI.LoadTexture2D("stand0.png");
-    private static Texture2D textureStand1 = GadgetCoreAPI.LoadTexture2D("stand1.png");
-    private static Texture2D textureStand2 = GadgetCoreAPI.LoadTexture2D("stand2.png");
-    private static Texture2D textureStand3 = GadgetCoreAPI.LoadTexture2D("stand3.png");
-    private static Texture2D textureStand4 = GadgetCoreAPI.LoadTexture2D("stand4.png");
-    private static Texture2D textureStand5 = GadgetCoreAPI.LoadTexture2D("stand5.png");
-    private static Texture2D textureStand6 = GadgetCoreAPI.LoadTexture2D("stand6.png");
-
-    private static IEnumerator DoUpdateLoadingAnimation(KylockeStand instance)
-    {
-      UpdateTexture(instance, textureStand0);
-      yield return new WaitForSeconds(1.43f);
-      UpdateTexture(instance, textureStand1);
-      yield return new WaitForSeconds(1.43f);
-      UpdateTexture(instance, textureStand2);
-      yield return new WaitForSeconds(1.43f);
-      UpdateTexture(instance, textureStand3);
-      yield return new WaitForSeconds(1.43f);
-      UpdateTexture(instance, textureStand4);
-      yield return new WaitForSeconds(1.43f);
-      UpdateTexture(instance, textureStand5);
-      yield return new WaitForSeconds(1.43f);
-      UpdateTexture(instance, textureStand6);
-    }
-
-    private static void UpdateTexture(KylockeStand instance, Texture2D texture)
-    {
-      Renderer renderer = instance.gameObject.transform.GetChild(0).gameObject.GetComponentInChildren<Renderer>();
-      renderer.material = new Material(Shader.Find("Unlit/Transparent"))
-      {
-        mainTexture = texture
-      };
-    }
-  }
-}