Esempio n. 1
0
        public override void Entry(IModHelper helper)
        {
            config = Helper.ReadConfig <Config>();
            TMXLoaderMod.helper = Helper;
            monitor             = Monitor;
            if (config.converter)
            {
                exportAllMaps();
                convert();
            }
            loadContentPacks();
            setTileActions();
            helper.Events.Player.Warped += OnWarped;
            PyLua.registerType(typeof(Map), false, true);
            PyLua.registerType(typeof(TMXActions), false, false);
            PyLua.addGlobal("TMX", new TMXActions());
            new ConsoleCommand("loadmap", "Teleport to a map", (s, st) => {
                Game1.player.warpFarmer(new Warp(int.Parse(st[1]), int.Parse(st[2]), st[0], int.Parse(st[1]), int.Parse(st[2]), false));
            });
            fixCompatibilities();
            harmonyFix();

            helper.Events.GameLoop.UpdateTicked += (s, e) =>
            {
                if (e.IsOneSecond && Context.IsWorldReady && Game1.IsMasterGame && Game1.IsMultiplayer && Game1.otherFarmers.Values.Where(f => f.isActive() && f != Game1.player && !syncedFarmers.Contains(f)) is IEnumerable <SFarmer> ef && ef.Count() is int i && i > 0)
                {
                    syncMaps(ef);
                }
            };
        }
        private void OnGameLaunched(object sender, GameLaunchedEventArgs e)
        {
            if (hasKisekae)
            {
                var registry = Helper.ModRegistry.GetType().GetField("Registry", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(Helper.ModRegistry);
                System.Collections.IList list = (System.Collections.IList)registry.GetType().GetField("Mods", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(registry);
                foreach (var m in list)
                {
                    IManifest mmanifest = (IManifest)m.GetType().GetProperty("Manifest").GetValue(m);
                    if (mmanifest.UniqueID == "Kabigon.kisekae")
                    {
                        kisekae = (IMod)m.GetType().GetProperty("Mod").GetValue(m);
                        break;
                    }
                }
            }

            loadPacks();

            if (_config.water)
            {
                new CustomObjectData("Platonymous.Water", "Water/1/2/Cooking -7/Water/Plain drinking water./drink/0 0 0 0 0 0 0 0 0 0 0/0", Game1.objectSpriteSheet.getTile(247).setSaturation(0), Color.Aqua, type: typeof(WaterItem));
                ButtonClick.ActionButton.onClick((pos) => clickedOnWateringCan(pos), (p) => convertWater());
            }

            PyLua.registerType(typeof(CustomMachine), registerAssembly: true);
        }
Esempio n. 3
0
        private void registerTileActions()
        {
            TileAction Game = new TileAction("Game", (action, location, tile, layer) =>
            {
                List <string> text = action.Split(' ').ToList();
                text.RemoveAt(0);
                action = String.Join(" ", text);
                return(location.performAction(action, Game1.player, new Location((int)tile.X, (int)tile.Y)));
            }).register();

            TileAction Lua = new TileAction("Lua", (action, location, tile, layer) =>
            {
                string[] a = action.Split(' ');
                if (a.Length > 2)
                {
                    if (a[1] == "this")
                    {
                        string id = location.Name + "." + layer + "." + tile.Y + tile.Y;
                        if (!PyLua.hasScript(id))
                        {
                            if (layer == "Map")
                            {
                                if (location.map.Properties.ContainsKey("Lua"))
                                {
                                    PyLua.loadScriptFromString(@"
                                function callthis(location,tile,layer)
                                " + location.map.Properties["Lua"].ToString() + @"
                                end", id);
                                }
                                else
                                {
                                    PyLua.loadScriptFromString("Luau.log(\"Error: Could not find Lua property on Map.\")", id);
                                }
                            }
                            else
                            {
                                if (location.doesTileHaveProperty((int)tile.X, (int)tile.Y, "Lua", layer) is string lua)
                                {
                                    PyLua.loadScriptFromString(@"
                                function callthis(location,tile,layer)
                                " + lua + @"
                                end", id);
                                }
                                else
                                {
                                    PyLua.loadScriptFromString("Luau.log(\"Error: Could not find Lua property on Tile.\")", id);
                                }
                            }
                        }
                        PyLua.callFunction(id, "callthis", new object[] { location, tile, layer });
                    }
                    else
                    {
                        PyLua.callFunction(a[1], a[2], new object[] { location, tile, layer });
                    }
                }
                return(true);
            }).register();
        }
Esempio n. 4
0
        public static string getLuaString(string call)
        {
            var script = PyLua.getNewScript();

            script.Globals["result"] = false;
            script.DoString("result = (" + call + ")");
            return((string)script.Globals["result"]);
        }
Esempio n. 5
0
        private IEnumerable <string> GetLuaString(string input)
        {
            var script = PyLua.getNewScript();

            script.Globals["result"] = "";
            script.DoString("result = (" + input + ")");
            yield return((string)script.Globals["result"]);
        }
        public override void Entry(IModHelper helper)
        {
            _helper  = Helper;
            _monitor = Monitor;
            _config  = Helper.ReadConfig <Config>();

            hasKisekae = helper.ModRegistry.IsLoaded("Kabigon.kisekae");

            if (hasKisekae)
            {
                var registry = helper.ModRegistry.GetType()
                               .GetField("Registry", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(helper.ModRegistry);
                System.Collections.IList list = (System.Collections.IList)registry.GetType()
                                                .GetField("Mods", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(registry);
                foreach (var m in list)
                {
                    IManifest mmanifest = (IManifest)m.GetType().GetProperty("Manifest").GetValue(m);
                    if (mmanifest.UniqueID == "Kabigon.kisekae")
                    {
                        kisekae = (IMod)m.GetType().GetProperty("Mod").GetValue(m);
                        break;
                    }
                }
            }

            loadPacks();
            MenuEvents.MenuChanged += MenuEvents_MenuChanged;
            SaveEvents.AfterLoad   += (s, e) =>
            {
                foreach (var c in craftingrecipes)
                {
                    if (Game1.player.craftingRecipes.ContainsKey(c.Key))
                    {
                        Game1.player.craftingRecipes[c.Key] = c.Value;
                    }
                    else
                    {
                        Game1.player.craftingRecipes.Add(c.Key, c.Value);
                    }
                }
            };

            harmonyFix();
            SaveHandler.addPreprocessor(legacyFix);
            SaveHandler.addReplacementPreprocessor(fixLegacyObject);
            helper.ConsoleCommands.Add("replace_custom_farming", "Triggers Custom Farming Replacement",
                                       replaceCustomFarming);

            if (_config.water)
            {
                new CustomObjectData("Platonymous.Water",
                                     "Water/1/2/Cooking -7/Water/Plain drinking water./drink/0 0 0 0 0 0 0 0 0 0 0/0",
                                     Game1.objectSpriteSheet.getTile(247).setSaturation(0), Color.Aqua, type: typeof(WaterItem));
                ButtonClick.ActionButton.onClick((pos) => clickedOnWateringCan(pos), (p) => convertWater());
            }

            PyLua.registerType(typeof(CustomMachine), registerAssembly: true);
        }
Esempio n. 7
0
 public static bool luaAction(string action, GameLocation location, Vector2 tile, string layer)
 {
     string[] a = action.Split(' ');
     if (a.Length > 2)
     {
         PyLua.callFunction(a[1], a[2], new object[] { location, tile, layer });
     }
     return(true);
 }
Esempio n. 8
0
        public static ConsoleCommand runScript()
        {
            Action <string, string[]> action = delegate(string s, string[] p)
            {
                if (p.Length < 1)
                {
                    return;
                }

                List <string> args = new List <string>(p);

                string fn = "";
                if (p[0] == "--f")
                {
                    args.Remove(p[0]);
                    fn = String.Join(" ", args);
                    PyLua.loadScriptFromFile(fn, PyLua.consoleCacheID);
                    return;
                }

                if (args[0] == "--reload")
                {
                    Monitor.Log("Reloading..", LogLevel.Trace);
                    PyLua.scripts.Remove(PyLua.consoleCacheID);
                    PyLua.loadScriptFromFile(PyLua.consoleChache, PyLua.consoleCacheID);
                    Monitor.Log("OK", LogLevel.Trace);
                    return;
                }

                if (args[0] == "--clear")
                {
                    Monitor.Log("Clearing..", LogLevel.Trace);
                    PyLua.scripts.Remove(PyLua.consoleCacheID);
                    Monitor.Log("OK", LogLevel.Trace);
                    return;
                }

                try
                {
                    PyLua.loadScriptFromString(String.Join(" ", args), "consoleScript");

                    if (args[0] == "--save")
                    {
                        PyLua.saveScriptToFile(PyLua.consoleCacheID, PyLua.consoleChache);
                        Monitor.Log("Saving..", LogLevel.Trace);
                    }

                    Monitor.Log("OK", LogLevel.Trace);
                }catch (Exception e)
                {
                    string em = "ERROR: LUA Script crashed. ";
                    Monitor.Log(em + e.Message, LogLevel.Alert);
                }
            };

            return(new ConsoleCommand("lua", "Runs lua code, just write code or use lua -f YOUR_PATH to load a file", (s, p) => action.Invoke(s, p)));
        }
 public override void Entry(IModHelper helper)
 {
     Monitor.Log("Environment:" + PyUtils.getContentFolder());
     exportAllMaps();
     convert();
     loadContentPacks();
     setTileActions();
     LocationEvents.CurrentLocationChanged += LocationEvents_CurrentLocationChanged;
     PyLua.registerType(typeof(Map), false, true);
     PyLua.registerType(typeof(TMXActions), false, false);
     PyLua.addGlobal("TMX", new TMXActions());
 }
Esempio n. 10
0
        public static bool checkLuaConditions(string conditions, object caller = null)
        {
            var script = PyLua.getNewScript();

            script.Globals["result"] = false;
            if (caller != null)
            {
                script.Globals["caller"] = caller;
            }
            script.DoString("result = (" + conditions + ")");
            return((bool)script.Globals["result"]);
        }
        public override void Entry(IModHelper helper)
        {
            _helper  = helper;
            _monitor = Monitor;

            //testing();

            harmonyFix();
            FormatManager.Instance.RegisterMapFormat(new NewTiledTmxFormat());

            SaveHandler.BeforeRebuilding += (a, b) => CustomObjectData.collection.useAll(k => k.Value.sdvId = k.Value.getNewSDVId());
            registerConsoleCommands();
            CustomTVMod.load();
            PyLua.init();
            SaveHandler.setUpEventHandlers();
        }
Esempio n. 12
0
        public override void Entry(IModHelper helper)
        {
            config = Helper.ReadConfig <Config>();
            TMXLoaderMod.helper = Helper;
            monitor             = Monitor;
            if (config.converter)
            {
                exportAllMaps();
                convert();
            }
            loadContentPacks();
            setTileActions();
            helper.Events.Player.Warped += OnWarped;
            PyLua.registerType(typeof(Map), false, true);
            PyLua.registerType(typeof(TMXActions), false, false);
            PyLua.addGlobal("TMX", new TMXActions());
            new ConsoleCommand("loadmap", "Teleport to a map", (s, st) => {
                Game1.player.warpFarmer(new Warp(int.Parse(st[1]), int.Parse(st[2]), st[0], int.Parse(st[1]), int.Parse(st[2]), false));
            }).register();

            new ConsoleCommand("removeNPC", "Removes an NPC", (s, st) => {
                if (Game1.getCharacterFromName(st.Last()) == null)
                {
                    Monitor.Log("Couldn't find NPC with that name!", LogLevel.Alert);
                }
                else
                {
                    Game1.removeThisCharacterFromAllLocations(Game1.getCharacterFromName(st.Last()));
                    if (Game1.player.friendshipData.ContainsKey(st.Last()))
                    {
                        Game1.player.friendshipData.Remove(st.Last());
                    }
                    Monitor.Log(st.Last() + " was removed!", LogLevel.Info);
                }
            }).register();

            fixCompatibilities();
            harmonyFix();

            helper.Events.GameLoop.UpdateTicked += (s, e) =>
            {
                if (e.IsOneSecond && Context.IsWorldReady && Game1.IsMasterGame && Game1.IsMultiplayer && Game1.otherFarmers.Values.Where(f => f.isActive() && f != Game1.player && !syncedFarmers.Contains(f)) is IEnumerable <SFarmer> ef && ef.Count() is int i && i > 0)
                {
                    syncMaps(ef);
                }
            };
        }
Esempio n. 13
0
        public override void Entry(IModHelper helper)
        {
            TMXLoaderMod.helper = Helper;
            monitor             = Monitor;
            Monitor.Log("Environment:" + PyUtils.getContentFolder());
            exportAllMaps();
            convert();
            loadContentPacks();
            setTileActions();
            PlayerEvents.Warped        += LocationEvents_CurrentLocationChanged;
            TimeEvents.AfterDayStarted += TimeEvents_AfterDayStarted;
            PyLua.registerType(typeof(Map), false, true);
            PyLua.registerType(typeof(TMXActions), false, false);
            PyLua.addGlobal("TMX", new TMXActions());
            fixCompatibilities();
            harmonyFix();

            GameEvents.OneSecondTick += (s, e) =>
            {
                if (Context.IsWorldReady && Game1.IsServer && Game1.IsMultiplayer)
                {
                    if (Game1.otherFarmers.Values.Where(f => f.isActive() && !syncedFarmers.Contains(f)) is IEnumerable <SFarmer> ef && ef.Count() is int i && i > 0)
                    {
                        syncMaps(ef);
                    }
                }
            };

            TimeEvents.AfterDayStarted += (s, e) => {
                List <SFarmer> toRemove = new List <SFarmer>();

                foreach (SFarmer farmer in syncedFarmers)
                {
                    if (!Game1.otherFarmers.ContainsKey(farmer.UniqueMultiplayerID) || !Game1.otherFarmers[farmer.UniqueMultiplayerID].isActive())
                    {
                        toRemove.Add(farmer);
                    }
                }

                foreach (SFarmer remove in toRemove)
                {
                    syncedFarmers.Remove(remove);
                }
            };
        }
Esempio n. 14
0
        public static bool luaAction(string action, GameLocation location, Vector2 tile, string layer)
        {
            string[] a = action.Split(' ');
            if (a.Length > 2)
            {
                if (a[2] == "this")
                {
                    string id = location.Name + "." + layer + "." + tile.Y + tile.Y;
                    if (!PyLua.hasScript(id))
                    {
                        if (layer == "Map")
                        {
                            if (location.map.Properties.ContainsKey("Lua"))
                            {
                                PyLua.loadScriptFromString(location.map.Properties["Lua"].ToString(), id);
                            }
                            else
                            {
                                PyLua.loadScriptFromString("Luau.log(\"Error: Could not find Lua property on Map.\")", id);
                            }
                        }
                        else
                        {
                            if (location.doesTileHaveProperty((int)tile.X, (int)tile.Y, "Lua", layer) is string lua)
                            {
                                PyLua.loadScriptFromString(lua, id);
                            }
                            else
                            {
                                PyLua.loadScriptFromString("Luau.log(\"Error: Could not find Lua property on Tile.\")", id);
                            }
                        }
                    }

                    PyLua.callFunction(id, a[2], new object[] { location, tile, layer });
                }
                else
                {
                    PyLua.callFunction(a[1], a[2], new object[] { location, tile, layer });
                }
            }
            return(true);
        }
Esempio n. 15
0
        public override void Entry(IModHelper helper)
        {
            _helper  = helper;
            _monitor = Monitor;

            //testing();
            //messageTest()

            harmonyFix();
            FormatManager.Instance.RegisterMapFormat(new NewTiledTmxFormat());

            SaveHandler.BeforeRebuilding += (a, b) => CustomObjectData.collection.useAll(k => k.Value.sdvId = k.Value.getNewSDVId());
            initializeResponders();
            startResponder();
            registerConsoleCommands();
            CustomTVMod.load();
            PyLua.init();
            SaveHandler.setUpEventHandlers();
            ContentSync.ContentSyncHandler.initialize();
            PlayerEvents.Warped += (s, e) => e.NewLocation?.Map.enableMoreMapLayers();
        }
Esempio n. 16
0
 public override void Entry(IModHelper helper)
 {
     maplayers           = new List <Map>();
     TMXLoaderMod.helper = Helper;
     monitor             = Monitor;
     Monitor.Log("Environment:" + PyUtils.getContentFolder());
     exportAllMaps();
     convert();
     loadContentPacks();
     setTileActions();
     PlayerEvents.Warped += LocationEvents_CurrentLocationChanged;
     PyLua.registerType(typeof(Map), false, true);
     PyLua.registerType(typeof(TMXActions), false, false);
     PyLua.addGlobal("TMX", new TMXActions());
     fixCompatibilities();
     harmonyFix();
     PlayerEvents.Warped += (s, e) => { if (e.NewLocation is GameLocation l && l.map is Map m)
                                        {
                                            addMoreMapLayers(m);
                                        }
     };
 }
Esempio n. 17
0
        public override void Entry(IModHelper helper)
        {
            _helper  = helper;
            _monitor = Monitor;

            harmonyFix();
            FormatManager.Instance.RegisterMapFormat(new NewTiledTmxFormat());

            SaveHandler.BeforeRebuilding += (a, b) => CustomObjectData.collection.useAll(k => k.Value.sdvId = k.Value.getNewSDVId());
            initializeResponders();
            startResponder();
            registerConsoleCommands();
            CustomTVMod.load();
            PyLua.init();
            registerTileActions();
            SaveHandler.setUpEventHandlers();
            CustomObjectData.CODSyncer.start();
            ContentSync.ContentSyncHandler.initialize();
            this.Helper.Events.Player.Warped                   += Player_Warped;
            this.Helper.Events.GameLoop.DayStarted             += OnDayStarted;
            this.Helper.Events.Multiplayer.PeerContextReceived += (s, e) =>
            {
                if (Game1.IsMasterGame && Game1.IsServer && CustomObjectData.collection.Values.Count > 0)
                {
                    List <CODSync> list = new List <CODSync>();
                    foreach (CustomObjectData data in CustomObjectData.collection.Values)
                    {
                        list.Add(new CODSync(data.id, data.sdvId));
                    }

                    PyNet.sendDataToFarmer(CustomObjectData.CODSyncerName, new CODSyncMessage(list), e.Peer.PlayerID, SerializationType.JSON);
                }
            };

            Helper.Events.Multiplayer.ModMessageReceived += PyNet.Multiplayer_ModMessageReceived;
        }
Esempio n. 18
0
        private void OnGameLaunched(object sender, GameLaunchedEventArgs e)
        {
            if (config.converter)
            {
                exportAllMaps();
                convert();
            }
            loadContentPacks();
            setTileActions();

            PyLua.registerType(typeof(Map), false, true);
            PyLua.registerType(typeof(TMXActions), false, false);
            PyLua.addGlobal("TMX", new TMXActions());
            new ConsoleCommand("loadmap", "Teleport to a map", (s, st) => {
                Game1.player.warpFarmer(new Warp(int.Parse(st[1]), int.Parse(st[2]), st[0], int.Parse(st[1]), int.Parse(st[2]), false));
            }).register();

            new ConsoleCommand("removeNPC", "Removes an NPC", (s, st) => {
                if (Game1.getCharacterFromName(st.Last()) == null)
                {
                    Monitor.Log("Couldn't find NPC with that name!", LogLevel.Alert);
                }
                else
                {
                    Game1.removeThisCharacterFromAllLocations(Game1.getCharacterFromName(st.Last()));
                    if (Game1.player.friendshipData.ContainsKey(st.Last()))
                    {
                        Game1.player.friendshipData.Remove(st.Last());
                    }
                    Monitor.Log(st.Last() + " was removed!", LogLevel.Info);
                }
            }).register();

            fixCompatibilities();
            harmonyFix();
        }
        public override void Entry(IModHelper helper)
        {
            _helper  = Helper;
            _monitor = Monitor;
            _config  = Helper.ReadConfig <Config>();

            loadPacks();
            MenuEvents.MenuChanged += MenuEvents_MenuChanged;
            SaveEvents.AfterLoad   += (s, e) =>
            {
                foreach (var c in craftingrecipes)
                {
                    if (Game1.player.craftingRecipes.ContainsKey(c.Key))
                    {
                        Game1.player.craftingRecipes[c.Key] = c.Value;
                    }
                    else
                    {
                        Game1.player.craftingRecipes.Add(c.Key, c.Value);
                    }
                }
            };

            harmonyFix();
            SaveHandler.addPreprocessor(legacyFix);
            SaveHandler.addReplacementPreprocessor(fixLegacyObject);
            helper.ConsoleCommands.Add("replace_custom_farming", "Triggers Custom Farming Replacement", replaceCustomFarming);

            if (_config.water)
            {
                new CustomObjectData("Platonymous.Water", "Water/1/2/Cooking -7/Water/Plain drinking water./drink/0 0 0 0 0 0 0 0 0 0 0/0", Game1.objectSpriteSheet.getTile(247).setSaturation(0), Color.Aqua, type: typeof(WaterItem));
                ButtonClick.ActionButton.onClick((pos) => clickedOnWateringCan(pos), (p) => convertWater());
            }

            PyLua.registerType(typeof(CustomMachine), registerAssembly: true);
        }
Esempio n. 20
0
        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);
                }
            }
        }
Esempio n. 21
0
        private void registerTileActions()
        {
            TileAction CC = new TileAction("CC", (action, location, tile, layer) =>
            {
                List <string> text = action.Split(' ').ToList();
                string key         = text[1];
                text.RemoveAt(0);
                text.RemoveAt(0);
                action = String.Join(" ", text);
                if (key == "cs")
                {
                    action += ";";
                }
                Helper.ConsoleCommands.Trigger(key, action.Split(' '));
                return(true);
            }).register();

            TileAction Game = new TileAction("Game", (action, location, tile, layer) =>
            {
                List <string> text = action.Split(' ').ToList();
                text.RemoveAt(0);
                action = String.Join(" ", text);
                return(location.performAction(action, Game1.player, new xTile.Dimensions.Location((int)tile.X, (int)tile.Y)));
            }).register();

            TileAction Lua = new TileAction("Lua", (action, location, tile, layer) =>
            {
                string[] a = action.Split(' ');
                if (a.Length > 2)
                {
                    if (a[1] == "this")
                    {
                        string id = location.Name + "." + layer + "." + tile.Y + tile.Y;
                        if (!PyLua.hasScript(id))
                        {
                            if (layer == "Map")
                            {
                                if (location.map.Properties.ContainsKey("Lua_" + a[2]))
                                {
                                    string script = @"
                                function callthis(location,tile,layer)
                                " + location.map.Properties["Lua_" + a[2]].ToString() + @"
                                end";

                                    PyLua.loadScriptFromString(script, id);
                                }
                            }
                            else
                            {
                                if (location.doesTileHaveProperty((int)tile.X, (int)tile.Y, "Lua_" + a[2], layer) is string lua)
                                {
                                    PyLua.loadScriptFromString(@"
                                function callthis(location,tile,layer)
                                " + lua + @"
                                end", id);
                                }
                            }
                        }

                        if (PyLua.hasScript(id))
                        {
                            PyLua.callFunction(id, "callthis", new object[] { location, tile, layer });
                        }
                    }
                    else
                    {
                        PyLua.callFunction(a[1], a[2], new object[] { location, tile, layer });
                    }
                }
                return(true);
            }).register();
        }
Esempio n. 22
0
        public override void Entry(IModHelper helper)
        {
            _instance = this;
            PostSerializer.Add(ModManifest, Rebuilder);
            PreSerializer.Add(ModManifest, Replacer);
            harmonyFix();

            FormatManager.Instance.RegisterMapFormat(new TMXTile.TMXFormat(Game1.tileSize / Game1.pixelZoom, Game1.tileSize / Game1.pixelZoom, Game1.pixelZoom, Game1.pixelZoom));

            initializeResponders();
            startResponder();
            registerConsoleCommands();
            CustomTVMod.load();
            PyLua.init();
            registerTileActions();
            registerEventPreconditions();
            SaveHandler.setUpEventHandlers();
            CustomObjectData.CODSyncer.start();
            ContentSync.ContentSyncHandler.initialize();

            helper.Events.GameLoop.DayStarted += (s, e) =>
            {
                if (ReInjectCustomObjects)
                {
                    ReInjectCustomObjects = false;
                    CustomObjectData.injector.Invalidate();
                    CustomObjectData.injectorBig.Invalidate();
                }
            };

            this.Helper.Events.Player.Warped                   += Player_Warped;
            this.Helper.Events.GameLoop.DayStarted             += OnDayStarted;
            this.Helper.Events.Multiplayer.PeerContextReceived += (s, e) =>
            {
                if (Game1.IsMasterGame && Game1.IsServer)
                {
                    if (CustomObjectData.collection.Values.Count > 0)
                    {
                        List <CODSync> list = new List <CODSync>();
                        foreach (CustomObjectData data in CustomObjectData.collection.Values)
                        {
                            list.Add(new CODSync(data.id, data.sdvId));
                        }

                        PyNet.sendDataToFarmer(CustomObjectData.CODSyncerName, new CODSyncMessage(list), e.Peer.PlayerID, SerializationType.JSON);
                    }

                    PyNet.sendDataToFarmer("PyTK.ModSavdDataReceiver", saveData, e.Peer.PlayerID, SerializationType.JSON);
                }
            };

            Helper.Events.Display.RenderingHud += (s, e) =>
            {
                if (Game1.displayHUD && Context.IsWorldReady)
                {
                    PyTK.PlatoUI.UIHelper.DrawHud(e.SpriteBatch, true);
                }
            };

            Helper.Events.Display.RenderedHud += (s, e) =>
            {
                if (Game1.displayHUD && Context.IsWorldReady)
                {
                    PyTK.PlatoUI.UIHelper.DrawHud(e.SpriteBatch, false);
                }
            };

            Helper.Events.Input.ButtonPressed += (s, e) =>
            {
                if (Game1.displayHUD && Context.IsWorldReady)
                {
                    if (e.Button == SButton.MouseLeft || e.Button == SButton.MouseRight)
                    {
                        PlatoUI.UIHelper.BaseHud.PerformClick(e.Cursor.ScreenPixels.toPoint(), e.Button == SButton.MouseRight, false, false);
                    }
                }
            };

            Helper.Events.Display.WindowResized += (s, e) =>
            {
                PlatoUI.UIElement.Viewportbase.UpdateBounds();
                PlatoUI.UIHelper.BaseHud.UpdateBounds();
            };

            Helper.Events.Multiplayer.ModMessageReceived += PyNet.Multiplayer_ModMessageReceived;
            helper.Events.GameLoop.Saving += (s, e) =>
            {
                if (Game1.IsMasterGame)
                {
                    try
                    {
                        helper.Data.WriteSaveData <PyTKSaveData>("PyTK.ModSaveData", saveData);
                    }
                    catch
                    {
                    }
                }
            };

            helper.Events.GameLoop.ReturnedToTitle += (s, e) =>
            {
                saveData = new PyTKSaveData();
            };

            helper.Events.GameLoop.SaveLoaded += (s, e) =>
            {
                if (Game1.IsMasterGame)
                {
                    try
                    {
                        saveData = helper.Data.ReadSaveData <PyTKSaveData>("PyTK.ModSaveData");
                    }
                    catch
                    {
                    }
                    if (saveData == null)
                    {
                        saveData = new PyTKSaveData();
                    }
                }
            };

            helper.Events.GameLoop.OneSecondUpdateTicked += (s, e) =>
            {
                if (Context.IsWorldReady && Game1.currentLocation is GameLocation location && location.Map is Map map)
                {
                    PyUtils.checkDrawConditions(map);
                }
            };


            helper.Events.GameLoop.GameLaunched += (s, e) =>
            {
                if (!Helper.ModRegistry.IsLoaded("spacechase0.GenericModConfigMenu"))
                {
                    return;
                }

                try
                {
                    registerCPTokens();
                }
                catch { }
            };

            helper.Events.GameLoop.DayStarted += (s, e) => UpdateLuaTokens = true;
        }
        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()
        {
            List <TMXContentPack> packs = new List <TMXContentPack>();

            PyUtils.loadContentPacks <TMXContentPack>(out packs, Path.Combine(Helper.DirectoryPath, contentFolder), SearchOption.AllDirectories, Monitor);

            foreach (TMXContentPack pack in packs)
            {
                if (pack.scripts.Count > 0)
                {
                    foreach (string script in pack.scripts)
                    {
                        PyLua.loadScriptFromFile(Path.Combine(Helper.DirectoryPath, contentFolder, pack.folderName, script), pack.folderName);
                    }
                }


                foreach (MapEdit edit in pack.addMaps)
                {
                    string filePath = Path.Combine(contentFolder, pack.folderName, edit.file);
                    Map    map      = TMXContent.Load(filePath, Helper);
                    editWarps(map, edit.addWarps, edit.removeWarps, map);
                    map.inject("Maps/" + edit.name);
                    addMoreMapLayers(map);
                    GameLocation location;
                    if (map.Properties.ContainsKey("Outdoors") && map.Properties["Outdoors"] == "F")
                    {
                        location = new GameLocation(map, edit.name)
                        {
                            isOutdoors = false
                        };
                        location.loadLights();
                        location.isOutdoors = false;
                    }
                    else
                    {
                        location = new GameLocation(map, edit.name);
                    }

                    location.seasonUpdate(Game1.currentSeason);

                    SaveEvents.AfterLoad += (s, e) => Game1.locations.Add(location);
                }

                foreach (MapEdit edit in pack.replaceMaps)
                {
                    string filePath = Path.Combine(contentFolder, pack.folderName, edit.file);
                    Map    map      = TMXContent.Load(filePath, Helper);
                    addMoreMapLayers(map);
                    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);
                }

                foreach (MapEdit edit in pack.mergeMaps)
                {
                    string filePath = Path.Combine(contentFolder, pack.folderName, edit.file);
                    Map    map      = TMXContent.Load(filePath, Helper);

                    Map       original   = Helper.Content.Load <Map>("Maps/" + edit.name, ContentSource.GameContent);
                    Rectangle?sourceArea = null;

                    foreach (KeyValuePair <string, PropertyValue> p in map.Properties)
                    {
                        if (original.Properties.ContainsKey(p.Key))
                        {
                            if (p.Key == "EntryAction")
                            {
                                original.Properties[p.Key] = original.Properties[p.Key] + ";" + p.Value;
                            }
                            else
                            {
                                original.Properties[p.Key] = p.Value;
                            }
                        }
                        else
                        {
                            original.Properties.Add(p.Key, p.Value);
                        }
                    }

                    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);
                    editWarps(map, edit.addWarps, edit.removeWarps, original);
                    addMoreMapLayers(map);
                    map.injectAs("Maps/" + edit.name);
                }

                foreach (MapEdit edit in pack.onlyWarps)
                {
                    Map map = Helper.Content.Load <Map>("Maps/" + edit.name, ContentSource.GameContent);
                    editWarps(map, edit.addWarps, edit.removeWarps, map);
                    map.injectAs("Maps/" + edit.name);
                }
            }
        }
Esempio n. 25
0
 public void doMagic(bool playedToday)
 {
     PyLua.loadScriptFromFile(Path.Combine(helper.DirectoryPath, "Assets", "luamagic.lua"), "luaMagic");
     PyLua.callFunction("luaMagic", "doMagic", playedToday);
 }
Esempio n. 26
0
        public override void Entry(IModHelper helper)
        {
            _instance = this;

            if (xTile.Format.FormatManager.Instance.GetMapFormatByExtension("tmx") is TMXFormat tmxf)
            {
                tmxf.DrawImageLayer = PyMaps.drawImageLayer;
            }

            Game1.mapDisplayDevice = new PyDisplayDevice(Game1.content, Game1.graphics.GraphicsDevice);

            helper.Events.Display.RenderingWorld += (s, e) =>
            {
                if (Game1.currentLocation is GameLocation location && location.Map is Map map && map.GetBackgroundColor() is TMXColor tmxColor)
                {
                    Game1.graphics.GraphicsDevice.Clear(tmxColor.toColor());
                }
            };

            PostSerializer.Add(ModManifest, Rebuilder);
            PreSerializer.Add(ModManifest, Replacer);

            harmonyFix();

            initializeResponders();
            startResponder();
            registerConsoleCommands();
            CustomTVMod.load();
            PyLua.init();
            registerTileActions();
            registerEventPreconditions();
            SaveHandler.setUpEventHandlers();
            CustomObjectData.CODSyncer.start();
            ContentSync.ContentSyncHandler.initialize();

            helper.Events.GameLoop.DayStarted += (s, e) =>
            {
                if (ReInjectCustomObjects)
                {
                    ReInjectCustomObjects = false;
                    CustomObjectData.injector?.Invalidate();
                    CustomObjectData.injectorBig?.Invalidate();
                }
            };

            this.Helper.Events.Player.Warped                   += Player_Warped;
            this.Helper.Events.GameLoop.DayStarted             += OnDayStarted;
            this.Helper.Events.Multiplayer.PeerContextReceived += (s, e) =>
            {
                if (Game1.IsMasterGame && Game1.IsServer)
                {
                    if (CustomObjectData.collection.Values.Count > 0)
                    {
                        List <CODSync> list = new List <CODSync>();
                        foreach (CustomObjectData data in CustomObjectData.collection.Values)
                        {
                            list.Add(new CODSync(data.id, data.sdvId));
                        }

                        PyNet.sendDataToFarmer(CustomObjectData.CODSyncerName, new CODSyncMessage(list), e.Peer.PlayerID, SerializationType.JSON);
                    }

                    PyNet.sendDataToFarmer("PyTK.ModSavdDataReceiver", saveData, e.Peer.PlayerID, SerializationType.JSON);
                }
            };

            Helper.Events.Display.RenderingHud += (s, e) =>
            {
                if (Game1.displayHUD && Context.IsWorldReady)
                {
                    PyTK.PlatoUI.UIHelper.DrawHud(e.SpriteBatch, true);
                }
            };

            Helper.Events.Display.RenderedHud += (s, e) =>
            {
                if (Game1.displayHUD && Context.IsWorldReady)
                {
                    PyTK.PlatoUI.UIHelper.DrawHud(e.SpriteBatch, false);
                }
            };

            Helper.Events.Input.ButtonPressed += (s, e) =>
            {
                if (Game1.displayHUD && Context.IsWorldReady)
                {
                    if (e.Button == SButton.MouseLeft || e.Button == SButton.MouseRight)
                    {
                        PlatoUI.UIHelper.BaseHud.PerformClick(e.Cursor.ScreenPixels.toPoint(), e.Button == SButton.MouseRight, false, false);
                    }
                }
            };

            Helper.Events.Display.WindowResized += (s, e) =>
            {
                PlatoUI.UIElement.Viewportbase.UpdateBounds();
                PlatoUI.UIHelper.BaseHud.UpdateBounds();
            };

            Helper.Events.Multiplayer.ModMessageReceived += PyNet.Multiplayer_ModMessageReceived;
            helper.Events.GameLoop.Saving += (s, e) =>
            {
                if (Game1.IsMasterGame)
                {
                    try
                    {
                        helper.Data.WriteSaveData <PyTKSaveData>("PyTK.ModSaveData", saveData);
                    }
                    catch
                    {
                    }
                }
            };

            helper.Events.GameLoop.ReturnedToTitle += (s, e) =>
            {
                saveData = new PyTKSaveData();
            };

            helper.Events.GameLoop.SaveLoaded += (s, e) =>
            {
                CustomTVMod.reloadStrings();

                if (Game1.IsMasterGame)
                {
                    try
                    {
                        saveData = helper.Data.ReadSaveData <PyTKSaveData>("PyTK.ModSaveData");
                    }
                    catch
                    {
                    }
                    if (saveData == null)
                    {
                        saveData = new PyTKSaveData();
                    }
                }
            };

            helper.Events.GameLoop.OneSecondUpdateTicked += (s, e) =>
            {
                if (Context.IsWorldReady && Game1.currentLocation is GameLocation location && location.Map is Map map)
                {
                    PyUtils.checkDrawConditions(map);
                }
            };

            helper.Events.GameLoop.DayStarted += (s, e) =>
            {
                if (Game1.currentLocation is GameLocation loc)
                {
                    UpdateLuaTokens = true;
                }
            };

            helper.Events.GameLoop.UpdateTicked += (s, e) => AnimatedTexture2D.ticked = e.Ticks;
        }
Esempio n. 27
0
        public override void Entry(IModHelper helper)
        {
            _helper  = helper;
            _monitor = Monitor;

            harmonyFix();

            // Monitor.Log("Harmony Patching failed", LogLevel.Error);

            FormatManager.Instance.RegisterMapFormat(new NewTiledTmxFormat());

            SaveHandler.BeforeRebuilding += (a, b) => CustomObjectData.collection.useAll(k => k.Value.sdvId = k.Value.getNewSDVId());
            initializeResponders();
            startResponder();
            registerConsoleCommands();
            CustomTVMod.load();
            PyLua.init();
            registerTileActions();
            registerEventPreconditions();
            SaveHandler.setUpEventHandlers();
            CustomObjectData.CODSyncer.start();
            ContentSync.ContentSyncHandler.initialize();
            this.Helper.Events.Player.Warped                   += Player_Warped;
            this.Helper.Events.GameLoop.DayStarted             += OnDayStarted;
            this.Helper.Events.Multiplayer.PeerContextReceived += (s, e) =>
            {
                if (Game1.IsMasterGame && Game1.IsServer)
                {
                    if (CustomObjectData.collection.Values.Count > 0)
                    {
                        List <CODSync> list = new List <CODSync>();
                        foreach (CustomObjectData data in CustomObjectData.collection.Values)
                        {
                            list.Add(new CODSync(data.id, data.sdvId));
                        }

                        PyNet.sendDataToFarmer(CustomObjectData.CODSyncerName, new CODSyncMessage(list), e.Peer.PlayerID, SerializationType.JSON);
                    }

                    PyNet.sendDataToFarmer("PyTK.ModSavdDataReceiver", saveData, e.Peer.PlayerID, SerializationType.JSON);
                }
            };

            Helper.Events.Display.RenderingHud += (s, e) =>
            {
                if (Game1.displayHUD && Context.IsWorldReady)
                {
                    PyTK.PlatoUI.UIHelper.DrawHud(e.SpriteBatch, true);
                }
            };

            Helper.Events.Display.RenderedHud += (s, e) =>
            {
                if (Game1.displayHUD && Context.IsWorldReady)
                {
                    PyTK.PlatoUI.UIHelper.DrawHud(e.SpriteBatch, false);
                }
            };

            Helper.Events.Input.ButtonPressed += (s, e) =>
            {
                if (Game1.displayHUD && Context.IsWorldReady)
                {
                    if (e.Button == SButton.MouseLeft || e.Button == SButton.MouseRight)
                    {
                        PlatoUI.UIHelper.BaseHud.PerformClick(e.Cursor.ScreenPixels.toPoint(), e.Button == SButton.MouseRight, false, false);
                    }
                }
            };

            Helper.Events.Display.WindowResized += (s, e) =>
            {
                PlatoUI.UIElement.Viewportbase.UpdateBounds();
                PlatoUI.UIHelper.BaseHud.UpdateBounds();
            };

            Helper.Events.Multiplayer.ModMessageReceived += PyNet.Multiplayer_ModMessageReceived;
            helper.Events.GameLoop.Saving += (s, e) =>
            {
                if (Game1.IsMasterGame)
                {
                    try
                    {
                        helper.Data.WriteSaveData <PyTKSaveData>("PyTK.ModSaveData", saveData);
                    }
                    catch
                    {
                    }
                }
            };

            helper.Events.GameLoop.ReturnedToTitle += (s, e) =>
            {
                saveData = new PyTKSaveData();
            };

            helper.Events.GameLoop.SaveLoaded += (s, e) =>
            {
                if (Game1.IsMasterGame)
                {
                    try
                    {
                        saveData = helper.Data.ReadSaveData <PyTKSaveData>("PyTK.ModSaveData");
                    }
                    catch
                    {
                    }
                    if (saveData == null)
                    {
                        saveData = new PyTKSaveData();
                    }
                }
            };

            helper.Events.GameLoop.OneSecondUpdateTicked += (s, e) =>
            {
                if (Context.IsWorldReady && Game1.currentLocation is GameLocation location && location.Map is Map map)
                {
                    PyUtils.checkDrawConditions(map);
                }
            };
        }
Esempio n. 28
0
        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);
                }
            }
        }