Example #1
0
        /// <summary>
        /// Add data before game data loads
        /// </summary>
        /// <param name="proto">要添加的Proto</param>
        public static void PreAddProto(Proto proto)
        {
            int index = ProtoIndex.GetIndex(proto.GetType());

            if (!PreToAdd[index].Contains(proto))
            {
                if (proto is StringProto)
                {
                    int id = FindAvailableStringID();
                    proto.ID = id;
                }

                Bind(proto);
                PreToAdd[index].Add(proto);
                TotalDict[index].Add(proto);
            }
        }
Example #2
0
        /// <summary>
        /// Check if string with id was already registered
        /// </summary>
        /// <param name="id">ID</param>
        private static bool HasStringIdRegisted(int id)
        {
            if (LDB.strings.dataIndices.ContainsKey(id))
            {
                return(true);
            }

            if (PreToAdd[ProtoIndex.GetIndex(typeof(StringProto))].Any(proto => proto.ID == id))
            {
                return(true);
            }
            if (PostToAdd[ProtoIndex.GetIndex(typeof(StringProto))].Any(proto => proto.ID == id))
            {
                return(true);
            }

            return(false);
        }
Example #3
0
        /// <summary>
        /// Bind the ID through the configuration file, allowing players to customize the ID in the event of conflict
        /// </summary>
        private static void IdBind(Proto proto)
        {
            if (proto is StringProto)
            {
                return;
            }
            int index = ProtoIndex.GetIndex(proto);

            var entry = CustomID.Bind(ProtoIndex.GetProtoName(proto), proto.Name, proto.ID);

            proto.ID = entry.Value;

            if (IDDict[index].ContainsKey(proto.Name))
            {
                LDBToolPlugin.logger.LogError($"[CustomID] ID:{proto.ID} Name:{proto.Name} There is a conflict, please check.");
            }
            else
            {
                IDDict[index].Add(proto.Name, entry);
            }
        }
Example #4
0
        /// <summary>
        /// Bind GridIndex through the configuration file, allowing players to customize GridIndex in the event of conflict
        /// Execute after custom ID
        /// </summary>
        private static void GridIndexBind(Proto proto)
        {
            ConfigEntry <int> entry = null;

            if (proto is ItemProto item)
            {
                entry = CustomGridIndex.Bind(ProtoIndex.GetProtoName(proto), item.ID.ToString(), 0, $"Default Grid Index = {item.GridIndex}\nItem Name = {item.Name}");

                if (entry.Value != 0)
                {
                    item.GridIndex = entry.Value;
                }
            }
            else if (proto is RecipeProto recipe)
            {
                entry = CustomGridIndex.Bind(ProtoIndex.GetProtoName(proto), recipe.ID.ToString(), 0, $"Default Grid Index = {recipe.GridIndex}\nRecipe Name = {recipe.Name}");

                if (entry.Value != 0)
                {
                    recipe.GridIndex = entry.Value;
                }
            }

            if (entry == null)
            {
                return;
            }

            int index = ProtoIndex.GetIndex(proto);

            if (GridIndexDict[index].ContainsKey(proto.Name))
            {
                LDBToolPlugin.logger.LogError($"[CustomGridIndex] ID:{proto.ID} Name:{proto.Name} There is a conflict, please check.");
            }
            else
            {
                GridIndexDict[index].Add(proto.Name, entry);
            }
        }