-
Notifications
You must be signed in to change notification settings - Fork 21
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
Ability to display variable values in text aka Hello, {$playername} #59
Comments
The new things have been added to the yarn syntax that are missing in bondagejs some yarn syntax instructions are now being added to yarn editor's help dialog. There is some discussion about using yarn spinner's documentation when yarn is using bondagejs which doesnt yet support some stuff |
@hylyh I believe we are completely lacking all Format functions that yarnSpinner supports, example: not sure If I can implement this myself, seems like a bigger task |
That is called an inline expression. I'm working on implementing this in my fork.
It returns an EndOfInput for the third lex call, instead of the expected EndInlineExp. I found and fixed the issue in lexer.js. The function isAtTheEndOfLine was using an incorrect condition. Should be like this (instead of ">=" it is ">"):
|
I would very much welcome a PR that adds this feature :) even the basic ability to display the player name would be amazing. More complicated syntax such as |
I am currently working on that. The main difficulty is in dealing with how the lexer removes leading spaces from text. Simply taking out the code that removes the leading whitespace breaks many tests. So that will be a challenge. Regarding whitespace importance, consider these test cases: Because of these different cases, I can't simply add a whitespace after the inline expression in the runner. The lexer is what is stripping out the preceding whitespaces of the text following EndInlineExp token. I'll get it eventually.
The syntax reference calls that "Format functions" and it is a totally different beast. I might do it later.
You're welcome! |
@alforno any progress on this? I noticed you have a branch of it. People keep asking about this feature |
I have not done any work on the format functions, but the issue I mention here is resolved in my fork. Last I check my previous pull request was not merged. I don't care if someone wants to take what I've done and make it work here, but I can't skip code revisions that led to this working. |
The format functions should be a separate pr anyways :) Sorry I haven't reviewed the other pr yet. I need to get back to my computer after the 9th and will give it a spin if @hylyh hasn't had a look yet. Thank you for working on these and sorry for the slow reactions. The fixes and features are very much welcome and requested by a wider community of users outside of this tracker |
If needed you can uses the javascript version of Message Format witch is used for YarnSpinner like something like that (my code is not perfect, don't hesitate to correct me) const MessageFormat = require('messageformat');
const mf = new MessageFormat('en');
if (result instanceof bondage.TextResult) {
const msg = mf.compile(result.text);
console.log(msg(runner.variables.data));
} |
@Chrissdroid that is a fantastic suggestion. If we can maintain less code by using this library, it would leave us in a much much better place. Whats even better, since YarnSpinner is also using it - I assume we will always have syntax parity with it without having to manually update it. Would you be interested in creating a PR for this feature? It has been by far the most requested feature on this and other trackers using bondagejs. If you do, your PR will get high priority and I promise will be reviewed quickly. If you have trouble with writing a test for it, I can help out with that after you put up the pr. As first step its great to have it in bondage.TextResult, but it could also be useful in returned bondage.OptionsResult, although we should confirm if that is supported in yarnSpinner @alforno @hylyh what do you think? |
There is now a PR for this, however its formater syntax is different from the yarnSpinner one. I raised a question at the library if we can make it work I am not sure if yarnSpinner actually does use MessageFormat. Its source code looks like they are doing it all manually They seem to be doing some string replacing there - maybe we can also do that before feeding it to MessageFormat? although correct me if I'm wrong :) We still need to get the syntax be the same somehow. Otherwise we would be deviating from the yarnSpinner docs |
The yarn spinner guys are adding this, so I wonder if you would be open to add it to bondagejs as well :)
So we could say
I have {$applesCount} apples
or
My name is {$playerName}
I can try to do a PR if this feature is welcome
The text was updated successfully, but these errors were encountered: