예제 #1
0
        /*
         * /// <summary>
         * /// Process an item from a file back into it's original storage container.
         * /// </summary>
         * /// <param name="path"></param>
         * /// <param name="thingsToAddBackIn"></param>
         * public void ProcessFileForCleanUpIntoContainer(string path, List<IItemSerializeable> thingsToAddBackIn)
         * {
         *
         *  //Log.AsyncC(path);
         *  string newLine = Environment.NewLine;
         *
         *  string[] chestArray= path.Split(new string[] { "/"}, StringSplitOptions.None);
         *  string[] chestArray2= path.Split(new string[] { "\\" }, StringSplitOptions.None);
         *  /*
         *  foreach (var v in chestArray)
         *  {
         *      Log.AsyncC("PART OF PATH "+v);
         *  }
         *  foreach (var v in chestArray2)
         *  {
         *      Log.AsyncC("PART OF PATH2 " + v);
         *  }
         *
         *  if (chestArray2.Length > chestArray.Length) chestArray = chestArray2;
         *
         *  GameLocation loc = Game1.getLocationFromName(chestArray[chestArray.Length - 3]);
         *  string[] chest = chestArray[chestArray.Length - 2].Split(',');
         *  StardewValley.Object chestObject;
         *  bool f = loc.objects.TryGetValue(new Microsoft.Xna.Framework.Vector2( Convert.ToInt32(chest[1]),Convert.ToInt32(chest[2])),out chestObject);
         *  if (f == true)
         *  {
         *      ModCore.ModMonitor.Log("YAY");
         *  }
         *  else
         *  {
         *      ModCore.ModMonitor.Log("BOO");
         *  }
         *
         *  string[] ehh = File.ReadAllLines(path);
         *  Item cObj;
         *  string a;
         *  string[] b;
         *  string s = "";
         *  // Log.AsyncC(path);
         *  //  Log.AsyncC(data);
         *  SerializedObjectBase obj = StardustCore.ModCore.ModHelper.ReadJsonFile<SerializedObjectBase>(path);
         *  try
         *  {
         *          //   Log.AsyncC(obj.thisType);
         *
         *          a = obj.SerializationName;
         *          ModCore.ModMonitor.Log(":THIS IS MY TYPE!!!:" + a);
         *          b = a.Split(',');
         *          s = b.ElementAt(0);
         *      //   Log.AsyncC(s);
         *  }
         *  catch (Exception e)
         *  {
         *      ModCore.ModMonitor.Log(e.ToString());
         *
         *      //USE XML STYLE DESERIALIZING
         *      foreach (KeyValuePair<string, SerializerDataNode> pair in acceptedTypes)
         *      {
         *          var word = ParseXMLType(path);
         *          if (pair.Key == word.ToString())
         *          {
         *              cObj = pair.Value.parse.Invoke(path);
         *              if (cObj is CoreObject)
         *              {
         *                  (cObj as CoreObject).thisLocation = Game1.getLocationFromName((cObj as CoreObject).locationsName);
         *                  (cObj as CoreObject).resetTexture();
         *                  if ((cObj as CoreObject).thisLocation == null)
         *                  {
         *                      // Game1.player.addItemToInventory(cObj);
         *                      try
         *                      {
         *
         *                          Utilities.addItemToOtherInventory((chestObject as StardewValley.Objects.Chest).items, (cObj as CoreObject));
         *                      }
         *                      catch (Exception err)
         *                      {
         *                          ModCore.ModMonitor.Log(err.ToString(), LogLevel.Error);
         *                      }
         *                      // Log.AsyncY("ADDED ITEM TO INVENTORY");
         *                      return;
         *                  }
         *                  else
         *                  {
         *                      (cObj as CoreObject).thisLocation.objects.Add((cObj as CoreObject).TileLocation, (StardewValley.Object)cObj);
         *                      thingsToAddBackIn.Add((cObj as CoreObject));
         *                      //Util.placementAction(cObj, cObj.thisLocation,(int)cObj.tileLocation.X,(int) cObj.tileLocation.Y,null,false);
         *                  }
         *              }
         *              else
         *              {
         *
         *                      try
         *                      {
         *                          Utilities.addItemToOtherInventory((chestObject as StardewValley.Objects.Chest).items, cObj);
         *                      }
         *                      catch (Exception err)
         *                      {
         *                          ModCore.ModMonitor.Log(err.ToString(), LogLevel.Error);
         *                      }
         *
         *              }
         *          }
         *      }
         *
         *      // Log.AsyncG("attempting to parse from path and value of s is " + s);
         *  }
         *
         *  // var cObj = parseBagOfHolding(path); //pair.Value.parse.Invoke(path);
         *  //  cObj.TextureSheet = Game1.content.Load<Texture2D>(Path.Combine("Revitalize", "CropsNSeeds", "Graphics", "seeds"));
         *  /*
         *  cObj.thisLocation = Game1.getLocationFromName(cObj.locationsName);
         *  if (cObj.thisLocation == null)
         *  {
         *      Game1.player.addItemToInventory(cObj);
         *      return;
         *  }
         *  else
         *  {
         *      cObj.thisLocation.objects.Add(cObj.tileLocation, cObj);
         *      Lists.trackedObjectList.Add(cObj);
         *      //Util.placementAction(cObj, cObj.thisLocation,(int)cObj.tileLocation.X,(int) cObj.tileLocation.Y,null,false);
         *  }
         *
         *
         *  //USE JSON STYLE DESERIALIZNG
         *  if (acceptedTypes.ContainsKey(s))
         *  {
         *      foreach (KeyValuePair<string, SerializerDataNode> pair in acceptedTypes)
         *      {
         *          //  Log.AsyncY(pair.Key);
         *          if (pair.Key == s)
         *          {
         *              try
         *              {
         *                  //parse from Json Style
         *                  //   Log.AsyncR("1");
         *                  cObj = pair.Value.parse.Invoke(path);
         *                  if (cObj is CoreObject)
         *                  {
         *                      (cObj as CoreObject).thisLocation = Game1.getLocationFromName((cObj as CoreObject).locationsName);
         *                      if ((cObj as CoreObject).thisLocation == null)
         *                      {
         *                          try
         *                          {
         *                              Utilities.addItemToOtherInventory((chestObject as StardewValley.Objects.Chest).items, (cObj as CoreObject));
         *
         *                              foreach (var v in (chestObject as StardewValley.Objects.Chest).items)
         *                              {
         *                                  ModCore.ModMonitor.Log(v.Name);
         *                              }
         *
         *                          }
         *                          catch (Exception err)
         *                          {
         *                              ModCore.ModMonitor.Log(err.ToString(), LogLevel.Error);
         *                          }
         *                          // Log.AsyncY("ADDED ITEM TO INVENTORY");
         *                          return;
         *                      }
         *                      else
         *                      {
         *                          (cObj as CoreObject).thisLocation.objects.Add((cObj as CoreObject).TileLocation, (StardewValley.Object)cObj);
         *                          thingsToAddBackIn.Add((cObj as CoreObject));
         *                          //Util.placementAction(cObj, cObj.thisLocation,(int)cObj.tileLocation.X,(int) cObj.tileLocation.Y,null,false);
         *                      }
         *                  }
         *                  else
         *                  {
         *                      try
         *                      {
         *                          Utilities.addItemToOtherInventory((chestObject as StardewValley.Objects.Chest).items, cObj);
         *                      }
         *                      catch (Exception err)
         *                      {
         *                          ModCore.ModMonitor.Log(err.ToString(), LogLevel.Error);
         *                      }
         *                  }
         *
         *              }
         *              catch (Exception e)
         *              {
         *                  ModCore.ModMonitor.Log(e.ToString());
         *                  // Log.AsyncO(e);
         *              }
         *          }
         *      }
         *  }
         *  else
         *  {
         *      ModCore.ModMonitor.Log("Error parsing unknown object type: " + s, LogLevel.Error);
         *  }
         *
         * }
         */

        public void ProcessFileForCleanUpIntoContainer(string path, List <IItemSerializeable> thingsToAddBackIn)
        {
            //Log.AsyncC(path);
            string newLine = Environment.NewLine;

            string[] chestArray  = path.Split(new string[] { "/" }, StringSplitOptions.None);
            string[] chestArray2 = path.Split(new string[] { "\\" }, StringSplitOptions.None);

            /*
             * foreach (var v in chestArray)
             * {
             *  Log.AsyncC("PART OF PATH "+v);
             * }
             * foreach (var v in chestArray2)
             * {
             *  Log.AsyncC("PART OF PATH2 " + v);
             * }
             */
            if (chestArray2.Length > chestArray.Length)
            {
                chestArray = chestArray2;
            }

            GameLocation loc = Game1.getLocationFromName(chestArray[chestArray.Length - 3]);

            string[]             chest = chestArray[chestArray.Length - 2].Split(',');
            StardewValley.Object chestObject;
            bool f = loc.objects.TryGetValue(new Microsoft.Xna.Framework.Vector2(Convert.ToInt32(chest[1]), Convert.ToInt32(chest[2])), out chestObject);

            try
            {
                string type  = "";
                int    count = 0;
                while (type == "" || type == null)
                {
                    if (count == 0)
                    {
                        //THE ERROR LIES HERE AS IT THINKS IT CAN TRY TO BE A CORE OBJECT WHEN IT IS NOT!!!!
                        CoreObject core_obj = StardustCore.ModCore.ModHelper.ReadJsonFile <CoreObject>(path); //FIND A WAY TO FIX THIS!!!!
                        type = (core_obj as CoreObject).serializationName;
                        //ModCore.ModMonitor.Log("UMM THIS CAN't BE RIGHT 1" + type);
                    }

                    if (count == 1)
                    {
                        //THIS NEEDS TO BE SOMETHING GENERIC!!!
                        SerializedObjectBase core_obj = StardustCore.ModCore.ModHelper.ReadJsonFile <SerializedObjectBase>(path);
                        type = (core_obj as SerializedObjectBase).SerializationName;
                        //ModCore.ModMonitor.Log("UMM THIS CAN't BE RIGHT 2" + type);
                    }

                    if (count == 2)
                    {
                        ModCore.ModMonitor.Log("A valid type could not be found for the file: " + path);
                        return;
                    }

                    count++;
                }

                foreach (KeyValuePair <string, SerializerDataNode> pair in acceptedTypes)
                {
                    //  Log.AsyncY(pair.Key);
                    if (pair.Key == type)
                    {
                        try
                        {
                            //parse from Json Style
                            //   Log.AsyncR("1");
                            var cObj = pair.Value.parse.Invoke(path);
                            if (cObj is CoreObject)
                            {
                                (cObj as CoreObject).thisLocation = Game1.getLocationFromName((cObj as CoreObject).locationsName);

                                if ((cObj as CoreObject).thisLocation == null)
                                {
                                    Utilities.addItemToOtherInventory((chestObject as Chest).items, cObj);
                                    // Log.AsyncY("ADDED ITEM TO INVENTORY");
                                    return;
                                }
                                else
                                {
                                    (cObj as CoreObject).thisLocation.objects.Add((cObj as CoreObject).TileLocation, (StardewValley.Object)cObj);
                                    thingsToAddBackIn.Add(cObj as CoreObject);
                                    //Util.placementAction(cObj, cObj.thisLocation,(int)cObj.tileLocation.X,(int) cObj.tileLocation.Y,null,false);
                                }
                            }
                            else
                            {
                                Utilities.addItemToOtherInventory((chestObject as Chest).items, cObj);
                            }
                        }
                        catch (Exception e)
                        {
                            ModCore.ModMonitor.Log(e.ToString());
                            // Log.AsyncO(e);
                        }
                    }
                }
            }
            catch (Exception err)
            {
                ModCore.ModMonitor.Log(err.ToString());
                //Tool t = StardustCore.ModCore.ModHelper.ReadJsonFile<Tool>(path);
            }
        }
