Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Encode Component into strings losslessly #292

Closed
magicus opened this issue Aug 12, 2022 · 6 comments
Closed

Encode Component into strings losslessly #292

magicus opened this issue Aug 12, 2022 · 6 comments
Assignees
Labels
enhancement New feature or request

Comments

@magicus
Copy link
Member

magicus commented Aug 12, 2022

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.

@magicus
Copy link
Member Author

magicus commented Aug 12, 2022

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.

@magicus
Copy link
Member Author

magicus commented Feb 16, 2023

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.

@magicus
Copy link
Member Author

magicus commented Feb 16, 2023

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.

@Seadragon91
Copy link

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

@magicus
Copy link
Member Author

magicus commented Mar 22, 2023

@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.

@kristofbolyai
Copy link
Member

Basically done by StyledText.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants