Files
web-page/src/pages/saju/_shell/helpers/deriveTraits.js

32 lines
1.2 KiB
JavaScript

const TRAIT_DEFS = {
fire: { id: 'challenge', ko: '도전정신', icon: 'challenge', color: 'var(--el-fire)' },
metal: { id: 'lead', ko: '리더십', icon: 'lead', color: 'var(--el-metal)' },
wood: { id: 'adapt', ko: '적응력', icon: 'adapt', color: 'var(--el-wood)' },
water: { id: 'wisdom', ko: '지혜', icon: 'wisdom', color: 'var(--el-water)' },
earth: { id: 'wealth', ko: '풍부함', icon: 'wealth', color: 'var(--el-earth)' },
};
const WILL_TRAIT = { id: 'will', ko: '의지', icon: 'will', color: 'var(--purple)' };
export default function deriveTraits(elements, sipsin = []) {
const sorted = Object.entries(elements || {})
.filter(([, v]) => typeof v === 'number')
.sort((a, b) => b[1] - a[1]);
const traits = [];
for (const [el, score] of sorted) {
if (score >= 30 && TRAIT_DEFS[el]) {
traits.push(TRAIT_DEFS[el]);
}
}
if (!traits.find((t) => t.id === 'will')) traits.push(WILL_TRAIT);
for (const [el] of sorted) {
if (traits.length >= 6) break;
if (TRAIT_DEFS[el] && !traits.find((t) => t.id === TRAIT_DEFS[el].id)) {
traits.push(TRAIT_DEFS[el]);
}
}
return traits.slice(0, 6);
}