コード例 #1
0
        internal static Texture2D GetBuildingTextureWithPaint(Building building, AlternativeTextureModel textureModel, int textureVariation, bool canBePaintedOverride = false)
        {
            var xOffset = building.tilesWide * 16;
            var yOffset = textureModel.GetTextureOffset(textureVariation);

            var textureWidth = building.CanBePainted() || canBePaintedOverride ? xOffset : textureModel.TextureWidth;

            var texture2D = textureModel.GetTexture(textureVariation).CreateSelectiveCopy(Game1.graphics.GraphicsDevice, new Rectangle(0, yOffset, textureWidth, textureModel.TextureHeight));

            if (building.paintedTexture != null)
            {
                building.paintedTexture = null;
            }

            if ((building.CanBePainted() || canBePaintedOverride) && xOffset * 2 <= textureModel.GetTexture(textureVariation).Width)
            {
                var paintedTexture2D = textureModel.GetTexture(textureVariation).CreateSelectiveCopy(Game1.graphics.GraphicsDevice, new Rectangle(xOffset, yOffset, xOffset, textureModel.TextureHeight));
                building.paintedTexture = GetPaintedOverlay(building, texture2D, paintedTexture2D, building.netBuildingPaintColor.Value);
                if (building.paintedTexture != null)
                {
                    texture2D = building.paintedTexture;
                }
            }

            return(texture2D);
        }
コード例 #2
0
ファイル: Api.cs プロジェクト: Pathoschild/smapi-mod-dump
 public void AddAlternativeTexture(AlternativeTextureModel model, string owner, Texture2D texture)
 {
     AddAlternativeTexture(model, owner, new List <Texture2D>()
     {
         texture
     });
 }
コード例 #3
0
        private static void AssignFarmModData(Farm farm, string modelName, AlternativeTextureModel textureModel, int variation, bool trackSeason = false)
        {
            farm.modData["AlternativeTextureOwner"] = textureModel.Owner;
            farm.modData["AlternativeTextureName"]  = String.Concat(textureModel.Owner, ".", modelName);

            if (trackSeason && !String.IsNullOrEmpty(textureModel.Season))
            {
                farm.modData["AlternativeTextureSeason"] = Game1.currentSeason;
            }

            farm.modData["AlternativeTextureVariation"] = variation.ToString();
        }
コード例 #4
0
        public void AddAlternativeTexture(AlternativeTextureModel model)
        {
            if (_alternativeTextures.Any(t => t.GetId() == model.GetId()))
            {
                var replacementIndex = _alternativeTextures.IndexOf(_alternativeTextures.First(t => t.GetId() == model.GetId()));
                _alternativeTextures[replacementIndex] = model;
            }
            else
            {
                _alternativeTextures.Add(model);
                _textureIdsInsensitive.Add(model.GetId());
            }

            RegisterTokens(model);
        }
コード例 #5
0
        private static void AssignObjectModData(Object obj, string modelName, AlternativeTextureModel textureModel, int variation, bool trackSeason = false, bool trackSheetId = false)
        {
            obj.modData["AlternativeTextureOwner"] = textureModel.Owner;
            obj.modData["AlternativeTextureName"]  = String.Concat(textureModel.Owner, ".", modelName);

            if (trackSeason && !String.IsNullOrEmpty(textureModel.Season))
            {
                obj.modData["AlternativeTextureSeason"] = Game1.currentSeason;
            }

            if (trackSheetId)
            {
                obj.modData["AlternativeTextureSheetId"] = obj.ParentSheetIndex.ToString();
            }

            obj.modData["AlternativeTextureVariation"] = variation.ToString();
        }
コード例 #6
0
        public void RegisterTokens(AlternativeTextureModel textureModel)
        {
            // Register for Content Patcher
            var token = $"{AlternativeTextures.TEXTURE_TOKEN_HEADER}{textureModel.GetTokenId()}";

            _tokenToModel[token] = new TokenModel()
            {
                Id = token, AlternativeTexture = textureModel
            };

            foreach (int variation in textureModel.Textures.Keys)
            {
                token = $"{AlternativeTextures.TEXTURE_TOKEN_HEADER}{textureModel.GetTokenId(variation)}";
                _tokenToModel[token] = new TokenModel()
                {
                    Id = token, Variation = variation, AlternativeTexture = textureModel
                };
            }
        }
