Advertisement
falling1

owot cursor

Nov 10th, 2022 (edited)
660
0
Never
2
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* original from https://github.com/KyleCypher/owot/blob/master/mouseCursor.js */
  2. /* other features by falling1 */
  3.  
  4. console.log('You can change settings in the menu');
  5. var lwriteBuffer = [];
  6. 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'))();
  7. 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});'))();
  8. setWriteInterval = new Function('return '+setWriteInterval.toString().replace('!writeBuffer.length','!writeBuffer.length && !lwriteBuffer.length'))();
  9. setWriteInterval();
  10. window.addEventListener('beforeunload', (e) => {
  11.     unloading = true;
  12.     defaultCursor = "text";
  13.     owot.style.cursor = defaultCursor;
  14.     if (!getCharProtection(...oldCoords)) lwriteCharTo(erase, erasecolor, ...oldCoords, true, 0, erasebgcolor, ...Object.values(erasedecorations ?? nodecorations));
  15.     flushWrites();
  16.     owot.removeEventListener("mousemove", showCursor);
  17. });
  18. owot.addEventListener("mousemove", showCursor);
  19. var ee = "🮰";
  20. var rcwo = false;
  21. var pos = [0, 0, 0, 0];
  22. var cursorcolor = YourWorld.Color;
  23. var cursorbgcolor = YourWorld.BgColor;
  24. var erase = getChar(...pos);
  25. var erasecolor = getCharColor(...pos);
  26. var erasedecorations = getCharDecoration(...pos);
  27. var erasebgcolor = getCharBgColor(...pos);
  28. var nodecorations = { bold: 0, italic: 0, under: 0, strike: 0 };
  29. var firstLetter = true;
  30. var unloading = false;
  31. var oldCoords = [0, 0, 0, 0];
  32.  
  33. w.setFlushInterval(50);
  34. function showCursor(e) {
  35.     if(isDragging) return;
  36.     pos = getTileCoordsFromMouseCoords(Math.trunc(e.pageX*zoomRatio), Math.trunc(e.pageY*zoomRatio));
  37.     if (getCharProtection(...pos) || !getCharInfo(...pos).loaded) defaultCursor = "default"; else defaultCursor = "none";
  38.     owot.style.cursor = defaultCursor;
  39.     firstLetter = true;
  40.     if (!getCharProtection(...oldCoords) && getCharInfo(...oldCoords).loaded) lwriteCharTo(erase, erasecolor, ...oldCoords, true, 0, erasebgcolor, ...Object.values(erasedecorations ?? nodecorations));
  41.     erase = getChar(...pos);
  42.     erasecolor = getCharColor(...pos);
  43.     erasedecorations = getCharDecoration(...pos);
  44.     erasebgcolor = getCharBgColor(...pos);
  45.     if (!getCharProtection(...pos) && getCharInfo(...pos).loaded) lwriteCharTo(ee, cursorcolor, ...pos, true, 0, cursorbgcolor);
  46.     oldCoords = pos;
  47. };
  48. w.on('tileUpdate', function() {
  49.     if (getChar(...pos) != ee && getCharColor(...pos) != cursorcolor && !unloading && getCharInfo(...pos).loaded) {
  50.         if (!getCharProtection(...pos)) {
  51.             erase = getChar(...pos);
  52.             erasecolor = getCharColor(...pos);
  53.             erasedecorations = getCharDecoration(...pos);
  54.             erasebgcolor = getCharBgColor(...pos);
  55.             if (!rcwo) return;
  56.             lwriteCharTo(ee, cursorcolor, ...pos, true, 0, cursorbgcolor);
  57.         }
  58.     };
  59. });
  60. w.on('write', function() {
  61.     if (getChar(...pos) != ee && !unloading && getCharInfo(...pos).loaded) {
  62.         if (!getCharProtection(...pos)) {
  63.             erase = getChar(...pos);
  64.             erasecolor = getCharColor(...pos);
  65.             erasedecorations = getCharDecoration(...pos);
  66.             erasebgcolor = getCharBgColor(...pos);
  67.             if (!rcwo) return;
  68.             lwriteCharTo(ee, cursorcolor, ...pos, true, 0, cursorbgcolor);
  69.         }
  70.     };
  71. });
  72.  
  73. menu.addOption("Change cursor color", function () {
  74.   I = prompt("Enter new color (hex code)", cursorcolor);
  75.   cursorcolor = resolveColorValue(I);
  76. });
  77. if (Permissions.can_color_cell(state.userModel, state.worldModel))
  78.   menu.addOption("Change cursor backgound color", function () {
  79.     I = prompt("Enter new color (hex code, -1 for none)", cursorbgcolor);
  80.     if (I == "-1") {
  81.       cursorbgcolor = -1;
  82.       return;
  83.     };
  84.     cursorbgcolor = resolveColorValue(I);
  85.   });
  86. menu.addOption("Change cursor character", function () {
  87.   I = prompt("Enter new character", ee);
  88.   if (I == null) return;
  89.   ee = Array.from(I)[0];
  90. });
  91.  
  92.  
  93. menu.addCheckboxOption("Rewrite cursor when overwritten", _=>rcwo = true, _=>rcwo = false, false);
  94.  
  95. defaultCursor = "none";
