"use strict"; /** * 存储 enum 管理 */ Object.defineProperty(exports, "__esModule", { value: true }); exports.removeEnumObserver = exports.addEnumObserver = exports.clearDynamicEnum = exports.clearEnum = exports.declareEnum = exports.removeDynamicEnumToType = exports.changeDynamicEnumValue = exports.declareDynamicEnumToType = exports.getDynamicEnumByType = exports.getEnumByType = void 0; const enumMap = new Map(); const dynamicEnumMap = new Map(); const enumEventMap = new Map(); function getEnumByType(type) { return enumMap.get(type) || []; } exports.getEnumByType = getEnumByType; function getDynamicEnumByType(type) { return dynamicEnumMap.get(type) || []; } exports.getDynamicEnumByType = getDynamicEnumByType; function emitEventByType(type) { const eventList = enumEventMap.get(type) || []; eventList.forEach((event) => event()); } /** * 用于动态声明枚举 * @param options */ function declareDynamicEnumToType(options) { const enumList = dynamicEnumMap.get(options.type) || []; if (!enumList.find((item) => item.name === options.name)) { enumList.push({ name: options.name, value: enumList.length, }); updateDynamicEnumMap(options.type, enumList); return true; } return false; } exports.declareDynamicEnumToType = declareDynamicEnumToType; function changeDynamicEnumValue(type, newValue, oldValue) { const enumList = dynamicEnumMap.get(type) || []; const index = enumList.findIndex((item) => item.name === oldValue); if (index !== -1) { enumList[index].name = newValue; updateDynamicEnumMap(type, enumList); } } exports.changeDynamicEnumValue = changeDynamicEnumValue; function removeDynamicEnumToType(type, singleEnum) { const enumList = dynamicEnumMap.get(type) || []; const index = enumList.findIndex((item) => item.name === singleEnum); if (index !== -1) { enumList.splice(index, 1); updateDynamicEnumMap(type, enumList); } } exports.removeDynamicEnumToType = removeDynamicEnumToType; function declareEnum(type, ccEnum) { updateEnumMap(type, ccEnumToList(ccEnum)); } exports.declareEnum = declareEnum; function clearEnum() { enumMap.clear(); enumMap.forEach((value, type) => removeEnumObserver(type)); } exports.clearEnum = clearEnum; function clearDynamicEnum() { dynamicEnumMap.clear(); dynamicEnumMap.forEach((value, type) => removeEnumObserver(type)); } exports.clearDynamicEnum = clearDynamicEnum; function addEnumObserver(type, func) { const eventList = enumEventMap.get(type) || []; eventList.push(func); enumEventMap.set(type, eventList); } exports.addEnumObserver = addEnumObserver; function removeEnumObserver(type) { enumEventMap.delete(type); } exports.removeEnumObserver = removeEnumObserver; function ccEnumToList(ccEnum) { const enums = []; for (const name in ccEnum) { const v = ccEnum[name]; if (Number.isInteger(v)) { enums.push({ name, value: v }); } } enums.sort((a, b) => a.value - b.value); return enums; } function updateEnumMap(type, enumList) { enumMap.set(type, enumList); emitEventByType(type); } function updateDynamicEnumMap(type, enumList) { dynamicEnumMap.set(type, enumList); emitEventByType(type); } //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZW51bS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9ibG9jay1mb3JnZS9lbnVtLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQTs7R0FFRzs7O0FBWUgsTUFBTSxPQUFPLEdBQTRCLElBQUksR0FBRyxFQUFFLENBQUM7QUFDbkQsTUFBTSxjQUFjLEdBQTRCLElBQUksR0FBRyxFQUFFLENBQUM7QUFDMUQsTUFBTSxZQUFZLEdBQTRCLElBQUksR0FBRyxFQUFFLENBQUM7QUFFeEQsU0FBZ0IsYUFBYSxDQUFDLElBQVk7SUFDdEMsT0FBTyxPQUFPLENBQUMsR0FBRyxDQUFDLElBQUksQ0FBQyxJQUFJLEVBQUUsQ0FBQztBQUNuQyxDQUFDO0FBRkQsc0NBRUM7QUFFRCxTQUFnQixvQkFBb0IsQ0FBQyxJQUFZO0lBQzdDLE9BQU8sY0FBYyxDQUFDLEdBQUcsQ0FBQyxJQUFJLENBQUMsSUFBSSxFQUFFLENBQUM7QUFDMUMsQ0FBQztBQUZELG9EQUVDO0FBRUQsU0FBUyxlQUFlLENBQUMsSUFBWTtJQUNqQyxNQUFNLFNBQVMsR0FBRyxZQUFZLENBQUMsR0FBRyxDQUFDLElBQUksQ0FBQyxJQUFJLEVBQUUsQ0FBQztJQUMvQyx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