コード例 #7
0
        private static void SetTexture(Monster monster, AlternativeTextureModel textureModel)
        {
            if (textureModel is null)
            {
                monster.Sprite.loadedTexture = String.Empty;
                return;
            }

            var textureVariation = Int32.Parse(monster.modData["AlternativeTextureVariation"]);

            if (textureVariation == -1 || AlternativeTextures.modConfig.IsTextureVariationDisabled(textureModel.GetId(), textureVariation))
            {
                monster.Sprite.loadedTexture = String.Empty;
                return;
            }
            var textureOffset = textureModel.GetTextureOffset(textureVariation);

            monster.Sprite.spriteTexture = textureModel.GetTexture(textureVariation);
            monster.Sprite.sourceRect.Y  = textureOffset + (monster.Sprite.currentFrame * monster.Sprite.SpriteWidth / monster.Sprite.Texture.Width * monster.Sprite.SpriteHeight);
        }
コード例 #8
0
        internal static bool AssignDefaultModData <T>(T type, string modelName, bool trackSeason = false, bool trackSheetId = false)
        {
            if (HasCachedTextureName(type))
            {
                return(false);
            }

            var textureModel = new AlternativeTextureModel()
            {
                Owner = AlternativeTextures.DEFAULT_OWNER, Season = trackSeason ? Game1.currentSeason : String.Empty
            };

            switch (type)
            {
            case Object obj:
                AssignObjectModData(obj, modelName, textureModel, -1, trackSeason, trackSheetId);
                return(true);

            case TerrainFeature terrain:
                AssignTerrainFeatureModData(terrain, modelName, textureModel, -1, trackSeason);
                return(true);

            case Character character:
                AssignCharacterModData(character, modelName, textureModel, -1, trackSeason);
                return(true);

            case Building building:
                AssignBuildingModData(building, modelName, textureModel, -1, trackSeason);
                return(true);

            case DecoratableLocation decoratableLocation:
                AssignDecoratableLocationModData(decoratableLocation, modelName, textureModel, -1, trackSeason);
                return(true);

            case Farm farm:
                AssignFarmModData(farm, modelName, textureModel, -1, trackSeason);
                return(true);
            }

            return(false);
        }
