Modding Help Save objects placed in custom maps

Discussion in 'Mods' started by weeryan17, Dec 15, 2018.

  1. weeryan17

    weeryan17 Void-Bound Voyager

    I was wondering how do you go about saving played placed objects in maps that you added (So a new map, not replacing any existing). I've so far found out that you can access the objects via
    Code:
    GameLocation#Objects
    witch essentially returns a list of serializable dictionaries with a vector2 as the key (I assume this is the tile location) and a StardewValley.Object as a value. The problem is trying to serialize this throws an error due to StardewValley.Object having a repeating reference. well I could make my own serializer I was wondering if their was an easier way to do it.
     
    • Pathoschild

      Pathoschild Tiy's Beard

      You can use a normal XML serializer to save the data, since that will recognise the XML serialisation attributes the game uses. For example:
      Code:
      string path = Path.Combine(this.Helper.DirectoryPath, "data", $"{Constants.SaveFolderName}.xml");
      using (XmlSerializer serializer = new XmlSerializer(typeof(GameLocation)))
      using (XmlWriter writer = XmlWriter.Create(path))
      {
         serializer.Serialize(writer, location);
      }
      
       
      • weeryan17

        weeryan17 Void-Bound Voyager

        Yep that worked. thanks!
         

        Share This Page