Please note: I don't want coding help here, I'm on
Programmers for a reason. I want to improve my program planning/writing skills not (just) my understanding of Java.
I'm trying to figure out how to make a tree which has an arbitrary category system, based on the skills listed for this LARP game here. My previous attempt had a bool for whether a skill was also a category. Trying to code around that was messy. Drawing out my tree I noticed that only my 'leaves' were skills and I'd labeled the others as categories.
What I'm after is a way to make a tree which attempts to separate Model and View, and allow adding an arbitary type of child node (with a separate way of being edited/rendered) to an arbitrary parent.
N.B Everything here is bought as a skill, even where it seems like a property. The End-Users will see this as buying skills (which they do on paper atm) so should be presented as such, all on the same page.
Explanation of tree: The Tree is 'born' with a set of hard coded highest level categories (Weapons, Physical and Mental, Medical and more etc.). From this the user needs to be able to add a skill. Ultimately they want to add the 'One-handed Sword Specialisation' skill (not item) for instance. To do so you'd ideally click 'add' with
Weapons selected and then select
One-handed from a combobox node that appears on that child, then click add again and enter a name in a text field on that child node that appears. Then click add again to add/specify a 'level' or 'tier' for that leaf; first proficiency, then specialisation (for example).
Of course if you want to buy a different skill it's a completely different route to the leaf. You might not need a combo box at the same level down the tree as you did with the weapon example, and need some other logic behind it too. This is what I'm having trouble getting my head around let alone programming in; how to make a set of classes and not specify what order to attach them together in, but still have them all fit.
What is a good system for describing this sort of tree in code? All the other JTree examples I've seen have some predictable pattern, and mine doesn't. I don't want to have to code this all in 'literals', with long lists of what type (combo-box, text field etc) of children node should be allowed on what parent. Should I be using abstract classes? Interfaces?
How can I make this sort of cluster of objects extensible when I add in other skills not listed above that behave differently?
If there is not a good system to use, is there a good process for working out how to do this sort of thing?
The gears in my head are turning:
I always need to:
- Check the parent
- Provide options based on the parent
I'm begining to think becasue of this commonality I need some sort of abstract/interface
skill class that defines/outlines common methods for skill and category. I can (hopefully) put rules and options in a database and read to-from there. The question is I think now, between an abstract or interface method and how to bes implement that.