Ejemplo n.º 1
0
 public void Test_CallFunction_ReturnString()
 {
     // Test a function that returns a string
     LuaUtilities.LoadScriptFromFile(testCode1Path);
     MoonSharp.Interpreter.DynValue value = LuaUtilities.CallFunction("test_func1");
     Assert.AreEqual("test_func1_returns", value.CastToString());
 }
Ejemplo n.º 2
0
 public void Test_CallFunction_InputInts_ReturnSum()
 {
     // Test passing more than one input
     LuaUtilities.LoadScriptFromFile(testCode1Path);
     MoonSharp.Interpreter.DynValue value = LuaUtilities.CallFunction("test_func3", 4, 7);
     Assert.AreEqual(11, (int)value.CastToNumber());
 }
Ejemplo n.º 3
0
 public void Test_CallFunction()
 {
     // Test a function that dosent return anything (void c# , nil/nan Lua)
     LuaUtilities.LoadScriptFromFile(testCode1Path);
     MoonSharp.Interpreter.DynValue value = LuaUtilities.CallFunction("test_func0");
     Assert.AreEqual(true, value.IsNilOrNan());
 }
Ejemplo n.º 4
0
 public void Test_CallFunction_InputString_ReturnInput()
 {
     // Test a function that returns the String passed to it
     LuaUtilities.LoadScriptFromFile(testCode1Path);
     MoonSharp.Interpreter.DynValue value = LuaUtilities.CallFunction("test_func2", "inputted value");
     Assert.AreEqual("inputted value", value.CastToString());
 }
Ejemplo n.º 5
0
        public static void LoadScripts()
        {
            string luaFilePath = Path.Combine(Application.streamingAssetsPath, "LUA");

            luaFilePath = Path.Combine(luaFilePath, "Events.lua");
            LuaUtilities.LoadScriptFromFile(luaFilePath);
        }
Ejemplo n.º 6
0
    private void LoadLuaScript()
    {
        string filePath = System.IO.Path.Combine(Application.streamingAssetsPath, "LUA");

        filePath = System.IO.Path.Combine(filePath, "GameEvent.lua");

        LuaUtilities.LoadScriptFromFile(filePath);
    }
Ejemplo n.º 7
0
 public static void LoadModsScripts(DirectoryInfo[] mods)
 {
     foreach (DirectoryInfo mod in mods)
     {
         string luaModFile = Path.Combine(mod.FullName, "Events.lua");
         if (File.Exists(luaModFile))
         {
             LuaUtilities.LoadScriptFromFile(luaModFile);
         }
     }
 }
Ejemplo n.º 8
0
    void CreateFurniturePrototypes()
    {
        string luaFilePath = System.IO.Path.Combine(Application.streamingAssetsPath, "LUA");

        luaFilePath = System.IO.Path.Combine(luaFilePath, "Furniture.lua");
        LuaUtilities.LoadScriptFromFile(luaFilePath);


        furniturePrototypes    = new Dictionary <string, Furniture>();
        furnitureJobPrototypes = new Dictionary <string, Job>();

        // READ FURNITURE PROTOTYPE XML FILE HERE
        // TODO:  Probably we should be getting past a StreamIO handle or the raw
        // text here, rather than opening the file ourselves.

        string dataPath         = System.IO.Path.Combine(Application.streamingAssetsPath, "Data");
        string filePath         = System.IO.Path.Combine(dataPath, "Furniture.xml");
        string furnitureXmlText = System.IO.File.ReadAllText(filePath);

        LoadFurniturePrototypesFromFile(furnitureXmlText);


        DirectoryInfo[] mods = WorldController.Instance.modsManager.GetMods();
        foreach (DirectoryInfo mod in mods)
        {
            string furnitureLuaModFile = System.IO.Path.Combine(mod.FullName, "Furniture.lua");
            if (File.Exists(furnitureLuaModFile))
            {
                LuaUtilities.LoadScriptFromFile(furnitureLuaModFile);
            }

            string furnitureXmlModFile = System.IO.Path.Combine(mod.FullName, "Furniture.xml");
            if (File.Exists(furnitureXmlModFile))
            {
                string furnitureXmlModText = System.IO.File.ReadAllText(furnitureXmlModFile);
                LoadFurniturePrototypesFromFile(furnitureXmlModText);
            }
        }
    }
