mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-09-23 15:03:24 +02:00
Merge branch 'hotfix-1.10.7' into wrong-save-slot
This commit is contained in:
commit
bdc2140a66
@ -396,7 +396,23 @@ export abstract class AbAttr {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class BlockRecoilDamageAttr extends AbAttr {
|
/**
|
||||||
|
* Abstract class for ability attributes that simply cancel an interaction
|
||||||
|
*
|
||||||
|
* @remarks
|
||||||
|
* Abilities that have simple cancel interactions (e.g. {@linkcode BlockRecoilDamageAttr}) can extend this class to reuse the `canApply` and `apply` logic
|
||||||
|
*/
|
||||||
|
abstract class CancelInteractionAbAttr extends AbAttr {
|
||||||
|
override canApply({ cancelled }: AbAttrParamsWithCancel): boolean {
|
||||||
|
return !cancelled.value;
|
||||||
|
}
|
||||||
|
|
||||||
|
override apply({ cancelled }: AbAttrParamsWithCancel): void {
|
||||||
|
cancelled.value = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class BlockRecoilDamageAttr extends CancelInteractionAbAttr {
|
||||||
private declare readonly _: never;
|
private declare readonly _: never;
|
||||||
constructor() {
|
constructor() {
|
||||||
super(false);
|
super(false);
|
||||||
@ -592,11 +608,7 @@ export class PreDefendFullHpEndureAbAttr extends PreDefendAbAttr {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class BlockItemTheftAbAttr extends AbAttr {
|
export class BlockItemTheftAbAttr extends CancelInteractionAbAttr {
|
||||||
override apply({ cancelled }: AbAttrParamsWithCancel): void {
|
|
||||||
cancelled.value = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
getTriggerMessage({ pokemon }: AbAttrBaseParams, abilityName: string) {
|
getTriggerMessage({ pokemon }: AbAttrBaseParams, abilityName: string) {
|
||||||
return i18next.t("abilityTriggers:blockItemTheft", {
|
return i18next.t("abilityTriggers:blockItemTheft", {
|
||||||
pokemonNameWithAffix: getPokemonNameWithAffix(pokemon),
|
pokemonNameWithAffix: getPokemonNameWithAffix(pokemon),
|
||||||
@ -869,8 +881,9 @@ export interface FieldPriorityMoveImmunityAbAttrParams extends AugmentMoveIntera
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class FieldPriorityMoveImmunityAbAttr extends PreDefendAbAttr {
|
export class FieldPriorityMoveImmunityAbAttr extends PreDefendAbAttr {
|
||||||
override canApply({ move, opponent: attacker }: FieldPriorityMoveImmunityAbAttrParams): boolean {
|
override canApply({ move, opponent: attacker, cancelled }: FieldPriorityMoveImmunityAbAttrParams): boolean {
|
||||||
return (
|
return (
|
||||||
|
!cancelled.value &&
|
||||||
!(move.moveTarget === MoveTarget.USER || move.moveTarget === MoveTarget.NEAR_ALLY) &&
|
!(move.moveTarget === MoveTarget.USER || move.moveTarget === MoveTarget.NEAR_ALLY) &&
|
||||||
move.getPriority(attacker) > 0 &&
|
move.getPriority(attacker) > 0 &&
|
||||||
!move.isMultiTarget()
|
!move.isMultiTarget()
|
||||||
@ -897,10 +910,8 @@ export class MoveImmunityAbAttr extends PreDefendAbAttr {
|
|||||||
this.immuneCondition = immuneCondition;
|
this.immuneCondition = immuneCondition;
|
||||||
}
|
}
|
||||||
|
|
||||||
override canApply({ pokemon, opponent: attacker, move }: MoveImmunityAbAttrParams): boolean {
|
override canApply({ pokemon, opponent: attacker, move, cancelled }: MoveImmunityAbAttrParams): boolean {
|
||||||
// TODO: Investigate whether this method should be checking against `cancelled`, specifically
|
return !cancelled.value && this.immuneCondition(pokemon, attacker, move);
|
||||||
// if not checking this results in multiple flyouts showing when multiple abilities block the move.
|
|
||||||
return this.immuneCondition(pokemon, attacker, move);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override apply({ cancelled }: MoveImmunityAbAttrParams): void {
|
override apply({ cancelled }: MoveImmunityAbAttrParams): void {
|
||||||
@ -1591,12 +1602,7 @@ export interface FieldPreventExplosiveMovesAbAttrParams extends AbAttrBaseParams
|
|||||||
cancelled: BooleanHolder;
|
cancelled: BooleanHolder;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class FieldPreventExplosiveMovesAbAttr extends AbAttr {
|
export class FieldPreventExplosiveMovesAbAttr extends CancelInteractionAbAttr {}
|
||||||
// TODO: investigate whether we need to check against `cancelled` in a `canApply` method
|
|
||||||
override apply({ cancelled }: FieldPreventExplosiveMovesAbAttrParams): void {
|
|
||||||
cancelled.value = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface FieldMultiplyStatAbAttrParams extends AbAttrBaseParams {
|
export interface FieldMultiplyStatAbAttrParams extends AbAttrBaseParams {
|
||||||
/** The kind of stat that is being checked for modification */
|
/** The kind of stat that is being checked for modification */
|
||||||
@ -2535,15 +2541,11 @@ export class IgnoreOpponentStatStagesAbAttr extends AbAttr {
|
|||||||
* Abilities with this attribute prevent the user from being affected by Intimidate.
|
* Abilities with this attribute prevent the user from being affected by Intimidate.
|
||||||
* @sealed
|
* @sealed
|
||||||
*/
|
*/
|
||||||
export class IntimidateImmunityAbAttr extends AbAttr {
|
export class IntimidateImmunityAbAttr extends CancelInteractionAbAttr {
|
||||||
constructor() {
|
constructor() {
|
||||||
super(false);
|
super(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
override apply({ cancelled }: AbAttrParamsWithCancel): void {
|
|
||||||
cancelled.value = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
getTriggerMessage({ pokemon }: AbAttrParamsWithCancel, abilityName: string, ..._args: any[]): string {
|
getTriggerMessage({ pokemon }: AbAttrParamsWithCancel, abilityName: string, ..._args: any[]): string {
|
||||||
return i18next.t("abilityTriggers:intimidateImmunity", {
|
return i18next.t("abilityTriggers:intimidateImmunity", {
|
||||||
pokemonNameWithAffix: getPokemonNameWithAffix(pokemon),
|
pokemonNameWithAffix: getPokemonNameWithAffix(pokemon),
|
||||||
@ -3577,8 +3579,8 @@ export class ProtectStatAbAttr extends PreStatStageChangeAbAttr {
|
|||||||
this.protectedStat = protectedStat;
|
this.protectedStat = protectedStat;
|
||||||
}
|
}
|
||||||
|
|
||||||
override canApply({ stat }: PreStatStageChangeAbAttrParams): boolean {
|
override canApply({ stat, cancelled }: PreStatStageChangeAbAttrParams): boolean {
|
||||||
return isNullOrUndefined(this.protectedStat) || stat === this.protectedStat;
|
return !cancelled.value && (isNullOrUndefined(this.protectedStat) || stat === this.protectedStat);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -3669,8 +3671,11 @@ export class PreSetStatusEffectImmunityAbAttr extends PreSetStatusAbAttr {
|
|||||||
this.immuneEffects = immuneEffects;
|
this.immuneEffects = immuneEffects;
|
||||||
}
|
}
|
||||||
|
|
||||||
override canApply({ effect }: PreSetStatusAbAttrParams): boolean {
|
override canApply({ effect, cancelled }: PreSetStatusAbAttrParams): boolean {
|
||||||
return (this.immuneEffects.length === 0 && effect !== StatusEffect.FAINT) || this.immuneEffects.includes(effect);
|
return (
|
||||||
|
!cancelled.value &&
|
||||||
|
((this.immuneEffects.length === 0 && effect !== StatusEffect.FAINT) || this.immuneEffects.includes(effect))
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -3720,7 +3725,8 @@ export interface UserFieldStatusEffectImmunityAbAttrParams extends AbAttrBasePar
|
|||||||
/**
|
/**
|
||||||
* Provides immunity to status effects to the user's field.
|
* Provides immunity to status effects to the user's field.
|
||||||
*/
|
*/
|
||||||
export class UserFieldStatusEffectImmunityAbAttr extends AbAttr {
|
export class UserFieldStatusEffectImmunityAbAttr extends CancelInteractionAbAttr {
|
||||||
|
private declare readonly _: never;
|
||||||
protected immuneEffects: StatusEffect[];
|
protected immuneEffects: StatusEffect[];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -3740,12 +3746,8 @@ export class UserFieldStatusEffectImmunityAbAttr extends AbAttr {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
// declare here to allow typescript to allow us to override `canApply` method without adjusting params
|
||||||
* Set the `cancelled` value to true, indicating that the status effect is prevented.
|
declare apply: (params: UserFieldStatusEffectImmunityAbAttrParams) => void;
|
||||||
*/
|
|
||||||
override apply({ cancelled }: UserFieldStatusEffectImmunityAbAttrParams): void {
|
|
||||||
cancelled.value = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -3776,14 +3778,7 @@ export class ConditionalUserFieldStatusEffectImmunityAbAttr extends UserFieldSta
|
|||||||
* @returns Whether the ability can be applied to cancel the status effect.
|
* @returns Whether the ability can be applied to cancel the status effect.
|
||||||
*/
|
*/
|
||||||
override canApply(params: UserFieldStatusEffectImmunityAbAttrParams): boolean {
|
override canApply(params: UserFieldStatusEffectImmunityAbAttrParams): boolean {
|
||||||
return this.condition(params.target, params.source) && super.canApply(params);
|
return !params.cancelled.value && this.condition(params.target, params.source) && super.canApply(params);
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the `cancelled` value to true, indicating that the status effect is prevented.
|
|
||||||
*/
|
|
||||||
override apply({ cancelled }: UserFieldStatusEffectImmunityAbAttrParams): void {
|
|
||||||
cancelled.value = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4019,20 +4014,16 @@ export class ConditionalCritAbAttr extends AbAttr {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class BlockNonDirectDamageAbAttr extends AbAttr {
|
export class BlockNonDirectDamageAbAttr extends CancelInteractionAbAttr {
|
||||||
constructor() {
|
constructor() {
|
||||||
super(false);
|
super(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
override apply({ cancelled }: AbAttrParamsWithCancel): void {
|
|
||||||
cancelled.value = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This attribute will block any status damage that you put in the parameter.
|
* This attribute will block any status damage that you put in the parameter.
|
||||||
*/
|
*/
|
||||||
export class BlockStatusDamageAbAttr extends AbAttr {
|
export class BlockStatusDamageAbAttr extends CancelInteractionAbAttr {
|
||||||
private effects: StatusEffect[];
|
private effects: StatusEffect[];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -4044,20 +4035,12 @@ export class BlockStatusDamageAbAttr extends AbAttr {
|
|||||||
this.effects = effects;
|
this.effects = effects;
|
||||||
}
|
}
|
||||||
|
|
||||||
override canApply({ pokemon }: AbAttrParamsWithCancel): boolean {
|
override canApply({ pokemon, cancelled }: AbAttrParamsWithCancel): boolean {
|
||||||
return !!pokemon.status?.effect && this.effects.includes(pokemon.status.effect);
|
return !cancelled.value && !!pokemon.status?.effect && this.effects.includes(pokemon.status.effect);
|
||||||
}
|
|
||||||
|
|
||||||
override apply({ cancelled }: AbAttrParamsWithCancel): void {
|
|
||||||
cancelled.value = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class BlockOneHitKOAbAttr extends AbAttr {
|
export class BlockOneHitKOAbAttr extends CancelInteractionAbAttr {}
|
||||||
override apply({ cancelled }: AbAttrParamsWithCancel): void {
|
|
||||||
cancelled.value = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface ChangeMovePriorityAbAttrParams extends AbAttrBaseParams {
|
export interface ChangeMovePriorityAbAttrParams extends AbAttrBaseParams {
|
||||||
/** The move being used */
|
/** The move being used */
|
||||||
@ -4131,8 +4114,8 @@ export class BlockWeatherDamageAttr extends PreWeatherDamageAbAttr {
|
|||||||
this.weatherTypes = weatherTypes;
|
this.weatherTypes = weatherTypes;
|
||||||
}
|
}
|
||||||
|
|
||||||
override canApply({ weather }: PreWeatherEffectAbAttrParams): boolean {
|
override canApply({ weather, cancelled }: PreWeatherEffectAbAttrParams): boolean {
|
||||||
if (!weather) {
|
if (!weather || cancelled.value) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
const weatherType = weather.weatherType;
|
const weatherType = weather.weatherType;
|
||||||
@ -4153,8 +4136,8 @@ export class SuppressWeatherEffectAbAttr extends PreWeatherEffectAbAttr {
|
|||||||
this.affectsImmutable = affectsImmutable;
|
this.affectsImmutable = affectsImmutable;
|
||||||
}
|
}
|
||||||
|
|
||||||
override canApply({ weather }: PreWeatherEffectAbAttrParams): boolean {
|
override canApply({ weather, cancelled }: PreWeatherEffectAbAttrParams): boolean {
|
||||||
if (!weather) {
|
if (!weather || cancelled.value) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return this.affectsImmutable || weather.isImmutable();
|
return this.affectsImmutable || weather.isImmutable();
|
||||||
@ -5151,15 +5134,11 @@ export class StatStageChangeCopyAbAttr extends AbAttr {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class BypassBurnDamageReductionAbAttr extends AbAttr {
|
export class BypassBurnDamageReductionAbAttr extends CancelInteractionAbAttr {
|
||||||
private declare readonly _: never;
|
private declare readonly _: never;
|
||||||
constructor() {
|
constructor() {
|
||||||
super(false);
|
super(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
override apply({ cancelled }: AbAttrParamsWithCancel): void {
|
|
||||||
cancelled.value = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ReduceBurnDamageAbAttrParams extends AbAttrBaseParams {
|
export interface ReduceBurnDamageAbAttrParams extends AbAttrBaseParams {
|
||||||
@ -5199,14 +5178,7 @@ export class DoubleBerryEffectAbAttr extends AbAttr {
|
|||||||
* Attribute to prevent opposing berry use while on the field.
|
* Attribute to prevent opposing berry use while on the field.
|
||||||
* Used by {@linkcode AbilityId.UNNERVE}, {@linkcode AbilityId.AS_ONE_GLASTRIER} and {@linkcode AbilityId.AS_ONE_SPECTRIER}
|
* Used by {@linkcode AbilityId.UNNERVE}, {@linkcode AbilityId.AS_ONE_GLASTRIER} and {@linkcode AbilityId.AS_ONE_SPECTRIER}
|
||||||
*/
|
*/
|
||||||
export class PreventBerryUseAbAttr extends AbAttr {
|
export class PreventBerryUseAbAttr extends CancelInteractionAbAttr {}
|
||||||
/**
|
|
||||||
* Prevent use of opposing berries.
|
|
||||||
*/
|
|
||||||
override apply({ cancelled }: AbAttrParamsWithCancel): void {
|
|
||||||
cancelled.value = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A Pokemon with this ability heals by a percentage of their maximum hp after eating a berry
|
* A Pokemon with this ability heals by a percentage of their maximum hp after eating a berry
|
||||||
@ -5664,11 +5636,7 @@ export class IncreasePpAbAttr extends AbAttr {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** @sealed */
|
/** @sealed */
|
||||||
export class ForceSwitchOutImmunityAbAttr extends AbAttr {
|
export class ForceSwitchOutImmunityAbAttr extends CancelInteractionAbAttr {}
|
||||||
override apply({ cancelled }: AbAttrParamsWithCancel): void {
|
|
||||||
cancelled.value = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface ReduceBerryUseThresholdAbAttrParams extends AbAttrBaseParams {
|
export interface ReduceBerryUseThresholdAbAttrParams extends AbAttrBaseParams {
|
||||||
/** Holds the hp ratio for the berry to proc, which may be modified by ability application */
|
/** Holds the hp ratio for the berry to proc, which may be modified by ability application */
|
||||||
@ -5747,8 +5715,8 @@ export class MoveAbilityBypassAbAttr extends AbAttr {
|
|||||||
this.moveIgnoreFunc = moveIgnoreFunc || ((_pokemon, _move) => true);
|
this.moveIgnoreFunc = moveIgnoreFunc || ((_pokemon, _move) => true);
|
||||||
}
|
}
|
||||||
|
|
||||||
override canApply({ pokemon, move }: MoveAbilityBypassAbAttrParams): boolean {
|
override canApply({ pokemon, move, cancelled }: MoveAbilityBypassAbAttrParams): boolean {
|
||||||
return this.moveIgnoreFunc(pokemon, move);
|
return !cancelled.value && this.moveIgnoreFunc(pokemon, move);
|
||||||
}
|
}
|
||||||
|
|
||||||
override apply({ cancelled }: MoveAbilityBypassAbAttrParams): void {
|
override apply({ cancelled }: MoveAbilityBypassAbAttrParams): void {
|
||||||
@ -5842,8 +5810,8 @@ export class IgnoreTypeImmunityAbAttr extends AbAttr {
|
|||||||
this.allowedMoveTypes = allowedMoveTypes;
|
this.allowedMoveTypes = allowedMoveTypes;
|
||||||
}
|
}
|
||||||
|
|
||||||
override canApply({ moveType, defenderType }: IgnoreTypeImmunityAbAttrParams): boolean {
|
override canApply({ moveType, defenderType, cancelled }: IgnoreTypeImmunityAbAttrParams): boolean {
|
||||||
return this.defenderType === defenderType && this.allowedMoveTypes.includes(moveType);
|
return !cancelled.value && this.defenderType === defenderType && this.allowedMoveTypes.includes(moveType);
|
||||||
}
|
}
|
||||||
|
|
||||||
override apply({ cancelled }: IgnoreTypeImmunityAbAttrParams): void {
|
override apply({ cancelled }: IgnoreTypeImmunityAbAttrParams): void {
|
||||||
|
@ -8140,9 +8140,12 @@ const failIfSingleBattle: MoveConditionFunc = (user, target, move) => globalScen
|
|||||||
|
|
||||||
const failIfDampCondition: MoveConditionFunc = (user, target, move) => {
|
const failIfDampCondition: MoveConditionFunc = (user, target, move) => {
|
||||||
const cancelled = new BooleanHolder(false);
|
const cancelled = new BooleanHolder(false);
|
||||||
globalScene.getField(true).map(p=>applyAbAttrs("FieldPreventExplosiveMovesAbAttr", {pokemon: p, cancelled}));
|
// temporary workaround to prevent displaying the message during enemy command phase
|
||||||
|
// TODO: either move this, or make the move condition func have a `simulated` param
|
||||||
|
const simulated = globalScene.phaseManager.getCurrentPhase()?.is('EnemyCommandPhase');
|
||||||
|
globalScene.getField(true).map(p=>applyAbAttrs("FieldPreventExplosiveMovesAbAttr", {pokemon: p, cancelled, simulated}));
|
||||||
// Queue a message if an ability prevented usage of the move
|
// Queue a message if an ability prevented usage of the move
|
||||||
if (cancelled.value) {
|
if (!simulated && cancelled.value) {
|
||||||
globalScene.phaseManager.queueMessage(i18next.t("moveTriggers:cannotUseMove", { pokemonName: getPokemonNameWithAffix(user), moveName: move.name }));
|
globalScene.phaseManager.queueMessage(i18next.t("moveTriggers:cannotUseMove", { pokemonName: getPokemonNameWithAffix(user), moveName: move.name }));
|
||||||
}
|
}
|
||||||
return !cancelled.value;
|
return !cancelled.value;
|
||||||
|
@ -6590,6 +6590,7 @@ export class EnemyPokemon extends Pokemon {
|
|||||||
ignoreAllyAbility: !p.getAlly()?.waveData.abilityRevealed,
|
ignoreAllyAbility: !p.getAlly()?.waveData.abilityRevealed,
|
||||||
ignoreSourceAllyAbility: false,
|
ignoreSourceAllyAbility: false,
|
||||||
isCritical,
|
isCritical,
|
||||||
|
simulated: true,
|
||||||
}).damage >= p.hp
|
}).damage >= p.hp
|
||||||
);
|
);
|
||||||
})
|
})
|
||||||
|
@ -61,12 +61,12 @@ export class TouchControl {
|
|||||||
* event, removes the keydown state, and removes the 'active' class from the node and the last touched element.
|
* event, removes the keydown state, and removes the 'active' class from the node and the last touched element.
|
||||||
*/
|
*/
|
||||||
bindKey(node: HTMLElement, key: string) {
|
bindKey(node: HTMLElement, key: string) {
|
||||||
node.addEventListener("touchstart", event => {
|
node.addEventListener("pointerdown", event => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
this.touchButtonDown(node, key);
|
this.touchButtonDown(node, key);
|
||||||
});
|
});
|
||||||
|
|
||||||
node.addEventListener("touchend", event => {
|
node.addEventListener("pointerup", event => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
this.touchButtonUp(node, key, event.target?.["id"]);
|
this.touchButtonUp(node, key, event.target?.["id"]);
|
||||||
});
|
});
|
||||||
|
@ -9,9 +9,9 @@ export const TOUCH_CONTROL_POSITIONS_PORTRAIT = "touchControlPositionsPortrait";
|
|||||||
type ControlPosition = { id: string; x: number; y: number };
|
type ControlPosition = { id: string; x: number; y: number };
|
||||||
|
|
||||||
type ConfigurationEventListeners = {
|
type ConfigurationEventListeners = {
|
||||||
touchstart: EventListener[];
|
pointerdown: EventListener[];
|
||||||
touchmove: EventListener[];
|
pointermove: EventListener[];
|
||||||
touchend: EventListener[];
|
pointerup: EventListener[];
|
||||||
};
|
};
|
||||||
|
|
||||||
type ToolbarRefs = {
|
type ToolbarRefs = {
|
||||||
@ -39,9 +39,9 @@ export class MoveTouchControlsHandler {
|
|||||||
* These are used to remove the event listeners when the configuration mode is disabled.
|
* These are used to remove the event listeners when the configuration mode is disabled.
|
||||||
*/
|
*/
|
||||||
private configurationEventListeners: ConfigurationEventListeners = {
|
private configurationEventListeners: ConfigurationEventListeners = {
|
||||||
touchstart: [],
|
pointerdown: [],
|
||||||
touchmove: [],
|
pointermove: [],
|
||||||
touchend: [],
|
pointerup: [],
|
||||||
};
|
};
|
||||||
|
|
||||||
private overlay: Phaser.GameObjects.Container;
|
private overlay: Phaser.GameObjects.Container;
|
||||||
@ -165,34 +165,33 @@ export class MoveTouchControlsHandler {
|
|||||||
/**
|
/**
|
||||||
* Start dragging the given button.
|
* Start dragging the given button.
|
||||||
* @param controlGroup The button that is being dragged.
|
* @param controlGroup The button that is being dragged.
|
||||||
* @param touch The touch event that started the drag.
|
* @param event The pointer event that started the drag.
|
||||||
*/
|
*/
|
||||||
private startDrag = (controlGroup: HTMLElement): void => {
|
private startDrag = (controlGroup: HTMLElement): void => {
|
||||||
this.draggingElement = controlGroup;
|
this.draggingElement = controlGroup;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Drags the currently dragged element to the given touch position.
|
* Drags the currently dragged element to the given pointer position.
|
||||||
* @param touch The touch event that is currently happening.
|
* @param event The pointer event that is currently happening.
|
||||||
* @param isLeft Whether the dragged element is a left button.
|
|
||||||
*/
|
*/
|
||||||
private drag = (touch: Touch): void => {
|
private drag = (event: PointerEvent): void => {
|
||||||
if (!this.draggingElement) {
|
if (!this.draggingElement) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const rect = this.draggingElement.getBoundingClientRect();
|
const rect = this.draggingElement.getBoundingClientRect();
|
||||||
// Map the touch position to the center of the dragged element.
|
// Map the pointer position to the center of the dragged element.
|
||||||
const xOffset = this.isLeft(this.draggingElement)
|
const xOffset = this.isLeft(this.draggingElement)
|
||||||
? touch.clientX - rect.width / 2
|
? event.clientX - rect.width / 2
|
||||||
: window.innerWidth - touch.clientX - rect.width / 2;
|
: window.innerWidth - event.clientX - rect.width / 2;
|
||||||
const yOffset = window.innerHeight - touch.clientY - rect.height / 2;
|
const yOffset = window.innerHeight - event.clientY - rect.height / 2;
|
||||||
this.setPosition(this.draggingElement, xOffset, yOffset);
|
this.setPosition(this.draggingElement, xOffset, yOffset);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stops dragging the currently dragged element.
|
* Stops dragging the currently dragged element.
|
||||||
*/
|
*/
|
||||||
private stopDrag = () => {
|
private stopDrag = (): void => {
|
||||||
this.draggingElement = null;
|
this.draggingElement = null;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -303,19 +302,19 @@ export class MoveTouchControlsHandler {
|
|||||||
*/
|
*/
|
||||||
private createConfigurationEventListeners(controlGroups: HTMLDivElement[]): ConfigurationEventListeners {
|
private createConfigurationEventListeners(controlGroups: HTMLDivElement[]): ConfigurationEventListeners {
|
||||||
return {
|
return {
|
||||||
touchstart: controlGroups.map((element: HTMLDivElement) => {
|
pointerdown: controlGroups.map((element: HTMLDivElement) => {
|
||||||
const startDrag = () => this.startDrag(element);
|
const startDrag = () => this.startDrag(element);
|
||||||
element.addEventListener("touchstart", startDrag, { passive: true });
|
element.addEventListener("pointerdown", startDrag, { passive: true });
|
||||||
return startDrag;
|
return startDrag;
|
||||||
}),
|
}),
|
||||||
touchmove: controlGroups.map(() => {
|
pointermove: controlGroups.map(() => {
|
||||||
const drag = event => this.drag(event.touches[0]);
|
const drag = (event: PointerEvent) => this.drag(event);
|
||||||
window.addEventListener("touchmove", drag, { passive: true });
|
window.addEventListener("pointermove", drag, { passive: true });
|
||||||
return drag;
|
return drag;
|
||||||
}),
|
}),
|
||||||
touchend: controlGroups.map(() => {
|
pointerup: controlGroups.map(() => {
|
||||||
const stopDrag = () => this.stopDrag();
|
const stopDrag = () => this.stopDrag();
|
||||||
window.addEventListener("touchend", stopDrag, { passive: true });
|
window.addEventListener("pointerup", stopDrag, { passive: true });
|
||||||
return stopDrag;
|
return stopDrag;
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
@ -373,12 +372,12 @@ export class MoveTouchControlsHandler {
|
|||||||
this.draggingElement = null;
|
this.draggingElement = null;
|
||||||
|
|
||||||
// Remove event listeners
|
// Remove event listeners
|
||||||
const { touchstart, touchmove, touchend } = this.configurationEventListeners;
|
const { pointerdown, pointermove, pointerup } = this.configurationEventListeners;
|
||||||
this.getControlGroupElements().forEach((element, index) =>
|
this.getControlGroupElements().forEach((element, index) =>
|
||||||
element.removeEventListener("touchstart", touchstart[index]),
|
element.removeEventListener("pointerdown", pointerdown[index]),
|
||||||
);
|
);
|
||||||
touchmove.forEach(listener => window.removeEventListener("touchmove", listener));
|
pointermove.forEach(listener => window.removeEventListener("pointermove", listener));
|
||||||
touchend.forEach(listener => window.removeEventListener("touchend", listener));
|
pointerup.forEach(listener => window.removeEventListener("pointerup", listener));
|
||||||
|
|
||||||
// Remove configuration toolbar
|
// Remove configuration toolbar
|
||||||
const toolbar = document.querySelector("#touchControls #configToolbar");
|
const toolbar = document.querySelector("#touchControls #configToolbar");
|
||||||
|
@ -111,7 +111,7 @@ class FakeMobile {
|
|||||||
if (!node) {
|
if (!node) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const event = new Event("touchstart");
|
const event = new Event("pointerdown");
|
||||||
node.dispatchEvent(event);
|
node.dispatchEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -120,7 +120,7 @@ class FakeMobile {
|
|||||||
if (!node) {
|
if (!node) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const event = new Event("touchend");
|
const event = new Event("pointerup");
|
||||||
node.dispatchEvent(event);
|
node.dispatchEvent(event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user