This commit is contained in:
2026-03-03 16:43:30 +00:00
commit 03452517b5
58 changed files with 13181 additions and 0 deletions

View File

@@ -0,0 +1,56 @@
import { downloadBlob } from './exportImport.js'
export { downloadBlob }
/**
* Build a rocket design JSON Blob for download.
* Schema version 1: inputs section is re-importable; results is reference-only.
*/
export function exportRocketJSON({ outerRadius, tankConfig, propDensities, payload, structure, engineData, geometry }) {
const payload_ = {
version: 1,
type: 'rocket_design',
exportedAt: new Date().toISOString(),
inputs: {
outerRadius,
tankConfig,
propDensities,
payload,
structure,
},
engineData: engineData ?? null,
results: geometry ?? null,
}
return new Blob([JSON.stringify(payload_, null, 2)], { type: 'application/json' })
}
/**
* Parse an imported rocket design JSON string and return the inputs section.
* Throws a descriptive Error if the file is invalid.
*/
export function parseRocketImport(jsonString) {
let data
try {
data = JSON.parse(jsonString)
} catch {
throw new Error('File is not valid JSON.')
}
if (data.type !== 'rocket_design') {
throw new Error('This file is not a rocket design export.')
}
if (data.version !== 1) {
throw new Error(`Unsupported export version: ${data.version}`)
}
const { outerRadius, tankConfig, propDensities, payload, structure } = data.inputs ?? {}
return {
outerRadius: outerRadius ?? null,
tankConfig: tankConfig ?? null,
propDensities: propDensities ?? null,
payload: payload ?? null,
structure: structure ?? null,
engineData: data.engineData ?? null,
}
}