Quellcode durchsuchen

[ScrapYard] [2.0.3.8] Stop duplications

Zariteis vor 4 Jahren
Ursprung
Commit
298c6aa6fe

+ 27 - 7
ScrapYard/API/ShopPlatform.cs

@@ -1,4 +1,5 @@
-using System.Collections.Generic;
+using System;
+using System.Collections.Generic;
 
 namespace ScrapYard.API
 {
@@ -10,21 +11,21 @@ namespace ScrapYard.API
 
     internal List<ShopPlatformEntry> Entries = new List<ShopPlatformEntry>();
 
-    internal static List<ShopPlatform> ShopPlatforms = new List<ShopPlatform>();
+    internal static Dictionary<string, ShopPlatform> ShopPlatforms = new Dictionary<string, ShopPlatform>();
 
     public static ShopPlatform DefaultObjects
     {
-      get => ShopPlatforms[0];
+      get => ShopPlatforms["DefaultObjects"];
     }
 
     public static ShopPlatform DefaultBlocks
     {
-      get => ShopPlatforms[1];
+      get => ShopPlatforms["DefaultBlocks"];
     }
 
     public static ShopPlatform DefaultWalls
     {
-      get => ShopPlatforms[2];
+      get => ShopPlatforms["DefaultWalls"];
     }
 
     public ShopPlatform(string title, ShopPlatformSpacingType spacingType = ShopPlatformSpacingType.Normal)
@@ -35,7 +36,15 @@ namespace ScrapYard.API
 
     public virtual ShopPlatform Register()
     {
-      ShopPlatforms.Add(this);
+      return Register(this.Title);
+    }
+
+    public virtual ShopPlatform Register(string id)
+    {
+      if (ShopPlatforms.ContainsKey(id))
+        ShopPlatforms.Remove(id);
+
+      ShopPlatforms.Add(id, this);
       return this;
     }
 
@@ -46,6 +55,12 @@ namespace ScrapYard.API
 
     public void AddShopPlatformEntry(ShopPlatformEntry row)
     {
+      foreach (var e in Entries)
+        if (e.CurrencyItemID == row.CurrencyItemID
+          && e.ItemID == row.ItemID
+          && e.Quantity == row.Quantity
+          && e.Price == row.Price)
+          return;
       Entries.Add(row);
     }
 
@@ -61,7 +76,7 @@ namespace ScrapYard.API
 
     public static ShopPlatform[] GetShopPlatforms()
     {
-      return ShopPlatforms.ToArray();
+      return new List<ShopPlatform>(ShopPlatforms.Values).ToArray();
     }
 
     internal int GetSpacesPerRow()
@@ -86,6 +101,11 @@ namespace ScrapYard.API
     {
       return ((Entries.Count - 1) / GetSpacesPerRow()) + 1;
     }
+
+    internal static void Reset()
+    {
+      ShopPlatforms = new Dictionary<string, ShopPlatform>();
+    }
   }
 
   public enum ShopPlatformSpacingType

BIN
ScrapYard/Assets/iScrapTrophy.png


BIN
ScrapYard/Assets/merchantBody.png


BIN
ScrapYard/Assets/merchantHead.png


BIN
ScrapYard/Assets/merchantPortrait.png


BIN
ScrapYard/Assets/parallax.png


BIN
ScrapYard/Assets/planetScrapYard.png


BIN
ScrapYard/Assets/planetScrapYardPrev.png


BIN
ScrapYard/Assets/scrapYardStand.png


BIN
ScrapYard/Assets/scrapYardStandInfo.png


BIN
ScrapYard/Assets/shopStand.png


BIN
ScrapYard/Assets/shopStand_old.png


BIN
ScrapYard/Assets/signScrapYard.png


+ 2 - 2
ScrapYard/Patches/Patch_KylockeStand_Awake.cs

