import SKILLS from '@constants/skills'; import style from './index.css'; function getInitials (string) { const numWords = (string.match(/\s/g) || []).length + 1; switch (numWords) { case 1: return string.slice(0, 3); case 2: return (string.match(/^\w{1,2}|\s\w{1,2}/g) || []).join('').replace(/\s/g, ''); default: return (string.match(/^\w|\s\w/g) || []).join('').replace(/\s/g, ''); } } export default function Skill ({ name = '?', text = 'Long description', ranks = 0, invested = 0, tier = 0, level = 1, effect = (rank, level) => `Rank ${rank} effect`, type = null, enabled = true, onChange = (oldValue, newValue) => null, }) { const isAugment = [ SKILLS.AUGMENT_CHEVRON, SKILLS.AUGMENT_DIAMOND, SKILLS.ACTION_SKILL, ].includes(type); let shapeStyle = null; if (type === SKILLS.AUGMENT_CHEVRON) { shapeStyle = style.chevron; } if (type === SKILLS.AUGMENT_DIAMOND) { shapeStyle = style.diamond; } if (type === SKILLS.ACTION_SKILL) { shapeStyle = style.actionSkill; } function clickListener (event) { var newValue; if (event.type === 'click') { newValue = Math.min(invested + 1, ranks); } else { // (event.type === 'contextmenu') newValue = Math.max(invested - 1, 0); } if (enabled && invested !== newValue) { onChange(invested, newValue); } event.preventDefault(); return false; } return (
0) ? style.usable : '', ].join(' ')} onClick={clickListener} onContextMenu={clickListener} >
{getInitials(name)}
{ enabled && ranks > 0 &&
{invested}/{ranks}
}

{name}

{text} { invested > 0 &&
Current Effect:
{effect(invested, level)}
} { type !== null &&
{effect(1, level)}
} { type == null && invested < ranks &&
Next Rank:
{effect(invested, level)}
}
); }