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
        /// <summary>
        ///     Custom piece from a prefab with a <see cref="PieceConfig"/> attached.<br />
        ///     The members and references from the <see cref="PieceConfig"/> will be referenced by Jötunn at runtime.
        /// </summary>
        /// <param name="piecePrefab">The prefab for this custom piece.</param>
        /// <param name="pieceConfig">The <see cref="PieceConfig"/> for this custom piece.</param>
        public CustomPiece(GameObject piecePrefab, PieceConfig pieceConfig)
        {
            PiecePrefab  = piecePrefab;
            Piece        = piecePrefab.GetComponent <Piece>();
            PieceTable   = pieceConfig.PieceTable;
            FixReference = true;

            pieceConfig.Apply(piecePrefab);
        }
示例#3
0
        /// <summary>
        ///     Custom piece created as a copy of a vanilla Valheim prefab with a <see cref="PieceConfig"/> attached.<br />
        ///     The members and references from the <see cref="PieceConfig"/> will be referenced by Jötunn at runtime.
        /// </summary>
        /// <param name="name">The new name of the prefab after cloning.</param>
        /// <param name="baseName">The name of the base prefab the custom item is cloned from.</param>
        /// <param name="pieceConfig">The <see cref="PieceConfig"/> for this custom piece.</param>
        public CustomPiece(string name, string baseName, PieceConfig pieceConfig)
        {
            PiecePrefab = PrefabManager.Instance.CreateClonedPrefab(name, baseName);
            if (PiecePrefab)
            {
                Piece      = PiecePrefab.GetComponent <Piece>();
                PieceTable = pieceConfig.PieceTable;
                FixConfig  = true;

                pieceConfig.Apply(PiecePrefab);
            }
        }
示例#4
0
        /// <summary>
        ///     Custom piece created as an "empty" primitive with a <see cref="PieceConfig"/> attached.<br />
        ///     The members and references from the <see cref="PieceConfig"/> will be referenced by Jötunn at runtime.
        /// </summary>
        /// <param name="name">Name of the new prefab. Must be unique.</param>
        /// <param name="addZNetView">If true a ZNetView component will be added to the prefab for network sync.</param>
        /// <param name="pieceConfig">The <see cref="PieceConfig"/> for this custom piece.</param>
        public CustomPiece(string name, bool addZNetView, PieceConfig pieceConfig)
        {
            PiecePrefab = PrefabManager.Instance.CreateEmptyPrefab(name, addZNetView);
            if (PiecePrefab)
            {
                Piece      = PiecePrefab.AddComponent <Piece>();
                PieceTable = pieceConfig.PieceTable;
                FixConfig  = true;

                pieceConfig.Apply(PiecePrefab);
            }
        }
示例#5
0
    public static void DecodeTable(string str)
    {
        Configs.Clear();
        str = StringUtils.Replace(str, '\r', '\n');
        str = StringUtils.Replace(str, "\n\n", '\n');
        List <List <string> > list = CSV.Parse(str);

        for (int i = 2, len = list.Count; i < len; i++)
        {
            PieceConfig item = new PieceConfig();
            item.Decode(list[i]);
            Configs.Add(item);
        }
    }
示例#6
0
        /// <summary>
        ///     Custom piece from a prefab loaded from an <see cref="AssetBundle"/> with a PieceConfig attached.<br />
        ///     Will be added to the <see cref="global::PieceTable"/> provided by name.
        /// </summary>
        /// <param name="assetBundle">A preloaded <see cref="AssetBundle"/></param>
        /// <param name="assetName">Name of the prefab in the bundle.</param>
        /// <param name="pieceConfig">The <see cref="PieceConfig"/> for this custom piece.</param>
        public CustomPiece(AssetBundle assetBundle, string assetName, PieceConfig pieceConfig)
        {
            var piecePrefab = (GameObject)assetBundle.LoadAsset(assetName);

            if (piecePrefab)
            {
                PiecePrefab = piecePrefab;
                Piece       = piecePrefab.GetComponent <Piece>();
                PieceTable  = pieceConfig.PieceTable;

                pieceConfig.Apply(piecePrefab);
            }
            FixReference = true;
        }
