aboutsummaryrefslogtreecommitdiffstats
path: root/index.js
diff options
context:
space:
mode:
authorJan Tuomi <jan.tuomi@eficode.com>2019-07-02 21:36:30 +0300
committerJan Tuomi <jan.tuomi@eficode.com>2019-07-02 21:36:30 +0300
commita3f42d69d6463fd30fdf054882493b835a54d001 (patch)
tree76b0999b609072d942939896eb249d128d7f37dd /index.js
parent05d8a2876fed9eb189264103eaad69c41f6836cb (diff)
Improve speed, immune field parsing
Diffstat (limited to 'index.js')
-rwxr-xr-xindex.js40
1 files changed, 32 insertions, 8 deletions
diff --git a/index.js b/index.js
index 6699975..90ae14c 100755
--- a/index.js
+++ b/index.js
@@ -70,16 +70,40 @@ const parseToXML = (obj) => {
? obj.senses.join(', ')
: null
);
- monster.ele('immune', obj.immune && obj.immune.length
- ? obj.immune.join(', ')
- : null
- );
-
- monster.ele('speed', obj.speed && Object.keys(obj.speed).map((key) => {
- const type = key == 'walk' ? '' : key;
- return `${type} ${obj.speed[key]} ft.`;
+ monster.ele('immune', obj.immune && obj.immune.length && obj.immune.map((item) => {
+ if (typeof item === 'string') {
+ return item;
+ } else {
+ let res = '';
+ if (item.preNote) {
+ res += item.preNote;
+ }
+ if (item.immune) {
+ res += item.immune.join(', ');
+ }
+ if (item.postNote) {
+ res += item.postNote;
+ }
+ return res;
+ }
}).join(', '));
+ const speedTypes = ['walk', 'burrow', 'climb', 'fly', 'swim'];
+ monster.ele('speed', obj.speed && speedTypes.map((key) => {
+ const value = obj.speed[key];
+ const type = key === 'walk' ? '' : key;
+ if (typeof value === 'object') {
+ const num = value.number;
+ const cond = value.condition || '';
+ return `${type} ${num} ft. ${cond}`.trim();
+ } else if (!!value) {
+ const num = obj.speed[key];
+ return `${type} ${num} ft.`;
+ } else {
+ return undefined;
+ }
+ }).filter(a => !!a).join(', ').trim());
+
monster.ele('save', obj.save && Object.keys(obj.save).map((key) => {
return `${key} ${obj.save[key]}`;
}).join(', '));