2015-02-28

Feb, Monkeys, etc...

I was really trying to have a demo of Crooked ready by the end of the month, but it isn't quite ready yet. There just aren't enough days in the hour. Anyway I started coding again (almost made it a month) and added some good stuff.

First I added the ability to set a priority for rules. It helps in scenarios where multiple rules have matching criteria counts, but one should be selected over others. I don't see myself using it all the time, but it was easy enough put together.

Then I added pre and post rules. For a while I planned on adding the ability to "sticky" passages, making them always be evaluated before the current passage is displayed. It turns out that is much easier to just have the system do a query for pre and post rules automatically. If there are no pre or post rules defined, then the system won't display anything.

The major thing I wanted to blog about is that I've settled on a unified way of modifying a span of text. Previously if you wanted to make text bold for example, you had to wrap the text in a set of html tags like this:
 <b>my text</b>
My idea was to make this better, and I came up with this:
[b, "my text"]
Sure, in this case there is not much of a gain as far as amount of syntax to write, but check out this comparison of adding colored text:
<color=#ff0080>my text</color>
[#ff0080, "my text"]
It's an improvement. The ease is really clear when you have multiple styles for a piece of text:
<b><i><color=#ff0080>my text</color></i></b>
[b, i, #ff0080, "my text"]

My thinking behind this is that there aught to be a unified way of marking spans of text that are special in some way. I've worked out four important categories for this stuff: Style, Mutability, Visibility and Interactivity.

Style

Styles are self explanatory like bold and italic. I believe they can also include interesting things like animations, fades, typewriting and other visual effects. I have to put more effort into this than I'd like because Unity's default text component is really basic.

Mutability

Mutability is all about changing the text in some interesting way. For example you can truncate a span of text like this:
[Truncate(12), "There is a red monkey on my back"]
Not the most useful feature considering you could just write out the truncation yourself. It is really intended for situations where you have a variable of unknown length that you want to truncate to a specific length:
[set($KEY = "There is a red monkey on my back")]
[Truncate(12), $KEY]
I've included the ability to call set directly within an embed. The variable $KEY in this example is automatically unwrapped and truncated, then the result is displayed.

An important simplification along with all of this is that print looks like this:
[$KEY]
as opposed to the old form:
print($KEY)
Ideally you could just do something like:
$KEY
but then the problem is making sure that normal usage of $ doesn't error out. Wrapping the variable in brackets leads to the other operations that can be done when displaying the variable.


Another piece to mutability is selecting one of several possible pieces of text. Here is an example of this:
[any(random), "random text A", "random text B", "random text C"]
Any text or variable can exist in the embed, then any(random) will decide which one of them is displayed in the final output. I have plans on expanding any() to include a few different means of selection, but for now it is a nice start. Without any() all of the different components in the embed would be displayed, though that probably isn't desirable in most use cases. Eventually I would like to try having format items like this: ["There is a red $KEY on my back"]

Visibility

Visibility is another important category. It isn't as diverse as the others but is equally powerful. The core of it is applying logic to the embed to determine if it should even be displayed. Here is quick example:
Enjoy the rest of your [if($isWeekend == enum.yes), "weekend"][if($isWeekend != enum.yes), "week"].
I prefer rules mostly, but there should be way of showing small pieces of text conditionally. I think this is better than my previous programmer focused if statement.
Enjoy the rest of your if($isWeekend == enum.yes) {weekend} else {week}.
The previous version did have the benifit of being shorter, but there was a limit of only allowing a single 'else if'.

Interactivity

The final category, Interactivity is the challenging one. Currently Unity UI doesn't have the ability to create inline links within the default text component. I have an idea for a way to hack together the feature, but it really sucks. I'll probably hold off on this because I have other things I could be doing, but my ideal syntax for interactive text would be like this:
[passage(Some Passage), "go to the passage"]

If I can figure out a way to work with individual words as unique objects, I'll have a lot of power to control how they are displayed and so forth.

Anyway, all of these embed features stack together. You could for example write a line like this:
There is a [repeat(7), set($m = "Monkey_On_My_Back, "; $a = "Ape_On_My_Back, "; $c = "Chimp_On_My_Back, "), b, #ff6fcf, any(random), Humanize, Lowercase, $m, $a, $c]again.
What this embed does:
  • repeat(7) makes the entire embed repeat it's output 7 times.
  • three variables ($m, $a, $c) are set to different strings of text.
  • the text is marked as bold and pink.
  • any(random) selects one of the three variables for output each iteration.
  • the text will be humanized (made human readable) then set to lowercase.
  • finally $m, $a, $c are the possible items to be selected by any(random).



With this embed setup it is really easy to expand into more interesting functionality. I don't want to get too set in code mode though, I just always have more ideas.

No comments:

Post a Comment