示例#7
0
        private void AddInvalidItems()
        {
            CustomItem CI = new CustomItem("item_faulty", false);

            if (CI != null)
            {
                CI.ItemDrop.m_itemData.m_shared.m_icons = new Sprite[]
                {
                    testSprite
                };
                ItemManager.Instance.AddItem(CI);

                CustomRecipe CR = new CustomRecipe(new RecipeConfig
                {
                    Item         = "item_faulty",
                    Requirements = new RequirementConfig[]
                    {
                        new RequirementConfig {
                            Item = "NotReallyThereResource", Amount = 99
                        }
                    }
                });
                ItemManager.Instance.AddRecipe(CR);
            }

            CustomPiece CP = new CustomPiece("piece_fukup", "Hammer");

            if (CP != null)
            {
                var piece = CP.Piece;
                piece.m_icon = testSprite;
                var prefab = CP.PiecePrefab;

                // Test faulty resource, do it manually cause there is no config on empty pieces atm
                var cfg = new PieceConfig
                {
                    Requirements = new RequirementConfig[]
                    {
                        new RequirementConfig {
                            Item = "StillNotThereResource", Amount = 99
                        }
                    }
                };
                cfg.Apply(prefab);
                CP.FixReference = true;

                PieceManager.Instance.AddPiece(CP);
            }
        }
示例#8
0
 public static void Decode()
 {
     CoordConfig.DecodeTable(Resources.Load("config/Coord") + "");
     LanguageConfig.DecodeTable(Resources.Load("config/Language") + "");
     LanguageTypeConfig.DecodeTable(Resources.Load("config/LanguageType") + "");
     LevelConfig.DecodeTable(Resources.Load("config/Level") + "");
     ModelConfig.DecodeTable(Resources.Load("config/Model") + "");
     PassScoreConfig.DecodeTable(Resources.Load("config/PassScore") + "");
     PieceConfig.DecodeTable(Resources.Load("config/Piece") + "");
     CoordConfig.DecodeTableItem();
     LanguageConfig.DecodeTableItem();
     LanguageTypeConfig.DecodeTableItem();
     LevelConfig.DecodeTableItem();
     ModelConfig.DecodeTableItem();
     PassScoreConfig.DecodeTableItem();
     PieceConfig.DecodeTableItem();
 }
示例#9
0
 public void DecodeConfigItem()
 {
     for (int i = 0; i < list.Count; i++)
     {
         if (i == 1)
         {
             List <string> itemList = StringUtils.Split(list[1], ',');
             for (int n = 0; n < itemList.Count; n++)
             {
                 if (itemList[n].Length == 0)
                 {
                     continue;
                 }
                 int item = (int)StringUtils.ToNumber(itemList[n]);
                 pieces.Add(PieceConfig.GetConfig(item));
             }
         }
         if (i == 2)
         {
             List <string> itemList = StringUtils.Split(list[2], ',');
             for (int n = 0; n < itemList.Count; n++)
             {
                 if (itemList[n].Length == 0)
                 {
                     continue;
                 }
                 int item = (int)StringUtils.ToNumber(itemList[n]);
                 pieces2.Add(PieceConfig.GetConfig(item));
             }
         }
         if (i == 3)
         {
             List <string> itemList = StringUtils.Split(list[3], ',');
             for (int n = 0; n < itemList.Count; n++)
             {
                 if (itemList[n].Length == 0)
                 {
                     continue;
                 }
                 int item = (int)StringUtils.ToNumber(itemList[n]);
                 coords.Add(CoordConfig.GetConfig(item));
             }
         }
     }
     list = null;
 }
示例#10
0
        private static void CreatePrefabPiece(GameObject prefab)
        {
            InitPieceData(prefab);

            var pieceConfig = new PieceConfig
            {
                Name              = prefab.name,
                Description       = GetPrefabFriendlyName(prefab),
                PieceTable        = "_HammerPieceTable",
                Category          = GetPrefabCategory(prefab),
                AllowedInDungeons = true,
                Icon              = CreatePrefabIcon(prefab)
            };

            var piece = new CustomPiece(prefab, true, pieceConfig);

            PieceManager.Instance.AddPiece(piece);
        }
示例#11
0
        // Add a custom item from an "empty" prefab
        private void AddEmptyItems()
        {
            CustomPiece CP = new CustomPiece("piece_lul", "Hammer");

            if (CP != null)
            {
                var piece = CP.Piece;
                piece.m_icon = testSprite;
                var prefab = CP.PiecePrefab;
                prefab.GetComponent <MeshRenderer>().material.mainTexture = testTex;

                // Test station extension, do it manually cause there is no config on empty pieces atm
                var cfg = new PieceConfig
                {
                    ExtendStation = "piece_workbench"
                };
                cfg.Apply(prefab);
                CP.FixReference = true;

                PieceManager.Instance.AddPiece(CP);
            }
        }