コード例 #9
0
ファイル: Api.cs プロジェクト: Pathoschild/smapi-mod-dump
        public void AddAlternativeTexture(AlternativeTextureModel model, string owner, List <Texture2D> textures)
        {
            if (String.IsNullOrEmpty(owner))
            {
                _framework.Monitor.Log($"Unable to add AlternativeTextureModel {model.GetNameWithSeason()}: Owner property is not set.");
                return;
            }

            if (textures.Count() == 0)
            {
                _framework.Monitor.Log($"Unable to add AlternativeTextureModel {model.GetNameWithSeason()}: Textures property is empty.");
                return;
            }

            model.Owner = owner;
            model.Type  = model.GetTextureType();

            var seasons = model.Seasons;

            for (int s = 0; s < 4; s++)
            {
                if ((seasons.Count() == 0 && s > 0) || (seasons.Count() > 0 && s >= seasons.Count()))
                {
                    continue;
                }

                // Parse the model and assign it the content pack's owner
                AlternativeTextureModel textureModel = model.ShallowCopy();

                // Override Grass Alternative Texture pack ItemNames to always be Grass, in order to be compatible with translations
                textureModel.ItemName = textureModel.GetTextureType() == "Grass" ? "Grass" : textureModel.ItemName;

                // Add the UniqueId to the top-level Keywords
                textureModel.Keywords.Add(model.Owner);

                // Add the top-level Keywords to any ManualVariations.Keywords
                foreach (var variation in textureModel.ManualVariations)
                {
                    variation.Keywords.AddRange(textureModel.Keywords);
                }

                // Set the season (if any)
                textureModel.Season = seasons.Count() == 0 ? String.Empty : seasons[s];

                // Set the ModelName and TextureId
                textureModel.ModelName = String.IsNullOrEmpty(textureModel.Season) ? String.Concat(textureModel.GetTextureType(), "_", textureModel.ItemName) : String.Concat(textureModel.GetTextureType(), "_", textureModel.ItemName, "_", textureModel.Season);
                textureModel.TextureId = String.Concat(textureModel.Owner, ".", textureModel.ModelName);

                // Verify we are given a singular texture, if not then stitch them all together
                if (textures.Count() > 1)
                {
                    if (textureModel.IsDecoration())
                    {
                        _framework.Monitor.Log($"Unable to add alternative texture for item {textureModel.ItemName} from {textureModel.TextureId}: Split textures (texture_1.png, texture_2.png, etc.) are not allowed for Decoration types (wallpapers / floors)!", LogLevel.Warn);
                        continue;
                    }

                    // Load in the first texture_#.png to get its dimensions for creating stitchedTexture
                    int maxVariationsPerTexture = AlternativeTextureModel.MAX_TEXTURE_HEIGHT / textureModel.TextureHeight;

                    int variation = 0;
                    foreach (var splitTexture in textures)
                    {
                        textureModel.Textures[variation] = splitTexture;

                        variation++;
                    }

                    textureModel.TileSheetPath = String.Empty;
                }
                else
                {
                    // Load in the single vertical texture
                    textureModel.TileSheetPath = String.Empty;
                    Texture2D singularTexture = textures.First();
                    if (singularTexture.Height >= AlternativeTextureModel.MAX_TEXTURE_HEIGHT)
                    {
                        _framework.Monitor.Log($"Unable to add alternative texture for {textureModel.Owner}: The texture {textureModel.TextureId} has a height larger than 16384!\nPlease split it into individual textures (e.g. texture_0.png, texture_1.png, etc.) to resolve this issue.", LogLevel.Warn);
                        continue;
                    }
                    else if (textureModel.IsDecoration() && singularTexture.Width < 256)
                    {
                        _framework.Monitor.Log($"Unable to add alternative texture for {textureModel.ItemName} from {textureModel.TextureId}: The required image width is 256 for Decoration types (wallpapers / floors). Please correct the image's width manually.", LogLevel.Warn);
                        continue;
                    }
                    else if (textureModel.IsDecoration())
                    {
                        if (singularTexture.Width < 256)
                        {
                            _framework.Monitor.Log($"Unable to add alternative texture for {textureModel.ItemName} from {textureModel.TextureId}: The required image width is 256 for Decoration types (wallpapers / floors). Please correct the image's width manually.", LogLevel.Warn);
                            continue;
                        }

                        textureModel.Textures[0] = singularTexture;
                    }
                    else if (!_framework.SplitVerticalTexturesToModel(textureModel, textureModel.TextureId, singularTexture))
                    {
                        continue;
                    }
                }

                // Track the texture model
                AlternativeTextures.textureManager.AddAlternativeTexture(textureModel);

                // Log it
                if (AlternativeTextures.modConfig.OutputTextureDataToLog)
                {
                    _framework.Monitor.Log(textureModel.ToString(), LogLevel.Trace);
                }
            }
        }
コード例 #10
0
        private static void AssignCharacterModData(Character character, string modelName, AlternativeTextureModel textureModel, int variation, bool trackSeason = false)
        {
            character.modData["AlternativeTextureOwner"] = textureModel.Owner;
            character.modData["AlternativeTextureName"]  = String.Concat(textureModel.Owner, ".", modelName);

            if (trackSeason && !String.IsNullOrEmpty(textureModel.Season))
            {
                character.modData["AlternativeTextureSeason"] = Game1.GetSeasonForLocation(character.currentLocation);
            }

            character.modData["AlternativeTextureVariation"] = variation.ToString();
        }