mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-02-11 02:35:43 +00:00
bac6c22973
* eslint config + packages * updated eslint config * fix the issue eslint adding ;;;; at interfaces * first round with eslint --fix . * removed config for unused export * Revert "first round with eslint --fix ." This reverts commit 77a88e0895f7c3389cb223651b90d918af778fe9. * removed config for camelCase * for real this time, first round of eslint --fix . * halfway to manual eslint fix * eslint done * added "how to setup" the hook to eslint --fix each new file before commit (if wanted) * removed eslintrc config file duplicat * fix human error + ignore build folder + merge overrides * added curly brace style + eslint * applied double quote linter rule * added lefthook * test precommit * test precommit * test precommit * test precommit * test precommit * test precommit * test precommit * github action to run eslint * added node_modules to ignore eslint * different action for typescript * no need for different glob (default src) * node 20 * node 20 * removed no longer needed install file * remove hooks part from README * eslint fixes --------- Co-authored-by: Frederico Santos <frederico.f.santos@tecnico.ulisboa.pt>
89 lines
2.1 KiB
TypeScript
89 lines
2.1 KiB
TypeScript
import BattleScene from "../battle-scene";
|
|
import * as Utils from "../utils";
|
|
|
|
export enum PokemonIconAnimMode {
|
|
NONE,
|
|
PASSIVE,
|
|
ACTIVE
|
|
}
|
|
|
|
type PokemonIcon = Phaser.GameObjects.Container | Phaser.GameObjects.Sprite;
|
|
|
|
export default class PokemonIconAnimHandler {
|
|
private icons: Map<PokemonIcon, PokemonIconAnimMode>;
|
|
private toggled: boolean;
|
|
|
|
setup(scene: BattleScene): void {
|
|
this.icons = new Map();
|
|
this.toggled = false;
|
|
|
|
const onAlternate = (tween: Phaser.Tweens.Tween) => {
|
|
const value = tween.getValue();
|
|
this.toggled = !!value;
|
|
for (const i of this.icons.keys()) {
|
|
i.y += this.getModeYDelta(this.icons.get(i)) * (this.toggled ? 1 : -1);
|
|
}
|
|
};
|
|
scene.tweens.addCounter({
|
|
duration: Utils.fixedInt(200),
|
|
from: 0,
|
|
to: 1,
|
|
yoyo: true,
|
|
repeat: -1,
|
|
onRepeat: onAlternate,
|
|
onYoyo: onAlternate
|
|
});
|
|
}
|
|
|
|
getModeYDelta(mode: PokemonIconAnimMode): number {
|
|
switch (mode) {
|
|
case PokemonIconAnimMode.NONE:
|
|
return 0;
|
|
case PokemonIconAnimMode.PASSIVE:
|
|
return -1;
|
|
case PokemonIconAnimMode.ACTIVE:
|
|
return -2;
|
|
}
|
|
}
|
|
|
|
addOrUpdate(icons: PokemonIcon | PokemonIcon[], mode: PokemonIconAnimMode): void {
|
|
if (!Array.isArray(icons)) {
|
|
icons = [ icons ];
|
|
}
|
|
for (const i of icons) {
|
|
if (this.icons.has(i) && this.icons.get(i) === mode) {
|
|
continue;
|
|
}
|
|
if (this.toggled) {
|
|
const lastYDelta = this.icons.has(i)
|
|
? this.icons.get(i)
|
|
: 0;
|
|
const yDelta = this.getModeYDelta(mode);
|
|
i.y += yDelta + lastYDelta;
|
|
}
|
|
this.icons.set(i, mode);
|
|
}
|
|
}
|
|
|
|
remove(icons: PokemonIcon | PokemonIcon[]): void {
|
|
if (!Array.isArray(icons)) {
|
|
icons = [ icons ];
|
|
}
|
|
for (const i of icons) {
|
|
if (this.toggled) {
|
|
i.y -= this.getModeYDelta(this.icons.get(i));
|
|
}
|
|
this.icons.delete(i);
|
|
}
|
|
}
|
|
|
|
removeAll(): void {
|
|
for (const i of this.icons.keys()) {
|
|
if (this.toggled) {
|
|
i.y -= this.getModeYDelta(this.icons.get(i));
|
|
}
|
|
this.icons.delete(i);
|
|
}
|
|
}
|
|
}
|