Ejemplo n.º 9
0
    /// <summary>
    /// Loads all TileType definitions in Data\ and Data\Mods
    /// </summary>
    public static void LoadTileTypes()
    {
        // Load lua code
        string luaPath     = System.IO.Path.Combine(Application.streamingAssetsPath, "LUA");
        string luaFilePath = System.IO.Path.Combine(luaPath, "Tile.lua");

        LuaUtilities.LoadScriptFromFile(luaFilePath);

        // Load all mod defined lua code
        foreach (DirectoryInfo mod in WorldController.Instance.modsManager.GetMods())
        {
            foreach (FileInfo file in mod.GetFiles("Tiles.lua"))
            {
                Debug.ULogChannel("TileType", "Loading mod " + mod.Name + " TileType definitions!");

                LuaUtilities.LoadScriptFromFile(file.FullName);
            }
        }

        // Load TileType xml definitions
        string dataPath = System.IO.Path.Combine(Application.streamingAssetsPath, "Data");
        string xmlPath  = System.IO.Path.Combine(dataPath, "Tiles.xml");
        string xmlText  = System.IO.File.ReadAllText(xmlPath);

        readTileTypesFromXml(xmlText);

        // Load all mod defined TileType definitions
        foreach (DirectoryInfo mod in WorldController.Instance.modsManager.GetMods())
        {
            foreach (FileInfo file in mod.GetFiles("Tiles.xml"))
            {
                Debug.ULogChannel("TileType", "Loading mod " + mod.Name + " TileType definitions!");

                xmlText = System.IO.File.ReadAllText(file.FullName);

                readTileTypesFromXml(xmlText);
            }
        }
    }
Ejemplo n.º 10
0
    /// <summary>
    /// Loads all TileType definitions in Data\ and Data\Mods.
    /// </summary>
    public static void LoadTileTypes()
    {
        // Load lua code
        string luaPath     = Path.Combine(Application.streamingAssetsPath, "LUA");
        string luaFilePath = Path.Combine(luaPath, TilesScriptFileName);

        LuaUtilities.LoadScriptFromFile(luaFilePath);

        // Load all mod defined lua code
        foreach (DirectoryInfo mod in WorldController.Instance.modsManager.GetMods())
        {
            foreach (FileInfo file in mod.GetFiles(TilesScriptFileName))
            {
                Debug.ULogChannel(ULogChanelName, "Loading Tile LUA scripts from mod: {0}", mod.Name);
                LuaUtilities.LoadScriptFromFile(file.FullName);
            }
        }

        // Load TileType xml definitions
        string dataPath = Path.Combine(Application.streamingAssetsPath, "Data");
        string xmlPath  = Path.Combine(dataPath, TilesDescriptionFileName);
        string xmlText  = File.ReadAllText(xmlPath);

        ReadTileTypesFromXml(xmlText);

        // Load all mod defined TileType definitions
        foreach (DirectoryInfo mod in WorldController.Instance.modsManager.GetMods())
        {
            foreach (FileInfo file in mod.GetFiles(TilesDescriptionFileName))
            {
                Debug.ULogChannel(ULogChanelName, "Loading TileType definitions from mod: {0}", mod.Name);
                xmlText = File.ReadAllText(file.FullName);
                ReadTileTypesFromXml(xmlText);
            }
        }
    }
Ejemplo n.º 11
0
 public void Test_LoadScript_BadLua_NoEnd()
 {
     // FIXME: use mocking to verify whats going on
     // Bad Lua Code is caught in side the method from this level we don't know if an error happened
     LuaUtilities.LoadScriptFromFile(testCode2Path);
 }
Ejemplo n.º 12
0
 public void Test_LoadScript_Null()
 {
     // Try loading a file from the path null
     LuaUtilities.LoadScriptFromFile(null);
 }
Ejemplo n.º 13
0
 public void Test_LoadScript_NoFile()
 {
     // Try loading some file that dosent exist , expect to get an exeption about no file found
     LuaUtilities.LoadScriptFromFile(testCode1Path + "DoesNotExist.txt");
 }
Ejemplo n.º 14
0
 public void Test_LoadScript()
 {
     // Load our good lua file, shouldn't get any errors and shouldnt raise any expetions
     LuaUtilities.LoadScriptFromFile(testCode1Path);
 }
Ejemplo n.º 15
0
 public GameEventActions(string luaFile)
 {
     // Tell the LUA interpreter system to load all the classes
     // that we have marked as [MoonSharpUserData]
     LuaUtilities.LoadScriptFromFile(luaFile);
 }