UNPKG

simc-ast-builder

Version:

Parser and AST generator for SimulationCraft files

54 lines 1.73 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.handleSetBonus = void 0; const fieldMaps_1 = require("../../utils/fieldMaps"); function extractSetInfo(input) { // First, check if it's a direct set name (like "tww2") const directSetMatch = input.match(/^(tww\d+|tier\d+)$/); if (directSetMatch) { return { fieldName: (0, fieldMaps_1.getDefaultField)("set_bonus"), setName: directSetMatch[1], }; } // Then check for the pattern with piece count const regex = /([a-z0-9_]+)_(\d+)pc/; const match = input.match(regex); if (!match) { return null; } let setName = match[1]; const pieceCount = parseInt(match[2], 10); // Check for "thewarwithin_season_X" pattern and normalize to "twwX" const seasonMatch = setName.match(/thewarwithin_season_(\d+)/); if (seasonMatch) { setName = `tww${seasonMatch[1]}`; } return { fieldName: `has_${pieceCount}pc`, setName, }; } /** * Handler for set_bonus access contexts */ const handleSetBonus = ({ parts }) => { if (parts.length < 2) { throw new Error("Invalid set_bonus access"); } const setInfo = extractSetInfo(parts[1]); if (!setInfo) { throw new Error(`Could not parse set_bonus: ${parts[1]}`); } // Get the appropriate field definition const fieldDef = (0, fieldMaps_1.getFieldDef)(setInfo.fieldName); return { expressionType: fieldDef.type, field: fieldDef, kind: "expression", nodeType: "set_bonus", setName: setInfo.setName, }; }; exports.handleSetBonus = handleSetBonus; //# sourceMappingURL=SetBonusHandler.js.map