centralize module typing overrides (#1786)
* optimize typings with declaration file
This commit is contained in:
parent
d15c01378d
commit
872f05d2a7
|
@ -51,21 +51,6 @@ export interface InterfaceConfig {
|
||||||
|
|
||||||
const repeatInputDelayMillis = 250;
|
const repeatInputDelayMillis = 250;
|
||||||
|
|
||||||
// Phaser.Input.Gamepad.GamepadPlugin#refreshPads
|
|
||||||
declare module "phaser" {
|
|
||||||
namespace Input {
|
|
||||||
namespace Gamepad {
|
|
||||||
interface GamepadPlugin {
|
|
||||||
/**
|
|
||||||
* Refreshes the list of connected Gamepads.
|
|
||||||
* This is called automatically when a gamepad is connected or disconnected, and during the update loop.
|
|
||||||
*/
|
|
||||||
refreshPads(): void;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Manages and handles all input controls for the game, including keyboard and gamepad interactions.
|
* Manages and handles all input controls for the game, including keyboard and gamepad interactions.
|
||||||
*
|
*
|
||||||
|
|
64
src/main.ts
64
src/main.ts
|
@ -73,75 +73,13 @@ const config: Phaser.Types.Core.GameConfig = {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets this object's position relative to another object with a given offset
|
* Sets this object's position relative to another object with a given offset
|
||||||
* @param guideObject {@linkcode Phaser.GameObjects.GameObject} to base the position off of
|
|
||||||
* @param x The relative x position
|
|
||||||
* @param y The relative y position
|
|
||||||
*/
|
*/
|
||||||
const setPositionRelative = function (guideObject: any, x: number, y: number) {
|
const setPositionRelative = function (guideObject: Phaser.GameObjects.GameObject, x: number, y: number) {
|
||||||
const offsetX = guideObject.width * (-0.5 + (0.5 - guideObject.originX));
|
const offsetX = guideObject.width * (-0.5 + (0.5 - guideObject.originX));
|
||||||
const offsetY = guideObject.height * (-0.5 + (0.5 - guideObject.originY));
|
const offsetY = guideObject.height * (-0.5 + (0.5 - guideObject.originY));
|
||||||
this.setPosition(guideObject.x + offsetX + x, guideObject.y + offsetY + y);
|
this.setPosition(guideObject.x + offsetX + x, guideObject.y + offsetY + y);
|
||||||
};
|
};
|
||||||
|
|
||||||
declare module "phaser" {
|
|
||||||
namespace GameObjects {
|
|
||||||
interface Container {
|
|
||||||
/**
|
|
||||||
* Sets this object's position relative to another object with a given offset
|
|
||||||
* @param guideObject {@linkcode Phaser.GameObjects.GameObject} to base the position off of
|
|
||||||
* @param x The relative x position
|
|
||||||
* @param y The relative y position
|
|
||||||
*/
|
|
||||||
setPositionRelative(guideObject: any, x: number, y: number): void;
|
|
||||||
}
|
|
||||||
interface Sprite {
|
|
||||||
/**
|
|
||||||
* Sets this object's position relative to another object with a given offset
|
|
||||||
* @param guideObject {@linkcode Phaser.GameObjects.GameObject} to base the position off of
|
|
||||||
* @param x The relative x position
|
|
||||||
* @param y The relative y position
|
|
||||||
*/
|
|
||||||
setPositionRelative(guideObject: any, x: number, y: number): void;
|
|
||||||
}
|
|
||||||
interface Image {
|
|
||||||
/**
|
|
||||||
* Sets this object's position relative to another object with a given offset
|
|
||||||
* @param guideObject {@linkcode Phaser.GameObjects.GameObject} to base the position off of
|
|
||||||
* @param x The relative x position
|
|
||||||
* @param y The relative y position
|
|
||||||
*/
|
|
||||||
setPositionRelative(guideObject: any, x: number, y: number): void;
|
|
||||||
}
|
|
||||||
interface NineSlice {
|
|
||||||
/**
|
|
||||||
* Sets this object's position relative to another object with a given offset
|
|
||||||
* @param guideObject {@linkcode Phaser.GameObjects.GameObject} to base the position off of
|
|
||||||
* @param x The relative x position
|
|
||||||
* @param y The relative y position
|
|
||||||
*/
|
|
||||||
setPositionRelative(guideObject: any, x: number, y: number): void;
|
|
||||||
}
|
|
||||||
interface Text {
|
|
||||||
/**
|
|
||||||
* Sets this object's position relative to another object with a given offset
|
|
||||||
* @param guideObject {@linkcode Phaser.GameObjects.GameObject} to base the position off of
|
|
||||||
* @param x The relative x position
|
|
||||||
* @param y The relative y position
|
|
||||||
*/
|
|
||||||
setPositionRelative(guideObject: any, x: number, y: number): void;
|
|
||||||
}
|
|
||||||
interface Rectangle {
|
|
||||||
/**
|
|
||||||
* Sets this object's position relative to another object with a given offset
|
|
||||||
* @param guideObject {@linkcode Phaser.GameObjects.GameObject} to base the position off of
|
|
||||||
* @param x The relative x position
|
|
||||||
* @param y The relative y position
|
|
||||||
*/
|
|
||||||
setPositionRelative(guideObject: any, x: number, y: number): void;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Phaser.GameObjects.Container.prototype.setPositionRelative = setPositionRelative;
|
Phaser.GameObjects.Container.prototype.setPositionRelative = setPositionRelative;
|
||||||
Phaser.GameObjects.Sprite.prototype.setPositionRelative = setPositionRelative;
|
Phaser.GameObjects.Sprite.prototype.setPositionRelative = setPositionRelative;
|
||||||
Phaser.GameObjects.Image.prototype.setPositionRelative = setPositionRelative;
|
Phaser.GameObjects.Image.prototype.setPositionRelative = setPositionRelative;
|
||||||
|
|
|
@ -0,0 +1,68 @@
|
||||||
|
import "phaser";
|
||||||
|
|
||||||
|
declare module "phaser" {
|
||||||
|
namespace GameObjects {
|
||||||
|
interface GameObject {
|
||||||
|
width: number;
|
||||||
|
|
||||||
|
height: number;
|
||||||
|
|
||||||
|
originX: number;
|
||||||
|
|
||||||
|
originY: number;
|
||||||
|
|
||||||
|
x: number;
|
||||||
|
|
||||||
|
y: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Container {
|
||||||
|
/**
|
||||||
|
* Sets this object's position relative to another object with a given offset
|
||||||
|
*/
|
||||||
|
setPositionRelative(guideObject: any, x: number, y: number): void;
|
||||||
|
}
|
||||||
|
interface Sprite {
|
||||||
|
/**
|
||||||
|
* Sets this object's position relative to another object with a given offset
|
||||||
|
*/
|
||||||
|
setPositionRelative(guideObject: any, x: number, y: number): void;
|
||||||
|
}
|
||||||
|
interface Image {
|
||||||
|
/**
|
||||||
|
* Sets this object's position relative to another object with a given offset
|
||||||
|
*/
|
||||||
|
setPositionRelative(guideObject: any, x: number, y: number): void;
|
||||||
|
}
|
||||||
|
interface NineSlice {
|
||||||
|
/**
|
||||||
|
* Sets this object's position relative to another object with a given offset
|
||||||
|
*/
|
||||||
|
setPositionRelative(guideObject: any, x: number, y: number): void;
|
||||||
|
}
|
||||||
|
interface Text {
|
||||||
|
/**
|
||||||
|
* Sets this object's position relative to another object with a given offset
|
||||||
|
*/
|
||||||
|
setPositionRelative(guideObject: any, x: number, y: number): void;
|
||||||
|
}
|
||||||
|
interface Rectangle {
|
||||||
|
/**
|
||||||
|
* Sets this object's position relative to another object with a given offset
|
||||||
|
*/
|
||||||
|
setPositionRelative(guideObject: any, x: number, y: number): void;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace Input {
|
||||||
|
namespace Gamepad {
|
||||||
|
interface GamepadPlugin {
|
||||||
|
/**
|
||||||
|
* Refreshes the list of connected Gamepads.
|
||||||
|
* This is called automatically when a gamepad is connected or disconnected, and during the update loop.
|
||||||
|
*/
|
||||||
|
refreshPads(): void;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue