brouberol/5esheets

Change the data model to avoid string concatenation in effect calculations

Closed this issue · 0 comments

To compute the spell DC, we currently need to compute the following effect: scores[spell_ability + '_mod'], meaning that we need to implement string concatenation in effects, at runtime.

To avoid having to do this, we should change the data model, from

"scores": {
  "strength": 8,
  "dexterity": 14,
  "constitution": 12,
  "intelligence": 18,
  "wisdom": 12,
  "charisma": 14,
  "strength_mod": 0,
  "dexterity_mod": 0,
  "constitution_mod": 0,
  "wisdom_mod": 0,
  "charisma_mod": 0,
  "intelligence_mod": 0,
  "strength_save_mod": 0,
  "dexterity_save_mod": 0,
  "constitution_save_mod": 0,
  "wisdom_save_mod": 0,
  "charisma_save_mod": 0,
  "intelligence_save_mod": 0
},
"proficiencies": {
  "saves": {
      "strength": 0,
      "dexterity": 0,
      "constitution": 1,
      "intelligence": 1,
      "wisdom": 0,
      "charisma": 0
  },

to

"abilities": {
  "strength": {
    "score": 10,
    "modifier": 0,
    "save": 0,
    "proficiency": 0
  }
}

This way, the effect formula could be expressed as abilities[spells.spellcasting_ability].modifier.

The same way, skills would change from

"proficiencies": {
  "skills": {
    "acrobatics": 0,
    "arcana": 0,
    "athletics": 0,
    "stealth": 0,
    "animal_handling": 0,
    "sleight_of_hand": 0,
    "history": 1,
    "intimidation": 0,
    "investigation": 0,
    "medicine": 0,
    "nature": 0,
    "perception": 1,
    "insight": 1,
    "persuasion": 1,
    "religion": 0,
    "performance": 0,
    "survival": 0,
    "deception": 0
  }
},

to

"skills": {
  "acrobatics": {
    "proficiency": 0,
    "modifier": 0
  },
  "arcana": {
    "proficiency": 0,
    "modifier": 0
  },
  ...
}