Пример #1
0
        internal void RegisterPiece()
        {
            logger.LogInfo("Registering Seed Totem Piece");
            Texture2D iconTexture = AssetUtils.LoadTexture(SeedTotemMod.GetAssetPath(iconPath));
            Sprite    iconSprite  = null;

            if (iconTexture == null)
            {
                logger.LogWarning("Icon missing, should be at " + iconPath + ", using default icon instead ");
            }
            else
            {
                iconSprite = Sprite.Create(iconTexture, new Rect(0f, 0f, iconTexture.width, iconTexture.height), Vector2.zero);
            }
            PieceConfig pieceConfig = new PieceConfig()
            {
                PieceTable   = configLocation.GetSerializedValue(),
                Description  = "$piece_seed_totem_description",
                Requirements = LoadJsonFile(SeedTotemMod.GetAssetPath("seed-totem-custom-requirements.json"))
            };

            if (iconSprite)
            {
                pieceConfig.Icon = iconSprite;
            }

            CustomPiece customPiece = new CustomPiece(Prefab, pieceConfig);

            PieceManager.Instance.AddPiece(customPiece);
        }
Пример #2
0
        private static RequirementConfig[] LoadJsonFile(string filename)
        {
            RequirementConfig[] defaultRecipe = new RequirementConfig[] {
                new RequirementConfig()
                {
                    Item    = "FineWood",
                    Amount  = 5,
                    Recover = true
                },
                new RequirementConfig()
                {
                    Item    = "GreydwarfEye",
                    Amount  = 5,
                    Recover = true
                },
                new RequirementConfig()
                {
                    Item    = "SurtlingCore",
                    Amount  = 1,
                    Recover = true
                },
                new RequirementConfig()
                {
                    Item    = "AncientSeed",
                    Amount  = 1,
                    Recover = true
                }
            };
            if (SeedTotem.configCustomRecipe.Value)
            {
                string assetPath = SeedTotemMod.GetAssetPath(filename);
                bool   fileFound = string.IsNullOrEmpty(assetPath);
                if (fileFound)
                {
                    logger.LogWarning("File not found: " + filename + " using default recipe");
                    return(defaultRecipe);
                }

                Dictionary <string, int> reqDict = ReadDict(assetPath);
                RequirementConfig[]      result  = new RequirementConfig[reqDict.Count];
                int i = 0;
                foreach (KeyValuePair <string, int> pair in reqDict)
                {
                    result[i] = new RequirementConfig()
                    {
                        Item    = pair.Key,
                        Amount  = pair.Value,
                        Recover = true
                    };
                }
                return(result);
            }
            else
            {
                return(defaultRecipe);
            }
        }