Tool SMAPI: Stardew Modding API

Discussion in 'Mods' started by ClxS, Mar 6, 2016.

Thread Status:
Not open for further replies.
  1. LordHelmchen

    LordHelmchen Void-Bound Voyager

    After passing your answer to the author, I got impatient and tried fixing it myself ...
    Now that the Version no longer poses a problem, I ran into the obsoletin of StardewValley.Farmer.friendships...

    Could aomeone give me a short crashcourse on how the old friendships compares to the new friendshipData I might be able to update this as well :)
    Dispclaimer: This is the first time I've looked at StardewValley mod code

    It's referenced three times in the existing Code:
    Code:
    private Dictionary<string, int[]> Friendships => Game1.player.friendships;
    
    Updating this to use friendshipData instead then compains it's not a Dictionary. It looks like I need to go one level deeper to access the wrapped Dictionary instead of the new wrapper ?
    Otherwise, I probably need to chage the two references to Friendships to access information from within the wrapper instead (also possible if I know how old and new objects map)

    Code:
     foreach (var friendship in Game1.player.friendships)
      {
      friendship.Value[1] = 0;
      friendship.Value[3] = 0;
      this.GiftMonitor.Reset();
      }
    
    Code:
    if (!this.GiftConfig.ShowGiftsForUnmetNPCs && !Game1.player.friendships.ContainsKey(this.CurrentGiftDrawData.NpcName))
    
    Both these can probably also be changed to go one level deeper and access the wrapped info instead...

    Regards,
    LordHelmchen
     
    • Pathoschild

      Pathoschild Tiy's Beard

      @denny.thray Can you come ask in #modding on the Stardew Valley Discord? It'll be easier to help there, since we can trade screenshots, I can send you test builds, etc.

      @LordHelmchen The new friendshipData field is a parsed model, so you need to rewrite that code to use the new properties. For example:
      Code:
      foreach (Friendship friendship in Game1.player.friendshipData.Values)
      {
        friendship.GiftsThisWeek = 0;
        friendship.GiftsToday = 0;
        this.GiftMonitor.Reset();
      }
      
      Code:
      if (!this.GiftConfig.ShowGiftsForUnmetNPCs && !Game1.player.friendshipData.ContainsKey(this.CurrentGiftDrawData.NpcName))
      
       
      • lpvinyl21

        lpvinyl21 Big Damn Hero

        I've been playing Stardew Valley on my MAC with my XBox controller with no issues. However, once I installed SMAPI it stopped working.

        Now Steam recognizes that I have the controller, and in big picture mode my controller works. The problem is only when the game has actually launched that I can no longer use my remote.

        Any help with this would be much appreciated since I would love to use some of the amazing mods out there. Thanks!
         
        • SomeGeiBoy

          SomeGeiBoy Orbital Explorer

          I keep on crashing while playing mods, it won't let me sleep to the next day (past spring 11th year1) and I'm unsure what is happening. My friend isn't crashing but I am. Does anyone know what to do? Nothing out of the ordinary happened besides the fact it crashed. If anyone could help ill be so very grateful
           
          • Pathoschild

            Pathoschild Tiy's Beard

            @SomeGeiBoy Next time it crashes, can you upload your SMAPI log (see instructions on that page) and post a link here?

            @lpvinyl21 Make sure that...
            • you didn't change the Steam launch options (that's only needed on Windows);
            • you launch the game through Steam;
            • you didn't add SMAPI as a 'non-Steam game';
            • the Steam overlay works in-game.
            As a last resort you could try bypassing Steam Controller using third-party controller support, but I don't know what you'd use for that on Mac. (You'd use InputMapper on Windows or SC-Controller on Linux.)
             
            • Guuther

              Guuther Void-Bound Voyager

              I do not know how I broke it, I simply updated SMAPI and some mods and wow, it hates me now. Reviewed the forums for similar issues and can't find any, so this is my last hope.

              https://log.smapi.io/4ytUH6MR
               
              • LordHelmchen

                LordHelmchen Void-Bound Voyager

                I finally got what was going on. (stupidly tried to keep the original Dictionary declaration in place, creating a confusing mess of dictionaries within dictionaries, instead of just actually using the dictionary that friendshipData is *facepalm*

                Your two usage examples helped a lot in finally figuring out how and what to access where previously Friendships was used.
                After sorting that out, It no longer crashes on load, apparently both Version and FriendshipData handling work again.

                Unfortunately, on opening of the menu ("e") the mod uses some dark magic reflection to get the ui element and position to attach the tooltip to.
                At least it no longer crashes once, on load, but instead complains on "e", but stays running.
                Tracking changes to GiftDatabase.json shows it does work correctly under the hood, just no tooltip :)

                Maybe (unless theres yet another roadblock that has yet to reveal itself), with one more round of help I'd be able to prepare a pull request.

                Declaration
                Code:
                private List<ClickableTextureComponent> FriendSlots;
                Definition and first use example
                Code:
                        public void OnResize(SDVSocialPage nativePage)
                        {
                            this.NativeSocialPage = nativePage;
                            this.FriendSlots = this.Reflection.GetField<List<ClickableTextureComponent>>(this.NativeSocialPage, "friendNames").GetValue();
                         
                            // Mostly arbitrary since there's no nice way (that i know of) to get the slots positioned correctly...
                            this.Offset = new SVector2(Game1.tileSize / 4, Game1.tileSize / 8);
                            this.Zoom = Game1.options.zoomLevel;
                            this.SlotHeight = this.GetSlotHeight();
                            this.LastSlotIndex = -1; // Invalidate
                        }
                I looked at the nativePage, but the only candidates I found were "npcNames" and "names", both which were just strings, not ClickableTextureComponents...
                As FriendSlots is used in (iirc) 3 other functions, it's probably easiest to keep it List<clickableTextureComponent> and populate it correctly...
                 
                • SomeGeiBoy

                  SomeGeiBoy Orbital Explorer

                • Pathoschild

                  Pathoschild Tiy's Beard

                  @Guuther Can you post a zip of your Mods folder here?

                  @LordHelmchen They replaced it with a "sprites" field (same type) in Stardew Valley 1.3, but I don't know how equivalent it is. Try switching to that field and see how the tooltip behaves in-game?

                  @SomeGeiBoy Your Alex_148415141 save is broken; see Saves#Troubleshooting on the wiki for help fixing that. The crash itself is caused by broken dialogue, probably due to one of your content packs. Can you post a zip of your save files and the Mods folder? I'll see which mod is causing the error and how to fix it.
                   
                  • LordHelmchen

                    LordHelmchen Void-Bound Voyager

                    Yep, after looking at the disassembled StardewValley.Menus.SocialPage that looked like the best bet. just haven't gotten around to trying that yet ;-)
                    ...
                    Great, no more Exceptions.
                    ...
                    But no tooltips either... Although now at least they are shown in the calendar, so while it's not perfect, it's worlds above what I started with :-D
                    ...
                    looks like most fields in sprites are empty, including the sought-after string name... I'll try building a Dictionary with the reflected names field as keys and adapt the comparisons, but if that doesn't work, I'll call it a success anyways.

                    Thanks a lot, that was an enlightening ride, and at least the character is finally able to make notes of useful gifts so I won't have to (and also won't be tempted to look at the wiki too much).

                    besides making a pull request at the mod's git, what is the agreed-upon policy for unofficial mod updates ?
                     
                    • Pathoschild

                      Pathoschild Tiy's Beard

                    • SomeGeiBoy

                      SomeGeiBoy Orbital Explorer

                      @Pathoschild
                      I figured it out, It was some random mod that I really don't remember getting that was messing it. It's all fixed now. Thanks for the help!! Lets hope its smooth sailing from here forward
                       
                      • LordHelmchen

                        LordHelmchen Void-Bound Voyager

                        I feel I'm so close... using a primitive for loop to populate the name field in the sprites with names from SocialPage.names (after casting then from object to string, which feels like it's waiting to break on the next SDV version) shows tooltips in the social tab.
                        Only they all read "no known gifts", though after each gift the information is correctly recorded in GiftDatabase.json. Which I didn't catch before, because the calendar doesn't show everybody and my GiftDatabase is more or less empty :)

                        UPDATE:
                        I'm an idiot. Tooltips were empty because only loved gifts are shown, and my database contained only liked gifts :-D

                        Update2:
                        ... and I'm even stuppider than I previously thought... Had I checked out the 2.8 (sdv 1.3 compat) branch instead of 2.7.1, everything after the first error would never have occured, and I wouldn't have had to reinvent the wheel. @Pathoschild , please forgive me for wasting your time. I'm tempted to delete my previous posts, but decided it could serve as a warning for others :-D
                         
                          Last edited: Sep 3, 2018
                        • Guuther

                          Guuther Void-Bound Voyager

                          @Pathoschild So I zip the file down to a 4.9 mb file and the site says its to large to upload, even though it says it can handle up to 10mb files. Any other ideas?
                           
                          • Pathoschild

                            Pathoschild Tiy's Beard

                            @Guuther Sorry for the slow response. You can upload it to a service like mixtape.moe instead, and post the link here.
                             
                            • Pathoschild

                              Pathoschild Tiy's Beard

                              SMAPI 2.8 beta 4 is now available! (For Stardew Valley 1.3.29 beta only.)

                              Release notes since beta 3:
                              • For players:
                                • Added support for parallel unofficial updates when there's a Stardew Valley or SMAPI beta.
                                • Fixed transparency issues on Linux/Mac for some mod images.
                                • Fixed 'no update keys' warning not shown for mods with only invalid update keys.
                                • Fixed installer not removing a file added in SMAPI 2.8.
                                • Updated compatibility list.
                              • For modders:
                                • Mods are no longer prevented from loading a PNG while the game is drawing.
                              See the release notes and compatibility list for more info. Note that many mods broke in Stardew Valley 1.3.29 and haven't been updated yet.
                               
                              • lonestarwolf

                                lonestarwolf Scruffy Nerf-Herder

                                [SMAPI] SMAPI 2.8-beta.4 with Stardew Valley 1.3.28 on Microsoft Windows 10 Home
                                [SMAPI] Mods go here: F:\Steam\SteamApps\common\Stardew Valley\Mods
                                [SMAPI] Oops! You're running Stardew Valley 1.3.28, but the oldest supported version is 1.3.29. Please update your game before using SMAPI.
                                [SMAPI] Game has ended. Press any key to exit.
                                 
                                • Pathoschild

                                  Pathoschild Tiy's Beard

                                  @lonestarwolf Installing SMAPI 2.7 instead should fix that. (SMAPI 2.8-beta is only for Stardew Valley 1.3.29-beta, which you don't have.)
                                   
                                  • caibat

                                    caibat Intergalactic Tourist

                                    https://log.smapi.io/NGy508U1
                                    I have SMAPI 2.7, CJB Cheats Menu 1.18 and CJB Item Spawner 1.11 installed.
                                    I tried uninstalling and reinstalling SMAPI and redownloaded and uploaded mods but my game is still crashing within a few minutes of launching.

                                    I can try to provide anything else that might be helpful, let me know!

                                    Thanks!!
                                     
                                    • Pathoschild

                                      Pathoschild Tiy's Beard

                                      @caibat Can you cause the crash again, then post a new log file (without relaunching the game after the crash)?
                                       
                                      Thread Status:
                                      Not open for further replies.

                                      Share This Page