Minor update to dialog (#1911)
* Do not load blank lines as dialogs. * Simplify render code slightly using random.choice * Remove import of io's open, not needed in python 3pull/1925/head
parent
531c5e51c1
commit
fa56e91b00
|
@ -13,8 +13,6 @@
|
|||
# limitations under the License.
|
||||
#
|
||||
import random
|
||||
from io import open
|
||||
|
||||
import os
|
||||
import re
|
||||
from pathlib import Path
|
||||
|
@ -48,8 +46,9 @@ class MustacheDialogRenderer(object):
|
|||
with open(filename, 'r') as f:
|
||||
for line in f:
|
||||
template_text = line.strip()
|
||||
# Skip all lines starting with '#'
|
||||
if not template_text.startswith('#'):
|
||||
# Skip all lines starting with '#' and all empty lines
|
||||
if (not template_text.startswith('#') and
|
||||
template_text != ''):
|
||||
if template_name not in self.templates:
|
||||
self.templates[template_name] = []
|
||||
|
||||
|
@ -86,10 +85,10 @@ class MustacheDialogRenderer(object):
|
|||
|
||||
template_functions = self.templates.get(template_name)
|
||||
if index is None:
|
||||
index = random.randrange(len(template_functions))
|
||||
line = random.choice(template_functions)
|
||||
else:
|
||||
index %= len(template_functions)
|
||||
line = template_functions[index]
|
||||
line = template_functions[index % len(template_functions)]
|
||||
# Replace {key} in line with matching values from context
|
||||
line = line.format(**context)
|
||||
return line
|
||||
|
||||
|
|
Loading…
Reference in New Issue