moody / Dejunk

Simple junk selling and destroying for WoW.
https://www.curseforge.com/wow/addons/dejunk
MIT License
10 stars 3 forks source link

How does this addon identify the level of items to sell? #216

Closed jsauerland closed 1 month ago

jsauerland commented 1 month ago

Curious how it identifies gear/items to sell based on item level. Say I enter 300 ilvl or less, sell it. Where in the script, what LUA file does that?

moody commented 1 month ago

This code block in the JunkFilter:IsJunkItem(item) method. It only applies to soulbound equipment. https://github.com/moody/Dejunk/blob/359a333bd65739c0a079540f4e51a182e7e2f64d/src/junk-filter.lua#L127-L135

jsauerland commented 1 month ago

Thanks @moody. Do you have any sort of guide or manifest as to how the add-on works? I'm not trying to copy it per se, but trying to learn from it for similar tasks. I have never programmed in LUA But I've been trying to create something similar as a practice project. Just to get down the fundamentals. This has been a really good exercise in figuring it out, the one thing I was really overwhelmed by was how many different files there are broken up all over the place. For example it seems like you have each individual component of the entire user interface in its own file, and I was trying to understand how they work together

moody commented 1 month ago

@jsauerland I don't have any additional documentation or guide for the code outside of what you can see in the repo.

Dejunk was my first real coding project when I started learning many years ago. The project has gone through several stages of refactoring and has even been rebuilt from scratch once before; a consequence of sloppy coding as I stumbled my way through learning everything.

I've added a lot more comments and documentation to the code somewhat recently, which hopefully serves useful as you look through it. Still, some sloppy code and confusing design decisions still exist in the project.

As for the UI though, I find it to be one of the most tedious aspects of making an addon. I hate using XML, so I avoided that route and just did everything in Lua. To make the UI code maintainable, I split everything into a separate file as you've noticed. A key part of this is the Widgets module, which is just a collection of methods to create composable pieces of the UI, such as a simple frame with a backdrop. These widgets are then used to construct bigger parts of the UI, by using them as the base frame.

A good example of this would be the MainWindow. Its base frame is a Window widget:

https://github.com/moody/Dejunk/blob/c472ddfe1a6aafebe0821e2b317274f1118fa03c/src/ui/main-window/main-window.lua#L51-L57

The Window widget itself is based from a TitleFrame widget (see line 46):

https://github.com/moody/Dejunk/blob/c472ddfe1a6aafebe0821e2b317274f1118fa03c/src/ui/widgets/window.lua#L33-L46

A TitleFrame widget is based from a simple Frame widget (see line 41):

https://github.com/moody/Dejunk/blob/c472ddfe1a6aafebe0821e2b317274f1118fa03c/src/ui/widgets/title-frame.lua#L27-L41

Finally, a Frame widget is actually just a basic frame created using the WoW API (see line 35):

https://github.com/moody/Dejunk/blob/c472ddfe1a6aafebe0821e2b317274f1118fa03c/src/ui/widgets/frame.lua#L24-L35


A core part of these widget methods is having only a single parameter, options, which is a table intended to be passed from top to bottom, containing all of the properties necessary for each widget in the hierarchy.

The layers of abstraction make things easier to manage, and I think of it like Lego; small blocks connected to one another to build something much more complicated.