Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* original from https://github.com/KyleCypher/owot/blob/master/mouseCursor.js */
- /* other features by falling1 */
- console.log('You can change settings in the menu');
- var lwriteBuffer = [];
- var lwriteCharTo = new Function('return '+writeCharTo.toString().replace('if(cell_props[charY]) {\n\t\tif(cell_props[charY][charX]) {\n\t\t\tdelete cell_props[charY][charX];\n\t\t\thasChanged = true;\n\t\t}\n\t}\n',' ').replace('writeBuffer','lwriteBuffer'))();
- flushWrites = new Function('return '+flushWrites.toString().replace('network.write(writeBuffer.splice(0, 512));','network.write(writeBuffer.splice(0, 512)); network.write(lwriteBuffer.splice(0, 512), {preserve_links: 1});'))();
- setWriteInterval = new Function('return '+setWriteInterval.toString().replace('!writeBuffer.length','!writeBuffer.length && !lwriteBuffer.length'))();
- setWriteInterval();
- window.addEventListener('beforeunload', (e) => {
- unloading = true;
- defaultCursor = "text";
- owot.style.cursor = defaultCursor;
- if (!getCharProtection(...oldCoords)) lwriteCharTo(erase, erasecolor, ...oldCoords, true, 0, erasebgcolor, ...Object.values(erasedecorations ?? nodecorations));
- flushWrites();
- owot.removeEventListener("mousemove", showCursor);
- });
- owot.addEventListener("mousemove", showCursor);
- var ee = "🮰";
- var rcwo = false;
- var pos = [0, 0, 0, 0];
- var cursorcolor = YourWorld.Color;
- var cursorbgcolor = YourWorld.BgColor;
- var erase = getChar(...pos);
- var erasecolor = getCharColor(...pos);
- var erasedecorations = getCharDecoration(...pos);
- var erasebgcolor = getCharBgColor(...pos);
- var nodecorations = { bold: 0, italic: 0, under: 0, strike: 0 };
- var firstLetter = true;
- var unloading = false;
- var oldCoords = [0, 0, 0, 0];
- w.setFlushInterval(50);
- function showCursor(e) {
- if(isDragging) return;
- pos = getTileCoordsFromMouseCoords(Math.trunc(e.pageX*zoomRatio), Math.trunc(e.pageY*zoomRatio));
- if (getCharProtection(...pos) || !getCharInfo(...pos).loaded) defaultCursor = "default"; else defaultCursor = "none";
- owot.style.cursor = defaultCursor;
- firstLetter = true;
- if (!getCharProtection(...oldCoords) && getCharInfo(...oldCoords).loaded) lwriteCharTo(erase, erasecolor, ...oldCoords, true, 0, erasebgcolor, ...Object.values(erasedecorations ?? nodecorations));
- erase = getChar(...pos);
- erasecolor = getCharColor(...pos);
- erasedecorations = getCharDecoration(...pos);
- erasebgcolor = getCharBgColor(...pos);
- if (!getCharProtection(...pos) && getCharInfo(...pos).loaded) lwriteCharTo(ee, cursorcolor, ...pos, true, 0, cursorbgcolor);
- oldCoords = pos;
- };
- w.on('tileUpdate', function() {
- if (getChar(...pos) != ee && getCharColor(...pos) != cursorcolor && !unloading && getCharInfo(...pos).loaded) {
- if (!getCharProtection(...pos)) {
- erase = getChar(...pos);
- erasecolor = getCharColor(...pos);
- erasedecorations = getCharDecoration(...pos);
- erasebgcolor = getCharBgColor(...pos);
- if (!rcwo) return;
- lwriteCharTo(ee, cursorcolor, ...pos, true, 0, cursorbgcolor);
- }
- };
- });
- w.on('write', function() {
- if (getChar(...pos) != ee && !unloading && getCharInfo(...pos).loaded) {
- if (!getCharProtection(...pos)) {
- erase = getChar(...pos);
- erasecolor = getCharColor(...pos);
- erasedecorations = getCharDecoration(...pos);
- erasebgcolor = getCharBgColor(...pos);
- if (!rcwo) return;
- lwriteCharTo(ee, cursorcolor, ...pos, true, 0, cursorbgcolor);
- }
- };
- });
- menu.addOption("Change cursor color", function () {
- I = prompt("Enter new color (hex code)", cursorcolor);
- cursorcolor = resolveColorValue(I);
- });
- if (Permissions.can_color_cell(state.userModel, state.worldModel))
- menu.addOption("Change cursor backgound color", function () {
- I = prompt("Enter new color (hex code, -1 for none)", cursorbgcolor);
- if (I == "-1") {
- cursorbgcolor = -1;
- return;
- };
- cursorbgcolor = resolveColorValue(I);
- });
- menu.addOption("Change cursor character", function () {
- I = prompt("Enter new character", ee);
- if (I == null) return;
- ee = Array.from(I)[0];
- });
- menu.addCheckboxOption("Rewrite cursor when overwritten", _=>rcwo = true, _=>rcwo = false, false);
- defaultCursor = "none";
Advertisement
Comments
-
- cool
-
- /* I remixed it, in https://pastebin.com/i92ikqhA */
- alert('You can change settings in the menu');
- console.log("Original from https://github.com/KyleCypher/owot/blob/master/mouseCursor.js")
- console.log("Pastebin by Falling1")
- window.open('https://pastebin.com/BzSdTnHg')
- /* still have no clue how to fix links */
- window.addEventListener('beforeunload', (event) => {
- if (getLink(...pos) !== null) return;
- event.preventDefault();
- unloading = true;
- if (!getCharProtection(...cursorCoords)) writeCharTo(erase, erasecolor, ...currentPosition, true);
- owot.removeEventListener("mousemove", showCursor);
- });
- owot.addEventListener("mousemove", showCursor);
- ee = "🮰";
- rcwo = false;
- pos = [0, 0, 0, 0];
- color = 0x000000;
- erase = getChar(...pos);
- erasecolor = getCharColor(...pos);
- erasedecorations = getCharDecoration(...pos);
- nodecorations = {bold: 0, italic: 0, under: 0, strike: 0};
- firstLetter = true;
- unloading = false;
- oldCoords = [0, 0, 0, 0];
- writeFlushRate=40; setWriteInterval();
- function showCursor(e) {
- pos = getTileCoordsFromMouseCoords(e.pageX, e.pageY);
- (getCharProtection(...pos) || !getCharInfo(...pos).loaded) ? defaultCursor = "default" : defaultCursor = "none";
- owot.style.cursor = defaultCursor;
- if (!getCharInfo(...pos).loaded) return;
- firstLetter = true;
- olddecorations = textDecorationModes;
- textDecorationModes = erasedecorations ?? nodecorations;
- if (!getCharProtection(...oldCoords) && getLink(...oldCoords) == null) writeCharTo(erase, erasecolor, ...oldCoords, true);
- textDecorationModes = olddecorations;
- erase = getChar(...pos);
- erasecolor = getCharColor(...pos);
- erasedecorations = getCharDecoration(...pos);
- if (!getCharProtection(...pos) && getLink(...pos) == null) writeCharTo(ee, color, ...pos, true);
- oldCoords = pos;
- };
- document.onkeydown = function(e) {
- if (e.key == "Escape") {
- owot.removeEventListener("mousemove", showCursor);
- location.reload();
- };
- };
- w.on('tileUpdate', function() {
- if (getChar(...pos) != ee && !unloading && getCharInfo(...pos).loaded) {
- if (!getCharProtection(...pos)) {
- erase = getChar(...pos);
- erasecolor = getCharColor(...pos);
- erasedecorations = getCharDecoration(...pos);
- if (!rcwo) return;
- writeCharTo(ee, color, ...pos, true);
- }
- };
- });
- w.on('write', function() {
- if (getChar(...pos) != ee && !unloading && getCharInfo(...pos).loaded) {
- if (!getCharProtection(...pos)) {
- erase = getChar(...pos);
- erasecolor = getCharColor(...pos);
- erasedecorations = getCharDecoration(...pos);
- if (!rcwo) return;
- writeCharTo(ee, color, ...pos, true);
- }
- };
- });
- document.onmousedown = function() {
- owot.removeEventListener("mousemove", showCursor)
- };
- document.onmouseup = function() {
- owot.addEventListener("mousemove", showCursor)
- };
- menu.addOption('Change cursor color', function() {I = prompt('Enter new color (hex code)', "000000"); if (I.startsWith('#')) I = I.substr(1); I = parseInt(I, 16); if(isNaN(I)) return; color = I});
- menu.addOption('Change cursor character', function() {I = prompt('Enter new character', ee); if(I == null) return; a = Array.from(I); ee = a[0]});
- menu.addCheckboxOption("Rewrite cursor when overwritten", function() {rcwo = true}, function() {rcwo = false}, false);
- defaultCursor = "none";
Add Comment
Please, Sign In to add comment
Advertisement