Ejemplo n.º 1
0
        private void VanillaRegistrations()
        {
            var fdict = _content.Load <Dictionary <int, string> >("Data\\Furniture");

            _furnitureDefaultDesc = _content.LoadString("Strings\\StringsFromCSFiles:Furniture.cs.12623");
            foreach (var i in fdict.Keys)
            {
                var plac = Placeable.ParseFromFurnitureString(fdict[i], _furnitureDefaultDesc);
                if (plac.IsError())
                {
                    GemfruitMod.Logger.Log(LogLevel.Error, "PlaceableRegistry", plac.UnwrapError().Message);
                }
                else
                {
                    var val = plac.Unwrap();
                    var r   = val.Rect;
                    r.Location = VanillaSpritesheetHelper.FurnitureIdToLocation(i);
                    val.AssignSpriteSheetReference(new ResourceKey("TileSheets\\furniture"), r);

                    val.Key = new ResourceKey(StringUtility.SanitizeName(val.Name));
                    if (_dictionary.ContainsKey(val.Key))
                    {
                        val.Key = new ResourceKey(StringUtility.SanitizeName(val.Name) + "_" + i);
                    }

                    Register(val.Key, val);
                }
            }

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

            foreach (var i in cdict.Keys)
            {
                var plac = Placeable.ParseFromBigCraftableString(cdict[i]);
                if (plac.IsError())
                {
                    GemfruitMod.Logger.Log(LogLevel.Error, "PlaceableRegistry", plac.UnwrapError().Message);
                }
                else
                {
                    var val = plac.Unwrap();
                    var r   = val.Rect;
                    r.Location = VanillaSpritesheetHelper.CraftableIdToLocation(i);
                    val.AssignSpriteSheetReference(new ResourceKey("TileSheets\\Craftables"), r);

                    val.Key = new ResourceKey(StringUtility.SanitizeName(val.Name));
                    if (_dictionary.ContainsKey(val.Key))
                    {
                        val.Key = new ResourceKey(StringUtility.SanitizeName(val.Name) + "_" + i);
                    }

                    Register(val.Key, val);
                }
            }
        }
Ejemplo n.º 2
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);
                }
            }
        }