Attempt to sort items on summary & battle screen for user's party. (#1188)

* Sort items in summary screen by type then name.

* Use modifierSortFunc from modifier.ts

* Implement proper sort function which also applies to the battle scene.

* Implement proper sort function which also applies to the battle scene.

* Run linter.

* Fix type assertions.
This commit is contained in:
HighMans 2024-06-06 12:10:38 -04:00 committed by GitHub
parent 223d8a731d
commit a221a46220
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 21 additions and 5 deletions

View File

@ -29,10 +29,25 @@ export type ModifierPredicate = (modifier: Modifier) => boolean;
const iconOverflowIndex = 24;
export const modifierSortFunc = (a: Modifier, b: Modifier) => {
const itemNameMatch = a.type.name.localeCompare(b.type.name);
const typeNameMatch = a.constructor.name.localeCompare(b.constructor.name);
const aId = a instanceof PokemonHeldItemModifier ? a.pokemonId : 4294967295;
const bId = b instanceof PokemonHeldItemModifier ? b.pokemonId : 4294967295;
return aId < bId ? 1 : aId > bId ? -1 : 0;
//First sort by pokemonID
if (aId < bId) {
return 1;
} else if (aId>bId) {
return -1;
} else if (aId === bId) {
//Then sort by item type
if (typeNameMatch === 0) {
return itemNameMatch;
//Finally sort by item name
} else {
return typeNameMatch;
}
}
};
export class ModifierBar extends Phaser.GameObjects.Container {
@ -50,18 +65,19 @@ export class ModifierBar extends Phaser.GameObjects.Container {
this.removeAll(true);
const visibleIconModifiers = modifiers.filter(m => m.isIconVisible(this.scene as BattleScene));
visibleIconModifiers.sort(modifierSortFunc);
const nonPokemonSpecificModifiers = visibleIconModifiers.filter(m => !(m as PokemonHeldItemModifier).pokemonId).sort(modifierSortFunc);
const pokemonSpecificModifiers = visibleIconModifiers.filter(m => (m as PokemonHeldItemModifier).pokemonId).sort(modifierSortFunc);
const sortedVisibleIconModifiers = nonPokemonSpecificModifiers.concat(pokemonSpecificModifiers);
const thisArg = this;
visibleIconModifiers.forEach((modifier: PersistentModifier, i: integer) => {
sortedVisibleIconModifiers.forEach((modifier: PersistentModifier, i: integer) => {
const icon = modifier.getIcon(this.scene as BattleScene);
if (i >= iconOverflowIndex) {
icon.setVisible(false);
}
this.add(icon);
this.setModifierIconPosition(icon, visibleIconModifiers.length);
this.setModifierIconPosition(icon, sortedVisibleIconModifiers.length);
icon.setInteractive(new Phaser.Geom.Rectangle(0, 0, 32, 24), Phaser.Geom.Rectangle.Contains);
icon.on("pointerover", () => {
(this.scene as BattleScene).ui.showTooltip(modifier.type.name, modifier.type.getDescription(this.scene as BattleScene));