As a school project, I'm creating a Discord Bot with Discord.js,
I'm currently trying to make multiple functions that can be executed through a JSON. I thought about storing every single function in a Map with an explicit key related to them, and putting my JSON like this :
"apple": {
"name": "Apple",
"description": "An apple. Gives 5 Health Points."
"heal": 1,
"saturation": 20,
},
So when the code goes through the JSON, it executes the heal() and saturation() function, found with the corresponding keys "heal" and "saturation".
Is it good practice to do it this way ?
Also, do you have any reference or exemples of an effecient way to register every function in a Map ? I'm currently thinking of just running a setup function like this :
const skillMap = new Map();
module.exports = {
setupSkills(client) {
skillMap.set("heal", heal);
skillMap.set("damage", damage);
}
}
function heal(quantity) {
console.log("Healed " + quantity);
}
function damage(quantity) {
console.log("Damaged " + quantity);
}
I understand that this question can be quite vague, but any help is greatly appreciated. Thanks in advance !