( flowFileName: string, flowData: SerializedNodeGraph, packName: string, flowOptions: UserFlowOptionValues | undefined, isDebug: boolean, )
| 1283 | } |
| 1284 | }; |
| 1285 | const prepareFlow = ( |
| 1286 | flowFileName: string, |
| 1287 | flowData: SerializedNodeGraph, |
| 1288 | packName: string, |
| 1289 | flowOptions: UserFlowOptionValues | undefined, |
| 1290 | isDebug: boolean, |
| 1291 | ): PreparedFlow => { |
| 1292 | const preparedNodes = deepClone(flowData.nodes); |
| 1293 | const preparedConnections = deepClone(flowData.connections); |
| 1294 | const flowNameWithoutPath = flowFileName.replace(/^.*[\\/]/, ""); |
| 1295 | const flowNameWithoutExt = flowNameWithoutPath.replace(/\.[^.]+$/, ""); |
| 1296 | const flowExecutionId = `${packName}_${flowNameWithoutExt}`; |
| 1297 | const currentGameSchema = DBNameToDBVersions[appData.currentGame]; |
| 1298 | const nodeConfigs: Record<string, unknown> = {}; |
| 1299 | const optionReplacements = |
| 1300 | flowData.options?.map((option) => { |
| 1301 | const userValue = flowOptions?.optionValues?.[option.id]; |
| 1302 | const valueToUse = userValue !== undefined ? userValue : option.value; |
| 1303 | const placeholder = `{{${option.id}}}`; |
| 1304 | return { |
| 1305 | placeholder, |
| 1306 | matcher: new RegExp(placeholder.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), "g"), |
| 1307 | replacement: String(valueToUse), |
| 1308 | }; |
| 1309 | }) ?? []; |
| 1310 | for (const node of preparedNodes) { |
| 1311 | if (optionReplacements.length > 0) { |
| 1312 | for (const fieldName of flowOptionTextFields) { |
| 1313 | const fieldValue = (node.data as any)[fieldName]; |
| 1314 | if (typeof fieldValue !== "string" || fieldValue.length === 0) { |
| 1315 | continue; |
| 1316 | } |
| 1317 | let modifiedValue = fieldValue; |
| 1318 | for (const optionReplacement of optionReplacements) { |
| 1319 | if (!modifiedValue.includes(optionReplacement.placeholder)) { |
| 1320 | continue; |
| 1321 | } |
| 1322 | modifiedValue = modifiedValue.replace(optionReplacement.matcher, optionReplacement.replacement); |
| 1323 | } |
| 1324 | if (modifiedValue !== fieldValue) { |
| 1325 | (node.data as any)[fieldName] = modifiedValue; |
| 1326 | } |
| 1327 | } |
| 1328 | } |
| 1329 | if (node.data.useCurrentPack === true) { |
| 1330 | if (node.type === "packfilesdropdown") { |
| 1331 | node.data.selectedPack = packName; |
| 1332 | } else if (node.type === "packedfiles") { |
| 1333 | node.data.textValue = packName; |
| 1334 | } |
| 1335 | } |
| 1336 | if (node.type === "savechanges") { |
| 1337 | (node.data as any).flowExecutionId = flowExecutionId; |
| 1338 | } |
| 1339 | if (schemaAwareFlowNodeTypes.has(node.type)) { |
| 1340 | const existingSchema = (node.data as any).DBNameToDBVersions; |
| 1341 | if (!existingSchema || Object.keys(existingSchema).length === 0) { |
| 1342 | (node.data as any).DBNameToDBVersions = currentGameSchema; |
no test coverage detected