britzl / defold-richtext

Defold-RichText is a system to create styled text based on an HTML inspired markup language
MIT License
75 stars 12 forks source link

wait tag #56

Closed subsoap closed 4 years ago

subsoap commented 4 years ago

I added this tag to a custom version of RichText for my needs in a visual novel style project. It would probably be useful for others but I'm not sure if it should be a part of the main project. These are the main changes.

    elseif tag == "wait" then
        settings.wait = tonumber(params)
        if is_empty then
            -- empty tag, ie tag without content
            -- example <br/> and <img=texture:image/>
            local tag_settings = parse_tag(name, params)
            merge_tags(word_settings, tag_settings)
            local add_this_word = ""
            if tag_settings.wait ~= nil and tag_settings.wait > 0 then
                local wait_word = "\226\128\139"
                for i=1, tag_settings.wait do
                    add_this_word = add_this_word .. wait_word
                end
            end
            add_word(add_this_word, word_settings, all_words)
        elseif not is_endtag then

Then the tag is used like <wait=30> which inserts 30 zero width characters. This is useful in visual novel projects where you have text appearing once character at a time and you want to add small delays between actions.

subsoap commented 4 years ago

If a wait tag is added similar to this then an action tag should be added too then these actions can be listened to within timer.delay(), and acted upon when using the truncate feature in games like visual novels. The action:name can be totally arbitrary and up to the project to deal with as it appears.

britzl commented 4 years ago

The wait tag is interesting but feels a bit too game specific. Maybe a "repeat" tag that will repeat the enclosed text one or more times?

Or maybe it should be possible to specify a callback function which will be invoked when an unknown tag is encountered while parsing the text. This would allow developers to handle game specific tags while parsing text.

The "action" tag is also quite interesting. The tag could trigger a callback function which would allow developers to react to these actions/events when encountered.

subsoap commented 4 years ago

Callback function methods would be cool as a way to define custom tag behavior / react to action tags. What I am doing in my project is using Broadcast to signal the data that is then used elsewhere. Playing sounds / animations / screen effects as certain text passes by.

<repeat=text:times/> ?

subsoap commented 4 years ago

Another example of how I'm using action tag, when this text is truncated a particlefx is positioned on the char and plays to give an effect to make that text more special.

"<action=particles:text_emitter>Make this pretty</action>"
britzl commented 4 years ago

For the repeat tag I was thinking like this:

<repeat=10>&zwsp;</repeat>
subsoap commented 4 years ago

That would work well. Then any tags that overlap would also be applied and repeat on the repeated text?