Skip to content

Commit

Permalink
send only the difference in imageUpdate
Browse files Browse the repository at this point in the history
  • Loading branch information
be195 committed Mar 30, 2024
1 parent c0efd16 commit 6b68486
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 10 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,16 +145,17 @@ ID (in 64-bit format) is specified in `data`.

#### `imageUpdate`
This OP code is sent only from the server whenever the image is changed.
The payload data contains the image and its difference between how it was updated
before and after.
The payload data contains its difference between how it was updated
before and after, as well as the Steam ID of the player (in 64-bit format)
who made the change.

##### Example payload
```json
{
"op": "imageUpdate",
"data": {
"image": [...],
"diff": {...}
"diff": {...},
"steamId": "76561198086180059"
}
}
```
Expand Down
4 changes: 2 additions & 2 deletions assets/externs.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ SteamResponse.prototype.avatar;

/** @interface */
function ImageUpdate() {}
/** @type {Array} */
ImageUpdate.prototype.image;
/** @type {Object} */
ImageUpdate.prototype.diff;
/** @type {string} */
ImageUpdate.prototype.steamId;
9 changes: 7 additions & 2 deletions assets/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,13 @@ class Artboard {
} break;

case 'imageUpdate': {
const { image } = /** @type {ImageUpdate} */ data;
this.data.image = image;
const { diff, steamId } = /** @type {ImageUpdate} */ data;
for (const position in diff) {
const color = diff[position] - 1;
const xy = parseInt(position);
this.data.steamIDs[xy] = steamId;
this.data.image[xy] = color;
}
} break;
}

Expand Down
2 changes: 1 addition & 1 deletion src/structures/Game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ export default class Game extends BaseStructure {
this.timeouts[steamID] = Date.now();

this.structures.Web.broadcast(WEBSOCKET_EVENTS.IMAGE_UPDATE, {
image: this.data.image,
diff: pixels,
steamId: steamID
});

this.structures.Web.broadcast(WEBSOCKET_EVENTS.EXECUTE_TIMEOUT, steamID);
Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ export interface WebSocketAPIEvents {
};
[WEBSOCKET_EVENTS.IMAGE_RESET]: true;
[WEBSOCKET_EVENTS.IMAGE_UPDATE]: {
image: number[];
diff: Record<number, number>;
steamId: string;
};
[WEBSOCKET_EVENTS.WRITE_ACCESS]: boolean;
}

0 comments on commit 6b68486

Please sign in to comment.