Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 5e69a63

Browse files
committedFeb 22, 2025
1.1.0
1 parent 7e304b5 commit 5e69a63

File tree

4 files changed

+179
-161
lines changed

4 files changed

+179
-161
lines changed
 

‎dist/display-list-watcher.es.js

Lines changed: 88 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,12 @@
11
import Phaser from "phaser";
2-
const chars = `ABCDEFGHIJKLMNOPQRSTUVWXYZ 12345abcdefghijklmnopqrstuvwxyz 67890{}[]()<>$*-+=/#_%^@\\&|~?'" !,.;:`;
3-
const charsPerRow = 32;
4-
const height = 13;
5-
const image = "proggy_clean_inv";
6-
const offset = { "x": 5, "y": 24 };
7-
const spacing = { "x": 0, "y": 0 };
8-
const width = 7;
92
const fontData = {
10-
chars,
11-
charsPerRow,
12-
height,
13-
image,
14-
offset,
15-
spacing,
16-
width
3+
chars: `ABCDEFGHIJKLMNOPQRSTUVWXYZ 12345abcdefghijklmnopqrstuvwxyz 67890{}[]()<>$*-+=/#_%^@\\&|~?'" !,.;:`,
4+
charsPerRow: 32,
5+
height: 13,
6+
image: "proggy_clean_inv",
7+
offset: { x: 5, y: 24 },
8+
spacing: { x: 0, y: 0 },
9+
width: 7
1710
};
1811
const fontImage = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAQ4AAABKCAMAAAB90UpZAAABEVBMVEUAAADUUP1/f398e3x+fn58fHx8fH3///97e3t6e3t5eXl3d3d2dXV2dXZzc3NzdHNxcnFxcXFvb29sbGxtbW1qamprampoaGhmZWVlZmVjY2JjY2NgX2BgYGBeXV5dXl1aWlpYWFdYV1dVVFVUVFVSUVJSUlJPT05PTk9MTEtMTExISUlISUhGRkZGRkVDQ0NCQ0M/QD9AP0A9PD06OTo6Ojk2Njc2Nzc0NDQ0MzMwMDEwMDAuLi0tLS4rKysqKisnKCcnJyckJSQlJSUiIiIfHx8gHx8cHB0ZGRkaGhoXGBcXFxcUFRUVFRQTEhISE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krIhR4XEAQIjjyRweR1XIaaMe1cFhPQ7RsBj37I4A7oY2FuRJmz5b9Q/Ie8ZxdOzmryCLAyT5inqXmjEX7sQ4VL5KzdlnKXJy2q53GKEV9w5ZcNnDuJyIZdpAOM7OW+aOlIgvvaRzqF2Po66hP7WoLi5bjiwApReJrETNmHm0+t7RHsfVVf91B4ovS5AWIUDbALq+aVGV9t4YmEa6az++CQCGgQAGht2nd1f+QLwKhG67CETzgmjdEO0HovNCdN+InhfR9yNKGVEpiGpD1PskGtJlPAcJ+yNWAAAAAElFTkSuQmCC";
1912
const twoSpaces = / {2,}/g;
@@ -73,30 +66,29 @@ const WalkDisplayListObj = (obj, output = [], currentDepth = 0, maxDepth = 10, m
7366
const { POSITIVE_INFINITY } = Number;
7467
const TextureEvents = Phaser.Textures.Events;
7568
const CacheEvents = Phaser.Cache.Events;
69+
const KeyboardEvents = Phaser.Input.Keyboard.Events;
7670
const SceneEvents = Phaser.Scenes.Events;
71+
const { KeyCodes } = Phaser.Input.Keyboard;
7772
const ParseRetroFont = Phaser.GameObjects.RetroFont.Parse;
7873
const fontTextureKey = fontData.image;
7974
const fontKey = fontData.image;
80-
let hasPendingFontImage = false;
8175
class DisplayListWatcher extends Phaser.Plugins.ScenePlugin {
8276
constructor(scene, pluginManager) {
8377
super(scene, pluginManager);
8478
this.camera = null;
8579
this.controls = null;
86-
this.hideKey = null;
8780
this.modKey = null;
88-
this.resetKey = null;
89-
this.showKey = null;
9081
this.text = null;
91-
this.toggleKey = null;
9282
}
9383
boot() {
9484
const { cache, events, settings, textures } = this.systems;
95-
if (!hasPendingFontImage && !textures.exists(fontTextureKey)) {
96-
hasPendingFontImage = true;
97-
textures.addBase64(fontKey, fontImage);
85+
if (!textures.exists(fontTextureKey)) {
86+
this.addImage(fontKey, fontImage);
9887
}
9988
textures.once(`${TextureEvents.ADD_KEY}${fontTextureKey}`, () => {
89+
if (cache.bitmapFont.has(fontKey)) {
90+
return;
91+
}
10092
cache.bitmapFont.add(fontKey, ParseRetroFont(this.scene, fontData));
10193
});
10294
if (settings.key === "__SYSTEM") {
@@ -109,77 +101,55 @@ class DisplayListWatcher extends Phaser.Plugins.ScenePlugin {
109101
this.start();
110102
}
111103
}
112-
startIfFontWasAdded(cache, key) {
104+
// For Phaser v3.87. Avoids errors from duplicate keys.
105+
addImage(key, url) {
106+
const { textures } = this.systems;
107+
if (textures.exists(key)) {
108+
}
109+
const image = new Image();
110+
image.onload = function onload() {
111+
image.onload = null;
112+
if (textures.exists(key)) {
113+
return;
114+
}
115+
textures.addImage(key, image);
116+
};
117+
image.src = url;
118+
}
119+
onFontCacheAdded(cache, key) {
113120
if (key !== fontKey) {
114121
return;
115122
}
116-
cache.events.off(CacheEvents.ADD, this.startIfFontWasAdded, this);
123+
cache.events.off(CacheEvents.ADD, this.onFontCacheAdded, this);
117124
this.start();
118125
}
119126
start() {
120-
const { cache, events, make, renderer } = this.systems;
127+
const { cache, events, input, make, renderer } = this.systems;
121128
const fontCache = cache.bitmapFont;
122-
const { keyboard } = this.systems.input;
123-
const { width: width2, height: height2 } = this.systems.scale;
129+
const keyboard = input == null ? void 0 : input.keyboard;
130+
const { width, height } = this.systems.scale;
124131
if (!fontCache.exists(fontKey)) {
125-
fontCache.events.on(CacheEvents.ADD, this.startIfFontWasAdded, this);
132+
fontCache.events.on(CacheEvents.ADD, this.onFontCacheAdded, this);
126133
return;
127134
}
128-
events.on(SceneEvents.UPDATE, this.update, this);
129135
events.on(SceneEvents.RENDER, this.render, this);
130-
this.camera = new Phaser.Cameras.Scene2D.Camera(
131-
0,
132-
0,
133-
width2,
134-
height2
135-
).setBounds(0, 0, POSITIVE_INFINITY, POSITIVE_INFINITY);
136-
this.controls = new Phaser.Cameras.Controls.FixedKeyControl({
137-
camera: this.camera,
138-
up: keyboard.addKey("UP"),
139-
down: keyboard.addKey("DOWN"),
140-
left: keyboard.addKey("LEFT"),
141-
right: keyboard.addKey("RIGHT"),
142-
speed: 1
143-
});
144-
this.modKey = keyboard.addKey("SHIFT");
145-
this.toggleKey = keyboard.addKey("Z");
146-
this.showKey = keyboard.addKey("X");
147-
this.hideKey = keyboard.addKey("C");
148-
this.resetKey = keyboard.addKey("V");
149-
this.toggleKey.on("down", (_key, event) => {
150-
if (event.shiftKey) {
151-
this.toggle();
152-
}
153-
});
154-
this.showKey.on("down", (_key, event) => {
155-
if (event.shiftKey) {
156-
this.show();
157-
}
158-
});
159-
this.hideKey.on("down", (_key, event) => {
160-
if (event.shiftKey) {
161-
this.hide();
162-
}
163-
});
164-
this.resetKey.on("down", (_key, event) => {
165-
if (event.shiftKey) {
166-
this.resetCamera();
167-
}
168-
});
136+
this.camera = new Phaser.Cameras.Scene2D.Camera(0, 0, width, height).setBounds(0, 0, POSITIVE_INFINITY, POSITIVE_INFINITY).setRoundPixels(true);
137+
if (keyboard) {
138+
events.on(SceneEvents.UPDATE, this.update, this);
139+
this.addKeyboardControls(keyboard);
140+
}
169141
this.text = make.bitmapText({ font: fontKey }, false);
170142
this.renderText = renderer.type === Phaser.WEBGL ? this.text.renderWebGL : this.text.renderCanvas;
171143
}
172144
stop() {
173145
const { cache, events, input, settings } = this.systems;
174-
const { keyboard } = input;
175-
cache.bitmapFont.events.off(CacheEvents.ADD, this.startIfFontWasAdded, this);
146+
const keyboard = input == null ? void 0 : input.keyboard;
147+
cache.bitmapFont.events.off(CacheEvents.ADD, this.onFontCacheAdded, this);
176148
events.off(SceneEvents.UPDATE, this.update, this);
177149
events.off(SceneEvents.RENDER, this.render, this);
178-
keyboard.removeKey(this.hideKey, true);
179-
keyboard.removeKey(this.modKey, true);
180-
keyboard.removeKey(this.resetKey, true);
181-
keyboard.removeKey(this.showKey, true);
182-
keyboard.removeKey(this.toggleKey, true);
150+
if (keyboard) {
151+
keyboard.off(KeyboardEvents.ANY_KEY_DOWN, this.onAnyKeyDown, this);
152+
}
183153
if (this.camera) {
184154
this.camera.destroy();
185155
}
@@ -195,11 +165,7 @@ class DisplayListWatcher extends Phaser.Plugins.ScenePlugin {
195165
}
196166
this.camera = null;
197167
this.controls = null;
198-
this.hideKey = null;
199168
this.modKey = null;
200-
this.resetKey = null;
201-
this.showKey = null;
202-
this.toggleKey = null;
203169
}
204170
update(_time, delta) {
205171
if (this.modKey.isDown) {
@@ -223,16 +189,36 @@ class DisplayListWatcher extends Phaser.Plugins.ScenePlugin {
223189
0
224190
);
225191
this.text.setPosition(x, y).setText(output);
192+
this.camera.setBounds(0, 0, POSITIVE_INFINITY, this.text.height);
226193
this.camera.preRender();
227194
this.renderText(renderer, this.text, this.camera);
228195
}
229196
destroy() {
230197
this.stop();
198+
this.systems.events.off(SceneEvents.START, this.start, this).off(SceneEvents.SHUTDOWN, this.stop, this).off(SceneEvents.DESTROY, this.destroy, this);
231199
this.pluginManager = null;
232200
this.game = null;
233201
this.scene = null;
234202
this.systems = null;
235203
}
204+
onAnyKeyDown(event) {
205+
if (!this.modKey.isDown) return;
206+
const method = this.keyMap[event.keyCode];
207+
if (!method) return;
208+
method.call(this);
209+
}
210+
addKeyboardControls(keyboard) {
211+
this.controls = new Phaser.Cameras.Controls.FixedKeyControl({
212+
camera: this.camera,
213+
up: keyboard.addKey(KeyCodes.UP),
214+
down: keyboard.addKey(KeyCodes.DOWN),
215+
left: keyboard.addKey(KeyCodes.LEFT),
216+
right: keyboard.addKey(KeyCodes.RIGHT),
217+
speed: 1
218+
});
219+
this.modKey = keyboard.addKey(KeyCodes.SHIFT);
220+
keyboard.on(KeyboardEvents.ANY_KEY_DOWN, this.onAnyKeyDown, this);
221+
}
236222
hide() {
237223
this.text.visible = false;
238224
}
@@ -245,7 +231,30 @@ class DisplayListWatcher extends Phaser.Plugins.ScenePlugin {
245231
resetCamera() {
246232
this.camera.setScroll(0, 0);
247233
}
234+
pageUp() {
235+
this.camera.scrollY -= this.camera.height;
236+
}
237+
pageDown() {
238+
this.camera.scrollY += this.camera.height;
239+
}
240+
pageStart() {
241+
this.camera.scrollY = 0;
242+
}
243+
pageEnd() {
244+
this.camera.scrollY = POSITIVE_INFINITY;
245+
}
248246
}
247+
const proto = DisplayListWatcher.prototype;
248+
proto.keyMap = {
249+
[KeyCodes.C]: proto.hide,
250+
[KeyCodes.END]: proto.pageEnd,
251+
[KeyCodes.HOME]: proto.pageStart,
252+
[KeyCodes.PAGE_DOWN]: proto.pageDown,
253+
[KeyCodes.PAGE_UP]: proto.pageUp,
254+
[KeyCodes.V]: proto.resetCamera,
255+
[KeyCodes.X]: proto.show,
256+
[KeyCodes.Z]: proto.toggle
257+
};
249258
export {
250259
DisplayListWatcher as default
251260
};

‎dist/display-list-watcher.umd.js

Lines changed: 88 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,14 @@
22
typeof exports === "object" && typeof module !== "undefined" ? module.exports = factory(require("phaser")) : typeof define === "function" && define.amd ? define(["phaser"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, global.DisplayListWatcher = factory(global.Phaser));
33
})(this, function(Phaser) {
44
"use strict";
5-
const chars = `ABCDEFGHIJKLMNOPQRSTUVWXYZ 12345abcdefghijklmnopqrstuvwxyz 67890{}[]()<>$*-+=/#_%^@\\&|~?'" !,.;:`;
6-
const charsPerRow = 32;
7-
const height = 13;
8-
const image = "proggy_clean_inv";
9-
const offset = { "x": 5, "y": 24 };
10-
const spacing = { "x": 0, "y": 0 };
11-
const width = 7;
125
const fontData = {
13-
chars,
14-
charsPerRow,
15-
height,
16-
image,
17-
offset,
18-
spacing,
19-
width
6+
chars: `ABCDEFGHIJKLMNOPQRSTUVWXYZ 12345abcdefghijklmnopqrstuvwxyz 67890{}[]()<>$*-+=/#_%^@\\&|~?'" !,.;:`,
7+
charsPerRow: 32,
8+
height: 13,
9+
image: "proggy_clean_inv",
10+
offset: { x: 5, y: 24 },
11+
spacing: { x: 0, y: 0 },
12+
width: 7
2013
};
2114
const fontImage = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAQ4AAABKCAMAAAB90UpZAAABEVBMVEUAAADUUP1/f398e3x+fn58fHx8f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W41qkywJZm7hSNSkONRTqeysBMVQoxzE1bUxan/RWlOAgleKwHFAcykLrUo1iX94DtThmZkMBhr/hZTioxWFcEhyqaNXzGEcbzTI3LziGDhb1SbwzihaDKsCBN1SHY2FRgiWTShM+rGJF63HECVlM+n0C/EatSUGEWTImy9rScmcDItWH8umU38pqNxcEpG+AY229bv+M6wPhoE8BsLHZWPhto5Gt+9FspDPcnfdv9H+ZEKCXkNna1nPTXJBF3h3JqAtYxhAJYnyUxDi6YrOz2xYHBcGsLujUui8cCHsOfePY2y/AYZYkrIhR4XEAQIjjyRweR1XIaaMe1cFhPQ7RsBj37I4A7oY2FuRJmz5b9Q/Ie8ZxdOzmryCLAyT5inqXmjEX7sQ4VL5KzdlnKXJy2q53GKEV9w5ZcNnDuJyIZdpAOM7OW+aOlIgvvaRzqF2Po66hP7WoLi5bjiwApReJrETNmHm0+t7RHsfVVf91B4ovS5AWIUDbALq+aVGV9t4YmEa6az++CQCGgQAGht2nd1f+QLwKhG67CETzgmjdEO0HovNCdN+InhfR9yNKGVEpiGpD1PskGtJlPAcJ+yNWAAAAAElFTkSuQmCC";
2215
const twoSpaces = / {2,}/g;
@@ -76,30 +69,29 @@
7669
const { POSITIVE_INFINITY } = Number;
7770
const TextureEvents = Phaser.Textures.Events;
7871
const CacheEvents = Phaser.Cache.Events;
72+
const KeyboardEvents = Phaser.Input.Keyboard.Events;
7973
const SceneEvents = Phaser.Scenes.Events;
74+
const { KeyCodes } = Phaser.Input.Keyboard;
8075
const ParseRetroFont = Phaser.GameObjects.RetroFont.Parse;
8176
const fontTextureKey = fontData.image;
8277
const fontKey = fontData.image;
83-
let hasPendingFontImage = false;
8478
class DisplayListWatcher extends Phaser.Plugins.ScenePlugin {
8579
constructor(scene, pluginManager) {
8680
super(scene, pluginManager);
8781
this.camera = null;
8882
this.controls = null;
89-
this.hideKey = null;
9083
this.modKey = null;
91-
this.resetKey = null;
92-
this.showKey = null;
9384
this.text = null;
94-
this.toggleKey = null;
9585
}
9686
boot() {
9787
const { cache, events, settings, textures } = this.systems;
98-
if (!hasPendingFontImage && !textures.exists(fontTextureKey)) {
99-
hasPendingFontImage = true;
100-
textures.addBase64(fontKey, fontImage);
88+
if (!textures.exists(fontTextureKey)) {
89+
this.addImage(fontKey, fontImage);
10190
}
10291
textures.once(`${TextureEvents.ADD_KEY}${fontTextureKey}`, () => {
92+
if (cache.bitmapFont.has(fontKey)) {
93+
return;
94+
}
10395
cache.bitmapFont.add(fontKey, ParseRetroFont(this.scene, fontData));
10496
});
10597
if (settings.key === "__SYSTEM") {
@@ -112,77 +104,55 @@
112104
this.start();
113105
}
114106
}
115-
startIfFontWasAdded(cache, key) {
107+
// For Phaser v3.87. Avoids errors from duplicate keys.
108+
addImage(key, url) {
109+
const { textures } = this.systems;
110+
if (textures.exists(key)) {
111+
}
112+
const image = new Image();
113+
image.onload = function onload() {
114+
image.onload = null;
115+
if (textures.exists(key)) {
116+
return;
117+
}
118+
textures.addImage(key, image);
119+
};
120+
image.src = url;
121+
}
122+
onFontCacheAdded(cache, key) {
116123
if (key !== fontKey) {
117124
return;
118125
}
119-
cache.events.off(CacheEvents.ADD, this.startIfFontWasAdded, this);
126+
cache.events.off(CacheEvents.ADD, this.onFontCacheAdded, this);
120127
this.start();
121128
}
122129
start() {
123-
const { cache, events, make, renderer } = this.systems;
130+
const { cache, events, input, make, renderer } = this.systems;
124131
const fontCache = cache.bitmapFont;
125-
const { keyboard } = this.systems.input;
126-
const { width: width2, height: height2 } = this.systems.scale;
132+
const keyboard = input == null ? void 0 : input.keyboard;
133+
const { width, height } = this.systems.scale;
127134
if (!fontCache.exists(fontKey)) {
128-
fontCache.events.on(CacheEvents.ADD, this.startIfFontWasAdded, this);
135+
fontCache.events.on(CacheEvents.ADD, this.onFontCacheAdded, this);
129136
return;
130137
}
131-
events.on(SceneEvents.UPDATE, this.update, this);
132138
events.on(SceneEvents.RENDER, this.render, this);
133-
this.camera = new Phaser.Cameras.Scene2D.Camera(
134-
0,
135-
0,
136-
width2,
137-
height2
138-
).setBounds(0, 0, POSITIVE_INFINITY, POSITIVE_INFINITY);
139-
this.controls = new Phaser.Cameras.Controls.FixedKeyControl({
140-
camera: this.camera,
141-
up: keyboard.addKey("UP"),
142-
down: keyboard.addKey("DOWN"),
143-
left: keyboard.addKey("LEFT"),
144-
right: keyboard.addKey("RIGHT"),
145-
speed: 1
146-
});
147-
this.modKey = keyboard.addKey("SHIFT");
148-
this.toggleKey = keyboard.addKey("Z");
149-
this.showKey = keyboard.addKey("X");
150-
this.hideKey = keyboard.addKey("C");
151-
this.resetKey = keyboard.addKey("V");
152-
this.toggleKey.on("down", (_key, event) => {
153-
if (event.shiftKey) {
154-
this.toggle();
155-
}
156-
});
157-
this.showKey.on("down", (_key, event) => {
158-
if (event.shiftKey) {
159-
this.show();
160-
}
161-
});
162-
this.hideKey.on("down", (_key, event) => {
163-
if (event.shiftKey) {
164-
this.hide();
165-
}
166-
});
167-
this.resetKey.on("down", (_key, event) => {
168-
if (event.shiftKey) {
169-
this.resetCamera();
170-
}
171-
});
139+
this.camera = new Phaser.Cameras.Scene2D.Camera(0, 0, width, height).setBounds(0, 0, POSITIVE_INFINITY, POSITIVE_INFINITY).setRoundPixels(true);
140+
if (keyboard) {
141+
events.on(SceneEvents.UPDATE, this.update, this);
142+
this.addKeyboardControls(keyboard);
143+
}
172144
this.text = make.bitmapText({ font: fontKey }, false);
173145
this.renderText = renderer.type === Phaser.WEBGL ? this.text.renderWebGL : this.text.renderCanvas;
174146
}
175147
stop() {
176148
const { cache, events, input, settings } = this.systems;
177-
const { keyboard } = input;
178-
cache.bitmapFont.events.off(CacheEvents.ADD, this.startIfFontWasAdded, this);
149+
const keyboard = input == null ? void 0 : input.keyboard;
150+
cache.bitmapFont.events.off(CacheEvents.ADD, this.onFontCacheAdded, this);
179151
events.off(SceneEvents.UPDATE, this.update, this);
180152
events.off(SceneEvents.RENDER, this.render, this);
181-
keyboard.removeKey(this.hideKey, true);
182-
keyboard.removeKey(this.modKey, true);
183-
keyboard.removeKey(this.resetKey, true);
184-
keyboard.removeKey(this.showKey, true);
185-
keyboard.removeKey(this.toggleKey, true);
153+
if (keyboard) {
154+
keyboard.off(KeyboardEvents.ANY_KEY_DOWN, this.onAnyKeyDown, this);
155+
}
186156
if (this.camera) {
187157
this.camera.destroy();
188158
}
@@ -198,11 +168,7 @@
198168
}
199169
this.camera = null;
200170
this.controls = null;
201-
this.hideKey = null;
202171
this.modKey = null;
203-
this.resetKey = null;
204-
this.showKey = null;
205-
this.toggleKey = null;
206172
}
207173
update(_time, delta) {
208174
if (this.modKey.isDown) {
@@ -226,16 +192,36 @@
226192
0
227193
);
228194
this.text.setPosition(x, y).setText(output);
195+
this.camera.setBounds(0, 0, POSITIVE_INFINITY, this.text.height);
229196
this.camera.preRender();
230197
this.renderText(renderer, this.text, this.camera);
231198
}
232199
destroy() {
233200
this.stop();
201+
this.systems.events.off(SceneEvents.START, this.start, this).off(SceneEvents.SHUTDOWN, this.stop, this).off(SceneEvents.DESTROY, this.destroy, this);
234202
this.pluginManager = null;
235203
this.game = null;
236204
this.scene = null;
237205
this.systems = null;
238206
}
207+
onAnyKeyDown(event) {
208+
if (!this.modKey.isDown) return;
209+
const method = this.keyMap[event.keyCode];
210+
if (!method) return;
211+
method.call(this);
212+
}
213+
addKeyboardControls(keyboard) {
214+
this.controls = new Phaser.Cameras.Controls.FixedKeyControl({
215+
camera: this.camera,
216+
up: keyboard.addKey(KeyCodes.UP),
217+
down: keyboard.addKey(KeyCodes.DOWN),
218+
left: keyboard.addKey(KeyCodes.LEFT),
219+
right: keyboard.addKey(KeyCodes.RIGHT),
220+
speed: 1
221+
});
222+
this.modKey = keyboard.addKey(KeyCodes.SHIFT);
223+
keyboard.on(KeyboardEvents.ANY_KEY_DOWN, this.onAnyKeyDown, this);
224+
}
239225
hide() {
240226
this.text.visible = false;
241227
}
@@ -248,6 +234,29 @@
248234
resetCamera() {
249235
this.camera.setScroll(0, 0);
250236
}
237+
pageUp() {
238+
this.camera.scrollY -= this.camera.height;
239+
}
240+
pageDown() {
241+
this.camera.scrollY += this.camera.height;
242+
}
243+
pageStart() {
244+
this.camera.scrollY = 0;
245+
}
246+
pageEnd() {
247+
this.camera.scrollY = POSITIVE_INFINITY;
248+
}
251249
}
250+
const proto = DisplayListWatcher.prototype;
251+
proto.keyMap = {
252+
[KeyCodes.C]: proto.hide,
253+
[KeyCodes.END]: proto.pageEnd,
254+
[KeyCodes.HOME]: proto.pageStart,
255+
[KeyCodes.PAGE_DOWN]: proto.pageDown,
256+
[KeyCodes.PAGE_UP]: proto.pageUp,
257+
[KeyCodes.V]: proto.resetCamera,
258+
[KeyCodes.X]: proto.show,
259+
[KeyCodes.Z]: proto.toggle
260+
};
252261
return DisplayListWatcher;
253262
});

‎package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "phaser-plugin-display-list-watcher",
3-
"version": "1.0.2",
3+
"version": "1.1.0",
44
"description": "Shows the scene display lists",
55
"keywords": [
66
"phaser",

0 commit comments

Comments
 (0)
Please sign in to comment.