コード例 #1
0
ファイル: ModEntry.cs プロジェクト: somnomania/smapi-mod-dump
        /// <summary>Load all .png files from specified directory into the correct sprite list.</summary>
        /// <param name="directory">The absolute directory containing the .png files.</param>
        /// <param name="contentPack">The content pack currently being loaded.</param>
        /// <param name="season">The season to load the images into.</param>
        private void LoadFilesFromDirectory(string directory, IContentPack contentPack, Season season)
        {
            foreach (var file in Directory.GetFiles(directory))
            {
                if (!file.EndsWith(".png"))
                {
                    Monitor.Log($"Invalid file in season folder: {file}");
                    return;
                }

                string    relativeDirectory = GetRelativeDirectory(directory);
                string    relativePath      = Path.Combine(relativeDirectory, Path.GetFileName(file));
                Texture2D grass             = contentPack.LoadAsset <Texture2D>(relativePath);
                if (grass == null)
                {
                    Monitor.Log($"Failed to get grass sprite. Path expected: {relativePath}");
                }
                else
                {
                    switch (season)
                    {
                    case Season.Spring:
                    {
                        SpringGrassSprites.Add(grass);
                        break;
                    }

                    case Season.Summer:
                    {
                        SummerGrassSprites.Add(grass);
                        break;
                    }

                    case Season.Fall:
                    {
                        FallGrassSprites.Add(grass);
                        break;
                    }

                    case Season.Winter:
                    {
                        WinterGrassSprites.Add(grass);
                        break;
                    }
                    }
                }
            }
        }
コード例 #2
0
ファイル: ModEntry.cs プロジェクト: somnomania/smapi-mod-dump
        /// <summary>Load individual sprites from a sprite sheet using the specificed rectangles.</summary>
        /// <param name="grassSpriteSheet">The sprite sheet containing the grass sprites.</param>
        /// <param name="grassBounds">The list of rectangles to get the sprites from the sheet.</param>
        /// <param name="season">The season to add the sprites to.</param>
        private void LoadGrassSprites(Texture2D grassSpriteSheet, Rectangle[] grassBounds, Season season)
        {
            foreach (var grassBound in grassBounds)
            {
                // create a new Texture2D using the grassBound
                Texture2D grassSprite = new Texture2D(Game1.graphics.GraphicsDevice, grassBound.Width, grassBound.Height);
                Color[]   grassData   = new Color[grassBound.Width * grassBound.Height];
                grassSpriteSheet.GetData(0, grassBound, grassData, 0, grassData.Length);
                grassSprite.SetData(grassData);

                switch (season)
                {
                case Season.Spring:
                {
                    SpringGrassSprites.Add(grassSprite);
                    break;
                }

                case Season.Summer:
                {
                    SummerGrassSprites.Add(grassSprite);
                    break;
                }

                case Season.Fall:
                {
                    FallGrassSprites.Add(grassSprite);
                    break;
                }

                case Season.Winter:
                {
                    WinterGrassSprites.Add(grassSprite);
                    break;
                }
                }
            }
        }