Stanzilla / WoWUIBugs

World of Warcraft UI Bug Tracker
166 stars 7 forks source link

Request for C_Map.GetBestAreaForUnit or Similar Functionality #660

Open Loadren opened 1 day ago

Loadren commented 1 day ago

While the API provides a reliable method to retrieve the map ID for the current location using C_Map.GetBestMapForUnit("player"), there’s no equivalent method for retrieving the sub-zone ID. Sub-zone IDs do exist in the game's internal tables, as evidenced by resources like Wago.tools AreaTable, but there is no built-in function to get the current sub-zone ID in a straightforward way.

For example, when a player moves from The Orecreg to Wanderer's Landing within the Isle of Dorn, developers are currently limited to using GetSubZoneText() to retrieve the sub-zone name, which is localized and not suitable for addons that aim for multi-language support or reliable sub-zone-specific logic.

A method akin to C_Map.GetBestMapForUnit("player") but for sub-zones would greatly improve addon development. Something like C_Map.GetBestAreaForUnit("player") could return a unique, non-localized sub-zone ID that corresponds to the current sub-zone the player is in.

SpareSimian commented 1 day ago

Should it be a separate API or another return value in the existing API?

Does an event exist to alert when one changes sub-zones?

Loadren commented 1 day ago

Should it be a separate API or an additional return value in the existing API?

It depends on what you mean by a "separate API."

If you're suggesting adding a completely new namespace (like C_Zones), I don't think that would be the best approach, as sub-zones are still part of the map. Additionally, there’s already a function, C_Map.GetAreaInfo, under C_Map, so moving that to a new namespace could create unnecessary complexity. I may be wrong, and I'm not against it if it's the best move, but I wouldn't be looking for a namespace named C_Zones if I wanted to find how to get my current subzone ID. I would check for map-related functions.

If you're talking about adding new functions within the C_Map namespace, I would agree. This is where I would logically expect to find functionality related to sub-zones. For instance, if I wanted to get the current sub-zone, I’d naturally look for a function in C_Map that provides that information.

As for adding a new return value to C_Map.GetBestMapForUnit(), I don't think that’s the right approach either. That function is specifically for retrieving the uiMapID, which is used for various purposes like map textures and data related to the whole map. Mixing sub-zone information into that function could complicate how it interacts with other C_Map functions.

Does an event exist to alert when one changes sub-zones?

Yes, the "ZONE_CHANGED" event is already triggered when a player changes sub-zones.

SpareSimian commented 1 day ago

No, not a new namespace. I'm asking whether it's sufficient to change the existing API to return two values, the zone and sub-zone. This somewhat depends on whether clients will commonly need both (which saves a server round-trip by only requiring one call) or if looking up the sub-zone on the server is expensive and rarely needed. Existing callers can ignore the additional return value, so that shouldn't break existing client code. Or perhaps we could look at what clients typically need after a ZONE_CHANGED event and package all that info into a table to be returned in one new call, further reducing network traffic.

Loadren commented 1 day ago

Ah, got it.

I can't speak much to the first part, as I’m not as familiar with the client-side handling, so I'll leave that to others who know it better.

However, regarding the second part about the "ZONE_CHANGED" event, I think that's a solid idea. Including the areaID as an argument in the ZONE_CHANGED event (and perhaps also the parent uiMapID if needed) would be really useful.