ensure die count and size are whole numbers
This commit is contained in:
		
							parent
							
								
									ed80e08755
								
							
						
					
					
						commit
						5c517fad67
					
				| 
						 | 
					@ -280,6 +280,9 @@ export const parseRoll = (fullCmd: string, modifiers: RollModifiers): SolvedRoll
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Translate the errorName to a specific errorMsg
 | 
					    // Translate the errorName to a specific errorMsg
 | 
				
			||||||
    switch (errorName) {
 | 
					    switch (errorName) {
 | 
				
			||||||
 | 
					      case 'WholeDieCountSizeOnly':
 | 
				
			||||||
 | 
					        errorMsg = 'Error: Die Size and Die Count must be whole numbers';
 | 
				
			||||||
 | 
					        break;
 | 
				
			||||||
      case 'YouNeedAD':
 | 
					      case 'YouNeedAD':
 | 
				
			||||||
        errorMsg = 'Formatting Error: Missing die size and count config';
 | 
					        errorMsg = 'Formatting Error: Missing die size and count config';
 | 
				
			||||||
        break;
 | 
					        break;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -73,6 +73,9 @@ export const roll = (rollStr: string, maximizeRoll: boolean, nominalRoll: boolea
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // Fill out the die count, first item will either be an int or empty string, short circuit execution will take care of replacing the empty string with a 1
 | 
					  // Fill out the die count, first item will either be an int or empty string, short circuit execution will take care of replacing the empty string with a 1
 | 
				
			||||||
  const rawDC = dPts.shift() || '1';
 | 
					  const rawDC = dPts.shift() || '1';
 | 
				
			||||||
 | 
					  if (rawDC.includes('.')) {
 | 
				
			||||||
 | 
					    throw new Error('WholeDieCountSizeOnly');
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
  const tempDC = rawDC.replace(/\D/g, '');
 | 
					  const tempDC = rawDC.replace(/\D/g, '');
 | 
				
			||||||
  // Rejoin all remaining parts
 | 
					  // Rejoin all remaining parts
 | 
				
			||||||
  let remains = dPts.join('d');
 | 
					  let remains = dPts.join('d');
 | 
				
			||||||
| 
						 | 
					@ -101,10 +104,14 @@ export const roll = (rollStr: string, maximizeRoll: boolean, nominalRoll: boolea
 | 
				
			||||||
    rollType = 'ova';
 | 
					    rollType = 'ova';
 | 
				
			||||||
    manualParse = true;
 | 
					    manualParse = true;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Get CWOD parts, setting count and getting difficulty
 | 
					    // Get OVA parts, setting count and getting difficulty
 | 
				
			||||||
    const ovaParts = rollStr.split('ovad');
 | 
					    const ovaParts = rollStr.split('ovad');
 | 
				
			||||||
 | 
					    const ovaPart1 = ovaParts[1] || '6';
 | 
				
			||||||
 | 
					    if (ovaPart1.search(/\d+\.\d/) === 0) {
 | 
				
			||||||
 | 
					      throw new Error('WholeDieCountSizeOnly');
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
    rollConf.dieCount = parseInt(ovaParts[0] || '1');
 | 
					    rollConf.dieCount = parseInt(ovaParts[0] || '1');
 | 
				
			||||||
    rollConf.dieSize = parseInt(ovaParts[1] || '6');
 | 
					    rollConf.dieSize = parseInt(ovaPart1);
 | 
				
			||||||
  } else if (remains.startsWith('f')) {
 | 
					  } else if (remains.startsWith('f')) {
 | 
				
			||||||
    // fate dice setup
 | 
					    // fate dice setup
 | 
				
			||||||
    rollType = 'fate';
 | 
					    rollType = 'fate';
 | 
				
			||||||
| 
						 | 
					@ -128,6 +135,10 @@ export const roll = (rollStr: string, maximizeRoll: boolean, nominalRoll: boolea
 | 
				
			||||||
    // Get the die size out of the remains and into the rollConf
 | 
					    // Get the die size out of the remains and into the rollConf
 | 
				
			||||||
    rollConf.dieSize = parseInt(remains.slice(0, afterDieIdx));
 | 
					    rollConf.dieSize = parseInt(remains.slice(0, afterDieIdx));
 | 
				
			||||||
    remains = remains.slice(afterDieIdx);
 | 
					    remains = remains.slice(afterDieIdx);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (remains.search(/\.\d/) === 0) {
 | 
				
			||||||
 | 
					      throw new Error('WholeDieCountSizeOnly');
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (!rollConf.dieCount || !rollConf.dieSize) {
 | 
					  if (!rollConf.dieCount || !rollConf.dieSize) {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue