此脚本不应直接安装,它是供其他脚本使用的外部库。如果你需要使用该库,请在脚本元属性加入:// @require https://update.cn-greasyfork.org/scripts/443844/1043319/PPCC.js
你需要先安装一款用户样式管理器扩展(如 Stylus)后才能安装此样式。
你需要先安装一款用户样式管理器扩展(如 Stylus)后才能安装此样式。
你需要先安装一款用户样式管理器扩展(如 Stylus)后才能安装此样式。
你需要先安装一款用户样式管理器扩展后才能安装此样式。
你需要先安装一款用户样式管理器扩展后才能安装此样式。
你需要先安装一款用户样式管理器扩展后才能安装此样式。
(我已安装用户样式管理器,立即安装用户样式!)
- // ==UserScript==
- // @name PPCC
- // @description Pixel Place Compile Client
- // @version 1.3.2
- // @author 0vC4
- // @namespace https://greasyfork.org/users/670183
- // @match https://pixelplace.io/*
- // @icon https://www.google.com/s2/favicons?sz=64&domain=pixelplace.io
- // @license MIT
- // @grant none
- // @run-at document-start
- // ==/UserScript==
-
-
-
-
-
- const PPCC = (() => {
- return {
- compile(client, PPML, CWSS, WorkerTimer) {
- Object.assign(client, {
- ws: null,
- map: {},
-
- onclick: null,
-
- last: [0, 0, 255],
- _pixelQueue: [],
- _posQueue: 0,
- safeEmit(x, y, pixel) {
- this._pixelQueue.push(x, y, pixel);
- },
-
- send(data) {
- CWSS.send.call(client.ws, data);
- }
- });
-
-
-
- PPML.onload = map => {
- Object.assign(client.map, map);
- client.map.pixels = new Uint8Array(map.pixels);
- };
-
-
-
- WorkerTimer.setInterval(() => {
- while (client._posQueue < client._pixelQueue.length) {
- const [x, y, pixel] = client._pixelQueue.slice(client._posQueue, client._posQueue + 3);
- client._posQueue += 3;
- if (client.map.get(x,y) === 255 || pixel === 255) continue;
- if (client.map.get(x,y) === pixel) continue;
- CWSS.send.call(client.ws, `42["p",[${x},${y},${pixel},1]]`);
- return;
- }
- client._posQueue = 0;
- client._pixelQueue = [];
- }, 1e3/30);
-
-
-
- CWSS.setHook({
- priority: 0,
- init() {
- if (client.ws) return arguments;
- client.ws = this;
- return arguments;
- },
-
- message({data}) {
- if (client.ws != this) return arguments;
-
- const message = JSON.parse(data.split(/(?<=^\d+)(?=[^\d])/)[1] || '[]');
- if (!message.length) return arguments;
-
- const [event, json] = message;
- if (event == 'canvas' || event == 'p') json.map(p => client.map.set(...p));
-
- return arguments;
- },
-
- send(data) {
- if (client.ws != this) return arguments;
-
- const message = JSON.parse(data.split(/(?<=^\d+)(?=[^\d])/)[1] || '[]');
- if (!message.length) return arguments;
-
- const [event, json] = message;
- if (event == 'p') {
- const [x, y, pixel] = json;
- client.last = [x, y, pixel];
- if (client.onclick && client.onclick(x, y, pixel) === false) return;
- }
-
- return arguments;
- }
- });
- }
- };
- })();
- // 0vC4#7152