示例#12
0
    public SaveLevelCommand(int level)
    {
        //读取配置
        //ConfigDecode.Decode();

        //删除之前的 level 相关信息
        if (LevelConfig.GetConfig(level) != null)
        {
            LevelConfig old = LevelConfig.GetConfig(level);
            LevelConfig.Configs.Remove(old);
            for (int i = 0; i < old.pieces.Count; i++)
            {
                PieceConfig.Configs.Remove(PieceConfig.GetConfig(old.pieces[i].id));
            }
            for (int i = 0; i < old.pieces2.Count; i++)
            {
                PieceConfig.Configs.Remove(PieceConfig.GetConfig(old.pieces2[i].id));
            }
        }

        if (EditorVO.Instance.level.pieces.Count > 0)
        {
            LevelConfig levelConfig = new LevelConfig();
            LevelConfig.Configs.Add(levelConfig);
            levelConfig.id = level;

            for (int i = 0; i < EditorVO.Instance.level.pieces.Count; i++)
            {
                EditorLevelPiece piece       = EditorVO.Instance.level.pieces[i];
                PieceConfig      pieceConfig = new PieceConfig();
                levelConfig.pieces.Add(pieceConfig);
                pieceConfig.id = level * 100 + i;
                for (int c = 0; c < piece.grids.Count; c++)
                {
                    if (CoordConfig.GetConfig(piece.grids[c].x * 1000 + -piece.grids[c].y) == null)
                    {
                        CoordConfig coord = new CoordConfig();
                        coord.x  = piece.grids[c].x;
                        coord.y  = piece.grids[c].y;
                        coord.id = piece.grids[c].x * 1000 + -piece.grids[c].y;
                        CoordConfig.Configs.Add(coord);
                    }
                    pieceConfig.coords.Add(CoordConfig.GetConfig(piece.grids[c].x * 1000 + -piece.grids[c].y));
                }
                PieceConfig.Configs.Add(pieceConfig);
            }

            for (int i = 0; i < EditorVO.Instance.level.otherPieces.Count; i++)
            {
                EditorLevelPiece piece       = EditorVO.Instance.level.otherPieces[i];
                PieceConfig      pieceConfig = new PieceConfig();
                levelConfig.pieces2.Add(pieceConfig);
                pieceConfig.id = level * 100 + EditorVO.Instance.level.pieces.Count + i;
                for (int c = 0; c < piece.grids.Count; c++)
                {
                    if (CoordConfig.GetConfig(piece.grids[c].x * 1000 + -piece.grids[c].y) == null)
                    {
                        CoordConfig coord = new CoordConfig();
                        coord.x  = piece.grids[c].x;
                        coord.y  = piece.grids[c].y;
                        coord.id = piece.grids[c].x * 1000 + -piece.grids[c].y;
                        CoordConfig.Configs.Add(coord);
                    }
                    pieceConfig.coords.Add(CoordConfig.GetConfig(piece.grids[c].x * 1000 + -piece.grids[c].y));
                }
                PieceConfig.Configs.Add(pieceConfig);
            }

            CheckLevelPiecePosition(levelConfig);
        }

        //CheckAllLevelPiecePosition();

        Save();
        //CheckOut();
    }
