Exemplo n.º 1
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)));
        }
Exemplo n.º 2
0
 public void doMagic(bool playedToday)
 {
     PyLua.loadScriptFromFile(Path.Combine(helper.DirectoryPath, "Assets", "luamagic.lua"), "luaMagic");
     PyLua.callFunction("luaMagic", "doMagic", playedToday);
 }
        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);
                }
            }
        }
Exemplo n.º 4
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);
                }
            }
        }
        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);
                }
            }
        }
Exemplo n.º 6
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);
                }
            }
        }