Exemplo n.º 1
0
        public static bool ClassHelpString(string classname)
        {
            Type t = Type.GetType(classname);

            if (t == null)
            {
                try
                {
                    t = Type.GetType(ScriptingCore.classhelpdict[classname]);
                }
                catch { }
            }
            if (t == null)
            {
                ScriptingCore.DebugLogError(" ClassHelperString " + classname + " Was not found. "); return(false);
            }
            var d = new LuaInterface.luahelper();

            //FieldInfo[] result = (FieldInfo[]) typeof(LuaInterface.luahelper).GetMethod("GetFields").MakeGenericMethod(t).Invoke(d, null);
            FieldInfo[] result = t.GetFields();
            // var fieldNames = result.Select(field => field.Name)                                        .ToList();

            string debuglogtext = " Luahelp: This lists Field names of the given class.\n";

            foreach (var i in result)
            {
                debuglogtext += i.Name + "\n";
            }
            ScriptingCore.DebugLog(debuglogtext);
            return(true);
        }
        public static bool RegisterType(string typename)
        {
            ScriptingCore.DebugLog("RegisterType: " + typename);
            Type t = Type.GetType(typename);

            if (t == null)
            {
                ScriptingCore.DebugLogError(" ClassHelperString " + typename + " Was not found. "); return(false);
            }

            ScriptingCore.typedirectdict.Add(typename, t);
            if (ScriptingCore.classhelpdict.ContainsKey(typename))
            {
                ScriptingCore.DebugLogError("The info " + typename + " is already registered skipping it! ");
            }
            else
            {
                ScriptingCore.classhelpdict.Add(typename, t.AssemblyQualifiedName);
            }
            // foreach (var i in Db.Get().Urges) { Debug.Log( i.Name );}

            /*
             * var d = new luahelper();
             * try
             * {
             *  var result = typeof(luahelper).GetMethod("RegisterType").MakeGenericMethod(t);
             *  RegisterTypeAdv<result>(typename);
             * }
             * catch(Exception e) { ScriptingCore.DebugLogError("RegisterType "+ typename+ " failed with error: " + e.Message ); }
             */
            return(true);
            //somehow convert the typename to the type
        }
        public static void RegisterTypeAdv <T>(System.Object dynv, string typename, string Helptext = "")
        {
            ScriptingCore.DebugLog("RegisterType: " + typename);
            if (dynv == null)
            {
                ScriptingCore.DebugLogError("The type " + typename + " is null! ");
                throw new ArgumentNullException("The type of " + typename + " is null! ");
            }
            DynValue dynvalue = UserData.Create(dynv);

            UserData.RegisterType <T>();
            if (ScriptingCore.typedict.ContainsKey(typename))
            {
                ScriptingCore.DebugLogError("The type " + typename + " is already registered skipping it! ");
            }
            else
            {
                if (dynvalue == null)
                {
                    ScriptingCore.DebugLogError("The  Dynvalue of " + typename + " is null! ");
                    throw new ArgumentNullException("The  Dynvalue of " + typename + " is null! ");
                }
                else
                {
                    ScriptingCore.typedict.Add(typename, dynvalue);
                }
            }
            AddHelpInfo <T>(typename, "Class: " + Helptext, false);
        }
Exemplo n.º 4
0
 public override BuildingDef CreateBuildingDef()
 {
     if (thisbuildingdef == null)
     {
         newbuildingdef(1, 1, "heavywatttile_conductive_kanim", 10, 10, new float[] { 1 }, new string[] { "steel" }, 10);
     }
     ScriptingCore.OnEvent(ID);
     ScriptingCore.DebugLog("CreateBuildingDef " + ID);
     return(thisbuildingdef);
 }
Exemplo n.º 5
0
        public static bool ClassHelp()
        {
            string fieldlist = " Use this strings with ClassHelpString " + "\n";

            foreach (var i in ScriptingCore.classhelpdict)
            {
                fieldlist += i.Key + " : " + i.Value + "\n";
            }
            ScriptingCore.DebugLog(fieldlist);
            return(true);
        }
Exemplo n.º 6
0
        public static bool Help()
        {
            string debuglogtext = " Luahelp: This lists Functions and classes, if you want to know more about a class do ClassHelp(classname) \n Functionname : Helptext\n";

            foreach (var i in ScriptingCore.helpdict)
            {
                debuglogtext += i.Key + " : " + i.Value + "\n";
            }
            ScriptingCore.DebugLog(debuglogtext);
            return(true);
        }
