From 25b4628348303091d9b4e24e8778c4b0ddf0b3f5 Mon Sep 17 00:00:00 2001 From: Adam Goldsmith Date: Wed, 8 Sep 2021 13:16:38 -0400 Subject: [PATCH] Improve handling of integers, including values of 'X' --- strange_eons_to_arkhamdb.js | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/strange_eons_to_arkhamdb.js b/strange_eons_to_arkhamdb.js index 350fea2..332632f 100644 --- a/strange_eons_to_arkhamdb.js +++ b/strange_eons_to_arkhamdb.js @@ -85,22 +85,33 @@ const card_types = { "AHLCG-WeaknessTreachery-Default": "treachery", }; +function int_or_null(inp) { + if (inp == 'None') { + return null; + } + else if (inp == 'X') { + return -2; + } + else { + return parseInt(inp); + } +} + var card_data = { code: String(code), - // TODO: handle None/X - cost: parseInt(Component.settings.get('ResourceCost')) || null, + cost: int_or_null(Component.settings.get('ResourceCost')), deck_limit: 2, // TODO: could be derived? faction_code: String(Component.settings.get('CardClass')).toLowerCase(), flavor: substitute_tags(String(Component.settings.get('Flavor'))), - health: parseInt(Component.settings.get('Stamina')) || null, + health: int_or_null(Component.settings.get('Stamina')), illustrator: String(Component.settings.get('Artist')), is_unique: Component.settings.getBoolean('Unique'), name: substitute_tags(String(Component.getName())), pack_code: pack_code, - position: parseInt(Component.settings.get('CollectionNumber')) || null, + position: int_or_null(Component.settings.get('CollectionNumber')), quantity: 2, // TODO //restrictions: null, // TODO - sanity: parseInt(Component.settings.get('Sanity')) || null, + sanity: int_or_null(Component.settings.get('Sanity')), skill_agility: skills["Agility"], skill_combat: skills["Combat"], skill_intellect: skills["Intellect"], @@ -111,7 +122,7 @@ var card_data = { Component.settings.get('Keywords') + '\n' + Component.settings.get('Rules'))), traits: substitute_tags(String(Component.settings.get('Traits'))), type_code: card_types[Component.getFrontTemplateKey()], - xp: parseInt(Component.settings.get('Level')) || null, + xp: int_or_null(Component.settings.get('Level')), }; var raw_slot = Component.settings.get('Slot');