Beispiel #1
0
        /// <summary>
        /// Private internal function for parsing vanilla data from the game's content files.
        /// </summary>
        /// <remarks>
        /// This is one of the hackiest methods in the entire project - it's meant to, ostenisbly, parse vanilla data.
        /// Since we're trying to fit as much data as we can with has little outside intervention as possible,
        /// we're forced to jump through a few hoops to interpret the data in a way that meshes with our
        /// system in a sensible way.
        /// </remarks>
        private void VanillaRegistration()
        {
            var objectInfo = _content.Load <Dictionary <int, string> >("Data\\ObjectInformation");

            foreach (var i in objectInfo.Keys)
            {
                var item = Item.ParseFromString(objectInfo[i]);
                if (item.IsError())
                {
                    GemfruitMod.Logger.Log(LogLevel.Error, "ItemRegistry", item.UnwrapError().Message);
                }
                else
                {
                    var val = item.Unwrap();
                    val.AssignSpriteSheetReference(new ResourceKey("Maps\\springobjects"), VanillaSpritesheetHelper.ItemIdToRectangle(i));
                    val.Key = VanillaResourceKeyTransformers.ApplyTransformerForKey(val, i, new ResourceKey(StringUtility.SanitizeName(val.Name)));
                    if (_dictionary.ContainsKey(val.Key))
                    {
                        val.Key = new ResourceKey(StringUtility.SanitizeName(val.Name) + "_" + i);
                    }

                    // If the item is presumably an artifact we're forced to perform some extra parsing on it.
                    if (val.Type.Contains("Arch"))
                    {
                        GemfruitMod.ArtifactDropRegistry.ParseVanillaItem(val.Key, objectInfo[i]);
                    }

                    // If the item is a Geode, we have to add the extra data geodes require.
                    if (val.Name.Contains("Geode"))
                    {
                        GemfruitMod.GeodeResultRegistry.ParseVanillaItem(val.Key, objectInfo[i], objectInfo);
                    }

                    Register(val.Key, val);
                }
            }

            var weaponsInfo = _content.Load <Dictionary <int, string> >("Data\\weapons");

            foreach (var i in weaponsInfo.Keys)
            {
                var item = Item.ParseWeaponFromString(weaponsInfo[i]);
                if (item.IsError())
                {
                    GemfruitMod.Logger.Log(LogLevel.Error, "ItemRegistry", item.UnwrapError().Message);
                }
                else
                {
                    var val = item.Unwrap();
                    val.AssignSpriteSheetReference(new ResourceKey("TileSheets\\weapons"), VanillaSpritesheetHelper.WeaponIdToRectangle(i));
                    val.Key = VanillaResourceKeyTransformers.ApplyTransformerForKey(val, i, new ResourceKey(StringUtility.SanitizeName(val.Name)));
                    if (_dictionary.ContainsKey(val.Key))
                    {
                        val.Key = new ResourceKey(StringUtility.SanitizeName(val.Name) + "_" + i);
                    }

                    Register(val.Key, val);
                }
            }
        }
        internal void ParseVanillaItem(ResourceKey item, string line, Dictionary <int, string> lines)
        {
            var items = new List <ResourceKey>();
            var parts = line.Split('/');

            if (parts.Length >= 7)
            {
                try
                {
                    var ids = parts[6].Split().Select(int.Parse).ToList();
                    items.AddRange(from i in ids
                                   let rname = lines[i].Split('/')[0]
                                               select VanillaResourceKeyTransformers.ApplyTransformerForKey(null, i,
                                                                                                            new ResourceKey(StringUtility.SanitizeName(rname))));
                    VanillaGeodes.Add(item, new GeodeResultData(items));
                }
                catch (Exception e)
                {
                    GemfruitMod.Logger.Log(LogLevel.Error, GetType().Name,
                                           $"error registering '{item}' geode drops - {e.Message}");
                    GemfruitMod.Logger.Log(LogLevel.Error, GetType().Name,
                                           e.StackTrace);
                }
            }
            else
            {
                GemfruitMod.Logger.Log(LogLevel.Warning, GetType().Name,
                                       $"for some reason, '{item}' doesn't look like a Geode");
            }
        }