Skip to content

Commit

Permalink
feat: QOL Update import site for ex.Input (#2697)
Browse files Browse the repository at this point in the history
This PR deprecates the old `ex.Input.*` import site in favor of just importing off of `ex.*`. 

This is a quality of life improvement, it is rather annoying to need to either import `Input` to use input types, or to type `ex.Input.SomeImport` to use a type.

The old import site will continue to work for now, you'll just see the deprecation warning in the editor.
  • Loading branch information
eonarheim authored Jul 18, 2023
1 parent 2903fe0 commit 83f08d8
Show file tree
Hide file tree
Showing 47 changed files with 480 additions and 260 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).

### Deprecated

- The `ex.Input.*` import site is deprecated, will be removed in v0.29.0. All the imports are still available on `ex.` now
- [[ex.Input.Gamepad]] `isButtonPressed` has been renamed to `isButtonHeld`
- `ex.EventDispatcher` is marked deprecated, will eventually be removed in v0.29.0

Expand Down
44 changes: 22 additions & 22 deletions sandbox/src/game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ var game = new ex.Engine({
canvasElementId: 'game',
pixelRatio: 1,
suppressPlayButton: true,
pointerScope: ex.Input.PointerScope.Canvas,
pointerScope: ex.PointerScope.Canvas,
displayMode: ex.DisplayMode.FitScreenAndFill,
antialiasing: false,
snapToPixel: false,
Expand Down Expand Up @@ -623,7 +623,7 @@ var airSpeed = 130;
var jumpSpeed = 500;
var direction = 1;
player.on('postupdate', () => {
if (game.input.keyboard.isHeld(ex.Input.Keys.Left)) {
if (game.input.keyboard.isHeld(ex.Keys.Left)) {
direction = -1;
if (!inAir) {
player.graphics.use(Animations.Left);
Expand All @@ -633,7 +633,7 @@ player.on('postupdate', () => {
return;
}
player.vel.x = -groundSpeed;
} else if (game.input.keyboard.isHeld(ex.Input.Keys.Right)) {
} else if (game.input.keyboard.isHeld(ex.Keys.Right)) {
direction = 1;
if (!inAir) {
player.graphics.use(Animations.Right);
Expand All @@ -645,7 +645,7 @@ player.on('postupdate', () => {
player.vel.x = groundSpeed;
}

if (game.input.keyboard.isHeld(ex.Input.Keys.Up)) {
if (game.input.keyboard.isHeld(ex.Keys.Up)) {
if (!inAir) {
player.vel.y = -jumpSpeed;
inAir = true;
Expand All @@ -659,15 +659,15 @@ player.on('postupdate', () => {
}
});

game.input.keyboard.on('up', (e?: ex.Input.KeyEvent) => {
game.input.keyboard.on('up', (e?: ex.KeyEvent) => {
if (inAir) return;

if (e.key === ex.Input.Keys.Left || e.key === ex.Input.Keys.Right) {
if (e.key === ex.Keys.Left || e.key === ex.Keys.Right) {
player.graphics.use(Animations.Idle);
}
});

player.on('pointerdown', (e?: ex.Input.PointerEvent) => {
player.on('pointerdown', (e?: ex.PointerEvent) => {
// alert('Player clicked!');
});
player.on('pointerdown', () => {
Expand Down Expand Up @@ -702,8 +702,8 @@ newScene.on('foo', (ev: ex.GameEvent<any>) => {});

game.addScene('label', newScene);

game.input.keyboard.on('down', (keyDown?: ex.Input.KeyEvent) => {
if (keyDown.key === ex.Input.Keys.F) {
game.input.keyboard.on('down', (keyDown?: ex.KeyEvent) => {
if (keyDown.key === ex.Keys.F) {
var a = new ex.Actor({x: player.pos.x + 10, y: player.pos.y - 50, width: 10, height: 10, color: new ex.Color(222, 222, 222)});
a.vel.x = 200 * direction;
a.vel.y = 0;
Expand All @@ -724,9 +724,9 @@ game.input.keyboard.on('down', (keyDown?: ex.Input.KeyEvent) => {
inAir = true;
});
game.add(a);
} else if (keyDown.key === ex.Input.Keys.U) {
} else if (keyDown.key === ex.Keys.U) {
game.goToScene('label');
} else if (keyDown.key === ex.Input.Keys.I) {
} else if (keyDown.key === ex.Keys.I) {
game.goToScene('root');
}
});
Expand All @@ -743,10 +743,10 @@ player.on('postcollision', (data: ex.PostCollisionEvent) => {
if (
data.other &&
!(
game.input.keyboard.isHeld(ex.Input.Keys.Left) ||
game.input.keyboard.isHeld(ex.Input.Keys.Right) ||
game.input.keyboard.isHeld(ex.Input.Keys.Up) ||
game.input.keyboard.isHeld(ex.Input.Keys.Down)
game.input.keyboard.isHeld(ex.Keys.Left) ||
game.input.keyboard.isHeld(ex.Keys.Right) ||
game.input.keyboard.isHeld(ex.Keys.Up) ||
game.input.keyboard.isHeld(ex.Keys.Down)
)
) {
player.vel.x = data.other.vel.x;
Expand Down Expand Up @@ -785,14 +785,14 @@ player.on('initialize', (evt?: ex.InitializeEvent) => {
console.log('Player initialized', evt.engine);
});

game.input.keyboard.on('down', (keyDown?: ex.Input.KeyEvent) => {
if (keyDown.key === ex.Input.Keys.B) {
game.input.keyboard.on('down', (keyDown?: ex.KeyEvent) => {
if (keyDown.key === ex.Keys.B) {
var block = new ex.Actor({x: currentX, y: 350, width: 44, height: 50, color: color});
currentX += 46;
block.graphics.add(blockAnimation);
game.add(block);
}
if (keyDown.key === ex.Input.Keys.D) {
if (keyDown.key === ex.Keys.D) {
game.toggleDebug();
}
});
Expand Down Expand Up @@ -866,7 +866,7 @@ var trigger = new ex.Trigger({

game.add(trigger);

game.input.pointers.primary.on('down', (evt: ex.Input.PointerEvent) => {
game.input.pointers.primary.on('down', (evt: ex.PointerEvent) => {
var c = tileMap.getTileByPoint(evt.worldPos);
if (c) {
if (c.solid) {
Expand All @@ -879,11 +879,11 @@ game.input.pointers.primary.on('down', (evt: ex.Input.PointerEvent) => {
}
});

game.input.keyboard.on('up', (evt?: ex.Input.KeyEvent) => {
if (evt.key == ex.Input.Keys.F) {
game.input.keyboard.on('up', (evt?: ex.KeyEvent) => {
if (evt.key == ex.Keys.F) {
jump.play();
}
if (evt.key == ex.Input.Keys.S) {
if (evt.key == ex.Keys.S) {
jump.stop();
}
});
Expand Down
8 changes: 4 additions & 4 deletions sandbox/tests/arcadecollider/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ var player = new ex.Actor({
player.onPostUpdate = () => {
player.vel.setTo(0, 0);
const speed = 64;
if (game.input.keyboard.isHeld(ex.Input.Keys.Right)) {
if (game.input.keyboard.isHeld(ex.Keys.Right)) {
player.vel.x = speed;
}
if (game.input.keyboard.isHeld(ex.Input.Keys.Left)) {
if (game.input.keyboard.isHeld(ex.Keys.Left)) {
player.vel.x = -speed;
}
if (game.input.keyboard.isHeld(ex.Input.Keys.Up)) {
if (game.input.keyboard.isHeld(ex.Keys.Up)) {
player.vel.y = -speed;
}
if (game.input.keyboard.isHeld(ex.Input.Keys.Down)) {
if (game.input.keyboard.isHeld(ex.Keys.Down)) {
player.vel.y = speed;
}
}
Expand Down
8 changes: 4 additions & 4 deletions sandbox/tests/boundingbox/bbtester.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,24 @@ var block2 = new ex.Actor({

// Set drag flag
var boxPointerDragging = false;
block2.on('pointerdragstart', (pe: ex.Input.PointerEvent) => {
block2.on('pointerdragstart', (pe: ex.PointerEvent) => {
boxPointerDragging = true;
});

// Set drag flag
block2.on('pointerdragend', (pe: ex.Input.PointerEvent) => {
block2.on('pointerdragend', (pe: ex.PointerEvent) => {
boxPointerDragging = false;
});

// Drag box around
block2.on('pointerdragmove', (pe: ex.Input.PointerEvent) => {
block2.on('pointerdragmove', (pe: ex.PointerEvent) => {
if (boxPointerDragging) {
block2.pos = pe.worldPos;
}
});

// Drag box around
block2.on('pointerdragleave', (pe: ex.Input.PointerEvent) => {
block2.on('pointerdragleave', (pe: ex.PointerEvent) => {
if (boxPointerDragging) {
block2.pos = pe.worldPos;
}
Expand Down
4 changes: 2 additions & 2 deletions sandbox/tests/camera/lerp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
var game = new ex.Engine({
width: 600,
height: 400,
pointerScope: ex.Input.PointerScope.Canvas
pointerScope: ex.PointerScope.Canvas
});
var actor = new ex.Actor({x: 100, y: 100, width: 50, height: 50, color: ex.Color.Red});

Expand All @@ -13,7 +13,7 @@ game.start().then(() => {});

var easingFn = ex.EasingFunctions.EaseInOutQuad;

game.input.pointers.primary.on('down', (evt: ex.Input.PointerEvent) => {
game.input.pointers.primary.on('down', (evt: ex.PointerEvent) => {
game.currentScene.camera.move(new ex.Vector(evt.worldPos.x, evt.worldPos.y), 500, easingFn).then((v) => onLerpEnd(v));
document.getElementById('lerp-false').style.display = 'none';
document.getElementById('lerp-true').style.display = 'inline';
Expand Down
2 changes: 1 addition & 1 deletion sandbox/tests/camera/strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
var game = new ex.Engine({
width: 600,
height: 400,
pointerScope: ex.Input.PointerScope.Canvas
pointerScope: ex.PointerScope.Canvas
});
var actor = new ex.Actor({x: 100, y: 100, width: 50, height: 50, color: ex.Color.Red});

Expand Down
2 changes: 1 addition & 1 deletion sandbox/tests/camera/zoom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ var actor = new ex.Actor({
game.add(actor);

var zoomedIn = false;
game.input.pointers.primary.on('down', (evt: ex.Input.PointerEvent) => {
game.input.pointers.primary.on('down', (evt: ex.PointerEvent) => {
if (!zoomedIn) {
zoomedIn = true;
game.currentScene.camera.zoomOverTime(5, 1000);
Expand Down
8 changes: 4 additions & 4 deletions sandbox/tests/collisionvelocity/vel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var engine = new ex.Engine({
canvasElementId: 'game',
width: 800,
height: 300,
pointerScope: ex.Input.PointerScope.Canvas
pointerScope: ex.PointerScope.Canvas
});
engine.showDebug(true);
engine.debug.body.showAll = true;
Expand All @@ -30,13 +30,13 @@ var player = new ex.Actor({
});

player.update = (e, ms) => {
if (engine.input.keyboard.isHeld(ex.Input.Keys.Space)) {
if (engine.input.keyboard.isHeld(ex.Keys.Space)) {
player.vel.x = 0;
}
if (engine.input.keyboard.isHeld(ex.Input.Keys.Left)) {
if (engine.input.keyboard.isHeld(ex.Keys.Left)) {
player.vel.x -= 10;
}
if (engine.input.keyboard.isHeld(ex.Input.Keys.Right)) {
if (engine.input.keyboard.isHeld(ex.Keys.Right)) {
player.vel.x += 10;
}
ex.Actor.prototype.update.call(player, e, ms);
Expand Down
22 changes: 11 additions & 11 deletions sandbox/tests/culling/culling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,28 @@ player.graphics.add('default', playerSprite);
//player.currentDrawing.scale = new ex.Point(0.5, 0.5);
engine.currentScene.add(player);

engine.input.keyboard.on('down', (keyDown?: ex.Input.KeyEvent) => {
if (keyDown.key === ex.Input.Keys.D) {
engine.input.keyboard.on('down', (keyDown?: ex.KeyEvent) => {
if (keyDown.key === ex.Keys.D) {
engine.toggleDebug();
} else if (keyDown.key === ex.Input.Keys.Up) {
} else if (keyDown.key === ex.Keys.Up) {
player.vel.y = -speed;
} else if (keyDown.key === ex.Input.Keys.Down) {
} else if (keyDown.key === ex.Keys.Down) {
player.vel.y = speed;
} else if (keyDown.key === ex.Input.Keys.Left) {
} else if (keyDown.key === ex.Keys.Left) {
player.vel.x = -speed;
} else if (keyDown.key === ex.Input.Keys.Right) {
} else if (keyDown.key === ex.Keys.Right) {
player.vel.x = speed;
}
});

engine.input.keyboard.on('up', (keyUp?: ex.Input.KeyEvent) => {
if (keyUp.key === ex.Input.Keys.Up) {
engine.input.keyboard.on('up', (keyUp?: ex.KeyEvent) => {
if (keyUp.key === ex.Keys.Up) {
player.vel.y = 0;
} else if (keyUp.key === ex.Input.Keys.Down) {
} else if (keyUp.key === ex.Keys.Down) {
player.vel.y = 0;
} else if (keyUp.key === ex.Input.Keys.Left) {
} else if (keyUp.key === ex.Keys.Left) {
player.vel.x = 0;
} else if (keyUp.key === ex.Input.Keys.Right) {
} else if (keyUp.key === ex.Keys.Right) {
player.vel.x = 0;
}
});
Expand Down
2 changes: 1 addition & 1 deletion sandbox/tests/debug/stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ floor.collider.useBoxCollider(50, 50);
game.add(floor);

game.input.keyboard.on('press', (evt) => {
if (evt.key === ex.Input.Keys.B) {
if (evt.key === ex.Keys.B) {
spawnBox();
}
});
Expand Down
6 changes: 3 additions & 3 deletions sandbox/tests/engine/timescale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ var game = new ex.Engine({
height: 400
});

game.input.keyboard.on('up', (ev: ex.Input.KeyEvent) => {
if (ev.key === ex.Input.Keys.W) {
game.input.keyboard.on('up', (ev: ex.KeyEvent) => {
if (ev.key === ex.Keys.W) {
increaseTimescale();
} else if (ev.key === ex.Input.Keys.S) {
} else if (ev.key === ex.Keys.S) {
decreaseTimescale();
}
});
Expand Down
2 changes: 1 addition & 1 deletion sandbox/tests/gotoscene/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Scene1 extends ex.Scene {

_engine.input.pointers.primary.on(
"down",
(event: ex.Input.PointerEvent): void => {
(event: ex.PointerEvent): void => {
_engine.goToScene("scene2");
}
);
Expand Down
6 changes: 3 additions & 3 deletions sandbox/tests/incorrectside/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ class Player4 extends ex.Actor {
console.log(this.collisions);
this.collisions = [];

if (engine.input.keyboard.wasPressed(ex.Input.Keys.ArrowUp)) {
if (engine.input.keyboard.wasPressed(ex.Keys.ArrowUp)) {
this.vel.y = -400;
}

if (engine.input.keyboard.isHeld(ex.Input.Keys.ArrowLeft)) {
if (engine.input.keyboard.isHeld(ex.Keys.ArrowLeft)) {
this.vel.x = -100;
} else if (engine.input.keyboard.isHeld(ex.Input.Keys.ArrowRight)) {
} else if (engine.input.keyboard.isHeld(ex.Keys.ArrowRight)) {
this.vel.x = 100;
} else {
this.vel.x = 0;
Expand Down
40 changes: 20 additions & 20 deletions sandbox/tests/input/gamepad.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,22 @@ function start() {

// Buttons
var buttonDefs = [
[ex.Input.Buttons.Face1, 544, 221],
[ex.Input.Buttons.Face2, 573, 193],
[ex.Input.Buttons.Face3, 516, 193],
[ex.Input.Buttons.Face4, 544, 166],
[ex.Input.Buttons.LeftBumper, 250, 100],
[ex.Input.Buttons.RightBumper, 547, 100],
[ex.Input.Buttons.LeftTrigger, 270, 88],
[ex.Input.Buttons.RightTrigger, 524, 88],
[ex.Input.Buttons.Select, 365, 193],
[ex.Input.Buttons.Start, 436, 193],
[ex.Input.Buttons.LeftStick, 330, 272],
[ex.Input.Buttons.RightStick, 470, 272],
[ex.Input.Buttons.DpadUp, 255, 166],
[ex.Input.Buttons.DpadDown, 255, 222],
[ex.Input.Buttons.DpadLeft, 227, 193],
[ex.Input.Buttons.DpadRight, 284, 193]
[ex.Buttons.Face1, 544, 221],
[ex.Buttons.Face2, 573, 193],
[ex.Buttons.Face3, 516, 193],
[ex.Buttons.Face4, 544, 166],
[ex.Buttons.LeftBumper, 250, 100],
[ex.Buttons.RightBumper, 547, 100],
[ex.Buttons.LeftTrigger, 270, 88],
[ex.Buttons.RightTrigger, 524, 88],
[ex.Buttons.Select, 365, 193],
[ex.Buttons.Start, 436, 193],
[ex.Buttons.LeftStick, 330, 272],
[ex.Buttons.RightStick, 470, 272],
[ex.Buttons.DpadUp, 255, 166],
[ex.Buttons.DpadDown, 255, 222],
[ex.Buttons.DpadLeft, 227, 193],
[ex.Buttons.DpadRight, 284, 193]
];
var buttons: { [key: number]: CircleActor } = {};

Expand All @@ -75,10 +75,10 @@ function start() {

if (pad1) {
// sticks
var leftAxisX = pad1.getAxes(ex.Input.Axes.LeftStickX);
var leftAxisY = pad1.getAxes(ex.Input.Axes.LeftStickY);
var rightAxisX = pad1.getAxes(ex.Input.Axes.RightStickX);
var rightAxisY = pad1.getAxes(ex.Input.Axes.RightStickY);
var leftAxisX = pad1.getAxes(ex.Axes.LeftStickX);
var leftAxisY = pad1.getAxes(ex.Axes.LeftStickY);
var rightAxisX = pad1.getAxes(ex.Axes.RightStickX);
var rightAxisY = pad1.getAxes(ex.Axes.RightStickY);

leftStick.pos = ex.vec(330 + leftAxisX * 20, 272 + leftAxisY * 20);
rightStick.pos = ex.vec(470 + rightAxisX * 20, 272 + rightAxisY * 20);
Expand Down
Loading

0 comments on commit 83f08d8

Please sign in to comment.