@@ -21,9 +21,9 @@ namespace ScrapYard.Patches
     {
       while (!Network.isServer && !Network.isClient)
       {
-        yield return new WaitForSeconds(0.5f);
+        yield return new WaitForSeconds(0.25f);
       }
-      yield return new WaitForSeconds(2f);
+      yield return new WaitForSeconds(0.5f);
       if (instance.itemID >= 2000 && instance.itemID < 2500 || instance.itemID == ItemRegistry.GetItemIDByRegistryName("Gadget Core:Crafter Block"))
       {
         instance.gameObject.SetActive(false);

+ 7 - 5
ScrapYard/ScrapYard.cs

@@ -7,10 +7,10 @@ using UnityEngine.SceneManagement;
 
 namespace ScrapYard
 {
-  [Gadget("ScrapYard")]
+  [Gadget("ScrapYard", GadgetVersionSpecificity: VersionSpecificity.NONBREAKING)]
   public class ScrapYard : Gadget<ScrapYard>
   {
-    public const string MOD_VERSION = "1.3"; // Set this to the version of your mod.
+    public const string MOD_VERSION = "1.4"; // 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.
 
     protected override void LoadConfig()
@@ -260,10 +260,12 @@ namespace ScrapYard
         tile.OnInteract += OnInteractStand;
       }
 
+      ShopPlatform.Reset();
+
       // Setting up default shop platforms
-      new ShopPlatform("Default Objects", ShopPlatformSpacingType.Near).Register();
-      new ShopPlatform("Default Blocks", ShopPlatformSpacingType.Near).Register();
-      new ShopPlatform("Default Walls", ShopPlatformSpacingType.Near).Register();
+      new ShopPlatform("Default Objects", ShopPlatformSpacingType.Near).Register("DefaultObjects");
+      new ShopPlatform("Default Blocks", ShopPlatformSpacingType.Near).Register("DefaultBlocks");
+      new ShopPlatform("Default Walls", ShopPlatformSpacingType.Near).Register("DefaultWalls");
 
       ShopPlatform.DefaultBlocks.AddShopPlatformEntry(new ShopPlatformEntry(2000, 100));
       ShopPlatform.DefaultBlocks.AddShopPlatformEntry(new ShopPlatformEntry(2001, 100));

+ 7 - 5
ScrapYard/ScrapYardGenerator.cs

@@ -9,6 +9,7 @@ namespace ScrapYard
   public class ScrapYardGenerator
   {
     private static readonly FieldInfo chunksField = typeof(SpawnerScript).GetField("chunks", BindingFlags.NonPublic | BindingFlags.Instance);
+    private static readonly Material materialaBackLight = new Material(Shader.Find("Unlit/Transparent")) { mainTexture = GadgetCoreAPI.LoadTexture2D("parallax.png") };
     private static readonly Material materialaParalex0 = new Material(Shader.Find("Unlit/Transparent")) { mainTexture = GadgetCoreAPI.LoadTexture2D("bScrapYardbg0.png") };
     private static readonly Material materialaParalex1 = new Material(Shader.Find("Unlit/Transparent")) { mainTexture = GadgetCoreAPI.LoadTexture2D("bScrapYardbg1.png") };
     private static readonly Material materialaParalex2 = new Material(Shader.Find("Unlit/Transparent")) { mainTexture = GadgetCoreAPI.LoadTexture2D("bScrapYardbg2.png") };
@@ -23,6 +24,7 @@ namespace ScrapYard
       {
         s.backLights.SetActive(true);
         s.mainLight.SetActive(true);
+        s.backLights.GetComponent<Renderer>().material = materialaBackLight;
         s.mainLight.GetComponentInChildren<Light>().color = new Color(0.05f, 0.05f, 0.05f, 0.1f);
 
         s.bg[0].GetComponent<Renderer>().material = materialaParalex0;
@@ -40,7 +42,7 @@ namespace ScrapYard
         int rowsNeeded = 0;
         foreach (var entry in ShopPlatform.ShopPlatforms)
         {
-          rowsNeeded += entry.GetRowsNeeded();
+          rowsNeeded += entry.Value.GetRowsNeeded();
         }
         int extensionAmount = System.Math.Max((rowsNeeded + 3) / 8, 0);
         for (int i = 0; i < extensionAmount; i++)
@@ -87,16 +89,16 @@ namespace ScrapYard
         int rowNumber = -1;
         foreach (var platform in ShopPlatform.ShopPlatforms)
         {
-          for (int i = 0; i < platform.Entries.Count; i++)
+          for (int i = 0; i < platform.Value.Entries.Count; i++)
           {
-            ShopPlatformEntry entry = platform.Entries[i];
-            if ((i % platform.GetSpacesPerRow()) == 0)
+            ShopPlatformEntry entry = platform.Value.Entries[i];
+            if ((i % platform.Value.GetSpacesPerRow()) == 0)
             {
               rowNumber++;
               networkStuff[temp] = (GameObject)Network.Instantiate(Resources.Load("prop/ScrapYard/metalPlatform"), new Vector3(300, rowNumber * 8f, 0.4f), Quaternion.identity, 0);
               temp++;
             }
-            var step = (i % platform.GetSpacesPerRow()) / (float)(platform.GetSpacesPerRow() - 1);
+            var step = (i % platform.Value.GetSpacesPerRow()) / (float)(platform.Value.GetSpacesPerRow() - 1);
             networkStuff[temp] = (GameObject)Network.Instantiate((GameObject)Resources.Load("prop/ScrapYard/stand"), new Vector3(300 - (40 / 2) + (step * 40), rowNumber * 8f + 0.5f - 0.05f, 0.2f), Quaternion.identity, 0);
             networkStuff[temp].GetComponent<ScrapYardShopStandScript>().StartCallSet(entry.ItemID, entry.Price, entry.Quantity, entry.CurrencyItemID);
             temp++;