give extensions a way to hook into pixel updates via

window.registerPixelUpdates
This commit is contained in:
HF 2022-11-11 00:51:05 +01:00
parent 65269f5af7
commit 9e11ea3729
2 changed files with 12 additions and 0 deletions

View File

@ -1,6 +1,8 @@
/*
* sends events via window.pixelPlanetEvents to potential
* Extensions and Userscripts
* Also check out ui/PixelTransferController.js, which sends received
* pixels to a window.registerPixelUpdates callback
*
*/

View File

@ -28,6 +28,13 @@ class PixelTransferController {
* [[i, j, offset, colorold, colornew], ...]
*/
this.clientPredictions = [];
/*
* allow extensions to hook into pixel updates
*/
this.extension = null;
window.registerPixelUpdates = (cb) => {
this.extension = cb;
};
}
initialize(store, socketClient, getRenderer) {
@ -211,6 +218,9 @@ class PixelTransferController {
j,
pixels,
}) {
if (this.extension) {
this.extension(i, j, pixels);
}
pixels.forEach((pxl) => {
const [offset, color] = pxl;
const { clientPredictions } = this;