jscad parameters default values and float type #582

Merged
hrgdavor merged 1 commits from fix-getParameterDefinitions into main 2022-01-08 20:32:32 +01:00
3 changed files with 11 additions and 3 deletions

1
.gitignore vendored
View File

@@ -1,4 +1,5 @@
.idea
.history
.DS_Store
.env
.netlify

View File

@@ -8,6 +8,7 @@ type JscadTypeNames =
| 'group'
| 'text'
| 'int'
| 'float'
| 'number'
| 'slider'
| 'email'
@@ -37,7 +38,7 @@ interface JscadTextParam extends JscadParamBase {
maxLength: number
}
interface JscadIntNumberSliderParam extends JscadParamBase {
type: 'int' | 'number' | 'slider'
type: 'int' | 'number' | 'float' | 'slider'
initial: number
min?: number
max?: number
@@ -93,6 +94,7 @@ export function jsCadToCadhubParams(input: JsCadParams[]): CadhubParams[] {
switch (param.type) {
case 'slider':
case 'number':
case 'float':
case 'int':
return {
type: 'number',

View File

@@ -315,9 +315,12 @@ function parseDef(code, line) {
}
const makeScriptWorker = ({ callback, convertToSolids }) => {
let onInit, main, scriptStats, entities
let onInit, main, scriptStats, entities, lastParamsDef
Irev-Dev commented 2022-01-07 22:52:24 +01:00 (Migrated from github.com)
Review

Should jscad handle a missing param and use the scripts default value by itself?

Should jscad handle a missing param and use the scripts default value by itself?
hrgdavor commented 2022-01-07 23:27:46 +01:00 (Migrated from github.com)
Review

Yes, that is expected behavior in jscad currently, just not properly implemented in my integration for CadHub.

Yes, that is expected behavior in jscad currently, just not properly implemented in my integration for CadHub.
function runMain(params = {}) {
if(lastParamsDef) lastParamsDef.forEach(def=>{
if(!(def.name in params) && 'initial' in def) params[def.name] = def.initial
})
let time = Date.now()
let solids
const transfer = []
@@ -397,10 +400,12 @@ const makeScriptWorker = ({ callback, convertToSolids }) => {
if (idx === -1) {
paramsDef.push(p)
} else {
paramsDef.splice(idx, 1, p)
paramsDef[idx] = p
}
})
}
console.log('paramsDef', paramsDef)
lastParamsDef = paramsDef
callback({
action: 'parameterDefinitions',
worker: 'main',