Exemplo n.º 1
0
        public ThnScript(string scriptfile)
        {
            var runner = new LuaRunner(ThnEnv);
            var output = runner.DoFile(scriptfile);

            Duration = (float)output["duration"];
            var entities = (LuaTable)output["entities"];

            for (int i = 0; i < entities.Capacity; i++)
            {
                var ent = (LuaTable)entities[i];
                var e   = GetEntity(ent);
                if (Entities.ContainsKey(e.Name))
                {
                    FLLog.Error("Thn", "Overwriting entity: \"" + e.Name + '"');
                    Entities[e.Name] = e;
                }
                else
                {
                    Entities.Add(e.Name, e);
                }
            }
            var events = (LuaTable)output["events"];

            for (int i = 0; i < events.Capacity; i++)
            {
                var ev = (LuaTable)events[i];
                var e  = GetEvent(ev);
                Events.Add(e);
            }
            Events.Sort((x, y) => x.Time.CompareTo(y.Time));
        }
Exemplo n.º 2
0
        public MotionPath(string pathdescriptor)
        {
            //Abuse the Lua runtime to parse the path descriptor for us
            var  rt             = new LuaRunner(env);
            var  path           = (LuaTable)(rt.DoString("path = {" + pathdescriptor + "}")["path"]);
            bool hasOrientation = true;
            var  type           = (int)path[0];

            loop = type == CLOSED;
            //detect if orientations are present
            var orient = (LuaTable)path[2];

            if (orient.Capacity < 4)
            {
                hasOrientation = false;
            }
            //Construct path

            for (int i = 1; i < path.Capacity; i++)
            {
                if (hasOrientation && i % 2 == 0)
                {
                    quaternions.Add(GetQuat(path[i]));
                }
                else
                {
                    points.Add(GetVec(path[i]));
                }
            }
            if (points.Count > 2)
            {
                curve = true;
            }
        }
Exemplo n.º 3
0
        public MotionPath(string pathdescriptor)
        {
            //Abuse the Lua runtime to parse the path descriptor for us
            var rt   = new LuaRunner(env);
            var path = (LuaTable)(rt.DoString("path = {" + pathdescriptor + "}")["path"]);
            var type = (int)path[0];

            loop = type == CLOSED;
            //detect if orientations are present
            var orient = (LuaTable)path[2];

            if (orient.Capacity >= 4)
            {
                HasOrientation = true;
            }
            var points      = new List <Vector3>();
            var quaternions = new List <Quaternion>();

            //Construct path
            for (int i = 1; i < path.Capacity; i++)
            {
                if (HasOrientation && i % 2 == 0)
                {
                    quaternions.Add(GetQuat(path[i]));
                }
                else
                {
                    points.Add(GetVec(path[i]));
                }
            }
            if (loop)
            {
                quaternions.Add(quaternions[0]);
            }
            if (points.Count < 2)
            {
                throw new Exception("Path does not have minimum two points");
            }
            if (points.Count > 2)
            {
                curve      = true;
                curveQuats = quaternions.ToArray();
            }

            startPoint = points[0];
            endPoint   = points[points.Count - 1];
            startQuat  = quaternions[0];
            endQuat    = quaternions[quaternions.Count - 1];
            //
            if (curve)
            {
                BuildSegments(points);
            }
        }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            // Fix a bug related to parsing numbers in Europe, among other things
            CultureInfo.DefaultThreadCurrentCulture   = CultureInfo.InvariantCulture;
            CultureInfo.DefaultThreadCurrentUICulture = CultureInfo.InvariantCulture;

            var root = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Content");

            // Need to do this for MacOS
            if (root.EndsWith("/MonoBundle/Content"))
            {
                root = root.Replace("/MonoBundle/Content", "/Resources/Content");
            }

            using (var game = new LuaRunner(root))
                game.Run();
        }
Exemplo n.º 5
0
        static string Decompile(string file)
        {
            var builder = new StringBuilder();
            var runner  = new LuaRunner(ThnEnv);
            var output  = runner.DoFile(file);

            foreach (var kv in output)
            {
                switch (kv.Key.ToLowerInvariant())
                {
                case "events":
                    ProcessEvents((LuaTable)kv.Value);
                    break;

                case "entities":
                    ProcessEntities((LuaTable)kv.Value);
                    break;
                }
                builder.AppendLine(string.Format("{0} = {1}", kv.Key, kv.Value));
            }
            return(builder.ToString());
        }
Exemplo n.º 6
0
 // Use this for initialization
 void Start()
 {
     AnotherGameObj = GameObject.Find("Player1").GetComponent <LuaRunner>();
     TargetGameObj  = GameObject.Find("Player0").GetComponent <LuaRunner>();
 }