Example #1
0
    /// <summary> the specific "Create"s use this abstracted one </summary>
    LuaWTBObject CreateObject(WTBObject _wtbo, Vector3?_position, Vector3?_angles)
    {
        if (!PhotonNetwork.isMasterClient)
        {
            throw new ScriptRuntimeException("You can only create parts on the host");
        }

        if (_position == null)
        {
            _position = Vector3.zero;
        }
        if (_angles == null)
        {
            _angles = Vector3.zero;
        }

        LuaWTBObject spawned = Task.GetOrMakeLuaPart(_wtbo);

        spawned.position = (Vector3)_position;
        spawned.angles   = (Vector3)_angles;

        spawned.WTBObject.GameObject.GetComponentInChildren <MeshRenderer>().enabled = true;

        Camera.main.GetComponent <MasterCamera>().luaRuntimeCreatedObjectList.Add(_wtbo);

        return(spawned);
    }
Example #2
0
 public LuaParticleSystem(WTBObject _WTBObject)
 {
     this.type = "Particles";
     if (_WTBObject != null)
     {
         WTBObject  = _WTBObject;
         components = _WTBObject.Components;
         Task.luaParticleSystems.Add(WTBObject.WTBIndex, this);
     }
 }
Example #3
0
 public LuaRespawn(WTBObject _WTBObject)
 {
     this.type = "Respawn";
     if (_WTBObject != null)
     {
         WTBObject  = _WTBObject;
         components = _WTBObject.Components;
         Task.luaRespawns.Add(WTBObject.WTBIndex, this);
     }
 }
 public LuaLight(WTBObject _WTBObject)
 {
     this.type = "Light";
     if (_WTBObject != null)
     {
         WTBObject  = _WTBObject;
         components = _WTBObject.Components;
         Task.luaLights.Add(WTBObject.WTBIndex, this);
     }
 }
Example #5
0
 public void OnTriggerExit(Collider collider)
 {
     if (luaScript != null && luaScript.Globals["EndCollision"] != null)
     {
         WTBObject WTBO = collider.gameObject.GetComponent <WTBObject>();
         if (WTBO != null)
         {
             luaScript.Call(luaScript.Globals["EndCollision"], Task.GetOrMakeLuaPart(WTBO));
         }
         else if (collider.gameObject.tag == "Player")
         {
             luaScript.Call(luaScript.Globals["EndCollision"], Task.GetOrMakeLuaPlayer(collider.gameObject));
         }
     }
 }
Example #6
0
 public void OnCollisionEnter(Collision collision)
 {
     if (luaScript != null && luaScript.Globals["StartCollision"] != null)
     {
         WTBObject WTBO = collision.gameObject.GetComponent <WTBObject>();
         if (WTBO != null)
         {
             luaScript.Call(luaScript.Globals["StartCollision"], Task.GetOrMakeLuaPart(WTBO));
         }
         else if (collision.gameObject.tag == "Player")
         {
             luaScript.Call(luaScript.Globals["StartCollision"], Task.GetOrMakeLuaPlayer(collision.gameObject));
         }
     }
 }
Example #7
0
    public List <LuaWTBObject> ChildrenByName(string name)
    {
        List <LuaWTBObject> l_transforms = new List <LuaWTBObject>();

        foreach (int ci in this.WTBObject.children)
        {
            WTBObject    wtbo  = Task.builderTransform.WTBObjectByIndex[ci];
            LuaWTBObject lwtbo = Task.GetOrMakeLuaPart(wtbo);

            if (lwtbo != null && lwtbo.name == name)
            {
                l_transforms.Add(lwtbo);
            }
        }
        return(l_transforms);
    }
Example #8
0
 public LuaWorldText(WTBObject _WTBObject)
 {
     this.type = "Text";
     if (_WTBObject != null)
     {
         WTBObject  = _WTBObject;
         components = _WTBObject.Components;
         if (Task.luaWorldTexts.ContainsKey(WTBObject.WTBIndex))
         {
             Task.luaWorldTexts.Add(WTBObject.WTBIndex, this);
         }
         else
         {
             Task.luaWorldTexts[WTBObject.WTBIndex] = this;
         }
     }
 }
