#StackBounty: #unity #data-structure #text #localization How to store and update presentation strings describing effects with parameters?

Bounty: 50

Consider this spell:

Drain Life

As you can see in my design a Spell is a composition of one or more Effects. An Effect has properties on it like value, range, etc. So, I can say that the Spell Description is an aggregate description of the composition of effects.

Presentation Layer

In my presentation, I want to decorate part of the description string in HTML tags and display as rich text. I also want to ensure that my string’s numeric values come from data.

Solution 1

Simply hard code the string. In this case the spell description would look like: Choose a target within <#f4b350>4</color> squares. Deal <#f33613>4</color> damage to that target and restore your HP by <#3cf73c>50%</color> of the damage done.

This approach has some obvious issues, namely:

  • Changing the color value of a particular tag would be a nightmare when there are hundreds of abilities
  • Changing the damage value of a spell means updating it in two places, the string and the data

Solution 2

Create a tag series separated by _ that indicates various properties. I could for example, do something like Deal {subtractive_value} damage to that target with the idea that when I go to parse the string, subtractive could be a tag indicating a red color, and value can be a tag indicating that its the effect’s value that should go there.

This is all fine except that a spell can have multiple effects. I need a way to associate the part of the description with the specific effect that drives it.

Modification to Solution 2

So then I suppose I could just add IDs to the spell effects such that the string defined in data becomes:

Choose a target within {neutral_damageEffect_range} squares. Deal {subtractive_damageEffect_value} damage to that target and restore your HP by {additive_healEffect_value}.

But now you see that its getting a bit cumbersome and I’m dubious of how scalable that solution is.

Non-Goal

Lastly I figured I’d mention a non-goal. If you take my approach thus far to its ultimate conclusion, you would probably end up with trying to find a way to generate your description text from the effect themselves. While this is an interesting idea, I think it’s a bit too ambitious, so I’m specifically not trying to do that. That said, if you feel like that’s easier than I think it is, feel free to make that suggestion!

Question

So, given what I’ve tried and the problem I’m trying to solve, there’s no way this is a unique problem to me. Is there a battle-tested solution to this problem? What’s a good way to go about it or some patterns to use I might not know about?

EDIT

Some have asked for some code, it is lengthy though so I can just link to a gist here:
https://gist.github.com/jsandersr/ef6d560ad95f1d63b1f8e3b2099038a5


Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.