diff options
| -rwxr-xr-x[-rw-r--r--] | index.js | 11 |
1 files changed, 10 insertions, 1 deletions
@@ -1,3 +1,5 @@ +#!/usr/bin/env node + const builder = require('xmlbuilder'); const fs = require('fs'); @@ -14,6 +16,11 @@ const inputData = JSON.parse(inputString); const printableNumber = n => (n > 0) ? "+" + n : n; +const capitalize = (s) => { + if (typeof s !== 'string') return '' + return s.charAt(0).toUpperCase() + s.slice(1) +}; + const replaceSpecialValuesInActionText = (text) => { text = text.replace(/\{@hit (\d+?)\}/g, (match, p1) => printableNumber(p1)) text = text.replace(/\{@h\}(\d+?)/g, '$1'); @@ -21,6 +28,8 @@ const replaceSpecialValuesInActionText = (text) => { text = text.replace(/\{@dc (\d+?)\}/g, 'DC $1'); text = text.replace(/\{@condition (\w+)\}/g, '$1'); text = text.replace(/\{@skill (\w+)\}/g, '$1'); + text = text.replace(/\{@dice (.+?)\}/g, '$1'); + text = text.replace(/\{@spell (.+?)\}/g, (match, p1) => capitalize(p1)); text = text.replace(/\{@atk (.+?)\}/g, (match, p1) => { p1 = p1.replace(/mw/g, 'Melee Weapon Attack'); p1 = p1.replace(/ms/g, 'Melee Spell Attack'); @@ -72,7 +81,7 @@ const parseToXML = (obj) => { }).join(', ')); monster.ele('save', obj.save && Object.keys(obj.save).map((key) => { - return `${type} ${obj.save[key]}`; + return `${key} ${obj.save[key]}`; }).join(', ')); monster.ele('skill', obj.skill && Object.keys(obj.skill).map((key) => { |