示例#13
0
        private static void RegisterPrefab(string ResourceName)
        {
            try
            {
                // read the json and parse it into it's respective json class
                string jsonData             = ReadEmbeddedJSON(ResourceName);
                Models.JSON.JSON_Prefab obj = SimpleJson.SimpleJson.DeserializeObject <Models.JSON.JSON_Prefab>(jsonData);
                GameObject prefab           = PrefabBundle.LoadAsset <GameObject>(obj.Prefab);

                switch (obj.Type)
                {
                case "Piece":
                    // create the piece config and prep it
                    var pieceConfig = new PieceConfig();
                    pieceConfig.PieceTable = obj.PieceConfig.PieceTable;

                    // Add the ingredient requirements to the recipe
                    var requirements = new List <RequirementConfig>();
                    foreach (KeyValuePair <string, int> requirement in obj.PieceConfig.Requirements)
                    {
                        var newRequirement = new RequirementConfig();
                        newRequirement.Item   = requirement.Key;
                        newRequirement.Amount = requirement.Value;
                        requirements.Add(newRequirement);
                    }
                    pieceConfig.Requirements = requirements.ToArray();

                    // init the piece and add it to the game with jotunn
                    CustomPiece newPiece = new CustomPiece(prefab, pieceConfig);
                    PieceManager.Instance.AddPiece(newPiece);
                    break;

                case "Item":
                    // init the item and add it to the game with jotunn
                    CustomItem newItem = new CustomItem(prefab, false);
                    ItemManager.Instance.AddItem(newItem);

                    // create the item recipe and prep some details
                    Recipe newRecipe = ScriptableObject.CreateInstance <Recipe>();
                    newRecipe.name              = "Recipe_" + newItem.ItemDrop.name;
                    newRecipe.m_item            = prefab.GetComponent <ItemDrop>();
                    newRecipe.m_craftingStation = Mock <CraftingStation> .Create(obj.RecipeConfig.CraftingStation);

                    // Add the ingredient requirements to the recipe
                    var ingredients = new List <Piece.Requirement>();
                    foreach (KeyValuePair <string, int> ingredient in obj.RecipeConfig.Ingredients)
                    {
                        ingredients.Add(MockRequirement.Create(ingredient.Key, ingredient.Value));
                    }
                    newRecipe.m_resources = ingredients.ToArray();

                    // add the custom recipe to the game with jotunn
                    CustomRecipe customRecipe = new CustomRecipe(newRecipe, true, true);
                    ItemManager.Instance.AddRecipe(customRecipe);
                    break;
                }

                // add the translations to our system list
                foreach (KeyValuePair <string, string> entry in obj.Translations)
                {
                    EnglishTranslations.Add(entry.Key, entry.Value);
                }
            }
            catch (Exception err)
            {
                Console.print("Unable to register prefab: " + ResourceName + " => " + err);
            }
        }
示例#14
0
        private static void AddStonePressurePlate(AssetBundle assetBundle)
        {
            GameObject basePlate = assetBundle.LoadAsset <GameObject>("pressure_plate.prefab");
            GameObject plate     = PrefabManager.Instance.CreateClonedPrefab("pressurePlate_stone_PressurePlate_Items_AddPlateItem", basePlate);
            Sprite     icon      = assetBundle.LoadAsset <Sprite>("pressure_plate_stone_icon.png");

            PieceConfig pieceConfig = new PieceConfig()
            {
                CraftingStation = "piece_stonecutter",
                Requirements    = new RequirementConfig[] {
                    new RequirementConfig()
                    {
                        Item = "Stone", Amount = 3, Recover = true
                    },
                    new RequirementConfig()
                    {
                        Item = "SurtlingCore", Amount = 1, Recover = true
                    },
                },
                PieceTable = "Hammer",
                Icon       = icon,
            };

            CustomPiece customPiece = new CustomPiece(plate, pieceConfig);

            Piece      piece     = customPiece.Piece;
            GameObject prefab    = customPiece.PiecePrefab;
            WearNTear  wearNTear = prefab.GetComponent <WearNTear>();

            piece.m_category = Piece.PieceCategory.Building;
            piece.m_name     = "$pressure_plate_stone";

            PrefabManager.OnPrefabsRegistered += ApplyEffects;
            void ApplyEffects()
            {
                PrefabManager.OnPrefabsRegistered -= ApplyEffects;
                Material   stoneMaterial       = PrefabManager.Cache.GetPrefab <Material>("stonefloor");
                GameObject vfxPlaceStoneFloor  = PrefabManager.Cache.GetPrefab <GameObject>("vfx_Place_stone_wall_2x1");
                GameObject sfxBuildHammerStone = PrefabManager.Cache.GetPrefab <GameObject>("sfx_build_hammer_stone");
                GameObject vfxRockDestroyed    = PrefabManager.Cache.GetPrefab <GameObject>("vfx_RockDestroyed");
                GameObject sfxRockDestroyed    = PrefabManager.Cache.GetPrefab <GameObject>("sfx_rock_destroyed");
                GameObject vfxRockHit          = PrefabManager.Cache.GetPrefab <GameObject>("vfx_RockHit");
                GameObject sfxRockHit          = PrefabManager.Cache.GetPrefab <GameObject>("sfx_rock_hit");

                stoneMaterial = new Material(stoneMaterial);
                stoneMaterial.SetTextureScale("_MainTex", new Vector2(0.14f, 0.14f));
                stoneMaterial.SetTextureOffset("_MainTex", new Vector2(0.28f, 0.08f));
                wearNTear.m_new.GetComponent <MeshRenderer>().materials = new[] { stoneMaterial };

                wearNTear.m_destroyedEffect.m_effectPrefabs = new[] {
                    new EffectList.EffectData()
                    {
                        m_prefab = vfxRockDestroyed
                    },
                    new EffectList.EffectData()
                    {
                        m_prefab = sfxRockDestroyed
                    },
                };
                wearNTear.m_hitEffect.m_effectPrefabs = new[] {
                    new EffectList.EffectData()
                    {
                        m_prefab = vfxRockHit
                    },
                    new EffectList.EffectData()
                    {
                        m_prefab = sfxRockHit
                    },
                };
                piece.m_placeEffect.m_effectPrefabs = new[] {
                    new EffectList.EffectData()
                    {
                        m_prefab = vfxPlaceStoneFloor
                    },
                    new EffectList.EffectData()
                    {
                        m_prefab = sfxBuildHammerStone
                    },
                };
            }

            PieceManager.Instance.AddPiece(customPiece);
        }
