-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(craft): refactor IngredientHolder and CurrentRecipe
- Loading branch information
1 parent
eab24f8
commit f06e0fa
Showing
8 changed files
with
164 additions
and
203 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
features/craft/src/main/java/net/okocraft/box/feature/craft/gui/SelectableIngredients.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
package net.okocraft.box.feature.craft.gui; | ||
|
||
import net.okocraft.box.feature.craft.model.BoxIngredientItem; | ||
import net.okocraft.box.feature.craft.model.IngredientHolder; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Unmodifiable; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* A class for handling multiple {@link BoxIngredientItem}s that can be selected | ||
*/ | ||
public class SelectableIngredients { | ||
|
||
private final IngredientHolder ingredientHolder; | ||
private final List<BoxIngredientItem> patterns; | ||
|
||
private int selected; | ||
|
||
public SelectableIngredients(@NotNull IngredientHolder ingredientHolder, @NotNull List<BoxIngredientItem> patterns) { | ||
this.ingredientHolder = ingredientHolder; | ||
this.patterns = patterns; | ||
} | ||
|
||
/** | ||
* Gets the currently selected {@link BoxIngredientItem}. | ||
* | ||
* @return the currently selected {@link BoxIngredientItem} | ||
*/ | ||
public @NotNull BoxIngredientItem getSelected() { | ||
return patterns.get(selected); | ||
} | ||
|
||
/** | ||
* Selects the next {@link BoxIngredientItem}. | ||
* | ||
* @return the position of the selected {@link BoxIngredientItem} | ||
*/ | ||
public int next() { | ||
selected++; | ||
|
||
if (patterns.size() <= selected) { | ||
selected = 0; | ||
} | ||
|
||
return selected; | ||
} | ||
|
||
/** | ||
* Selects the {@link BoxIngredientItem} at the specified position. | ||
* | ||
* @param num the position | ||
*/ | ||
public void select(int num) { | ||
selected = num; | ||
|
||
if (patterns.size() <= selected) { | ||
selected = 0; | ||
} | ||
} | ||
|
||
/** | ||
* Returns the {@link IngredientHolder#patterns()}. | ||
* | ||
* @return the {@link IngredientHolder#patterns()} | ||
*/ | ||
public @NotNull @Unmodifiable List<BoxIngredientItem> get() { | ||
return patterns; | ||
} | ||
|
||
/** | ||
* Returns the number of {@link BoxIngredientItem}s. | ||
* | ||
* @return the number of {@link BoxIngredientItem}s | ||
*/ | ||
public int size() { | ||
return patterns.size(); | ||
} | ||
|
||
/** | ||
* Checks if this and the specified {@link SelectableIngredients} are same. | ||
* | ||
* @param other {@link SelectableIngredients} to check | ||
* @return {@code true} if two {@link SelectableIngredients} are same, otherwise {@code false} | ||
*/ | ||
public boolean isSameIngredient(@NotNull SelectableIngredients other) { | ||
return this.ingredientHolder.equals(other.ingredientHolder); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (!(o instanceof SelectableIngredients that)) return false; | ||
return this.isSameIngredient(that); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return this.ingredientHolder.hashCode(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.