RELEASED [SMAPI] Lookup Anything

Discussion in 'Mods' started by Pathoschild, Aug 22, 2016.

  1. Pathoschild

    Pathoschild Giant Laser Beams

    Update: Lookup Anything is now released on Nexus Mods! Go there to download the latest version. This thread is the best place for bug reports, suggestions, feedback, and discussion. :)

    ——————

    I'm working on a mod that shows live info about whatever's under your cursor when you hit F1. (Because I got tired of checking the wiki for NPCs' favourite gifts.)

    For example, here's F1 on a growing crop:
    [​IMG]

    And here's F1 on an NPC:
    [​IMG]

    This is an early prototype. The groundwork is done, but there's lots of work left (like supporting inventory items, adding more fields, cleaning up the UI, etc). It's open-source on GitHub if you want to take a look (or contribute!), but it's not stable enough to try out yet.

    I'd love to hear your thoughts — would this be useful? Does something like this already exist?
     
      Last edited: Sep 19, 2016
      Erzoid, Kulturbanause, Beon and 22 others like this.
    • sheeppoops

      sheeppoops Astral Cartographer

      This is so perfect!!
      I want to see this completed so bad and would so use it like every day ;;;ww;;;
      amazing that you made this! Can't wait to see it fully fleshed out!
       
        Pathoschild likes this.
      • Pathoschild

        Pathoschild Giant Laser Beams

        Slowly making progress towards 1.0. Most of the current work is supporting more targets and showing more info.

        Here's what works so far:
        • Crops (unchanged).
        • NPCs:
          [​IMG]
        • Farm animals (the happiness and complaints fields make it much easier to figure out why your animals are unhappy):
          [​IMG]
        • Inventory items:
          [​IMG]
        • Trees (the next growth field will tell you when they'll grow, or what's blocking their growth):
          [​IMG]
        • Map objects:
          [​IMG]
        • and, uh, this:
          [​IMG]
         
        • Snarkypie

          Snarkypie Void-Bound Voyager

          Are you going to include the crafting recipe on craftable map objects?
           
          • Pathoschild

            Pathoschild Giant Laser Beams

            Something like this?
            [​IMG]

            (Yeah, Krobus really does love getting cheese presses.)
             
              Davrial, Snarkypie and Acerbicon like this.
            • Pathoschild

              Pathoschild Giant Laser Beams

              The mod is almost ready for an early beta release; it has decent coverage and the framework is alright, but the user experience needs some work.

              The mod now supports:
              • Characters:
                • NPCs (unchanged);
                • Pets:
                  [​IMG]
                • Farm animals:
                  [​IMG]
                • Monsters ('dust sprites' are internally called 'dust spirits'):
                  [​IMG]
              • Items:
                • crops (unchanged);
                • inventory items (unchanged);
              • Map objects:
                • crafting objects:
                  [​IMG]
                • fruit trees:
                  [​IMG]
                • wild trees (unchanged);
                • mine objects:
                  [​IMG]
                  [​IMG]
                  [​IMG]
              • And several other things in those categories.

              There's two last things to figure out before beta:
              1. Letting you lookup something by pointing at any visible part of its sprite. This is how the mod (and the game in general) handles interaction:
                [​IMG]
                You can lookup the dog while your cursor is in the green square (the dog's "tile"), but not when it's in one of the red squares. If another mod developer has figured this out yet, let me know! :)

              2. Pagination. When an item has too much information for one page, you should be able to scroll through it. I already have an idea on how to do this.
               
                Davrial, Acerbicon and foghorn like this.
              • foghorn

                foghorn Pangalactic Porcupine

                Great mod, @Pathoschild . I'm only using the Crop Info (minus the gift tastes) because the other info is way too OP for me, but I really like the whole 'offline wiki' concept. Thank you.

                As for overriding hover in animalquery with only SMAPI (per the Pet example you gave): maybe @Entoarox can help?
                (pardon my not-so-subtle Entoarox page)
                 
                  Pathoschild likes this.
                • Pathoschild

                  Pathoschild Giant Laser Beams

                  More progress towards 1.0:
                  • Added pagination (scrolling) for long content.
                  • Added controller support.
                  • Added config.json to change keyboard/controller mappings.
                  • Added fences.
                  • Finished the backend.
                  • Improved some of the lookup results.
                  The mod now covers:
                  • NPCs:
                    • villagers (now with liked gifts):
                      [​IMG]
                    • pets (unchanged);
                    • farm animals (unchanged);
                    • monsters (unchanged).
                  • Items:
                    • crops (added date of next harvest, which I've found really useful for planning your next few days):
                      [​IMG]
                    • inventory items (unchanged besides formatting).
                  • map objects:
                    • crafting objects (unchanged);
                    • fences:
                      [​IMG]
                    • fruit trees (unchanged);
                    • wild trees (unchanged);
                    • mining objects (unchanged).
                  All that's left is letting you point at any part of the sprite, not just its tile. This is a bit complicated, though I have some ideas on how to do it.
                   
                    Davrial, bulbaswat, foghorn and 2 others like this.
                  • Savannah94

                    Savannah94 Void-Bound Voyager

                    Looks amazing! I love all your other mods and this will definitely be installed when released for sure. :nod:
                     
                      Pathoschild likes this.
                    • Pathoschild

                      Pathoschild Giant Laser Beams

                      You can now point at the visible sprite instead of its tile. Here's an example in debug mode (the hover text isn't normally shown):
                      [​IMG][​IMG]

                      And that's pretty much it for pre-release development. I'll spend some time testing and polishing the mod, then it'll be ready for beta!

                      ---

                      I didn't find any mod that does this kind of pixel check, but the technique could be useful in other mods. If you want to know how it works, you can expand the box below. Don't forget the code is open-source. :)


                      (TL;DR: the mod converts the cursor position into coordinates on the object's sprite sheet, then checks the transparency of that pixel. If it's transparent, the cursor isn't over that object. This is an expensive operation, so the mod reduces the number of possible targets first.)

                      When you hit F1, the mod figures out what you're pointing out in four steps.
                      1. Find targets whose sprites could theoretically intersect the cursor. This assumes that each tile could potentially have the tallest and widest sprite (e.g. a tree). We can ignore any tile above the cursor, because sprites never extend downward from their tile. This calculation is very fast and eliminates 98.7% of possible targets on the farm in the example images.

                        The potential targets are highlighted in this image. Green squares contain targets you can look up (e.g. worm bin), and red squares contain unknown targets (e.g. flooring isn't supported yet).
                        [​IMG]
                      2. For each target in this range, calculate a sprite area and check whether it intersects the cursor. A "sprite area" is a rough approximation of where the sprite might be drawn; it's guaranteed to contain the sprite, but isn't necessarily super accurate. In this example, there are three valid targets: the lamp post, preserves jar, and worm bin. There are only two targets whose sprite areas overlap the cursor (the worm bin and preserves jar), so we can ignore the rest.
                        [​IMG]

                        Note that the sprite area isn't enough to find the target. For example, here's the sprite area for a sapling. Anywhere within that box could theoretically be the bottom sapling; we'll need two more steps to decide which sprite you're actually pointing at.
                        [​IMG]
                      3. Sort potential targets by descending Y, then ascending X. This matches the way sprites are layered on the screen (i.e. sprites in the foreground can hide sprites behind them).
                      4. For each target, convert the cursor position into coordinates on its sprite sheet and check that pixel for transparency. This is possible because the "sprite area" (in the world) and "source rectangle" (in the sprite sheet) are equivalent. This involves several steps:
                        1. Change the origin of the cursor coordinates from the viewport to the sprite area. (Basically subtract the sprite area's top-left corner.)
                        2. Scale down the coordinates to correct for the game's zoom level.
                        3. Convert to coordinates within the sprite sheet. (Basically add the source rectangle's top-left corner.)
                        4. Convert the coordinates to a pixel index (basically the pixel's position in a one-dimensional array containing every pixel in the sprite sheet).
                        5. Get the color value of the pixel at that position.
                        6. Check whether the color value is transparent. If not, that's the lookup target!
                      And that's pretty much it. The actual pixel check is fairly straightforward; the main difficulty is that the game is inconsistent in the way it uses sprite sheets, and often uses clever tricks (like applying a formula to get a fruit tree's sprite, or combining two different sprites for a wild tree, or flipping sprites) that need to be duplicated by the mod.
                       
                        Last edited: Sep 10, 2016
                        Davrial, foghorn, Snarkypie and 2 others like this.
                      • Pathoschild

                        Pathoschild Giant Laser Beams

                        I'm considering villager descriptions based on the wikis and dev updates:
                        [​IMG]

                        ...but I'm worried that's too much information, and players might prefer to learn about their neighbours through the game instead. (The mod is really meant to demystify the game mechanics, not spoil the game.)

                        Any preference on whether to add villager descriptions?
                         
                          Davrial likes this.
                        • Snarkypie

                          Snarkypie Void-Bound Voyager

                          I would leave it out, for the reasons you gave.
                           
                          • Androxilogin

                            Androxilogin Existential Complex

                            Any way to make it a progress check sort of mod? (I don't know the term). I like to have all the info I can while playing but yeah that would kind of suck to just know right off from the beginning.
                             
                            • Pathoschild

                              Pathoschild Giant Laser Beams

                              @Androxilogin not easily. A lot of the information comes from normal dialogue lines, but the game doesn't track which ones you've seen. Some of the background information also comes from the dev blog, so there's no way to learn it in-game.

                              I'll leave out the descriptions for now; maybe in a future version I can look into unlocking details as you learn them.
                               
                              • Pathoschild

                                Pathoschild Giant Laser Beams

                                The mod is ready for beta!

                                Note that this is the first beta release (version 0.1):
                                • The game might crash when you're using the mod; if that would be inconvenient, consider waiting for 1.0 instead. (That said, a crash is unlikely because the mod will handle most errors gracefully. Also, since the mod doesn't change any game data, it has no effect on your save.)
                                • If the mod runs into a problem, you'll normally see a message like this and your game will continue unaffected. If you see that message, let me know so I can fix the problem. Just reply here or message me with:
                                  • a description of what you did when the error happened;
                                  • a screenshot of the game when it happened (if possible);
                                  • and a copy of the error log in %AppData%\StardewValley\ErrorLogs (the file with "LATEST" in the name).
                                • Watch this thread for updated versions!
                                To install this version:
                                1. Install SMAPI 0.40+ (if you don't already have it).
                                2. Unzip the attached mod into Stardew Valley/Mods.
                                3. Run the game using SMAPI.

                                See the mod readme for instructions, screenshots, and optional configuration.

                                Feedback and suggestions welcome! Here's your chance to influence how the released mod will work. :)

                                (EDIT: see latest version.)
                                 
                                  Last edited: Sep 19, 2016
                                • Pathoschild

                                  Pathoschild Giant Laser Beams

                                  Here's a small followup beta release.

                                  Changes:
                                  • When a new version is available, you'll now see a small message for a few seconds when you start the game. The update check won't affect your load time at all (because it happens in the background), and you can disable it in the config.json.
                                  • Improved error handling.
                                  I added the update check since there's no mod manager that tracks versions yet; let me know if this feature is undesirable. :)

                                  To install this version:
                                  1. Install SMAPI 0.40+ (if you don't already have it).
                                  2. Unzip the attached mod into Stardew Valley/Mods.
                                  3. Run the game using SMAPI.
                                  (EDIT: see latest version.)
                                   
                                    Last edited: Sep 19, 2016
                                  • Snarkypie

                                    Snarkypie Void-Bound Voyager

                                    0.2 does not work for me :( SMAPI states it's loaded, but in-game nothing happens when I hover over objects
                                     
                                    • foghorn

                                      foghorn Pangalactic Porcupine

                                      Works fine here, Snarkypie. Are you hovering, and then pressing F1?
                                       
                                      • Pathoschild

                                        Pathoschild Giant Laser Beams

                                        @Snarkypie: yep, you need to press F1 like foghorn said. The mod's debug mode shows hover text if that's what you mean, but it's not meant to be used during normal play. (It also adds distracting overlays and may impact performance.) If you like the hover text, I could look into making it an optional feature in 1.1.
                                         
                                        • Snarkypie

                                          Snarkypie Void-Bound Voyager

                                          For whatever reason, it kicked in the second time I loaded it, sorry for not updating!
                                           

                                          Share This Page