Skip to content

Commit

Permalink
Update new.js
Browse files Browse the repository at this point in the history
  • Loading branch information
24c02 committed May 2, 2024
1 parent ee97d24 commit 9e66a11
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions pages/api/bin/wokwi/new.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,34 @@ const createProject = async (partsList=[]) => {
tableName: 'Supported Parts'
})

// adjust these to taste:
const PADDING = 30;
const MAX_WIDTH = 320; // big question mark on this one
const ROW_HEIGHT = 215; // close enough for jazz, keypad is too big for this but ¯\_(ツ)_/¯

const parts = [
{ "type": "board-pi-pico-w", "id": "pico", "top": 0, "left": 0, "attrs": {} }
]

let x = 88 + PADDING; // for already included Pico
let y = 0;
await Promise.all(partsList.map(async (part) => {
const airPart = await airtable.read({
filterByFormula: `{Wokwi Name}= "${part}"`,
maxRecords: 1
})
return airPart[0].fields['Wokwi Name'].split(',').forEach((name, i) => {
const width = airPart[0].fields['Wokwi X-Offset'];
if((x + width + PADDING) > MAX_WIDTH) {
x = 0;
y += ROW_HEIGHT;
}
parts.push({
type: name,
id: name + '-' + i,
left: i * 100, // this is roughtly the width of most parts
left: x,
top: y
})
x += width + PADDING;
})
}))

Expand Down

0 comments on commit 9e66a11

Please sign in to comment.