예제 #2
0
        public void ProcessFileForCleanUp(string path, List <IItemSerializeable> thingsToAddBackIn)
        {
            try
            {
                string type  = "";
                int    count = 0;
                while (type == "" || type == null)
                {
                    if (count == 0)
                    {
                        //THE ERROR LIES HERE AS IT THINKS IT CAN TRY TO BE A CORE OBJECT WHEN IT IS NOT!!!!
                        CoreObject core_obj = StardustCore.ModCore.ModHelper.ReadJsonFile <CoreObject>(path); //FIND A WAY TO FIX THIS!!!!
                        type = (core_obj as CoreObject).serializationName;
                        //ModCore.ModMonitor.Log("UMM THIS CAN't BE RIGHT 1" + type);
                    }

                    if (count == 1)
                    {
                        //THIS NEEDS TO BE SOMETHING GENERIC!!!
                        SerializedObjectBase core_obj = StardustCore.ModCore.ModHelper.ReadJsonFile <SerializedObjectBase>(path);
                        type = (core_obj as SerializedObjectBase).SerializationName;
                        //ModCore.ModMonitor.Log("UMM THIS CAN't BE RIGHT 2" + type);
                    }

                    if (count == 2)
                    {
                        ModCore.ModMonitor.Log("A valid type could not be found for the file: " + path);
                        return;
                    }

                    count++;
                }

                foreach (KeyValuePair <string, SerializerDataNode> pair in acceptedTypes)
                {
                    //  Log.AsyncY(pair.Key);
                    if (pair.Key == type)
                    {
                        try
                        {
                            //parse from Json Style
                            //   Log.AsyncR("1");
                            var cObj = pair.Value.parse.Invoke(path);
                            if (cObj is CoreObject)
                            {
                                (cObj as CoreObject).thisLocation = Game1.getLocationFromName((cObj as CoreObject).locationsName);

                                if ((cObj as CoreObject).thisLocation == null)
                                {
                                    Game1.player.addItemToInventory(cObj);
                                    // Log.AsyncY("ADDED ITEM TO INVENTORY");
                                    return;
                                }
                                else
                                {
                                    try
                                    {
                                        (cObj as CoreObject).thisLocation.objects.Add((cObj as CoreObject).TileLocation, (StardewValley.Object)cObj);
                                        thingsToAddBackIn.Add(cObj as CoreObject);
                                    }
                                    catch (Exception err)
                                    {
                                        //throw new Exception(err.ToString());
                                        return;
                                    }
                                    //Util.placementAction(cObj, cObj.thisLocation,(int)cObj.tileLocation.X,(int) cObj.tileLocation.Y,null,false);
                                }
                            }
                            else
                            {
                                Game1.player.addItemToInventory(cObj);
                            }
                        }
                        catch (Exception e)
                        {
                            ModCore.ModMonitor.Log(e.ToString());
                            // Log.AsyncO(e);
                        }
                    }
                }
            }
            catch (Exception err)
            {
                ModCore.ModMonitor.Log(err.ToString());
                //Tool t = StardustCore.ModCore.ModHelper.ReadJsonFile<Tool>(path);
            }
        }