public void Edit <T>(IAssetData asset) { foreach (var injection in Injections.Where(p => asset.AssetNameEquals(p.AssetName) && (p.Method != InjectionMethod.Load) && p.ConditionsMet)) { if (injection is DataInjection dataInjection) { if (dataInjection.GetKeyType == typeof(int)) { asset.ReplaceWith(injectData <int>(asset, dataInjection)); } else if (dataInjection.GetKeyType == typeof(string)) { asset.ReplaceWith(injectData <string>(asset, dataInjection)); } } else if (injection is TextureInjection textureInjection) { if (textureInjection.Method == InjectionMethod.Replace) { asset.ReplaceWith(textureInjection.Value); } else if (textureInjection.Method == InjectionMethod.Merge || textureInjection.Method == InjectionMethod.Overlay) { asset.AsImage().PatchImage( textureInjection.Value, textureInjection.SourceArea, textureInjection.TargetArea, textureInjection.Method == InjectionMethod.Overlay ? PatchMode.Overlay : PatchMode.Replace); } } else if (injection is MapInjection mapInjection) { if (mapInjection.Method == InjectionMethod.Merge) { asset.AsMap().PatchMap(mapInjection.Value, mapInjection.SourceArea, mapInjection.TargetArea); } if (mapInjection.Method == InjectionMethod.Overlay) { asset.ReplaceWith(Helper.Content.Maps.PatchMapArea(asset.AsMap().Data, mapInjection.Value, mapInjection.TargetArea.HasValue ? new Point(mapInjection.TargetArea.Value.X, mapInjection.TargetArea.Value.Y) : Point.Zero, mapInjection.SourceArea, true, false)); } else if (mapInjection.Method == InjectionMethod.Replace) { asset.ReplaceWith(mapInjection.Value); } } else if (injection is ObjectInjection objectInjection) { asset.ReplaceWith(objectInjection.Value); } } }
/// <summary>Apply the patch to a loaded asset.</summary> /// <typeparam name="T">The asset type.</typeparam> /// <param name="asset">The asset to edit.</param> public override void Edit <T>(IAssetData asset) { string errorPrefix = $"Can't apply map patch \"{this.LogName}\" to {this.TargetAsset}"; // validate if (typeof(T) != typeof(Map)) { this.Monitor.Log($"{errorPrefix}: this file isn't a map file (found {typeof(T)}).", LogLevel.Warn); return; } if (this.AppliesMapPatch && !this.FromAssetExists()) { this.Monitor.Log($"{errorPrefix}: the {nameof(PatchConfig.FromFile)} file '{this.FromAsset}' doesn't exist.", LogLevel.Warn); return; } // get map IAssetDataForMap targetAsset = asset.AsMap(); Map target = targetAsset.Data; // apply map area patch if (this.AppliesMapPatch) { Map source = this.ContentPack.Load <Map>(this.FromAsset); if (!this.TryApplyMapPatch(source, targetAsset, out string error)) { this.Monitor.Log($"{errorPrefix}: map patch couldn't be applied: {error}", LogLevel.Warn); } } // patch map tiles if (this.AppliesTilePatches) { int i = 0; foreach (EditMapPatchTile tilePatch in this.MapTiles) { i++; if (!this.TryApplyTile(target, tilePatch, out string error)) { this.Monitor.Log($"{errorPrefix}: {nameof(PatchConfig.MapTiles)} > entry {i + 1} couldn't be applied: {error}", LogLevel.Warn); } } } // patch map properties foreach (EditMapPatchProperty property in this.MapProperties) { string key = property.Key.Value; string value = property.Value.Value; if (value == null) { target.Properties.Remove(key); } else { target.Properties[key] = value; } } }
public void Edit <T>(IAssetData asset) { var option = config.HutchInterior == 1 ? (int)currentHutchType : config.HutchInterior - 1; if (asset.AssetNameEquals("Maps/SlimeHutch")) { var editor = asset.AsMap(); var newVal = maps[option]; if (newVal != null) { editor.ReplaceWith(newVal); } } if (asset.AssetNameEquals("Maps/townInterior")) { var editor = asset.AsImage(); var newVal = waterTextures[option]; if (newVal != null) { editor.PatchImage(newVal, targetArea: new Rectangle(352, 1056, 32, 16)); } } }
public void Edit <T>(IAssetData asset) { if (!Unlocked || !Active || !asset.AssetNameEquals(Consts.GreenhouseMapPath)) { return; } var mapEditor = asset.AsMap(); string assetKey = null; bool fileExists = false; foreach (var extension in _mapExtensions) { assetKey = Path.Combine(_helper.DirectoryPath, Consts.GreenhouseUpgradePath + extension); if (!File.Exists(assetKey)) { continue; } assetKey = Consts.GreenhouseUpgradePath + extension; //gets rid of absolute pathing for smapi fileExists = true; break; } if (!fileExists) { _monitor.Log("No map file was found. Please make sure there is a GreenhouseUpgrade map file in the assets folder. If there isn't, redownload this mod or follow instructions on the mod page for adding a custom greenhouse.", LogLevel.Error); return; } var sourceMap = _helper.Content.Load <Map>(assetKey, ContentSource.ModFolder); mapEditor.PatchMap(sourceMap); }
/// <inheritdoc /> public void Edit <T>(IAssetData asset) { // add altar if (asset.AssetNameEquals($"Maps/{this.Config.AltarLocation}")) { (int altarX, int altarY) = this.GetAltarPosition(); Map altar = this.Content.Load <Map>("assets/altar.tmx"); asset.AsMap().PatchMap(altar, targetArea: new Rectangle(altarX, altarY, 3, 3)); } // add radio to Wizard's tower else if (asset.AssetNameEquals($"Maps/{this.Config.RadioLocation}")) { Map map = asset.AsMap().Data; // get buildings layer Layer buildingsLayer = map.GetLayer("Buildings"); if (buildingsLayer == null) { Log.Warn("Can't add radio to Wizard's tower: 'Buildings' layer not found."); return; } // get front layer Layer frontLayer = map.GetLayer("Front"); if (frontLayer == null) { Log.Warn("Can't add radio to Wizard's tower: 'Front' layer not found."); return; } // get tilesheet TileSheet tilesheet = map.GetTileSheet("untitled tile sheet"); if (tilesheet == null) { Log.Warn("Can't add radio to Wizard's tower: main tilesheet not found."); return; } // add radio (int radioX, int radioY) = this.GetRadioPosition(); frontLayer.Tiles[radioX, radioY] = new StaticTile(frontLayer, tilesheet, BlendMode.Alpha, 512); (buildingsLayer.Tiles[radioX, radioY] ?? frontLayer.Tiles[radioX, radioY]).Properties["Action"] = "MagicRadio"; } }
public void Edit <T>(IAssetData asset) { if (asset.DataType == typeof(Map) && GetMapMerges().FirstOrDefault(m => asset.AssetNameEquals(m.Target)) is MapMergeData merge && Plato.ModHelper.Content.Load <Map>(merge.Source, ContentSource.GameContent) is Map patch) { Map patched = Plato.Content.Maps.PatchMapArea(asset.AsMap().Data, patch, new Point(merge.ToArea.X, merge.ToArea.Y), merge.FromArea, merge.PatchMapProperties, merge.RemoveEmpty); asset.AsMap().PatchMap(patched, merge.ToArea, merge.ToArea); if (merge.PatchMapProperties) { foreach (KeyValuePair <string, PropertyValue> p in patched.Properties) { asset.AsMap().Data.Properties[p.Key] = p.Value; } } } }
/// <summary>Edit a matched asset.</summary> /// <param name="asset">A helper which encapsulates metadata about an asset and enables changes to it.</param> public void Edit <T>(IAssetData asset) { if (asset.AssetNameEquals("Maps/Town") && !Utility.doesMasterPlayerHaveMailReceivedButNotMailForTomorrow("ccMovieTheater")) { var editor = asset.AsMap(); SMonitor.Log($"Patching Maps/Town"); Map pierre = Helper.Content.Load <Map>("assets/pierrebuilding.tmx"); Map joja = Helper.Content.Load <Map>("assets/jojabuilding.tmx"); editor.PatchMap(pierre, null, new Rectangle(90, 41, 12, 13), PatchMapMode.Replace); editor.PatchMap(joja, null, new Rectangle(38, 47, 12, 11), PatchMapMode.Replace); } }
public void Edit <T>(IAssetData asset) { if (!Unlocked || !Active || !asset.AssetNameEquals(Consts.GreenhouseMapPath)) { return; } var mapEditor = asset.AsMap(); var sourceMap = Helper.Content.Load <Map>($"{Consts.GreenhouseMapPath}_Upgrade", ContentSource.GameContent); mapEditor.PatchMap(sourceMap); }
/// <summary>Edit a matched asset.</summary> /// <param name="asset">A helper which encapsulates metadata about an asset and enables changes to it.</param> public void Edit <T>(IAssetData asset) { // Add info about the mattock to the weapons data. if (asset.AssetNameEquals("Data/weapons")) { IDictionary <int, string> data = asset.AsDictionary <int, string>().Data; data[70] = "Mattock/A piece of dwarf history, it's a very versatile tool./16/16/1/0/0/0/0/-1/-1/2/.02/4"; } // Add info about the mattock artifact to the object info data. if (asset.AssetNameEquals("Data/ObjectInformation")) { IDictionary <int, string> data = asset.AsDictionary <int, string>().Data; data[934] = "Dwarf Mattock/250/-300/Arch/Dwarf Mattock/It's an ancient dwarf tool, used for mining and clearing rubble. It's in bad shape, maybe it could be repaired?/Volcano .01/Money 1 500"; } // Add the dwarf mattock artifact as a liked gift for the dwarf. if (asset.AssetNameEquals("Data/NPCGiftTastes")) { IDictionary <string, string> data = asset.AsDictionary <string, string>().Data; string[] currentTastes = data["Dwarf"].Split('/'); currentTastes[3] += " 934"; data["dwarf"] = String.Join("/", currentTastes); } // Add the mattock artifact to the item sprite sheet. if (asset.AssetNameEquals("Maps/springobjects")) { var editor = asset.AsImage(); editor.PatchImage(mattockIcons, sourceArea: new Rectangle(0, 0, 32, 16), targetArea: new Rectangle(352, 608, 32, 16)); } if (asset.AssetNameEquals("Maps/Blacksmith")) { var map = asset.AsMap(); // Add an invisible tile to the front layer so later we can replace it. map.Data.GetLayer("Front").Tiles[6, 12] = new StaticTile(map.Data.GetLayer("Front"), map.Data.TileSheets[0], BlendMode.Alpha, 48); map.Data.GetLayer("Front").Tiles[5, 10] = new StaticTile(map.Data.GetLayer("Front"), map.Data.TileSheets[0], BlendMode.Alpha, 48); map.Data.GetLayer("Front").Tiles[6, 10] = new StaticTile(map.Data.GetLayer("Front"), map.Data.TileSheets[0], BlendMode.Alpha, 48); map.Data.GetLayer("Front").Tiles[5, 11] = new StaticTile(map.Data.GetLayer("Front"), map.Data.TileSheets[0], BlendMode.Alpha, 48); map.Data.GetLayer("Front").Tiles[6, 11] = new StaticTile(map.Data.GetLayer("Front"), map.Data.TileSheets[0], BlendMode.Alpha, 48); } // Add the mattock weapon icons to the weapon sprite sheet. if (asset.AssetNameEquals("TileSheets/weapons")) { var editor = asset.AsImage(); editor.PatchImage(mattockIcons, sourceArea: new Rectangle(16, 0, 32, 16), targetArea: new Rectangle(96, 128, 32, 16)); } }
/// <summary>Edit a matched asset.</summary> /// <param name="asset">A helper which encapsulates metadata about an asset and enables changes to it.</param> public void Edit <T>(IAssetData asset) { Monitor.Log("Editing asset" + asset.AssetName); if (asset.AssetName.StartsWith("Maps")) { try { var mapData = asset.AsMap(); for (int x = 0; x < mapData.Data.Layers[0].LayerWidth; x++) { for (int y = 0; y < mapData.Data.Layers[0].LayerHeight; y++) { //Monitor.Log($"{x},{y},{map.GetLayer("Buildings").Tiles[x, y]?.TileIndex},{map.GetLayer("Front").Tiles[x, y]?.TileIndex}",LogLevel.Warn); if (mapData.Data.GetLayer("Buildings").Tiles[x, y]?.TileIndex == 1955) { Monitor.Log("Removing existing mailbox stand."); mapData.Data.GetLayer("Buildings").Tiles[x, y] = null; } if (mapData.Data.GetLayer("Front").Tiles[x, y]?.TileIndex == 1930) { Monitor.Log("Removing existing mailbox top."); mapData.Data.GetLayer("Front").Tiles[x, y] = null; } } } } catch (Exception ex) { Monitor.Log($"Exception removing existing mailbox.\n{ex}", LogLevel.Error); } return; } if (asset.AssetNameEquals("Tilesheets/Craftables")) { int id = mJsonAssets.GetBigCraftableId("Mailbox"); Monitor.Log($"mailbox id {id}"); if (id > 0) { int x = id % 8 * 16; int y = id / 8 * 32; asset.AsImage().PatchImage(Helper.Content.Load <Texture2D>($"json-assets/BigCraftables/Mailbox/big-craftable.png"), targetArea: new Rectangle(x, y, 16, 32)); Monitor.Log("patched craftables."); } } }
public void Edit <T>(IAssetData asset) { var mapAsset = asset.AsMap(); var map = mapAsset.Data; Func <Layer, bool> layerPredicate = (l) => l.Properties.TryGetValue(MapExtrasHandler.UseProperty, out PropertyValue value) && value.ToString().Split(' ') is string[] p && p.Length >= 2 && (p[0] == "Merge" || p[0] == "Replace") && (!l.Properties.TryGetValue(MapExtrasHandler.UseConditionProperty, out PropertyValue conditions) || Plato.CheckConditions(conditions.ToString(), l)); if (!map.Layers.Any(layerPredicate)) { return; } List <OrderedAction> actions = new List <OrderedAction>(); map.Layers.Where(layerPredicate).ToList().ForEach((layer) => { string[] p = layer.Properties[MapExtrasHandler.UseProperty].ToString().Split(' '); int order = layer.Properties.TryGetValue(UseOrderProperty, out PropertyValue value) && int.TryParse(value.ToString(), out int o) ? o : (p[0] == "Replace" && p.Length < 6) ? 0 : 1; Layer original = map.GetLayer(p[1]); if (p[0] == "Replace" && p.Length < 6) { actions.Add(new OrderedAction(order, () => ReplaceLayer(map, layer, original))); } else { actions.Add(new OrderedAction(order, () => MergeLayer(map, layer, original, p.Length > 5 && int.TryParse(p[2], out int x) && int.TryParse(p[3], out int y) && int.TryParse(p[4], out int w) && int.TryParse(p[5], out int h) ? new Rectangle?(new Rectangle(x, y, w, h)) : null, p[0] == "Merge"))); } }); actions.OrderBy(a => a.Order).ToList().ForEach(a => a.Call()); mapAsset.ReplaceWith(map); }
public void Edit <T>(IAssetData asset) { foreach (string name in mapCollectionData.mapDataDict.Keys) { if (asset.AssetNameEquals("Maps/" + name)) { Monitor.Log("Editing map " + asset.AssetName); var mapData = asset.AsMap(); MapData data = mapCollectionData.mapDataDict[name]; int count = 0; foreach (var kvp in data.tileDataDict) { foreach (Layer layer in mapData.Data.Layers) { if (layer.Id == "Paths") { continue; } try { layer.Tiles[(int)kvp.Key.X, (int)kvp.Key.Y] = null; } catch { } } foreach (var kvp2 in kvp.Value.tileDict) { try { List <StaticTile> tiles = new List <StaticTile>(); for (int i = 0; i < kvp2.Value.tiles.Count; i++) { TileInfo tile = kvp2.Value.tiles[i]; tiles.Add(new StaticTile(mapData.Data.GetLayer(kvp2.Key), mapData.Data.GetTileSheet(tile.tileSheet), tile.blendMode, tile.tileIndex)); foreach (var prop in kvp2.Value.tiles[i].properties) { tiles[i].Properties[prop.Key] = prop.Value; } } if (kvp2.Value.tiles.Count == 1) { mapData.Data.GetLayer(kvp2.Key).Tiles[(int)kvp.Key.X, (int)kvp.Key.Y] = tiles[0]; } else { mapData.Data.GetLayer(kvp2.Key).Tiles[(int)kvp.Key.X, (int)kvp.Key.Y] = new AnimatedTile(mapData.Data.GetLayer(kvp2.Key), tiles.ToArray(), kvp2.Value.frameInterval); } count++; } catch { } } } Monitor.Log($"Added {count} custom tiles to map {name}"); cleanMaps.Add(name); } } }
/// <summary>Edit a matched asset.</summary> /// <param name="asset">A helper which encapsulates metadata about an asset and enables changes to it.</param> public void Edit <T>(IAssetData asset) { Monitor.Log("Editing asset" + asset.AssetName); if (asset.AssetNameEquals("Maps/FarmHouse2") || asset.AssetNameEquals("Maps/FarmHouse2_marriage")) { try { var mapData = asset.AsMap(); TileSheet indoor = mapData.Data.TileSheets.First(s => s.Id == "indoor"); TileSheet untitled = mapData.Data.TileSheets.First(s => s.Id == "untitled tile sheet"); int x = config.MainFloorStairsX; int y = config.MainFloorStairsY; mapData.Data.GetLayer("Front").Tiles[x, y].TileIndex = 162; mapData.Data.GetLayer("Front").Tiles[x + 1, y] = null; mapData.Data.GetLayer("Front").Tiles[x + 2, y] = null; mapData.Data.GetLayer("Front").Tiles[x + 1, y + 1] = null; mapData.Data.GetLayer("Front").Tiles[x + 2, y + 1] = null; mapData.Data.GetLayer("Front").Tiles[x + 1, y + 2] = null; mapData.Data.GetLayer("Front").Tiles[x + 2, y + 2] = null; mapData.Data.GetLayer("Buildings").Tiles[x + 1, y + 1] = null; mapData.Data.GetLayer("Buildings").Tiles[x + 2, y + 1] = null; mapData.Data.GetLayer("Buildings").Tiles[x + 1, y + 2] = null; mapData.Data.GetLayer("Buildings").Tiles[x + 2, y + 2] = null; mapData.Data.GetLayer("Back").Tiles[x + 1, y + 1] = null; mapData.Data.GetLayer("Back").Tiles[x + 2, y + 1] = null; mapData.Data.GetLayer("Back").Tiles[x + 1, y + 2] = null; mapData.Data.GetLayer("Back").Tiles[x + 2, y + 2] = null; mapData.Data.GetLayer("Buildings").Tiles[x + 3, y].TileIndex = 68; mapData.Data.GetLayer("Front").Tiles[x + 3, y].TileIndex = 68; mapData.Data.GetLayer("Buildings").Tiles[x, y + 1] = new StaticTile(mapData.Data.GetLayer("Buildings"), indoor, BlendMode.Alpha, 64); mapData.Data.GetLayer("Front").Tiles[x, y + 1] = new StaticTile(mapData.Data.GetLayer("Front"), indoor, BlendMode.Alpha, 64); mapData.Data.GetLayer("Buildings").Tiles[x, y + 2] = new StaticTile(mapData.Data.GetLayer("Buildings"), indoor, BlendMode.Alpha, 96); mapData.Data.GetLayer("Front").Tiles[x + 1, y + 2] = new StaticTile(mapData.Data.GetLayer("Front"), indoor, BlendMode.Alpha, 165); mapData.Data.GetLayer("Front").Tiles[x + 2, y + 2] = new StaticTile(mapData.Data.GetLayer("Front"), indoor, BlendMode.Alpha, 165); mapData.Data.GetLayer("Back").Tiles[x + 1, y + 1] = new StaticTile(mapData.Data.GetLayer("Back"), untitled, BlendMode.Alpha, 181); mapData.Data.GetLayer("Back").Tiles[x + 2, y + 1] = new StaticTile(mapData.Data.GetLayer("Back"), untitled, BlendMode.Alpha, 181); mapData.Data.GetLayer("Back").Tiles[x + 1, y + 1].Properties["NoFurniture"] = "t"; mapData.Data.GetLayer("Back").Tiles[x + 2, y + 1].Properties["NoFurniture"] = "t"; mapData.Data.GetLayer("Back").Tiles[x + 1, y + 1].Properties["NPCBarrier"] = "t"; mapData.Data.GetLayer("Back").Tiles[x + 2, y + 1].Properties["NPCBarrier"] = "t"; mapData.Data.GetLayer("Back").Tiles[x + 1, y + 2] = new StaticTile(mapData.Data.GetLayer("Back"), untitled, BlendMode.Alpha, 181); mapData.Data.GetLayer("Back").Tiles[x + 2, y + 2] = new StaticTile(mapData.Data.GetLayer("Back"), untitled, BlendMode.Alpha, 181); mapData.Data.GetLayer("Back").Tiles[x + 1, y + 2].Properties["NoFurniture"] = "t"; mapData.Data.GetLayer("Back").Tiles[x + 2, y + 2].Properties["NoFurniture"] = "t"; mapData.Data.GetLayer("Buildings").Tiles[x + 3, y + 1] = new StaticTile(mapData.Data.GetLayer("Buildings"), indoor, BlendMode.Alpha, 68); mapData.Data.GetLayer("Front").Tiles[x + 3, y + 1] = new StaticTile(mapData.Data.GetLayer("Front"), indoor, BlendMode.Alpha, 68); mapData.Data.GetLayer("Buildings").Tiles[x + 3, y + 2] = new StaticTile(mapData.Data.GetLayer("Buildings"), indoor, BlendMode.Alpha, 130); mapData.Data.GetLayer("Front").Tiles[x + 1, y + 3] = new StaticTile(mapData.Data.GetLayer("Front"), indoor, BlendMode.Alpha, 0); mapData.Data.GetLayer("Front").Tiles[x + 2, y + 3] = new StaticTile(mapData.Data.GetLayer("Front"), indoor, BlendMode.Alpha, 0); mapData.Data.GetLayer("Buildings").Tiles[x + 1, y + 1] = null; mapData.Data.GetLayer("Buildings").Tiles[x + 2, y + 1] = null; } catch (Exception ex) { Monitor.Log($"Exception adding stair tiles.\n{ex}", LogLevel.Error); } return; } }
/// <summary>Edit a matched asset.</summary> /// <param name="asset">A helper which encapsulates metadata about an asset and enables changes to it.</param> public void Edit <T>(IAssetData asset) { Monitor.Log("Editing asset: " + asset.AssetName); string mapName = asset.AssetName.Replace("Maps/", "").Replace("Maps\\", ""); if (false && changeLocations.ContainsKey(mapName)) { IAssetDataForMap map = asset.AsMap(); for (int x = 0; x < map.Data.Layers[0].LayerWidth; x++) { for (int y = 0; y < map.Data.Layers[0].LayerHeight; y++) { if (SwimUtils.doesTileHaveProperty(map.Data, x, y, "Water", "Back") != null) { Tile tile = map.Data.GetLayer("Back").PickTile(new Location(x, y) * Game1.tileSize, Game1.viewport.Size); if (tile != null && (((mapName == "Beach" || mapName == "UnderwaterBeach") && x > 58 && x < 61 && y > 11 && y < 15) || mapName != "Beach")) { if (tile.TileIndexProperties.ContainsKey("Passable")) { tile.TileIndexProperties.Remove("Passable"); } } tile = map.Data.GetLayer("Front").PickTile(new Location(x, y) * Game1.tileSize, Game1.viewport.Size); if (tile != null) { if (tile.TileIndexProperties.ContainsKey("Passable")) { //tile.TileIndexProperties.Remove("Passable"); } } if (map.Data.GetLayer("AlwaysFront") != null) { tile = map.Data.GetLayer("AlwaysFront").PickTile(new Location(x, y) * Game1.tileSize, Game1.viewport.Size); if (tile != null) { if (tile.TileIndexProperties.ContainsKey("Passable")) { //tile.TileIndexProperties.Remove("Passable"); } } } tile = map.Data.GetLayer("Buildings").PickTile(new Location(x, y) * Game1.tileSize, Game1.viewport.Size); if (tile != null) { if ( ((mapName == "Beach" || mapName == "UnderwaterBeach") && x > 58 && x < 61 && y > 11 && y < 15) || (mapName != "Beach" && mapName != "UnderwaterBeach" && ((tile.TileIndex > 1292 && tile.TileIndex < 1297) || (tile.TileIndex > 1317 && tile.TileIndex < 1322) || (tile.TileIndex % 25 > 17 && tile.TileIndex / 25 < 53 && tile.TileIndex / 25 > 48) || (tile.TileIndex % 25 > 1 && tile.TileIndex % 25 < 7 && tile.TileIndex / 25 < 53 && tile.TileIndex / 25 > 48) || (tile.TileIndex % 25 > 11 && tile.TileIndex / 25 < 51 && tile.TileIndex / 25 > 48) || (tile.TileIndex % 25 > 10 && tile.TileIndex % 25 < 14 && tile.TileIndex / 25 < 49 && tile.TileIndex / 25 > 46) || tile.TileIndex == 734 || tile.TileIndex == 759 || tile.TileIndex == 628 || tile.TileIndex == 629 || (mapName == "Forest" && x == 119 && ((y > 42 && y < 48) || (y > 104 && y < 119))) ) ) ) { if (tile.TileIndexProperties.ContainsKey("Passable")) { tile.TileIndexProperties["Passable"] = "T"; } else { tile.TileIndexProperties.Add("Passable", "T"); } } else if (mapName == "Beach" && tile.TileIndex == 76) { if (x > 58 && x < 61 && y > 11 && y < 15) { Game1.getLocationFromName(mapName).removeTile(x, y, "Buildings"); } if (tile.TileIndexProperties.ContainsKey("Passable")) { tile.TileIndexProperties.Remove("Passable"); } } } } } } } }
/// <summary>Edit a matched asset.</summary> /// <param name="asset">A helper which encapsulates metadata about an asset and enables changes to it.</param> public void Edit <T>(IAssetData asset) { Monitor.Log("Editing asset" + asset.AssetName); if (asset.AssetName.EndsWith("outdoorsTileSheet")) { var image = asset.AsImage(); int y = 0; if (asset.AssetName.EndsWith("summer_outdoorsTileSheet")) { y = 1; } else if (asset.AssetName.EndsWith("fall_outdoorsTileSheet")) { y = 2; } else if (asset.AssetName.EndsWith("winter_outdoorsTileSheet")) { y = 3; } Rectangle rect = new Rectangle(0, y * 16, 32, 16); image.PatchImage(tilesTexture, rect, new Rectangle(208, 1232, 32, 16)); return; } else if (asset.AssetName.StartsWith("Maps")) { try { var mapData = asset.AsMap(); for (int x = 0; x < mapData.Data.Layers[0].LayerWidth; x++) { for (int y = 0; y < mapData.Data.Layers[0].LayerHeight; y++) { //Monitor.Log($"{x},{y},{map.GetLayer("Buildings").Tiles[x, y]?.TileIndex},{map.GetLayer("Front").Tiles[x, y]?.TileIndex}",LogLevel.Warn); if (mapData.Data.GetLayer("Buildings").Tiles[x, y]?.TileIndex == 1938) { Monitor.Log("Removing existing pet bowl."); mapData.Data.GetLayer("Buildings").Tiles[x, y] = null; mapData.Data.GetLayer("Back").Tiles[x, y].TileIndex = 1938; try { mapData.Data.GetLayer("Back").Tiles[x - 1, y].Properties.Remove("NoFurniture"); mapData.Data.GetLayer("Back").Tiles[x - 1, y].Properties.Remove("Placeable"); } catch { } try { mapData.Data.GetLayer("Back").Tiles[x - 1, y + 1].Properties.Remove("NoFurniture"); mapData.Data.GetLayer("Back").Tiles[x - 1, y + 1].Properties.Remove("Placeable"); } catch { } try { mapData.Data.GetLayer("Back").Tiles[x, y + 1].Properties.Remove("NoFurniture"); mapData.Data.GetLayer("Back").Tiles[x, y + 1].Properties.Remove("Placeable"); } catch { } } } } } catch (Exception ex) { Monitor.Log($"Exception removing existing pet bowl.\n{ex}", LogLevel.Error); } return; } }
/// <summary>Edit a matched asset.</summary> /// <param name="asset">A helper which encapsulates metadata about an asset and enables changes to it.</param> public void Edit <T>(IAssetData asset) { IAssetDataForMap mapAsset = asset.AsMap(); Map map = mapAsset.Data; }
/// <inheritdoc /> public override void Edit <T>(IAssetData asset) { // validate if (typeof(T) != typeof(Map)) { this.WarnForPatch($"this file isn't a map file (found {typeof(T)})."); return; } if (this.AppliesMapPatch && !this.FromAssetExists()) { this.WarnForPatch($"the {nameof(PatchConfig.FromFile)} file '{this.FromAsset}' doesn't exist."); return; } // get map IAssetDataForMap targetAsset = asset.AsMap(); Map target = targetAsset.Data; // apply map area patch if (this.AppliesMapPatch) { Map source = this.ContentPack.ModContent.Load <Map>(this.FromAsset !); if (!this.TryApplyMapPatch(source, targetAsset, out string?error)) { this.WarnForPatch($"map patch couldn't be applied: {error}"); } } // patch map tiles if (this.AppliesTilePatches) { int i = 0; foreach (EditMapPatchTile tilePatch in this.MapTiles) { i++; if (!this.TryApplyTile(target, tilePatch, out string?error)) { this.WarnForPatch($"{nameof(PatchConfig.MapTiles)} > entry {i} couldn't be applied: {error}"); } } } // patch map properties foreach (EditMapPatchProperty property in this.MapProperties) { string key = property.Key.Value !; string?value = property.Value?.Value; if (value == null) { target.Properties.Remove(key); } else { target.Properties[key] = value; } } // apply map warps if (this.AddWarps.Any()) { this.ApplyWarps(target, out IDictionary <string, string> errors); foreach ((string warp, string error) in errors) { this.WarnForPatch($"{nameof(PatchConfig.AddWarps)} > warp '{warp}' couldn't be applied: {error}"); } } // apply text operations for (int i = 0; i < this.TextOperations.Length; i++) { if (!this.TryApplyTextOperation(target, this.TextOperations[i], out string?error)) { this.WarnForPatch($"{nameof(PatchConfig.TextOperations)} > entry {i} couldn't be applied: {error}"); } } }