Add support for sprintf() formatting to tutorial
<message> tags can now contain sprintf() format strings (%d, %.2f etc), with <message-param> <property>/some/prop</property> </message-param> used as the substitute value. Could be extended in the future with perhaps Nasal evaluation?
This commit is contained in:
parent
60c6e73258
commit
6f2ccdd395
2 changed files with 18 additions and 2 deletions
|
@ -84,6 +84,10 @@ in detail below:
|
||||||
<step> is entered; allowed multiple times, in
|
<step> is entered; allowed multiple times, in
|
||||||
which case one is chosen at random
|
which case one is chosen at random
|
||||||
|
|
||||||
|
<message-param> optional; allowed up to 4 times.
|
||||||
|
<property>...</property> property to substitute into the <message> string
|
||||||
|
</message-param> using sprintf() formatting. E.g. %d, %.2f
|
||||||
|
|
||||||
<audio>...</audio> optional; file name of *.wav sample to be played;
|
<audio>...</audio> optional; file name of *.wav sample to be played;
|
||||||
may be used multiple times (random)
|
may be used multiple times (random)
|
||||||
<set>
|
<set>
|
||||||
|
@ -473,5 +477,3 @@ terminal, for example:
|
||||||
</marker>
|
</marker>
|
||||||
|
|
||||||
This just needs to be copied to the tutorial XML file.
|
This just needs to be copied to the tutorial XML file.
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -414,6 +414,20 @@ var say_message = func(node, default = nil) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (msg != nil) {
|
if (msg != nil) {
|
||||||
|
var params = [];
|
||||||
|
|
||||||
|
foreach (var p; node.getChildren("message-param")) {
|
||||||
|
if (p.getNode("property") != nil) {
|
||||||
|
append(params, getprop(p.getNode("property").getValue()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# Ugly
|
||||||
|
if (size(params) == 1) { msg = sprintf(msg, params[0]); }
|
||||||
|
if (size(params) == 2) { msg = sprintf(msg, params[0], params[1]); }
|
||||||
|
if (size(params) == 3) { msg = sprintf(msg, params[0], params[1], params[2]); }
|
||||||
|
if (size(params) == 4) { msg = sprintf(msg, params[0], params[1], params[2], params[3]); }
|
||||||
|
|
||||||
display.write(msg, 1, 1, 1);
|
display.write(msg, 1, 1, 1);
|
||||||
if (audio == nil) {
|
if (audio == nil) {
|
||||||
# Link to text-to-speech
|
# Link to text-to-speech
|
||||||
|
|
Loading…
Add table
Reference in a new issue