Advertisement
Comments
  • KKosty4ka
    1 year
    # text 0.00 KB | 1 0
    1. cool
  • Dimka69
    1 year
    1. /* I remixed it, in https://pastebin.com/i92ikqhA */
    2. alert('You can change settings in the menu');
    3. console.log("Original from https://github.com/KyleCypher/owot/blob/master/mouseCursor.js")
    4. console.log("Pastebin by Falling1")
    5. window.open('https://pastebin.com/BzSdTnHg')
    6. /* still have no clue how to fix links */
    7. window.addEventListener('beforeunload', (event) => {
    8.     if (getLink(...pos) !== null) return;
    9.     event.preventDefault();
    10.     unloading = true;
    11.     if (!getCharProtection(...cursorCoords)) writeCharTo(erase, erasecolor, ...currentPosition, true);
    12.     owot.removeEventListener("mousemove", showCursor);
    13. });
    14. owot.addEventListener("mousemove", showCursor);
    15. ee = "🮰";
    16. rcwo = false;
    17. pos = [0, 0, 0, 0];
    18. color = 0x000000;
    19. erase = getChar(...pos);
    20. erasecolor = getCharColor(...pos);
    21. erasedecorations = getCharDecoration(...pos);
    22. nodecorations = {bold: 0, italic: 0, under: 0, strike: 0};
    23. firstLetter = true;
    24. unloading = false;
    25. oldCoords = [0, 0, 0, 0];
    26. writeFlushRate=40; setWriteInterval();
    27. function showCursor(e) {
    28.     pos = getTileCoordsFromMouseCoords(e.pageX, e.pageY);
    29.     (getCharProtection(...pos) || !getCharInfo(...pos).loaded) ? defaultCursor = "default" : defaultCursor = "none";
    30.     owot.style.cursor = defaultCursor;
    31.     if (!getCharInfo(...pos).loaded) return;
    32.     firstLetter = true;
    33.     olddecorations = textDecorationModes;
    34.     textDecorationModes = erasedecorations ?? nodecorations;
    35.     if (!getCharProtection(...oldCoords) && getLink(...oldCoords) == null) writeCharTo(erase, erasecolor, ...oldCoords, true);
    36.     textDecorationModes = olddecorations;
    37.     erase = getChar(...pos);
    38.     erasecolor = getCharColor(...pos);
    39.     erasedecorations = getCharDecoration(...pos);
    40.     if (!getCharProtection(...pos) && getLink(...pos) == null) writeCharTo(ee, color, ...pos, true);
    41.     oldCoords = pos;
    42. };
    43. document.onkeydown = function(e) {
    44.     if (e.key == "Escape") {
    45.         owot.removeEventListener("mousemove", showCursor);
    46.         location.reload();
    47.     };
    48. };
    49. w.on('tileUpdate', function() {
    50.     if (getChar(...pos) != ee && !unloading && getCharInfo(...pos).loaded) {
    51.         if (!getCharProtection(...pos)) {
    52.             erase = getChar(...pos);
    53.             erasecolor = getCharColor(...pos);
    54.             erasedecorations = getCharDecoration(...pos);
    55.             if (!rcwo) return;
    56.             writeCharTo(ee, color, ...pos, true);
    57.         }
    58.     };
    59. });
    60. w.on('write', function() {
    61.     if (getChar(...pos) != ee && !unloading && getCharInfo(...pos).loaded) {
    62.         if (!getCharProtection(...pos)) {
    63.             erase = getChar(...pos);
    64.             erasecolor = getCharColor(...pos);
    65.             erasedecorations = getCharDecoration(...pos);
    66.             if (!rcwo) return;
    67.             writeCharTo(ee, color, ...pos, true);
    68.         }
    69.     };
    70. });
    71. document.onmousedown = function() {
    72.     owot.removeEventListener("mousemove", showCursor)
    73. };
    74. document.onmouseup = function() {
    75.     owot.addEventListener("mousemove", showCursor)
    76. };
    77.  
    78. 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});
    79. menu.addOption('Change cursor character', function() {I = prompt('Enter new character', ee); if(I == null) return; a = Array.from(I); ee = a[0]});
    80. menu.addCheckboxOption("Rewrite cursor when overwritten", function() {rcwo = true}, function() {rcwo = false}, false);
    81.  
    82. defaultCursor = "none";
Add Comment
Please, Sign In to add comment
Advertisement