AtomicZBRA
AtomicZBRA
WBWeb Bae
Created by AtomicZBRA on 5/16/2024 in #❓︱questions
Local vs Prod Dev (with a twist)
I'm trying to setup separate dev scripts but a little differently, because i don't want the dev script to be limited to the webflow.io domain, rather just whenever the localhost is available. So if the localhost is running, then it loads the relevant script from localhost. If the localhost is not running, then it loads the public script instead Now, i've got this kind of working using fetch with some try catch to ensure that it doesn't just give up when the localhost is unavailable. My issue with fetch though is that it prints out a nice big CONNECTION_REFUSED error even if i try to catch and print the error in a log instead of an error For example:
const localScriptURL = 'http://localhost:3000/some-page.js';

try {
const response = await fetch(localScriptURL);
} catch (error) {
console.log('There was an error ', error);
}

// or

fetch(localScriptURL).catch((error) => {
console.log('Error:', error);
});
const localScriptURL = 'http://localhost:3000/some-page.js';

try {
const response = await fetch(localScriptURL);
} catch (error) {
console.log('There was an error ', error);
}

// or

fetch(localScriptURL).catch((error) => {
console.log('Error:', error);
});
Still displaying the error but in a console log just for demo purposes as opposed to console.error
22 replies
WBWeb Bae
Created by AtomicZBRA on 3/21/2024 in #❓︱questions
Mobile Terminal Based Snake Game
Hey everyone! I've built out this terminal in webflow on my website https://corsetti.dev If you type in the command snake you can play snake in the terminal. My problem comes in on mobile, I've got the touch controls working correctly and I know you can't exit the game yet, but my grid just doesn't seem to be adjusting correctly
function calculateGridSize(canvasWidth, canvasHeight) {
const maxGridSize = 20; // Maximum grid size you'd like to use
const minGridSize = 10; // Minimum grid size you find acceptable
let idealGridSize = Math.min(canvasWidth, canvasHeight) / 25; // Example calculation

// Clamp the grid size between minGridSize and maxGridSize
idealGridSize = Math.max(minGridSize, Math.min(maxGridSize, idealGridSize));

// Ensure the grid size is a whole number
idealGridSize = Math.floor(idealGridSize);

// Adjust canvas size to fit an exact number of grids
canvas.width = Math.floor(canvas.width / idealGridSize) * idealGridSize;
canvas.height = Math.floor(canvas.height / idealGridSize) * idealGridSize;

return idealGridSize;
}
function calculateGridSize(canvasWidth, canvasHeight) {
const maxGridSize = 20; // Maximum grid size you'd like to use
const minGridSize = 10; // Minimum grid size you find acceptable
let idealGridSize = Math.min(canvasWidth, canvasHeight) / 25; // Example calculation

// Clamp the grid size between minGridSize and maxGridSize
idealGridSize = Math.max(minGridSize, Math.min(maxGridSize, idealGridSize));

// Ensure the grid size is a whole number
idealGridSize = Math.floor(idealGridSize);

// Adjust canvas size to fit an exact number of grids
canvas.width = Math.floor(canvas.width / idealGridSize) * idealGridSize;
canvas.height = Math.floor(canvas.height / idealGridSize) * idealGridSize;

return idealGridSize;
}
this is my function to calculate the grid size, and I thought I could get the results I wanted by manipulating the values but I'm just really spinning my wheels at this point Whole repo is on github if you want to check it out https://github.com/corsettiDev/personal-terminal
6 replies