コード例 #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());
 }
コード例 #2
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());
 }
コード例 #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());
 }
コード例 #4
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());
 }
コード例 #5
0
    public void DoWork(float workTime)
    {
        // We don't know if the Job can actually be worked, but still call the callbacks
        // so that animations and whatnot can be updated.
        if (cbJobWorked != null)
        {
            cbJobWorked(this);
        }

        if (cbJobWorkedLua != null)
        {
            foreach (string luaFunction in cbJobWorkedLua.ToList())
            {
                LuaUtilities.CallFunction(luaFunction, this);
            }
        }

        // Check to make sure we actually have everything we need.
        // If not, don't register the work time.
        if (MaterialNeedsMet() == false)
        {
            ////Debug.LogError("Tried to do work on a job that doesn't have all the material.");
            return;
        }

        jobTime -= workTime;

        if (jobTime <= 0)
        {
            // Do whatever is supposed to happen with a job cycle completes.
            if (cbJobCompleted != null)
            {
                cbJobCompleted(this);
            }

            foreach (string luaFunction in cbJobCompletedLua.ToList())
            {
                LuaUtilities.CallFunction(luaFunction, this);
            }

            if (jobRepeats == false)
            {
                // Let everyone know that the job is officially concluded
                if (cbJobStopped != null)
                {
                    cbJobStopped(this);
                }
            }
            else
            {
                // This is a repeating job and must be reset.
                jobTime += jobTimeRequired;
            }
        }
    }
コード例 #6
0
    public string GetSpriteName()
    {
        if (getSpriteNameAction == null || getSpriteNameAction.Length == 0)
        {
            return(objectType);
        }

        DynValue ret = LuaUtilities.CallFunction(getSpriteNameAction, this);

        return(ret.String);
    }
コード例 #7
0
    public string GetSpriteName()
    {
        if (string.IsNullOrEmpty(getSpriteNameAction))
        {
            return(ObjectType);
        }

        DynValue ret = LuaUtilities.CallFunction(getSpriteNameAction, this);

        return(ret.String);
    }
コード例 #8
0
    public static void CallFunctionsWithEvent(string[] functionNames, GameEvent gameEvent)
    {
        foreach (string fn in functionNames)
        {
            DynValue result = LuaUtilities.CallFunction(fn, gameEvent);

            if (result.Type == DataType.String)
            {
                Debug.ULogErrorChannel("Lua", result.String);
            }
        }
    }
コード例 #9
0
    public static void CallFunctionsWithFurniture(string[] functionNames, Furniture furn, float deltaTime)
    {
        foreach (string fn in functionNames)
        {
            DynValue result = LuaUtilities.CallFunction(fn, furn, deltaTime);

            if (result.Type == DataType.String)
            {
                Debug.Log(result.String);
            }
        }
    }
コード例 #10
0
    public static void CallFunctionsWithNeed(string[] functionNames, Need need, float deltaTime)
    {
        foreach (string fn in functionNames)
        {
            DynValue result = LuaUtilities.CallFunction(fn, need, deltaTime);

            if (result.Type == DataType.String)
            {
                Debug.ULogChannel("NeedActions", "Lua response:", result.String);
            }
        }
    }
コード例 #11
0
    public Enterability IsEnterable()
    {
        if (string.IsNullOrEmpty(isEnterableAction))
        {
            return(Enterability.Yes);
        }

        //// FurnitureActions.CallFunctionsWithFurniture( isEnterableActions.ToArray(), this );

        DynValue ret = LuaUtilities.CallFunction(isEnterableAction, this);

        return((Enterability)ret.Number);
    }
コード例 #12
0
    public ENTERABILITY IsEnterable()
    {
        if (isEnterableAction == null || isEnterableAction.Length == 0)
        {
            return(ENTERABILITY.Yes);
        }

        //// FurnitureActions.CallFunctionsWithFurniture( isEnterableActions.ToArray(), this );

        DynValue ret = LuaUtilities.CallFunction(isEnterableAction, this);

        return((ENTERABILITY)ret.Number);
    }
コード例 #13
0
    // Checks whether the given floor type is allowed to be built on the tile.
    // TODO Export this kind of check to an XML/LUA file for easier modding of floor types.
    private bool CanBuildTileTypeHere(Tile t, TileType tileType)
    {
        DynValue value = LuaUtilities.CallFunction(tileType.CanBuildHereLua, t);

        if (value != null)
        {
            return(value.Boolean);
        }
        else
        {
            Debug.ULogChannel("Lua", "Found no lua function " + tileType.CanBuildHereLua);

            return(false);
        }
    }
コード例 #14
0
    public void Update(float deltaTime)
    {
        int conditionsMet = 0;

        foreach (string precondition in preconditions)
        {
            // Call lua precondition it should return 1 if met otherwise 0
            conditionsMet += (int)LuaUtilities.CallFunction(precondition, this, deltaTime).Number;
        }

        if (conditionsMet >= preconditions.Count && executed == false && (MaxRepeats <= 0 || repeats < MaxRepeats))
        {
            repeats++;
            Execute();
        }
    }
コード例 #15
0
        public ScheduledEvent(ScheduledEvent eventPrototype, float cooldown, float timeToWait, bool repeatsForever = false, int repeats = 1)
        {
            this.Name = eventPrototype.Name;
            if (eventPrototype.EventType == EventType.CSharp)
            {
                this.OnFire = eventPrototype.OnFire;
            }
            else
            {
                this.OnFire = (evt) => LuaUtilities.CallFunction(eventPrototype.LuaFunctionName, evt);
            }

            this.Cooldown       = cooldown;
            this.TimeToWait     = timeToWait;
            this.RepeatsForever = repeatsForever;
            this.RepeatsLeft    = repeats;
            this.EventType      = eventPrototype.EventType;
        }
コード例 #16
0
    public static void CallFunctionsWithFurniture <T>(string[] functionNames, T furn, float deltaTime)
    {
        if (furn == null)
        {
            Debug.LogError("Furn is null, cannot call LUA function (something is fishy).");
        }

        foreach (string fn in functionNames)
        {
            if (fn == null)
            {
                Debug.LogError("'" + fn + "' is not a LUA function.");
                return;
            }

            DynValue result = LuaUtilities.CallFunction(fn, furn, deltaTime);

            if (result.Type == DataType.String)
            {
                Debug.Log(result.String);
            }
        }
    }
コード例 #17
0
    public static void CallFunctionsWithFurniture <T>(string[] functionNames, T furn, float deltaTime)
    {
        if (furn == null)
        {
            //These errors are about the lua code so putting themin the lua channel
            Debug.ULogErrorChannel("Lua", "Furn is null, cannot call LUA function (something is fishy).");
        }

        foreach (string fn in functionNames)
        {
            if (fn == null)
            {
                Debug.ULogErrorChannel("Lua", "'" + fn + "' is not a LUA function.");
                return;
            }

            DynValue result = LuaUtilities.CallFunction(fn, furn, deltaTime);

            if (result.Type == DataType.String)
            {
                Debug.ULogErrorChannel("Lua", result.String);
            }
        }
    }
コード例 #18
0
 private void InvokeContextMenuLuaAction(string luaFunction, Character character)
 {
     LuaUtilities.CallFunction(luaFunction, this, character);
 }