public CommandRecipes(Main game)
            : base(game)
        {
            Order = -10;

              config = new RecConfig();
              Log = new RecipeLog();
        }
Exemple #2
0
        public CmdRec(Main game)
            : base(game)
        {
            Order = -10;

            config = new RecConfig();
            Log    = new RecipeLog();
        }
Exemple #3
0
        public CmdRec(Main game)
            : base(game)
        {
            // Why did we need a lower order again?
            Order = -10;

            config = new RecConfig();
            Log    = new RecipeLog();
        }
Exemple #4
0
        public static void SetUpConfig()
        {
            try
            {
                if (!Directory.Exists(CmdRec.configDir))
                {
                    Directory.CreateDirectory(CmdRec.configDir);
                }

                if (File.Exists(CmdRec.configPath))
                {
                    CmdRec.config = RecConfig.Read(CmdRec.configPath);
                }
                else
                {
                    CmdRec.config.Write(CmdRec.configPath);
                }

                foreach (Recipe rec in CmdRec.config.Recipes)
                {
                    if (!CmdRec.recs.Contains(rec.name.ToLower()))
                    {
                        CmdRec.recs.Add(rec.name.ToLower());
                    }
                    rec.categories.ForEach((item) =>
                    {
                        CmdRec.cats.Add(item.ToLower());
                    });
                }
            }
            catch (Exception ex)
            {
                // Why were you using this instead of Log.ConsoleError?
                //Console.ForegroundColor = ConsoleColor.Red;
                //Console.WriteLine("Error in recConfig.json!");
                //Console.ResetColor();
                TShock.Log.ConsoleError("Error in recConfig.json!");
                TShock.Log.ConsoleError(ex.ToString());
            }
        }
 public static RecConfig Write(RecConfig config)
 {
     File.WriteAllText(CommandRecipes.configPath, JsonConvert.SerializeObject(config, Formatting.Indented));
       return config;
 }
        public static RecConfig Read()
        {
            if (!File.Exists(CommandRecipes.configPath)) {
            RecConfig res = new RecConfig();
            res.Recipes.Add(new Recipe("Copper Broadsword",
              new List<Ingredient>() {
            new Ingredient("Copper Bar", 8, 0, 1),
            new Ingredient("Iron Bar", 8, 0, 1),
            new Ingredient("Stone Block", 20, 0, 0),
            new Ingredient("Wooden Hammer", 1, 0, 0) },
              new List<Product>() {
            new Product("Copper Broadsword", 1, 41, 1, 50),
            new Product("Copper Shortsword", 1, 41, 1, 50),
            new Product("Wooden Hammer", 1, 39, 0, 100) },
              new List<string> { "Example" },
              new List<string> { "" },
              new List<string> { "" }));
            res.Recipes.Add(new Recipe("Iron Broadsword",
              new List<Ingredient>() {
            new Ingredient("Iron Bar", 8, 0, 0),
            new Ingredient("Stone Block", 20, 0, 0),
            new Ingredient("Wooden Hammer", 1, -1, 0) },
              new List<Product>() {
            new Product("Iron Broadsword", 1, 41, 0, 100),
            new Product("Wooden Hammer", 1, 39, 0, 100) },
              new List<string> { "Example", "Example2" },
              new List<string> { "cmdrec.craft.example" },
              new List<string> { "" }));
            Write(res);
            return res;
              }

              try {
            return Write(JsonConvert.DeserializeObject<RecConfig>(File.ReadAllText(CommandRecipes.configPath)));
              }
              catch (Exception ex) {
            TShock.Log.Error("[CommandRecipes] An error has occurred while reading the config file! See below for more info:");
            TShock.Log.Error(ex.ToString());
            return new RecConfig();
              }
        }