Exemplo n.º 7
0
        public static bool ListFieldsString(string typename)
        {
            string fieldlist = " List all fields of " + typename;

            foreach (var i in Type.GetType(typename).GetFields())
            {
                fieldlist += i.Name + " : " + i.GetValue(i).ToString();
            }
            ScriptingCore.DebugLog(fieldlist);
            return(true);
        }
 public static void AddFunction(string Functionnameinlua, Delegate Function, string Helptext = "")
 {
     ScriptingCore.DebugLog("RegisterFunction: " + Functionnameinlua);
     if (ScriptingCore.functiondict.ContainsKey(Functionnameinlua))
     {
         ScriptingCore.DebugLogError("The type " + Functionnameinlua + " is already registered skipping it! ");
     }
     else
     {
         ScriptingCore.functiondict.Add(Functionnameinlua, Function);
     }
     AddHelpInfo(Functionnameinlua, Helptext);
 }
 public static void RegisterTypeAdv <T>(string typename, string Helptext = "")
 {
     ScriptingCore.DebugLog("RegisterType: " + typename);
     UserData.RegisterType <T>();
     if (ScriptingCore.typedict.ContainsKey(typename))
     {
         ScriptingCore.DebugLogError("The type " + typename + " is already registered skipping it! ");
     }
     else
     {
         ScriptingCore.typedirectdict.Add(typename, typeof(T));
     }
     AddHelpInfo <T>(typename, "Class: " + Helptext, false);
 }
Exemplo n.º 10
0
        public static bool ListResearchsWithTypes()
        {
            string debuglogstring = " ListResearchsWithTypes ";

            foreach (Tech techtoadd in Db.Get().Techs.resources)
            {
                debuglogstring += techtoadd.Id + "\n";
                var res = Research.Instance.Get(techtoadd);
                foreach (var i in res.tech.costsByResearchTypeID.Keys.ToList())
                {
                    debuglogstring += i + res.tech.costsByResearchTypeID[i] + "\n";
                }
            }
            ScriptingCore.DebugLog(debuglogstring);
            return(true);
        }
 public static bool AddHelpInfo(string Functionnameinlua, string Helptext = "", bool log = true)
 {
     if (log)
     {
         ScriptingCore.DebugLog("AddHelpInfo: " + Functionnameinlua);
     }
     if (ScriptingCore.helpdict.ContainsKey(Functionnameinlua))
     {
         ScriptingCore.DebugLogError("The info " + Functionnameinlua + " is already registered skipping it! ");
     }
     else
     {
         ScriptingCore.helpdict.Add(Functionnameinlua, Helptext);
     }
     return(true);
 }
        public static void RegisterType <T>(string typename, string Helptext = "") where T : new()
        {
            ScriptingCore.DebugLog("RegisterType: " + typename);
            UserData.RegisterType <T>();
            DynValue dynv = UserData.Create(new T());

            if (ScriptingCore.typedict.ContainsKey(typename))
            {
                ScriptingCore.DebugLogError("The type " + typename + " is already registered skipping it! ");
            }
            else
            {
                ScriptingCore.typedict.Add(typename, dynv);
            }
            AddHelpInfo <T>(typename, "Class: " + Helptext, false);
        }
Exemplo n.º 13
0
        static public bool ListAllTypes(string fileName)
        {
            if (fileName == null)
            {
                ScriptingCore.DebugLogError(" ClassHelperString " + fileName + " Filename is null. "); return(false);
            }
            Assembly assembly;

            try
            {
                assembly = Assembly.Load(fileName);
            }
            catch (Exception e) { ScriptingCore.DebugLogError(" RegisterAllTypes " + e.Message); return(false); }

            foreach (Type type in assembly.GetTypes())
            {
                ScriptingCore.DebugLog(type.AssemblyQualifiedName);
            }
            return(true);
        }
Exemplo n.º 14
0
 public static void Postfix()
 {
     ScriptingCore.DebugLog("loadbuildings");
     ScriptingCore.OnEvent("loadbuildings");
 }
Exemplo n.º 15
0
 public static void Prefix()
 {
     ScriptingCore.ScriptInit();
     ScriptingCore.DebugLog("preloadbuildings");
     ScriptingCore.OnEvent("preloadbuildings");
 }