def _compile_line(self, line): text = scp.quote(line['text'][1]) if line['speaker'] is None: self.add_line(text) else: if line['speaker'][0] is 'id': self.add_line(line['speaker'][1] + ' ' + text) else: self.add_line(scp.quote(line['speaker'][1]) + ' ' + text)
def make_varset(self, varset): line = '' if scp.typed_check(varset['value'], 'boolean'): return self.make_flagset(varset) var = scp.to_words(varset['name'][1]).lower() value = scp.get_expr(varset['value']) if scp.typed_check(varset['value'], 'incdec'): readable = scp.to_human_readable(var + value) var_in = readable.rfind(var) var_str = readable[var_in:].replace(var, scp.quote(var, "'"), 1) readable = readable[0:var_in] + var_str line = readable.strip().capitalize() + '.' else: line = 'Set the variable ' + scp.quote(var, "'") + ' to ' + value + '.' return (line, False)
def _write_chars(self): for cid in self._chars: c = self._chars[cid] color = c['color'] if color is None: color = '#000000' self.add_line("define %s = Character(%s, color=%s)" % (c['id'], scp.quote(c['name']), scp.quote(color))) self.add_line()
def _compile_CHOICE(self, choice): label = "" if scp.typed_check(choice['label'], 'id'): label = " " + choice['label'][1] self.add_line("menu" + label + ":") self._inc_indent() if scp.typed_check(choice['title'], 'string'): self.add_line(scp.quote(choice['title'][1])) self.add_line() for c in choice['choices']: cond = "" if c['condition'] is not None: cond = " if " + str(c['condition'][1]) self.add_line(scp.quote(c['text'][1]) + cond + ":") self._inc_indent() for v in c['sets']: self._compile_VARSET(v, noline=True) self.add_line('jump ' + c['target'][1]) self.add_line() self._dec_indent() self._dec_indent()
def make_flagset(self, flagset): line = '' value = scp.get_expr(flagset['value']) tvalue = flagset['value'][1] flag = scp.to_words(flagset['name'][1]).lower() nat_lang = flag.startswith('have ') if nat_lang: phrase = flag[len('have '):] if scp.typed_check(flagset['value'], 'boolean'): if not nat_lang: if tvalue: line = 'Set the flag ' + scp.quote(flag, "'") + '.' else: line = 'Unset the flag ' + scp.quote(flag, "'") + '.' else: if tvalue: line = 'We have now ' + phrase + '.' else: line = 'We have now not ' + phrase + '.' elif scp.typed_check(flagset['value'], 'id'): if nat_lang: line = 'Whether we have ' + phrase + ' is determined by ' else: line = 'Set the flag ' + scp.quote(flag, "'") + ' to the same as ' value_id = scp.to_words(value).lower() if value_id.startswith('have '): val_phrase = value_id[len('have '):] line += 'whether we have ' + val_phrase + '.' else: line += 'the value of the variable ' + scp.quote(value_id, "'") + '.' elif scp.typed_check(flagset['value'], 'expr'): if nat_lang: line = 'Whether we have now ' + flag + ' is determined by the value of the variable ' + value + '.' else: line = 'Set the flag ' + scp.quote(flag, "'") + ' to the same as the value of the variable ' + value + '.' return (line, nat_lang)
def _compile_EXECUTE(self, execute): params = "" use_pass = False for p in execute['params']: if 'name' in p: use_pass = True params += p['name'][1] + "=" params += scp.get_expr(p['value']) params += ', ' if len(params) > 0: params = '(' + params[:-2] + ')' if use_pass: self.add_line('call expression %s pass %s' % (scp.quote(execute['section'][1]), params)) else: self.add_line('call %s%s' % (execute['section'][1], params)) self.add_line()
def _compile_IF(self, ifstmt): elsebr = None firstbr = True had_output = False for br in ifstmt['branches']: if br['condition'] is None: elsestmt = br else: if not self.contains_writeable(br['statements']): continue had_output = True negation = '' if firstbr: line = '%s do the following' firstbr = False else: line = 'Otherwise,%s do the following' cond = scp.get_expr(br['condition']) if scp.typed_check(br['condition'], 'boolean'): tcond = br['condition'][1] if tcond: negation = ' always' line += ':' else: negation = ' never' line += ':' elif scp.typed_check(br['condition'], 'id'): cond_words = scp.to_words(br['condition'][1]).lower() if cond_words.startswith('have '): cond_ph = cond_words[len('have '):] line += ' only if we have ' + cond_ph + ':' else: line += ' only if ' + scp.quote(cond_words, "'") + ' is set:' else: line += ' only if ' + scp.to_human_readable(cond) + ':' self.add_paragraph((line % negation).strip().capitalize(), style='Engine Instruction') self.compile_block(br['statements']) if elsebr is not None and had_output and self.contains_writeable(elsebr['statements']): self.add_paragraph("Otherwise, do the following:", style='Engine Instruction') self.compile_block(elsebr['statements']) if not had_output: self._add_break = False
def _compile_SFX(self, sfx): if sfx['action'] == 'start': self.add('play sound ') if scp.typed_check(sfx['target'], 'string'): self.add(scp.quote(sfx['target'][1])) else: self.add(sfx['target'][1]) if scp.typed_check(sfx['loop'], 'boolean', True): self.add(' loop') elif sfx['action'] == 'stop': explicit_all = False if scp.typed_check(sfx['target'], 'rel', 'ALL'): explicit_all = True self.add('stop sound') if not explicit_all: self._warnings['targeted_sfx_stop'] = ["Ren'Py does not support targeted sound stop; any such directives will be compiled as if they were STOP ALL"] if sfx['duration'] is not None: time = scp.get_duration(sfx['duration'], self.quickly_rel, self.slowly_rel, self.default_duration) self.add(' fadeout ' + str(time)) self.add_line() self.add_line()
def _compile_MUSIC(self, music): if music['action'] == 'start': self.add('play music ') if scp.typed_check(music['target'], 'id'): self.add(music['target'][1]) elif scp.typed_check(music['target'], 'string'): self.add(scp.quote(music['target'][1])) if music['fadeout'] is not None: time = scp.get_duration(music['fadeout'], self.quickly_rel, self.slowly_rel, self.default_duration) self.add(' fadeout ' + str(time)) elif music['action'] == 'stop': explicit_all = False if scp.typed_check(music['target'], 'rel', 'ALL'): explicit_all = True self.add('stop music') if not explicit_all: self._warnings['targeted_music_stop'] = ["Ren'Py does not support targeted music stop; any such directives will be compiled as if they were STOP ALL"] if music['duration'] is not None: time = scp.get_duration(music['duration'], self.quickly_rel, self.slowly_rel, self.default_duration) self.add(' fadeout ' + str(time)) self.add_line() self.add_line()
def _compile_WHILE(self, whilestmt): line = "Do the following " cond = scp.get_expr(whilestmt['condition']) if scp.typed_check(whilestmt['condition'], 'boolean'): tcond = whilestmt['condition'][1] if tcond: line += 'forever:' else: line = 'Never do the following:' elif scp.typed_check(whilestmt['condition'], 'id'): cond_words = scp.to_words(whilestmt['condition'][1]).lower() if cond_words.startswith('have '): cond_ph = cond_words[len('have '):] line += 'while we have ' + cond_ph + ':' else: line += 'while ' + scp.quote(cond_words, "'") + ' is set:' else: line += 'while ' + scp.to_human_readable(cond) + ':' if self.contains_writeable(whilestmt['statements']): self.add_paragraph(line, style='Engine Instruction') self.compile_block(whilestmt['statements']) else: self._add_break = False
def _compile_FMV(self, fmv): name = fmv['target'][1] if scp.typed_check(fmv['target'], 'string'): name = scp.quote(name) self.add_line('renpy.movie_cutscene(' + name + ')') self.add_line()