Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
maz0r committed Feb 6, 2024
2 parents f390c08 + 584855c commit 39f445b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 7 deletions.
15 changes: 14 additions & 1 deletion src/app/configurator/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ export const Archetype = {
},
lengths: [3],
fitment: 1,
spacer: true,
},
blackbird: {
label: 'Blackbird',
Expand Down Expand Up @@ -202,6 +203,7 @@ export const Archetype = {
},
lengths: [2, 3],
fitment: 1,
spacer: true,
},
zephyr: {
label: 'Zephyr',
Expand Down Expand Up @@ -342,7 +344,18 @@ export const Archetype = {
},
},
},
mods: {},
mods: {
spacer: {
label: 'Probe Spacer',
files: {
spacer: {
generic: {
spacer: 'Archetype Core/Probes/[a]_fan_splitter_spacer',
},
},
},
},
},
},
}
};
Expand Down
25 changes: 19 additions & 6 deletions src/app/configurator/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,17 @@ const getLength = (length) => {

const BASE_URI = 'https://raw.githubusercontent.com/Armchair-Engineering/Archetype/Experimental'

const getSelectedFiles = (selections, mods) => {
const getSelectedFiles = (selections, mods, useSpacer) => {
const files = []
let length = getLength(Archetype.components.hotends.options[selections.hotends].length)
let length = Archetype.components.hotends.options[selections.hotends].length;

// special logic for spacer ducts
if (useSpacer) {
length -= 1;
files.push(Archetype.components.probes.mods.spacer.files.spacer.generic.spacer)
}

length = getLength(length);

Object.keys(selections).forEach((type) => {
const definition = Archetype.components[type].options[selections[type]];
Expand All @@ -36,6 +44,7 @@ const getSelectedFiles = (selections, mods) => {
if (isset(definition.files, 'generic')) {
const generics = definition.files.generic

// check for mods
Object.keys(definition.files.generic).forEach((component_type) => {
if (isset(mods, type) && mods[type] !== null && isset(Archetype.components[type].mods[mods[type]].files[selected].generic, component_type)) {
generics[component_type] = Archetype.components[type].mods[mods[type]].files[selected].generic[component_type]
Expand Down Expand Up @@ -63,9 +72,7 @@ const downloadBlob = (blob, name) => {
URL.revokeObjectURL(link.href);
};

const download = async (selections, mods) => {
const files = getSelectedFiles(selections, mods)

const download = async (files) => {
const downloads = files.map((file) => fetch(`${BASE_URI}/${file}.stl`));
const responses = await Promise.all(downloads);

Expand All @@ -82,6 +89,7 @@ export default function Page () {
const [mods, setMods] = useState({});
const [length, setLength] = useState(null);
const [fitment, setFitment] = useState(null);
const [useSpacer, setUseSpacer] = useState(false);

// find any components with length restrictions
useEffect(
Expand Down Expand Up @@ -189,10 +197,15 @@ export default function Page () {
[name]: component_name
});

console.log(Archetype.components[name].options[component_name]);
if (isset(Archetype.components[name].options[component_name], 'length')) {
setLength(Archetype.components[name].options[component_name].length)
}

if (isset(Archetype.components[name].options[component_name], 'spacer')) {
setUseSpacer(Archetype.components[name].options[component_name].spacer)
}

if (isset(Archetype.components[name].options[component_name], 'fitment')) {
setFitment(Archetype.components[name].options[component_name].fitment)
}
Expand Down Expand Up @@ -264,7 +277,7 @@ export default function Page () {
'rounded-md px-3.5 py-2.5 text-sm font-semibold text-white shadow-sm',
Object.keys(selections).length !== Object.keys(Archetype.components).length ? 'bg-indigo-950 cursor-not-allowed' : 'bg-indigo-500 hover:bg-indigo-400 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-500'
)}
onClick={() => { download(selections, mods) }}
onClick={() => { download(getSelectedFiles(selections, mods, useSpacer)) }}
>
Download
</button>
Expand Down

0 comments on commit 39f445b

Please sign in to comment.