For the sake of clarity, I will do my best to frame the question through the lens of an example, rather than a code dump.
Before getting into my example, my question is as follows: How can I write a method that takes an enum as a parameter, and returns the static-information stored in an object (which inherits from a communal parent, where the static information is defined).
The example:
I am creating a game which includes many player-skills. These skills are created via an object tree, with the following inheritance (SomeSkill represents any of a dozen or so skills):
Skill > ActiveSkill > SomeSkill and Skill > PassiveSkill > SomeSkill
Psuedo-code for the class Skill:
Class Skill{
static string name = "Default Skill"
int level;
Skill(int level){
this.level = level;
}
static getName{
return name;
}
}
Name is static, since the name of the skill shouldn't change, regardless of the intance. In my actual implementation, Skill also includes static information description, and id.
Actual implementation of enum:
public enum SkillType
{
basic, speed_buff, leap, beat_down
}
The problem:
What I am struggling to do is write a method that takes a SkillType enum as an argument, and returns a usable Skill object (NOT an instance of the Skill object)
In Psuedo code: As an example, if I wanted to loop through the Enum and print out the names of all skills...
method getSkillClass(SkillType skillType){
if(skillType == beat_down) return BeatDown
if(skillType == leap) return Leap
...
}
for(e : SkillType.getKeys){
print(getSkillClass(e).getName);
}
My current "solution" would be to create a map that matches SkillType to a list of instanced out Skills, with all non-static skill information set to default values.
This seems like an abuse of the system though.
How can I cleanly link my enum-list to the static information (the non-static information can be ignored) in my various skill classes?