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
        }
Beispiel #2
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 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);
        }
Beispiel #4
0
 public static Storage GetComponentStorage(GameObject go)
 {
     if (go == null)
     {
         ScriptingCore.DebugLogError("The GameObject is Null!");
     }
     return(go.AddOrGet <Storage>());
 }
Beispiel #5
0
        public static BuildingDef GetBuildingDef(string prefab_id)
        {
            BuildingDef returndef = Assets.GetBuildingDef(prefab_id);

            if (returndef == null)
            {
                ScriptingCore.DebugLogError("GetBuildingDef for " + prefab_id + " could not be found!");
            }
            return(returndef);
        }
Beispiel #6
0
        public static BuildingDef GetBuildingDef(GameObject prefab_id)
        {
            BuildingDef returndef = prefab_id.GetComponent <BuildingDef>();

            if (returndef == null)
            {
                ScriptingCore.DebugLogError("GetBuildingDef for " + prefab_id + " could not be found!");
            }
            return(returndef);
        }
Beispiel #7
0
        public static GameObject GetBuildingGameObject(string prefab_id)
        {
            GameObject returndef = Assets.GetPrefab(prefab_id);

            if (returndef == null)
            {
                ScriptingCore.DebugLogError("GameObject for " + prefab_id + " could not be found!");
            }
            return(returndef);
        }
Beispiel #8
0
        public static PrimaryElement GetBuildingPrimaryElement(GameObject prefab_id)
        {
            PrimaryElement returndef = prefab_id.GetComponent <PrimaryElement>();

            if (returndef == null)
            {
                ScriptingCore.DebugLogError("GetBuildingDef for " + prefab_id + " could not be found!");
            }
            return(returndef);
        }
 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);
 }
Beispiel #11
0
        public static Component GetComponent(GameObject go, string componentname)
        {
            Type t = Type.GetType(componentname);

            if (t == null)
            {
                ScriptingCore.DebugLogError("The Component " + componentname + " could not be found!");
            }
            if (go == null)
            {
                ScriptingCore.DebugLogError("The GameObject is Null!");
            }
            return(go.GetComponent(t));
        }
Beispiel #12
0
        public static string GetRandomAvailableResearch()
        {
            int counter = 0;

            while (counter++ < 100)
            {
                var tech = Db.Get().Techs.resources.RandomElement();
                if (tech.ArePrerequisitesComplete() && !tech.IsComplete())
                {
                    return(tech.Id);
                }
            }
            ScriptingCore.DebugLogError("GetRandomAvailableResearch failed returning InteriorDecor ");
            return("InteriorDecor");
        }
 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);
        }
Beispiel #15
0
 public void clonebuildindef(string buildingname, string clonename)
 {
     if (TagManager.GetProperName(clonename) != null)
     {
         ScriptingCore.DebugLogError(" The building cannot be cloned, the name " + clonename + " is already used.");
         return;
     }
     foreach (var i in configTable)
     {
         if (i.Value.PrefabID == buildingname)
         {
             clonebuildingdef = i.Value;
         }
     }
     if (clonebuildingdef == null)
     {
         ScriptingCore.DebugLogError(" The configTable did not contain, the name " + clonename + ".");
         return;
     }
 }
Beispiel #16
0
        static public bool RegisterAllTypes(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())
            {
                LuaInterface.RegisterType(type.AssemblyQualifiedName);
            }
            return(true);
        }
Beispiel #17
0
        public static bool SetResearchCost(string research, string costtype, float costamount)
        {
            if (Db.Get().Techs.resources == null)
            {
                return(false);
            }
            foreach (Tech techtoadd in Db.Get().Techs.resources)
            {
                if (techtoadd.Id == research)
                {
                    var res = Research.Instance.Get(techtoadd);

                    if (res.tech.costsByResearchTypeID.ContainsKey(costtype))
                    {
                        res.tech.costsByResearchTypeID[costtype] = costamount;
                    }
                    return(true);
                }
            }
            ScriptingCore.DebugLogError("SetResearchCost did not find: " + research);
            return(false);
        }
Beispiel #18
0
 public static bool AddResearch(string research)
 {
     foreach (Tech techtoadd in Db.Get().Techs.resources)
     {
         if (techtoadd.Id == research)
         {
             var res = Research.Instance.Get(techtoadd);
             var req = Research.Instance.Get(techtoadd).tech.requiredTech;
             foreach (var i in req)
             {
                 AddResearch(i.Id);
             }
             if (res == null)
             {
                 ScriptingCore.DebugLogError("AddResearch did not find: " + research);
                 return(false);
             }
             res.Purchased();
             return(true);
         }
     }
     ScriptingCore.DebugLogError("AddResearch did not find: " + research);
     return(false);
 }