Example #9
0
    //[MoonSharpHidden] public List<WTBComponent> components;

    public LuaWTBObject(WTBObject _WTBObject)
    {
        this.type = "Part";
        if (_WTBObject != null)
        {
            WTBObject = _WTBObject;
            //components = _WTBObject.Components;
            if (!Task.luaObjects.ContainsKey(_WTBObject.WTBIndex))
            {
                Task.luaObjects.Add(_WTBObject.WTBIndex, this);
            }
            else
            {
                Task.luaObjects[_WTBObject.WTBIndex] = this;
            }
        }
    }
Example #10
0
 public LuaWTBObject PartByID(int id)
 {
     if (PhotonNetwork.offlineMode)
     {
         return(Task.GetOrMakeLuaPart(Task.builderTransform.WTBObjectByIndex[id]));
     }
     else
     {
         PhotonView obj = PhotonView.Find(id);
         if (obj != null && obj.gameObject != null)
         {
             WTBObject wtbobj = obj.gameObject.GetComponent <WTBObject>();
             if (wtbobj == null)
             {
                 return(null);
             }
             return(Task.GetOrMakeLuaPart(wtbobj));
         }
     }
     return(null);
 }
Example #11
0
    /// <summary>
    /// Loads a new script string in place of the old one
    /// </summary>
    public void Run()
    {
        AccessibleLuaScript accessibleLuaScript = Task.GetOrMakeAccessibleLuaScript(luaScript, scriptName);

        if (!GetComponent <WTBObject>().scripts.Contains(accessibleLuaScript))
        {
            GetComponent <WTBObject>().scripts.Add(accessibleLuaScript);
        }
        //if (scriptName == "" || hasRun) return;
        //hasRun = true;

        // tableprint credit to https://stackoverflow.com/questions/9168058/how-to-dump-a-table-to-console

        string builtInEnvironment = @"
            function TablePrint (tbl, indent)
                if not indent then indent = 0 end
                for k, v in pairs(tbl) do
                    formatting = string.rep('  ', indent) .. k .. ': ';
                    if (type(v) == 'table') then
                        print(formatting)
                        TablePrint(v, indent+1)
                    elseif (type(v) == 'boolean') then
                        print(formatting .. tostring(v))
                    else
                        print(formatting .. v)
                    end
                end
            end

            function count(tbl)
                local count = 0
                for k, v in pairs(tbl) do
                    count = count + 1
                end
                return count
            end

            function lerp(a, b, t)
                return a * (1-t) + (b*t)
            end

            


            ";

        try
        {
            if (Task.ScriptTextTable.ContainsKey(scriptName))
            {
                luaScript.DoString(Task.ScriptTextTable[scriptName] + builtInEnvironment);
            }

            if (luaScript != null && luaScript.Globals["Start"] != null)
            {
                luaScript.Call(luaScript.Globals["Start"]);
            }

            hasRun = true;
        }
        catch (ScriptRuntimeException ex)
        {
            Debug.Log("Lua Error: " + ex.DecoratedMessage);

            string partIdentifier = gameObject.name;

            // null check series
            WTBObject wtbo = GetComponent <WTBObject>();
            if (wtbo != null)
            {
                WorldComponent wc = (WorldComponent)wtbo.ComponentByName("World");
                if (wc != null)
                {
                    PropertyName pn = (PropertyName)wc.PropertyByName("Name");
                    if (pn != null)
                    {
                        partIdentifier = pn.dataString + ":" + gameObject.GetPhotonView().viewID;
                    }
                }
            }

            Task.consoleControllerGlobal.Print("ERROR: [" + partIdentifier + "] " + ex.DecoratedMessage);
            if (Task.consoleController != null)
            {
                Task.consoleController.Print("ERROR: [" + partIdentifier + "] " + ex.DecoratedMessage);
            }
        }
        catch (InterpreterException ex)
        {
            Debug.Log("Lua Error: " + ex.DecoratedMessage);

            string partIdentifier = gameObject.name;

            // null check series
            WTBObject wtbo = GetComponent <WTBObject>();
            if (wtbo != null)
            {
                WorldComponent wc = (WorldComponent)wtbo.ComponentByName("World");
                if (wc != null)
                {
                    PropertyName pn = (PropertyName)wc.PropertyByName("Name");
                    if (pn != null)
                    {
                        partIdentifier = pn.dataString + ":" + gameObject.GetPhotonView().viewID;
                    }
                }
            }

            Task.consoleControllerGlobal.Print("ERROR: [" + partIdentifier + "] " + ex.DecoratedMessage);
            if (Task.consoleController != null)
            {
                Task.consoleController.Print("ERROR: [" + partIdentifier + "] " + ex.DecoratedMessage);
            }
        }
    }