Wynntils

Wynntils

611k Downloads

Encode Component into strings losslessly

magicus opened this issue · 6 comments

commented

Several parts of Wynntils (like the ChatManager, and the Translation API) would benefit from us being able to convert a Component into a text encoding, which can then losslessly be converted back to a Component. Basically, I'm thinking something like this:

§6{Hello there, }§7{Stranger!} §0{Click on §L{http://www.wynntils.com;this link}!}

In the best of all worlds, we could even use this encoding to do regexp matching. The current code that converts to the "classic" format codes is a one-way street, basically since we lose the "end of formatting" information that is present in the Component. While it might have it's uses (it's served us well, so far), I think it is suboptimal. But the regexp matching on strings is much easier than trying to match an actual Component. So a faithful but still readable representation of Components as a string would be a benefit for all of the mod.

Before deciding on a format, I need to look into what kind of formatting is allowed by Component. The format also needs to be regexp friendly. And trivial to parse and generate.

commented

Notices from another bug, specifically about translations:

Things we can do:

preserve leading spaces
preserve Wynntils item coding
encode a Component into a string using a custom format, keeping "hover" and "onclick" attributes.

At the moment, none of these seems really worth the effort. Keeping it here as a reminder.

commented

Here are some ideas from discord on how to encode hover texts:

One of the problems I have not fully solved is that this might partially defeat our purpose of doing this in the first place. If you have a large hover text, then it will appear to be part of the message itself (I mean, in a way it is, but also not as we mean it), and any regex matches can mistakenly be triggered by the hover text instead.

Maybe we should just append the hover text as an "appendix" and reference it with a number or has from within the "real" string. We could then have the regexp cut off at a marker between the "real" text and the list of over appendices.

§aYou found a §3§{hover:1}Magical Unicorn!<EOTMARKER>1:§7Actually, it is a fake plastic copy.§r

That way we can chose whether we want to do regexp searches (and/or replacements) in both the "real" text and the hover, or only the real text. With that, we could even have like highlight of your user name in hovers.

commented

More discord logs:

Or we could transform a Component into a record CodedString(String realMsg, List<Appendix> appendices)

If we do that, we get an additional change which might be both good and bad. I've been thinking about doing it intentionally, but have also dreaded the consequences: We need to replace all String with CodedString, wherever we have a coded string.

On the one hand, I think it is good to be explicit about this. But on the other hand, it is used in a loooot of places. And we'd probably have to convert back and forth between String and CodedString in several places.

commented

@Seadragon91 That has nothing to do with this enhancement. In fact, I have never heard of such a bug in Wynntils. Please go to the Discord if you need support.

commented

Hello. Just curious when this will be fixed. Tested the mod and was not able to click on a link for a item bomb.

commented

Basically done by StyledText.