示例#15
0
        private static void AddWoodPressurePlate(AssetBundle assetBundle)
        {
            GameObject basePlate = assetBundle.LoadAsset <GameObject>("pressure_plate.prefab");
            GameObject plate     = PrefabManager.Instance.CreateClonedPrefab("pressurePlate_PressurePlate_Items_AddPlateItem", basePlate);
            Sprite     icon      = assetBundle.LoadAsset <Sprite>("pressure_plate_wood_icon.png");

            PieceConfig pieceConfig = new PieceConfig()
            {
                CraftingStation = "piece_workbench",
                Requirements    = new RequirementConfig[] {
                    new RequirementConfig()
                    {
                        Item = "Wood", Amount = 3, Recover = true
                    },
                    new RequirementConfig()
                    {
                        Item = "SurtlingCore", Amount = 1, Recover = true
                    },
                },
                PieceTable = "Hammer",
                Icon       = icon,
            };

            CustomPiece customPiece = new CustomPiece(plate, pieceConfig);

            Piece      piece     = customPiece.Piece;
            GameObject prefab    = customPiece.PiecePrefab;
            WearNTear  wearNTear = prefab.GetComponent <WearNTear>();

            piece.m_category = Piece.PieceCategory.Building;
            piece.m_name     = "$pressure_plate_wood";

            PrefabManager.OnPrefabsRegistered += ApplyEffects;
            void ApplyEffects()
            {
                PrefabManager.OnPrefabsRegistered -= ApplyEffects;
                Material   woodMaterial       = PrefabManager.Cache.GetPrefab <Material>("woodwall");
                GameObject vfxPlaceWoodFloor  = PrefabManager.Cache.GetPrefab <GameObject>("vfx_Place_wood_floor");
                GameObject sfxBuildHammerWood = PrefabManager.Cache.GetPrefab <GameObject>("sfx_build_hammer_wood");
                GameObject sfxWoodDestroyed   = PrefabManager.Cache.GetPrefab <GameObject>("sfx_wood_destroyed");
                GameObject vfxSawDust         = PrefabManager.Cache.GetPrefab <GameObject>("vfx_SawDust");

                wearNTear.m_new.GetComponent <MeshRenderer>().materials = new[] { woodMaterial };
                wearNTear.m_destroyedEffect.m_effectPrefabs             = new[] {
                    new EffectList.EffectData()
                    {
                        m_prefab = sfxWoodDestroyed
                    },
                    new EffectList.EffectData()
                    {
                        m_prefab = vfxSawDust
                    },
                };
                wearNTear.m_hitEffect.m_effectPrefabs = new[] {
                    new EffectList.EffectData()
                    {
                        m_prefab = vfxSawDust
                    },
                };
                piece.m_placeEffect.m_effectPrefabs = new[] {
                    new EffectList.EffectData()
                    {
                        m_prefab = vfxPlaceWoodFloor
                    },
                    new EffectList.EffectData()
                    {
                        m_prefab = sfxBuildHammerWood
                    },
                };
            }

            PieceManager.Instance.AddPiece(customPiece);
        }