-
-
Notifications
You must be signed in to change notification settings - Fork 84
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor container matcher implementations into interfaces #788
Refactor container matcher implementations into interfaces #788
Conversation
Don't we love refactoring PRs? Anyways uh ig my only nitpick is that I personally don't like interfaces being called "Abstract". "Abstract" makes me think i'm dealing with an abstract class. |
Don't really like that neither |
I get that, but there's no other way that I can think of, other than that and the
But then there would be 2 ContainerSolvers. We'd have to rename the other one to ContainerSolverImpl and that doesn't sound like a good solution either as usually -Impl classes mean that the interface is supposed to have only one implementor, and they are usually abstracted away behind builders or static methods in the interface. |
ContainerSolverInterface maybe? idk |
Interfaces are inherently abstract, so you are implictly naming the file an abstract abstractContainerSolver rn haha |
Perhaps I could remove the |
From my understanding the java-centric way of doing it is to add the extra info into the implementation i.e. the List interface is implemented by the LinkedList Class & ArrayList Class |
Oh, I would have done abstract too, but since so many people are arguing against it, this is fine. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Additional changes in this pr:
- Adds key bind that shows different info.
- Passes stack and slot id instead of slot instance to slot text adders.
src/main/java/de/hysky/skyblocker/utils/container/ContainerMatcher.java
Outdated
Show resolved
Hide resolved
src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/TooltipManager.java
Outdated
Show resolved
Hide resolved
Need to wait for a few other prs due to merge conflict. |
deadf33
to
e5a04c4
Compare
This PR needs a way to fix the config to change value of the slottext config from a boolean to one of the SlotTextState enums. I know this is possible with some datafix shenanigans but I have no idea how they work or where to begin from, so any guidance would be appreciated. |
Oh hey, this is next. Do you want me to rebase this or you will? I can handle the data fixer parts but I need to know which options map to which. It seems like |
I'd appreciate it. I've been procrastinating on my internship project a little, and now most of my time is spent on that to make up for that. Don't exactly have the time or motivation for this and probably won't for another week or two.
Exactly.
It holds the toggle state for the |
- Refactored SlotTextAdders to take in ItemStack and int slotId rather than Slot - Refactored the renderSlotText method from HandledScreenMixin into SlotTextManager and added an overloading function that takes in the itemstack, slot id, x and y and the previous function with the Slot parameter just delegates to it with the relevant fields from that Slot object - As a result of the above 2 changes the logic in CommunityShopAdder had to be changed too, now it figures out the screen from the method calls to `getText` rather than the Slot's inventory. - Fixed slot text not being rendered in backpack preview - Added private constructor for BackpackPreview (because it's all static methods anyway)
…e the `Abstract` prefix and rename simple implementations with a `Simple` prefix
The enum SlotTextState is very self-descriptive if you wonder what the states are
Btw, next time anyone does a refactor pr, please try not to break the api this badly. Follow conventions like keeping old methods and marking them as deprecated. |
d261bca
to
a846b52
Compare
I thought that since the mod doesn't have any external APIs, changing it directly without deprecating the previous way is fine as long as I change all usages. I guess that resulted in way more merge conflicts than necessary. Sorry, will be more careful next time. |
Yes, we don't really have an api, but it's more about other prs that use the old "internal api" which can be a bit annoying. It's all good now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still need to look at container solver and manager classes.
src/main/java/de/hysky/skyblocker/skyblock/item/slottext/adders/PotionLevelAdder.java
Show resolved
Hide resolved
src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/adders/MuseumTooltip.java
Outdated
Show resolved
Hide resolved
This reverts commit c6c3f30.
.name(Text.translatable("skyblocker.config.shortcutToKeybindsSettings")) | ||
.action((screen, opt) -> MinecraftClient.getInstance().setScreen(new KeybindsScreen(screen, MinecraftClient.getInstance().options))) | ||
.text(Text.translatable("skyblocker.config.shortcutToKeybindsSettings.@Text")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These translation keys don't exist btw. Do you not have mcdev installed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lgtm.
Simple explanation of what this PR separates these classes into:
The very base interface:
AbstractContainerMatcher
. The main method in it takes a screen and returns a boolean. There's an abstract class calledRegexContainerMatcher
implementing it that takes a pattern in and matches it against the given screen's title.Then there's the 3 interfaces for the different types we have:
AbstractContainerSolver
,AbstractSlotTextAdder
andAbstractTooltipAdder
. These contain the methods relevant to their types, basically all the methods from the previous way.Then there are 3 simple implementations of those 3 interfaces,
ContainerSolver
,SlotTextAdder
andTooltipAdder
, all of which also extendRegexContainerMatcher
. These 3 classes don't have much logic to themselves and have constructors for the regex stuff. Most adders will want to extend these 3 classes. But the separation of the base methods into interfaces that all extend the base interface allows an implementing class to implement multiple of the interfaces.End of wall of text.
This PR also moves the container stuff into their own directory inside of the
utils
package.The
RegexContainerMatcher
abstract class also saves the matched groups in a variable, so any class extending it will have access to the groups matched by the title pattern. This removes the need to pass around a parameter to allContainerSolver
s when only 1 of them make use of it, and also makes it possible for theSlotTextAdder
s and theTooltipAdder
s to use it if it's ever needed.There's one possibly unwanted result of this change, and that is the implementation of interfaces have to have a visibility modifier of
public
.