smoothretro82

Multi-line autopaster

Dec 3rd, 2025 (edited)
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.05 KB | None | 0 0
  1. // ================== EDIT THIS ==================
  2. const TEXT = `Originally Made by Infinity!
  3. Modified by dominoguy_.
  4. Autopaste is working like a charm and now it even has borders with auto word wrapping.`;
  5. // ===============================================
  6.  
  7. // Max inside width (in characters)
  8. const MAX_WIDTH = 32;
  9.  
  10. // Padding inside border
  11. const PADDING_X = 1;
  12. const PADDING_Y = 1;
  13.  
  14. // Colors
  15. const TEXT_COLOR = '#fff';
  16. const BORDER_COLOR = '#0ff';
  17.  
  18. // Tile size
  19. const TILE_WIDTH = 1;
  20. const TILE_HEIGHT = 1;
  21.  
  22. // -----------------------------------------------
  23.  
  24. function wordWrap(text, maxWidth) {
  25. const words = text.replace(/\n/g, " \n ").split(" ");
  26. const lines = [];
  27. let line = "";
  28.  
  29. for (let word of words) {
  30. if (word === "\n") {
  31. lines.push(line);
  32. line = "";
  33. continue;
  34. }
  35.  
  36. if ((line + word).length > maxWidth) {
  37. lines.push(line);
  38. line = word + " ";
  39. } else {
  40. line += word + " ";
  41. }
  42. }
  43.  
  44. if (line.trim() !== "") lines.push(line.trim());
  45. return lines;
  46. }
  47.  
  48. // Wrap text first
  49. const wrappedLines = wordWrap(TEXT, MAX_WIDTH);
  50.  
  51. // Find box size
  52. const BOX_WIDTH = Math.max(...wrappedLines.map(l => l.length)) + (PADDING_X * 2);
  53. const BOX_HEIGHT = wrappedLines.length + (PADDING_Y * 2);
  54.  
  55. // Prepare arrays
  56. atxt = [];
  57. acol = [];
  58. bx = [];
  59. by = [];
  60.  
  61. // Helper to add char
  62. function addChar(char, x, y, color) {
  63. atxt.push(char);
  64. acol.push(color);
  65. bx.push(x * TILE_WIDTH);
  66. by.push(y * TILE_HEIGHT);
  67. }
  68.  
  69. // ---- DRAW BORDER ----
  70.  
  71. // Top border
  72. addChar("┌", 0, 0, BORDER_COLOR);
  73. for (let x = 1; x <= BOX_WIDTH; x++) addChar("─", x, 0, BORDER_COLOR);
  74. addChar("┐", BOX_WIDTH + 1, 0, BORDER_COLOR);
  75.  
  76. // Sides
  77. for (let y = 1; y <= BOX_HEIGHT; y++) {
  78. addChar("│", 0, y, BORDER_COLOR);
  79. addChar("│", BOX_WIDTH + 1, y, BORDER_COLOR);
  80. }
  81.  
  82. // Bottom border
  83. addChar("└", 0, BOX_HEIGHT + 1, BORDER_COLOR);
  84. for (let x = 1; x <= BOX_WIDTH; x++) addChar("─", x, BOX_HEIGHT + 1, BORDER_COLOR);
  85. addChar("┘", BOX_WIDTH + 1, BOX_HEIGHT + 1, BORDER_COLOR);
  86.  
  87. // ---- WRITE TEXT ----
  88. wrappedLines.forEach((line, row) => {
  89. const chars = line.split("");
  90. chars.forEach((char, col) => {
  91. addChar(char, col + 1 + PADDING_X, row + 1 + PADDING_Y, TEXT_COLOR);
  92. });
  93. });
  94.  
  95. // Function to check tile
  96. function ct(x, y, t, c) {
  97. const tx = Math.floor(x / TILE_WIDTH) * TILE_WIDTH;
  98. const ty = Math.floor(y / TILE_HEIGHT) * TILE_HEIGHT;
  99.  
  100. if (!Tile.exists(tx, ty)) return false;
  101.  
  102. const charInfo = getCharInfoXY(x, y);
  103. return charInfo.char === t && charInfo.color === c;
  104. }
  105.  
  106. // Autopaster engine
  107. let currentIndex = 0;
  108.  
  109. function ap() {
  110. if (currentIndex >= atxt.length) return;
  111.  
  112. while (
  113. currentIndex < atxt.length &&
  114. ct(bx[currentIndex], by[currentIndex], atxt[currentIndex], acol[currentIndex])
  115. ) {
  116. currentIndex++;
  117. }
  118.  
  119. if (currentIndex < atxt.length) {
  120. writeCharAt(atxt[currentIndex], acol[currentIndex], bx[currentIndex], by[currentIndex]);
  121. currentIndex++;
  122. }
  123.  
  124. requestAnimationFrame(ap);
  125. }
  126.  
  127. // Start
  128. ap();
  129.  
Advertisement
Add Comment
Please, Sign In to add comment