Hello, I just found your library recently and even if you write it three years ago, I have a question :D
I noticed that a key value should be unique for the find method to work efficiently. If not, the method will return the first occurence found in the tree.
How would you handle those use case :
weapon = new Tree()
// type
var sword = tree.add("sword", WEAPON.SWORD);
var axe = tree.add("axe", WEAPON.AXE);
// stats
var sword_attack = sword.add("attack", 10);
var sword_sprite = sword.add("sprite", spr_sword);
var axe_attack = axe.add("attack", 15);
var axe_sprite = axe.add("sprite", spr_axe);
Here each of the sword and axe tree got an attack and sprite key.
if I do weapon.find("attack"), it will obviously return the first one found in the list (probably the sword one since it was the first declared)
The proper way to get it is to chain the find method :
var _attack = weapon.find("sword").find("attack").value
But what if I don't know the number of level ? Or if I want to return all the attack value ? Or all the sword tree if, for instance, I have two weapon tree each cjild of right_hand and left_hand, themselves child of a character tree ?
The two way that come at the top of my head are:
- a
find_all method that would return an array of the relevent trees.
- a
find_from_parent where you would have also a parent parameter that would look one level up the tree (and/or recursively, like the find method does it ?)
Waht do you think ? Am I thinking too much about it ?
Hello, I just found your library recently and even if you write it three years ago, I have a question :D
I noticed that a
keyvalue should be unique for thefindmethod to work efficiently. If not, the method will return the first occurence found in the tree.How would you handle those use case :
Here each of the
swordandaxetree got anattackandspritekey.if I do
weapon.find("attack"), it will obviously return the first one found in thelist(probably theswordone since it was the first declared)The proper way to get it is to chain the
findmethod :But what if I don't know the number of level ? Or if I want to return all the attack value ? Or all the
swordtree if, for instance, I have twoweapontree each cjild ofright_handandleft_hand, themselves child of acharactertree ?The two way that come at the top of my head are:
find_allmethod that would return an array of the relevent trees.find_from_parentwhere you would have also aparentparameter that would look one level up the tree (and/or recursively, like thefindmethod does it ?)Waht do you think ? Am I thinking too much about it ?