Browse Source

[ShipDecorations] [2.0.3.6] ScrapYard.API link

Zariteis 4 years ago
parent
commit
2b8f519621

+ 0 - 3
ShipDecorations/Core.cs

@@ -9,9 +9,6 @@ namespace ShipDecorations
 {
   internal static class Core
   {
-    public static List<int> itemStoreList = new List<int>();
-    public static Dictionary<int, int> itemStorePriceList = new Dictionary<int, int>();
-
     public static GadgetLogger logger;
   }
 }

+ 2 - 1
ShipDecorations/Manifest.ini

@@ -1,3 +1,4 @@
 [Metadata]
 Name=Ship Decorations
-Assembly=ShipDecorations.dll
+Assembly=ShipDecorations.dll
+Dependencies=Scrap Yard

+ 0 - 76
ShipDecorations/Patches/Patch_KylockeStand_Awake.cs

@@ -1,76 +0,0 @@
-using GadgetCore.API;
-using GadgetCore.Util;
-using HarmonyLib;
-using System.Collections;
-using System.Threading;
-using System.Windows.Threading;
-using UnityEngine;
-
-namespace ShipDecorations.Patches
-{
-
-  [HarmonyPatch(typeof(KylockeStand))]
-  [HarmonyPatch("Awake")]
-  [HarmonyGadget("ShipDecorations")]
-  public static class Patch_KylockeStand_Awake
-  {
-    [HarmonyPostfix]
-    public static void Prefix(KylockeStand __instance)
-    {
-      __instance.StartCoroutine(StartUpdateLoop(__instance));
-    }
-
-    public static IEnumerator DecpStockUpdateLoop(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 = Core.itemStoreList[colorIndex];
-            instance.cost = Core.itemStorePriceList[instance.itemID];
-            instance.GetComponent<NetworkView>().RPC("Set", RPCMode.All, new object[]
-            {
-              new int[]{ instance.itemID, instance.cost }
-            });
-          }
-          yield return new WaitForSeconds(9f);
-          colorIndex = (colorIndex + 1) % Core.itemStoreList.Count;
-        }
-      }
-    }
-
-    private static IEnumerator StartUpdateLoop(KylockeStand instance)
-    {
-      if (instance.itemID == Core.itemStoreList[0])
-      {
-        instance.StartCoroutine(DecpStockUpdateLoop(instance));
-        CoroutineManager newComponent = instance.gameObject.AddComponent<CoroutineManager>();
-        newComponent.SetAction(new System.Action(() => { newComponent.StartCoroutine(DecpStockUpdateLoop(instance)); }));
-      }
-      else if (instance.itemID == 2403)
-      {
-        while (!Network.isServer && !Network.isClient)
-        {
-          yield return new WaitForSeconds(0f);
-        }
-        if (Network.isServer)
-        {
-          var obj = ((GameObject)Network.Instantiate(Resources.Load("npc/buildStand"), new Vector3(-250f + 4 * 1, -5.99f, 0.19f), instance.transform.rotation, 0));
-          obj.GetComponent<KylockeStand>().GetComponent<NetworkView>().RPC("Set", RPCMode.AllBuffered, new object[] { new int[] { Core.itemStoreList[0], 1000 } });
-          obj.GetComponent<KylockeStand>().Awake();
-        }
-      }
-      yield break;
-    }
-
-    private static int colorIndex = 0;
-  }
-}

+ 0 - 114
ShipDecorations/Patches/Patch_KylockeStand_Set.cs

@@ -1,114 +0,0 @@
-using GadgetCore.API;
-using GadgetCore.Util;
-using HarmonyLib;
-using System.Collections;
-using UnityEngine;
-
-namespace ShipDecorations.Patches
-{
-
-  [HarmonyPatch(typeof(KylockeStand))]
-  [HarmonyPatch("Set")]
-  [HarmonyGadget("ShipDecorations")]
-  public static class Patch_KylockeStand_Set
-  {
-    [HarmonyPostfix]
-    public static bool Prefix(KylockeStand __instance, int[] p)
-    {
-      if(animate == null)
-      {
-        animate = true;
-        foreach (var gadget in GadgetCore.API.Gadgets.ListAllEnabledGadgets())
-          if (gadget.Info?.ModName == "More Lights")
-          {
-            animate = false;
-            break;
-          }
-      }
-
-      if (animate ?? false)
-        __instance.StartCoroutine(DoUpdateLampAnimation(__instance));
-      if (Core.itemStoreList.Contains(p[0]))
-        __instance.StartCoroutine(DoUpdateLoadingAnimation(__instance));
-
-      if (p[0] == Core.itemStoreList[0])
-      {
-        __instance.itemID = p[0];
-        __instance.cost = p[1];
-        __instance.icon.GetComponent<Renderer>().material = (Material)Resources.Load("i/i" + __instance.itemID.ToString());
-        __instance.txtCost[0].text = string.Empty + __instance.cost.ToString();
-        __instance.txtCost[1].text = __instance.txtCost[0].text;
-        __instance.txtName[0].text = string.Empty + ItemRegistry.GetItem(__instance.itemID).GetName();
-        __instance.txtName[1].text = __instance.txtName[0].text;
-        __instance.StartCoroutine(Patch_KylockeStand_Set.DoUpdatePlatformStand(__instance));
-        return false;
-      }
-      return true;
-    }
-
-    private static IEnumerator DoUpdatePlatformStand(KylockeStand instance)
-    {
-      instance.isBuild = true;
-      instance.isCredits = false;
-      instance.isTrophies = false;
-      instance.currency.GetComponent<Renderer>().material = (Material)Resources.Load("i/i57");
-      yield break;
-    }
-
-    private static bool? animate = null;
-
-    private static IEnumerator DoUpdateLampAnimation(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
-      };
-    }
-  }
-}

