Advertisement
jargon

Extensions.js

Mar 3rd, 2025
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function Extensions()
  2. {  
  3.     if (!jsonData[col] || jsonData[col][row] === undefined) {
  4.         return;
  5.     }
  6.                            
  7.     let entry = jsonData[col][row];
  8.     let conn = entry.connections;
  9.  
  10.     // Ensure `conn` exists to prevent errors
  11.     if (!conn) return;
  12.  
  13.     const flip = {
  14.         'left': 'right',
  15.         'right': 'left',
  16.         'up': 'down',
  17.         'down': 'up'
  18.     };
  19.  
  20.     const axis = {
  21.         'left': 'column',
  22.         'right': 'column',
  23.         'up': 'row',
  24.         'down': 'row'
  25.     };
  26.  
  27.     // Find the corresponding grid item
  28.     let gridItem = document.querySelector(`#grid-item-${col}-${row}`);
  29.     if (!gridItem) return; // Ensure gridItem exists
  30.  
  31.     // Handle "T" connections first
  32.     if (conn.type === "t") {
  33.         let newTConnection = document.createElement("div");
  34.  
  35.         // Determine T connection direction
  36.         if (conn.left && conn.right) {
  37.             newTConnection.classList.add("connection-t-horizontal");
  38.         } else if (conn.up && conn.down) {
  39.             newTConnection.classList.add("connection-t-vertical");
  40.         } else if (conn.up && conn.left) {
  41.             newTConnection.classList.add("connection-t-up-left");
  42.         } else if (conn.up && conn.right) {
  43.             newTConnection.classList.add("connection-t-up-right");
  44.         } else if (conn.down && conn.left) {
  45.             newTConnection.classList.add("connection-t-down-left");
  46.         } else if (conn.down && conn.right) {
  47.             newTConnection.classList.add("connection-t-down-right");
  48.         }
  49.  
  50.         gridItem.appendChild(newTConnection);
  51.         return; // Skip further processing
  52.     }
  53.  
  54.     // Process standard connections
  55.     ['up', 'down', 'left', 'right'].forEach(direction => {
  56.         if (!conn[direction]) return;
  57.  
  58.         let target = parseInt(conn[direction], 10);
  59.         let pass = conn[direction] !== undefined;
  60.  
  61.         let d = flip[direction];
  62.         let a = axis[direction];
  63.  
  64.         // Create a new connection element for each direction
  65.         let newConnection = document.createElement("div");
  66.         newConnection.classList.add("connection", `connection-${direction}`, "connection-extend");
  67.  
  68.         // Apply data attribute only if `pass` is false and `entry.text !== false`
  69.         if (!pass && entry.text !== false) {
  70.             newConnection.setAttribute(`data-target-${a}`, target);
  71.         }
  72.  
  73.         // Append the new connection to the grid item
  74.         gridItem.appendChild(newConnection);
  75.     });
  76. }
  77.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement