Ejemplo n.º 1
0
        internal static void LoadingTheMaps()
        {
            Type mod = Type.GetType("CustomFarmTypes.Mod, CustomFarmTypes");

            if (mod == null)
            {
                return;
            }

            Helper = (mod.GetField("instance", BindingFlags.Static | BindingFlags.Public).GetValue(null) as Mod).Helper;
            TMXLoaderMod.monitor.Log("Checking for TMX Custom Farmtypes...");
            string[] choices = Directory.GetDirectories(Path.Combine(Helper.DirectoryPath, "FarmTypes"));
            int      i       = 0;

            foreach (string choice in choices)
            {
                if (File.Exists(Path.Combine(choice, "type.json")) && File.Exists(Path.Combine(choice, "map.tmx")) && File.Exists(Path.Combine(choice, "icon.png")))
                {
                    Type       farmType       = Type.GetType("CustomFarmTypes.FarmType, CustomFarmTypes");
                    string     path           = Path.Combine(choice, "type.json");
                    var        farmTypeObject = Activator.CreateInstance(farmType);
                    MethodInfo m    = Helper.GetType().GetMethod("ReadJsonFile", BindingFlags.Instance | BindingFlags.Public);
                    MethodInfo gm   = m.MakeGenericMethod(new Type[] { farmTypeObject.GetType() });
                    var        type = gm.Invoke(Helper, new object[] { path });

                    if (type == null)
                    {
                        TMXLoaderMod.monitor.Log("Problem reading type.json for custom farm type \"" + choice + "\".");
                        continue;
                    }

                    farmTypeObject.GetType().GetProperty("Folder", BindingFlags.Public | BindingFlags.Instance).SetValue(type, Path.Combine("FarmTypes", Path.GetFileName(choice)));
                    farmTypeObject.GetType().GetMethod("register", BindingFlags.Static | BindingFlags.Public).Invoke(null, new object[] { type });
                    i++;
                }
            }
            TMXLoaderMod.monitor.Log(i + " Found");
        }