+ 8 - 27
ShipDecorations/ShipDecorations.cs

@@ -4,10 +4,11 @@ using UnityEngine.SceneManagement;
 using System.Reflection;
 using GadgetCore.API.ConfigMenu;
 using System;
+using ScrapYard.API;
 
 namespace ShipDecorations
 {
-  [Gadget("ShipDecorations")]
+  [Gadget("ShipDecorations", LoadAfter: new string[] { "ScrapYard" }, Dependencies: new string[] { "ScrapYard" })]
   public class ShipDecorations : Gadget<ShipDecorations>
   {
     public const string MOD_VERSION = "1.0"; // Set this to the version of your mod.
@@ -26,34 +27,14 @@ namespace ShipDecorations
       Logger.Log("Ship Decorations v" + Info.Mod.Version);
       Core.logger = Logger;
 
-      AddToList(ItemUtil.CreatePlacableDecoItem("cBed.png", "iBed.png", "Bed"), 1000);
-      AddToList(ItemUtil.CreatePlacableDecoItem("cTree5Plant.png", "iTree5Plant.png", "Tree Plant"), 2000);
-      AddToList(ItemUtil.CreatePlacableDecoItem("cPlant0Plant.png", "iPlant0Plant.png", "Bush Plant"), 2000);
-      AddToList(ItemUtil.CreatePlacableDecoItem("cTreantHeadPlant.png", "iTreantHeadPlant.png", "Treant Plant"), 10000);
-      AddToList(ItemUtil.CreatePlacableSlideDoorItem("cDoor.png", "cDoorOpen.png", "iDoor.png", "Door"), 5000);
+      var lightsPlatform = new ShopPlatform("Decorations").Register();
 
-      // SceneManager.sceneLoaded += OnSceneLoaded;
-    }
+      lightsPlatform.AddShopPlatformEntry(new ShopPlatformEntry(ItemUtil.CreatePlacableDecoItem("cBed.png", "iBed.png", "Bed"), 1000));
+      lightsPlatform.AddShopPlatformEntry(new ShopPlatformEntry(ItemUtil.CreatePlacableDecoItem("cPlant0Plant.png", "iPlant0Plant.png", "Bush Plant"), 1000));
+      lightsPlatform.AddShopPlatformEntry(new ShopPlatformEntry(ItemUtil.CreatePlacableDecoItem("cTree5Plant.png", "iTree5Plant.png", "Tree Plant"), 1000));
+      lightsPlatform.AddShopPlatformEntry(new ShopPlatformEntry(ItemUtil.CreatePlacableDecoItem("cTreantHeadPlant.png", "iTreantHeadPlant.png", "Treant Plant"), 1000));
+      lightsPlatform.AddShopPlatformEntry(new ShopPlatformEntry(ItemUtil.CreatePlacableSlideDoorItem("cDoor.png", "cDoorOpen.png", "iDoor.png", "Door"), 1000));
 
-    internal static void OnSceneLoaded(Scene scene, LoadSceneMode mode)
-    {
-      if (scene.buildIndex == 1)
-      {
-        try
-        {
-          // GameObject obj = GadgetCoreAPI.CreateMarketStand(ItemRegistry.GetItem(Core.itemStoreList[0]), new Vector2(-138f - 2 * 4, -7.49f), 100);
-          // // NetworkView network = obj.GetComponent<NetworkView>();
-          // // network.viewID = NetworkViewID.unassigned;
-          // // obj.GetComponent<KylockeStand>().Awake();
-        }
-        catch (Exception e) { Core.logger.LogConsole(e.Message); }
-      }
-    }
-
-    private void AddToList(int id, int price)
-    {
-      Core.itemStoreList.Add(id);
-      Core.itemStorePriceList.Add(id, price);
     }
   }
 }

+ 8 - 0
ShipDecorations/ShipDecorations.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>
@@ -308,4 +313,7 @@
       <EmbedInteropTypes>false</EmbedInteropTypes>
     </Reference>
   </ItemGroup>
+  <ItemGroup>
+    <Folder Include="Patches\" />
+  </ItemGroup>
 </Project>