Beispiel #1
0
        /// <summary>Loads all the content packs.</summary>
        private void LoadContentPacks()
        {
            foreach (var contentPack in this.Helper.ContentPacks.GetOwned())
            {
                this.Monitor.Log($"Loading {contentPack.Manifest.Name}", LogLevel.Info);

                // try loading content file
                if (!contentPack.HasFile("content.json"))
                {
                    this.Monitor.Log("\"content.json\" couldn't be found, skipping", LogLevel.Error);
                    continue;
                }

                var parsedOverwearDatas = contentPack.LoadAsset <List <ParsedOuterwearData> >("content.json");
                foreach (var parsedOverwearData in parsedOverwearDatas)
                {
                    // try loading asset file
                    if (!contentPack.HasFile(Path.Combine(parsedOverwearData.Asset)))
                    {
                        this.Monitor.Log($"Specified asset: \"{parsedOverwearData.Asset}\" couldn't be found, skipping", LogLevel.Error);
                        continue;
                    }

                    var equippedtexture = contentPack.LoadAsset <Texture2D>(parsedOverwearData.Asset);
                    OuterwearData.Add(new OuterwearData(Utilities.ResolveToken(parsedOverwearData.ObjectId), parsedOverwearData.Type, parsedOverwearData.Effects, equippedtexture));
                }
            }
        }
Beispiel #2
0
        /*********
        ** Private Methods
        *********/
        /// <summary>Invoked when a save is loaded.</summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event data.</param>
        private void OnSaveLoaded(object sender, SaveLoadedEventArgs e)
        {
            OuterwearData.Clear();

            LoadContentPacks();

            FixStaminaAndHealth();
        }
Beispiel #3
0
        /// <summary>Load all the content packs for this mod.</summary>
        private void LoadContentPacks()
        {
            foreach (IContentPack contentPack in this.Helper.ContentPacks.GetOwned())
            {
                Monitor.Log($"Loading {contentPack.Manifest.Name}");

                foreach (var contentPackOuterwearPath in Directory.GetDirectories(contentPack.DirectoryPath))
                {
                    // get folder name for this outerwear item
                    var pathSplit           = contentPackOuterwearPath.Split(Path.DirectorySeparatorChar);
                    var outerwearFolderName = pathSplit[pathSplit.Length - 1];

                    // verify the files exist
                    if (!VerifyContentPackFilesExist(contentPack, outerwearFolderName))
                    {
                        continue;
                    }

                    // get files
                    var outerwearContent         = contentPack.ReadJsonFile <ContentPackContent>(Path.Combine(outerwearFolderName, "content.json"));
                    var outerwearMenuIcon        = contentPack.LoadAsset <Texture2D>(Path.Combine(outerwearFolderName, "menuicon.png"));
                    var outerwearEquippedTexture = contentPack.LoadAsset <Texture2D>(Path.Combine(outerwearFolderName, "equippedtexture.png"));

                    // ensure an item with the same name hasn't already been added
                    if (ModEntry.OuterwearData.Where(data => data.DisplayName.ToLower() == outerwearContent.DisplayName.ToLower()).Any())
                    {
                        this.Monitor.Log($"An item with the name \"{outerwearContent.DisplayName}\" has already been added.");
                        continue;
                    }

                    // add outerwear to collection
                    var outerwearData = new OuterwearData(
                        id: Api.CreateId(outerwearContent.DisplayName),
                        displayName: outerwearContent.DisplayName,
                        description: outerwearContent.Description,
                        buyFrom: outerwearContent.BuyFrom,
                        buyPrice: outerwearContent.BuyPrice,
                        menuIcon: outerwearMenuIcon,
                        equippedTexture: outerwearEquippedTexture
                        );

                    ModEntry.OuterwearData.Add(outerwearData);
                }
            }

            // log all added items
            this.Monitor.Log("All added overwear items: ");
            foreach (var data in ModEntry.OuterwearData)
            {
                this.Monitor.Log($"Id: {data.Id}, DisplayName: {data.DisplayName}, Description: {data.Description}, BuyFrom: {data.BuyFrom}, BuyPrice: {data.BuyPrice}, SellTo: {data.SellTo}");
            }
        }
Beispiel #4
0
        internal static void DrawPostFix(SpriteBatch b, FarmerSprite.AnimationFrame animationFrame, int currentFrame, Rectangle sourceRect, Vector2 position, Vector2 origin, float layerDepth, int facingDirection, Color overrideColor, float rotation, float scale, Farmer who, FarmerRenderer __instance)
        {
            if (ModEntry.EquippedOuterwear == null)
            {
                return;
            }

            OuterwearData outerwearData = ModEntry.OuterwearData
                                          .Where(data => data.DisplayName == ModEntry.EquippedOuterwear.DisplayName)
                                          .FirstOrDefault();

            // get private member values
            Vector2 positionOffset = (Vector2)typeof(FarmerRenderer).GetField("positionOffset", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(__instance);

            positionOffset.Y -= 4;

            Rectangle?    sourceRectangle = null;
            SpriteEffects spriteEffects   = SpriteEffects.None;

            switch (facingDirection)
            {
            case 0:
                positionOffset.Y += 4;
                sourceRectangle   = new Rectangle(0, 64, 16, 32);
                break;

            case 1:
                sourceRectangle = new Rectangle(0, 32, 16, 32);
                break;

            case 2:
                sourceRectangle = new Rectangle(0, 0, 16, 32);
                break;

            case 3:
                sourceRectangle = new Rectangle(0, 32, 16, 32);
                spriteEffects   = SpriteEffects.FlipHorizontally;
                break;
            }

            b.Draw(
                texture: outerwearData.EquippedTexture,
                position: position + origin + positionOffset + new Vector2(FarmerRenderer.featureXOffsetPerFrame[currentFrame] * 4, FarmerRenderer.featureYOffsetPerFrame[currentFrame] * 4),
                sourceRectangle: sourceRectangle,
                color: Color.White,
                rotation: rotation,
                origin: origin,
                scale: 4f * scale,
                effects: spriteEffects,
                layerDepth: layerDepth + 4.9E-04f
                );
        }