Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ================== EDIT THIS ==================
- const TEXT = `Originally Made by Infinity!
- Modified by dominoguy_.
- Autopaste is working like a charm and now it even has borders with auto word wrapping.`;
- // ===============================================
- // Max inside width (in characters)
- const MAX_WIDTH = 32;
- // Padding inside border
- const PADDING_X = 1;
- const PADDING_Y = 1;
- // Colors
- const TEXT_COLOR = '#fff';
- const BORDER_COLOR = '#0ff';
- // Tile size
- const TILE_WIDTH = 1;
- const TILE_HEIGHT = 1;
- // -----------------------------------------------
- function wordWrap(text, maxWidth) {
- const words = text.replace(/\n/g, " \n ").split(" ");
- const lines = [];
- let line = "";
- for (let word of words) {
- if (word === "\n") {
- lines.push(line);
- line = "";
- continue;
- }
- if ((line + word).length > maxWidth) {
- lines.push(line);
- line = word + " ";
- } else {
- line += word + " ";
- }
- }
- if (line.trim() !== "") lines.push(line.trim());
- return lines;
- }
- // Wrap text first
- const wrappedLines = wordWrap(TEXT, MAX_WIDTH);
- // Find box size
- const BOX_WIDTH = Math.max(...wrappedLines.map(l => l.length)) + (PADDING_X * 2);
- const BOX_HEIGHT = wrappedLines.length + (PADDING_Y * 2);
- // Prepare arrays
- atxt = [];
- acol = [];
- bx = [];
- by = [];
- // Helper to add char
- function addChar(char, x, y, color) {
- atxt.push(char);
- acol.push(color);
- bx.push(x * TILE_WIDTH);
- by.push(y * TILE_HEIGHT);
- }
- // ---- DRAW BORDER ----
- // Top border
- addChar("┌", 0, 0, BORDER_COLOR);
- for (let x = 1; x <= BOX_WIDTH; x++) addChar("─", x, 0, BORDER_COLOR);
- addChar("┐", BOX_WIDTH + 1, 0, BORDER_COLOR);
- // Sides
- for (let y = 1; y <= BOX_HEIGHT; y++) {
- addChar("│", 0, y, BORDER_COLOR);
- addChar("│", BOX_WIDTH + 1, y, BORDER_COLOR);
- }
- // Bottom border
- addChar("└", 0, BOX_HEIGHT + 1, BORDER_COLOR);
- for (let x = 1; x <= BOX_WIDTH; x++) addChar("─", x, BOX_HEIGHT + 1, BORDER_COLOR);
- addChar("┘", BOX_WIDTH + 1, BOX_HEIGHT + 1, BORDER_COLOR);
- // ---- WRITE TEXT ----
- wrappedLines.forEach((line, row) => {
- const chars = line.split("");
- chars.forEach((char, col) => {
- addChar(char, col + 1 + PADDING_X, row + 1 + PADDING_Y, TEXT_COLOR);
- });
- });
- // Function to check tile
- function ct(x, y, t, c) {
- const tx = Math.floor(x / TILE_WIDTH) * TILE_WIDTH;
- const ty = Math.floor(y / TILE_HEIGHT) * TILE_HEIGHT;
- if (!Tile.exists(tx, ty)) return false;
- const charInfo = getCharInfoXY(x, y);
- return charInfo.char === t && charInfo.color === c;
- }
- // Autopaster engine
- let currentIndex = 0;
- function ap() {
- if (currentIndex >= atxt.length) return;
- while (
- currentIndex < atxt.length &&
- ct(bx[currentIndex], by[currentIndex], atxt[currentIndex], acol[currentIndex])
- ) {
- currentIndex++;
- }
- if (currentIndex < atxt.length) {
- writeCharAt(atxt[currentIndex], acol[currentIndex], bx[currentIndex], by[currentIndex]);
- currentIndex++;
- }
- requestAnimationFrame(ap);
- }
- // Start
- ap();
Advertisement
Add Comment
Please, Sign In to add comment