I have a game where I have a hierarchy where a season has multiple levels and a level has multiple tasks.
Now, I have an Activity that shows a congratulatory message for each of these parts of the hierarchy which are divided in different strings. Each of them have:
- Exclamation
- Header
- Description
- Continue Message
For example season:
- "HURRAY!"
- "Season Finished"
- "You have successfully finished season X"
- "Continue to season X+1"
My first idea was to create an enum that holds the appropriate values. Like this:
enum class CongratulationsType(val exclamation: String, val header: String) {
SEASON("HURRAY!", "You finished season %d!!"),
LEVEL("YAY!", "Well done! Level over!"),
TASK("NICE!", "This looked too easy")
}
...
val headerString = CongratulationsType.SEASON.header
But strings should be saved in resources. So I would have to put the strings into the resources and correctly link the resources to the enum values.
This would mean that I kinda do the work twice. I would define the strings in the resource file without a "binding structure", just to then put them into the enum to have a "binding structure". By "binding structure" I mean the structure described above where it's mandatory for the specific fields to exist and where I would be able to call something like CongratulationsType.SEASON.header.
My question is: Is it possible to "pack" strings in some defined structure and have that structure be something like an enum or a hashmap? Something like:
Pack definition
<resources>
<pack_def name="congrats">
<string name="exclamation"/>
<string name="header"/>
...
</pack_def>
<resources>
Pack implementation
<resources>
<pack name="season" type="congrats">
<string name="exclamation">HURRAY!</string>
<string name="header">Season Finished</string>
...
</pack>
<resources>
Usage
// In code
//// function definition
fun setMessage(congrats: Congrats) {
exclamationTextView.text = congratsType.exclamation
headerTextView.text = congratsType.header
...
}
//// function use
setMessage(Congrats.Season)
// In Resources
<TextView
android:text="@packs/congrats/season/exclamation"
/>
I know that I could use string array resources but they seem a little bit "unclean" because, as I said, I want the structure to be "binding" and called like enums. I'm specifically asking for a way to do it as close to enums as possible without having to assign a resource to each field for each enum value.