private void loadContentPacks() { foreach (StardewModdingAPI.IContentPack pack in Helper.ContentPacks.GetOwned()) { TMXContentPack tmxPack = pack.ReadJsonFile <TMXContentPack>("content.json"); if (tmxPack.scripts.Count > 0) { foreach (string script in tmxPack.scripts) { PyLua.loadScriptFromFile(Path.Combine(pack.DirectoryPath, script), pack.Manifest.UniqueID); } } PyLua.loadScriptFromFile(Path.Combine(Helper.DirectoryPath, "sr.lua"), "Platonymous.TMXLoader.SpouseRoom"); List <MapEdit> spouseRoomMaps = new List <MapEdit>(); foreach (SpouseRoom room in tmxPack.spouseRooms) { if (room.tilefix && !Overrides.NPCs.Contains(room.name)) { Overrides.NPCs.Add(room.name); } if (room.file != "none") { spouseRoomMaps.Add(new MapEdit() { info = room.name, name = "FarmHouse1_marriage", file = room.file, position = new[] { 29, 1 } }); spouseRoomMaps.Add(new MapEdit() { info = room.name, name = "FarmHouse2_marriage", file = room.file, position = new[] { 35, 10 } }); } } foreach (MapEdit edit in spouseRoomMaps) { string filePath = Path.Combine(pack.DirectoryPath, edit.file); Map map = TMXContent.Load(edit.file, Helper, pack); if (edit.info != "none") { foreach (Layer layer in map.Layers) { layer.Id = layer.Id.Replace("Spouse", edit.info); } } map.Properties.Add("EntryAction", "Lua Platonymous.TMXLoader.SpouseRoom entry"); Map original = Helper.Content.Load <Map>("Maps/" + edit.name, ContentSource.GameContent); map = map.mergeInto(original, new Vector2(edit.position[0], edit.position[1]), null, true); map.injectAs("Maps/" + edit.name); // mapsToSync.AddOrReplace(edit.name, map); } foreach (TileShop shop in tmxPack.shops) { tileShops.AddOrReplace(shop.id, shop.inventory); foreach (string path in shop.portraits) { pack.LoadAsset <Texture2D>(path).inject(@"Portraits/" + Path.GetFileNameWithoutExtension(path)); } } foreach (NPCPlacement edit in tmxPack.festivalSpots) { Map reference = Helper.Content.Load <Map>("Maps/Town", ContentSource.GameContent); Map original = Helper.Content.Load <Map>("Maps/" + edit.map, ContentSource.GameContent); Texture2D springTex = Helper.Content.Load <Texture2D>("Maps/spring_outdoorsTileSheet", ContentSource.GameContent); Dictionary <string, string> source = Helper.Content.Load <Dictionary <string, string> >("Data\\NPCDispositions", ContentSource.GameContent); int index = source.Keys.ToList().IndexOf(edit.name); TileSheet spring = original.GetTileSheet("ztemp"); if (spring == null) { spring = new TileSheet("ztemp", original, "Maps/spring_outdoorsTileSheet", new xTile.Dimensions.Size(springTex.Width, springTex.Height), original.TileSheets[0].TileSize); original.AddTileSheet(spring); } original.GetLayer("Set-Up").Tiles[edit.position[0], edit.position[1]] = new StaticTile(original.GetLayer("Set-Up"), spring, BlendMode.Alpha, (index * 4) + edit.direction); original.injectAs("Maps/" + edit.map); // mapsToSync.AddOrReplace(edit.map, original); } foreach (NPCPlacement edit in tmxPack.placeNPCs) { helper.Events.GameLoop.SaveLoaded += (s, e) => { if (Game1.getCharacterFromName(edit.name) == null) { Game1.locations.Where(gl => gl.Name == edit.map).First().addCharacter(new NPC(new AnimatedSprite("Characters\\" + edit.name, 0, 16, 32), new Vector2(edit.position[0], edit.position[1]), edit.map, 0, edit.name, edit.datable, (Dictionary <int, int[]>)null, Helper.Content.Load <Texture2D>("Portraits\\" + edit.name, ContentSource.GameContent))); } }; } foreach (MapEdit edit in tmxPack.addMaps) { string filePath = Path.Combine(pack.DirectoryPath, edit.file); Map map = TMXContent.Load(edit.file, Helper, pack); editWarps(map, edit.addWarps, edit.removeWarps, map); map.inject("Maps/" + edit.name); edit._map = map; addedLocations.Add(edit); //mapsToSync.AddOrReplace(edit.name, map); } foreach (MapEdit edit in tmxPack.replaceMaps) { string filePath = Path.Combine(pack.DirectoryPath, edit.file); Map map = TMXContent.Load(edit.file, Helper, pack); Map original = edit.retainWarps ? Helper.Content.Load <Map>("Maps/" + edit.name, ContentSource.GameContent) : map; editWarps(map, edit.addWarps, edit.removeWarps, original); map.injectAs("Maps/" + edit.name); // mapsToSync.AddOrReplace(edit.name, map); } foreach (MapEdit edit in tmxPack.mergeMaps) { string filePath = Path.Combine(pack.DirectoryPath, edit.file); Map map = TMXContent.Load(edit.file, Helper, pack); Map original = Helper.Content.Load <Map>("Maps/" + edit.name, ContentSource.GameContent); Rectangle?sourceArea = null; if (edit.sourceArea.Length == 4) { sourceArea = new Rectangle(edit.sourceArea[0], edit.sourceArea[1], edit.sourceArea[2], edit.sourceArea[3]); } map = map.mergeInto(original, new Vector2(edit.position[0], edit.position[1]), sourceArea, edit.removeEmpty); editWarps(map, edit.addWarps, edit.removeWarps, original); map.injectAs("Maps/" + edit.name); // mapsToSync.AddOrReplace(edit.name, map); } foreach (MapEdit edit in tmxPack.onlyWarps) { Map map = Helper.Content.Load <Map>("Maps/" + edit.name, ContentSource.GameContent); editWarps(map, edit.addWarps, edit.removeWarps, map); map.injectAs("Maps/" + edit.name); // mapsToSync.AddOrReplace(edit.name, map); } } }
private void loadContentPacks() { foreach (StardewModdingAPI.IContentPack pack in Helper.GetContentPacks()) { TMXContentPack tmxPack = pack.ReadJsonFile <TMXContentPack>("content.json"); if (tmxPack.scripts.Count > 0) { foreach (string script in tmxPack.scripts) { PyLua.loadScriptFromFile(Path.Combine(pack.DirectoryPath, script), pack.Manifest.UniqueID); } } foreach (MapEdit edit in tmxPack.addMaps) { string filePath = Path.Combine(pack.DirectoryPath, edit.file); Map map = TMXContent.Load(edit.file, Helper, pack); editWarps(map, edit.addWarps, edit.removeWarps, map); map.inject("Maps/" + edit.name); map.enableMoreMapLayers(); GameLocation location; if (map.Properties.ContainsKey("Outdoors") && map.Properties["Outdoors"] == "F") { location = new GameLocation(Path.Combine("Maps", edit.name), edit.name) { IsOutdoors = false }; location.loadLights(); location.IsOutdoors = false; } else { location = new GameLocation(Path.Combine("Maps", edit.name), edit.name); } location.seasonUpdate(Game1.currentSeason); mapsToSync.AddOrReplace(edit.name, map); SaveEvents.AfterLoad += (s, e) => Game1.locations.Add(location); } foreach (MapEdit edit in tmxPack.replaceMaps) { string filePath = Path.Combine(pack.DirectoryPath, edit.file); Map map = TMXContent.Load(edit.file, Helper, pack); map.enableMoreMapLayers(); Map original = edit.retainWarps ? Helper.Content.Load <Map>("Maps/" + edit.name, ContentSource.GameContent) : map; editWarps(map, edit.addWarps, edit.removeWarps, original); map.injectAs("Maps/" + edit.name); mapsToSync.AddOrReplace(edit.name, map); } foreach (MapEdit edit in tmxPack.mergeMaps) { string filePath = Path.Combine(pack.DirectoryPath, edit.file); Map map = TMXContent.Load(edit.file, Helper, pack); Map original = Helper.Content.Load <Map>("Maps/" + edit.name, ContentSource.GameContent); Rectangle?sourceArea = null; if (edit.sourceArea.Length == 4) { sourceArea = new Rectangle(edit.sourceArea[0], edit.sourceArea[1], edit.sourceArea[2], edit.sourceArea[3]); } map = map.mergeInto(original, new Vector2(edit.position[0], edit.position[1]), sourceArea, true); editWarps(map, edit.addWarps, edit.removeWarps, original); map.enableMoreMapLayers(); map.injectAs("Maps/" + edit.name); mapsToSync.AddOrReplace(edit.name, map); } foreach (MapEdit edit in tmxPack.mergeMaps) { string filePath = Path.Combine(pack.DirectoryPath, edit.file); Map map = TMXContent.Load(edit.file, Helper, pack); Map original = Helper.Content.Load <Map>("Maps/" + edit.name, ContentSource.GameContent); Rectangle?sourceArea = null; if (edit.sourceArea.Length == 4) { sourceArea = new Rectangle(edit.sourceArea[0], edit.sourceArea[1], edit.sourceArea[2], edit.sourceArea[3]); } map = map.mergeInto(original, new Vector2(edit.position[0], edit.position[1]), sourceArea, true); editWarps(map, edit.addWarps, edit.removeWarps, original); map.enableMoreMapLayers(); map.injectAs("Maps/" + edit.name); mapsToSync.AddOrReplace(edit.name, map); } foreach (MapEdit edit in tmxPack.onlyWarps) { Map map = Helper.Content.Load <Map>("Maps/" + edit.name, ContentSource.GameContent); editWarps(map, edit.addWarps, edit.removeWarps, map); map.injectAs("Maps/" + edit.name); mapsToSync.AddOrReplace(edit.name, map); } } }
private void loadContentPacks() { foreach (StardewModdingAPI.IContentPack pack in Helper.GetContentPacks()) { TMXContentPack tmxPack = pack.ReadJsonFile <TMXContentPack>("content.json"); if (tmxPack.scripts.Count > 0) { foreach (string script in tmxPack.scripts) { PyLua.loadScriptFromFile(Path.Combine(pack.DirectoryPath, script), pack.Manifest.UniqueID); } } PyLua.loadScriptFromFile(Path.Combine(Helper.DirectoryPath, "sr.lua"), "Platonymous.TMXLoader.SpouseRoom"); List <MapEdit> spouseRoomMaps = new List <MapEdit>(); foreach (SpouseRoom room in tmxPack.spouseRooms) { if (room.tilefix && !Overrides.NPCs.Contains(room.name)) { Overrides.NPCs.Add(room.name); } if (room.file != "none") { spouseRoomMaps.Add(new MapEdit() { info = room.name, name = "FarmHouse1_marriage", file = room.file, position = new[] { 29, 1 } }); spouseRoomMaps.Add(new MapEdit() { info = room.name, name = "FarmHouse2_marriage", file = room.file, position = new[] { 35, 10 } }); } } foreach (MapEdit edit in spouseRoomMaps) { string filePath = Path.Combine(pack.DirectoryPath, edit.file); Map map = TMXContent.Load(edit.file, Helper, pack); if (edit.info != "none") { foreach (Layer layer in map.Layers) { layer.Id = layer.Id.Replace("Spouse", edit.info); } } map.Properties.Add("EntryAction", "Lua Platonymous.TMXLoader.SpouseRoom entry"); Map original = Helper.Content.Load <Map>("Maps/" + edit.name, ContentSource.GameContent); map = map.mergeInto(original, new Vector2(edit.position[0], edit.position[1]), null, true); map.injectAs("Maps/" + edit.name); mapsToSync.AddOrReplace(edit.name, map); } foreach (NPCPlacement edit in tmxPack.festivalSpots) { Map reference = Helper.Content.Load <Map>("Maps/Town", ContentSource.GameContent); Map original = Helper.Content.Load <Map>("Maps/" + edit.map, ContentSource.GameContent); Texture2D springTex = Helper.Content.Load <Texture2D>("Maps/spring_outdoorsTileSheet", ContentSource.GameContent); Dictionary <string, string> source = Helper.Content.Load <Dictionary <string, string> >("Data\\NPCDispositions", ContentSource.GameContent); int index = source.Keys.ToList().IndexOf(edit.name); TileSheet spring = original.GetTileSheet("ztemp"); if (spring == null) { spring = new TileSheet("ztemp", original, "Maps/spring_outdoorsTileSheet", new xTile.Dimensions.Size(springTex.Width, springTex.Height), original.TileSheets[0].TileSize); original.AddTileSheet(spring); } original.GetLayer("Set-Up").Tiles[edit.position[0], edit.position[1]] = new StaticTile(original.GetLayer("Set-Up"), spring, BlendMode.Alpha, (index * 4) + edit.direction); original.injectAs("Maps/" + edit.map); mapsToSync.AddOrReplace(edit.map, original); } foreach (MapEdit edit in tmxPack.addMaps) { string filePath = Path.Combine(pack.DirectoryPath, edit.file); Map map = TMXContent.Load(edit.file, Helper, pack); editWarps(map, edit.addWarps, edit.removeWarps, map); map.inject("Maps/" + edit.name); GameLocation location; if (map.Properties.ContainsKey("Outdoors") && map.Properties["Outdoors"] == "F") { location = new GameLocation(Path.Combine("Maps", edit.name), edit.name) { IsOutdoors = false }; location.loadLights(); location.IsOutdoors = false; } else { location = new GameLocation(Path.Combine("Maps", edit.name), edit.name); } location.seasonUpdate(Game1.currentSeason); mapsToSync.AddOrReplace(edit.name, map); helper.Events.GameLoop.SaveLoaded += (s, e) => Game1.locations.Add(location); } foreach (MapEdit edit in tmxPack.replaceMaps) { string filePath = Path.Combine(pack.DirectoryPath, edit.file); Map map = TMXContent.Load(edit.file, Helper, pack); Map original = edit.retainWarps ? Helper.Content.Load <Map>("Maps/" + edit.name, ContentSource.GameContent) : map; editWarps(map, edit.addWarps, edit.removeWarps, original); map.injectAs("Maps/" + edit.name); mapsToSync.AddOrReplace(edit.name, map); } foreach (MapEdit edit in tmxPack.mergeMaps) { string filePath = Path.Combine(pack.DirectoryPath, edit.file); Map map = TMXContent.Load(edit.file, Helper, pack); Map original = Helper.Content.Load <Map>("Maps/" + edit.name, ContentSource.GameContent); Rectangle?sourceArea = null; if (edit.sourceArea.Length == 4) { sourceArea = new Rectangle(edit.sourceArea[0], edit.sourceArea[1], edit.sourceArea[2], edit.sourceArea[3]); } map = map.mergeInto(original, new Vector2(edit.position[0], edit.position[1]), sourceArea, edit.removeEmpty); editWarps(map, edit.addWarps, edit.removeWarps, original); map.injectAs("Maps/" + edit.name); mapsToSync.AddOrReplace(edit.name, map); } foreach (MapEdit edit in tmxPack.onlyWarps) { Map map = Helper.Content.Load <Map>("Maps/" + edit.name, ContentSource.GameContent); editWarps(map, edit.addWarps, edit.removeWarps, map); map.injectAs("Maps/" + edit.name); mapsToSync.AddOrReplace(edit.name, map); } } }