Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Extensions()
- {
- if (!jsonData[col] || jsonData[col][row] === undefined) {
- return;
- }
- let entry = jsonData[col][row];
- let conn = entry.connections;
- // Ensure `conn` exists to prevent errors
- if (!conn) return;
- const flip = {
- 'left': 'right',
- 'right': 'left',
- 'up': 'down',
- 'down': 'up'
- };
- const axis = {
- 'left': 'column',
- 'right': 'column',
- 'up': 'row',
- 'down': 'row'
- };
- // Find the corresponding grid item
- let gridItem = document.querySelector(`#grid-item-${col}-${row}`);
- if (!gridItem) return; // Ensure gridItem exists
- // Handle "T" connections first
- if (conn.type === "t") {
- let newTConnection = document.createElement("div");
- // Determine T connection direction
- if (conn.left && conn.right) {
- newTConnection.classList.add("connection-t-horizontal");
- } else if (conn.up && conn.down) {
- newTConnection.classList.add("connection-t-vertical");
- } else if (conn.up && conn.left) {
- newTConnection.classList.add("connection-t-up-left");
- } else if (conn.up && conn.right) {
- newTConnection.classList.add("connection-t-up-right");
- } else if (conn.down && conn.left) {
- newTConnection.classList.add("connection-t-down-left");
- } else if (conn.down && conn.right) {
- newTConnection.classList.add("connection-t-down-right");
- }
- gridItem.appendChild(newTConnection);
- return; // Skip further processing
- }
- // Process standard connections
- ['up', 'down', 'left', 'right'].forEach(direction => {
- if (!conn[direction]) return;
- let target = parseInt(conn[direction], 10);
- let pass = conn[direction] !== undefined;
- let d = flip[direction];
- let a = axis[direction];
- // Create a new connection element for each direction
- let newConnection = document.createElement("div");
- newConnection.classList.add("connection", `connection-${direction}`, "connection-extend");
- // Apply data attribute only if `pass` is false and `entry.text !== false`
- if (!pass && entry.text !== false) {
- newConnection.setAttribute(`data-target-${a}`, target);
- }
- // Append the new connection to the grid item
- gridItem.appendChild(newConnection);
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement