예제 #1
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();
        }
예제 #2
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)));
        }
예제 #3
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);
        }
예제 #4
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();
        }