Line 112: |
Line 112: |
| If you're using SMAPI: | | If you're using SMAPI: |
| :<source lang="c#"> | | :<source lang="c#"> |
− | public void Entry(IModHelper helper) | + | public override void Entry(IModHelper helper) |
| + | { |
| + | helper.Events.GameLoop.SaveLoaded += this.OnSaveLoaded; |
| + | } |
| + | |
| + | private void OnSaveLoaded(object sender, SaveLoadedEventArgs args) |
| { | | { |
| // This gets the asset key for a tilesheet.png file from your mod's folder. You can also load a game tilesheet like | | // This gets the asset key for a tilesheet.png file from your mod's folder. You can also load a game tilesheet like |
| // this: helper.Content.GetActualAssetKey("spring_town", ContentSource.GameContent). | | // this: helper.Content.GetActualAssetKey("spring_town", ContentSource.GameContent). |
− | string tilesheetPath = helper.Content.GetActualAssetKey("tilesheet.png", ContentSource.ModFolder); | + | string tilesheetPath = this.Helper.Content.GetActualAssetKey("tilesheet.png", ContentSource.ModFolder); |
| | | |
| // Get an instance of the in-game location you want to patch. For the farm, use Game1.getFarm() instead. | | // Get an instance of the in-game location you want to patch. For the farm, use Game1.getFarm() instead. |
Line 154: |
Line 159: |
| If you're using SMAPI: | | If you're using SMAPI: |
| : <source lang="c#"> | | : <source lang="c#"> |
− | public void Entry(IModHelper helper) | + | public override void Entry(IModHelper helper) |
| + | { |
| + | helper.Events.GameLoop.SaveLoaded += this.OnSaveLoaded; |
| + | } |
| + | |
| + | private void OnSaveLoaded(object sender, SaveLoadedEventArgs args) |
| { | | { |
| // get the 'Music' value | | // get the 'Music' value |
− | Game1.currentLocation.map.Properties.TryGetValue("Music", out string value); | + | string currentMusic = Game1.currentLocation.map.Properties.TryGetValue("Music", out PropertyValue rawMusic) |
| + | ? rawMusic.ToString() |
| + | : null; |
| | | |
| // add or set the 'Music' value | | // add or set the 'Music' value |
Line 176: |
Line 188: |
| If you're using SMAPI: | | If you're using SMAPI: |
| : <source lang="C#"> | | : <source lang="C#"> |
− | public void Entry(IModHelper helper) | + | public override void Entry(IModHelper helper) |
| { | | { |
− | // get property | + | helper.Events.GameLoop.SaveLoaded += this.OnSaveLoaded; |
− | string value = Game1.currentLocation.doesTileHaveProperty(tileX, tileY, "Diggable", "Back");
| + | } |
| + | |
| + | private void OnSaveLoaded(object sender, SaveLoadedEventArgs args) |
| + | { |
| + | // example location & tile coordinate |
| + | GameLocation location = Game1.currentLocation; |
| + | int tileX = 10; |
| + | int tileY = 20; |
| + | |
| + | // get property |
| + | string value = location.doesTileHaveProperty(tileX, tileY, "Diggable", "Back"); |
| | | |
− | // add or set property
| + | // add or set property |
− | Game1.currentLocation.setTileProperty(tileX, tileY, "Back", "Diggable", "T");
| + | location.setTileProperty(tileX, tileY, "Back", "Diggable", "T"); |
| | | |
− | // remove tile property
| + | // remove tile property |
− | Layer layer = Game1.currentLocation.map.GetLayer("Back");
| + | Layer layer = location.map.GetLayer("Back"); |
− | Tile tile = layer.PickTile(new xTile.Dimensions.Location(x, y) * Game1.tileSize, Game1.viewport.Size);
| + | Tile tile = layer.PickTile(new xTile.Dimensions.Location(tileX, tileY) * Game1.tileSize, Game1.viewport.Size); |
− | tile.Properties.Remove("Diggable");
| + | tile.Properties.Remove("Diggable"); |
− | //tile.TileIndexProperties.Remove("Diggable"); // NOTE: removing a tile index property will affect all tiles of this type
| + | //tile.TileIndexProperties.Remove("Diggable"); // NOTE: removing a tile index property will affect all tiles of this type |
| } | | } |
| </source> | | </source> |
Line 215: |
Line 237: |
| If you're using SMAPI: | | If you're using SMAPI: |
| :<source lang="c#"> | | :<source lang="c#"> |
− | public void Entry(IModHelper helper) | + | public override void Entry(IModHelper helper) |
| { | | { |
− | // remove tile from layer | + | helper.Events.GameLoop.SaveLoaded += this.OnSaveLoaded; |
− | location.removeTile(tileX, tileY, "Back");
| + | } |
| | | |
− | // add tile
| + | private void OnSaveLoaded(object sender, SaveLoadedEventArgs args) |
− | Layer layer = location.map.GetLayer("Back");
| + | { |
− | TileSheet tilesheet = location.map.GetTilesheet("tilesheet name");
| + | // example location & tile coordinate |
− | layer.Tiles[tileX, tileY] = new StaticTile(layer, tilesheet, BlendMode.Alpha, tileID);
| + | GameLocation location = Game1.currentLocation; |
| + | int tileX = 10; |
| + | int tileY = 20; |
| + | |
| + | // remove tile from layer |
| + | location.removeTile(tileX, tileY, "Back"); |
| + | |
| + | // add tile |
| + | Layer layer = location.map.GetLayer("Back"); |
| + | TileSheet tilesheet = location.map.GetTileSheet("tilesheet name"); |
| + | layer.Tiles[tileX, tileY] = new StaticTile(layer, tilesheet, BlendMode.Alpha, tileIndex: 100); // change tile index |
| | | |
− | // toggle water tile behaviour
| + | // toggle water tile behaviour |
− | location.waterTiles[tileX, tilyY] = false; // true: water, false: not water
| + | location.waterTiles[tileX, tileY] = false; // true: water, false: not water |
| } | | } |
| </source> | | </source> |
Line 239: |
Line 271: |
| If you're using SMAPI: | | If you're using SMAPI: |
| :<source lang="c#"> | | :<source lang="c#"> |
− | public void Entry(IModHelper helper) | + | public override void Entry(IModHelper helper) |
| { | | { |
− | //add Animated Tile
| + | helper.Events.GameLoop.SaveLoaded += this.OnSaveLoaded; |
− | Layer layer = location.map.GetLayer("Buildings");
| + | } |
− | TileSheet tilesheet = location.map.GetTilesheet("tilesheet name");
| + | |
− | layer.Tiles[tileX, tileY] = new AnimatedTile(
| + | private void OnSaveLoaded(object sender, SaveLoadedEventArgs args) |
− | layer,
| + | { |
− | new StaticTile[]{
| + | //add Animated Tile |
− | new StaticTile(layer, tilesheet, BlendMode.Alpha, tileID),
| + | Layer layer = location.map.GetLayer("Buildings"); |
− | new StaticTile(layer, tilesheet, BlendMode.Alpha, tileID),
| + | TileSheet tilesheet = location.map.GetTilesheet("tilesheet name"); |
− | new StaticTile(layer, tilesheet, BlendMode.Alpha, tileID),
| + | layer.Tiles[tileX, tileY] = new AnimatedTile( |
− | new StaticTile(layer, tilesheet, BlendMode.Alpha, tileID)
| + | layer, |
− | },
| + | new StaticTile[] { |
− | 250 //int for the interval in milliseconds
| + | new StaticTile(layer, tilesheet, BlendMode.Alpha, tileID), |
− | );
| + | new StaticTile(layer, tilesheet, BlendMode.Alpha, tileID), |
| + | new StaticTile(layer, tilesheet, BlendMode.Alpha, tileID), |
| + | new StaticTile(layer, tilesheet, BlendMode.Alpha, tileID) |
| + | }, |
| + | 250 // interval in milliseconds |
| + | ); |
| } | | } |
| </source> | | </source> |