Exemple #1
0
	def _compile_CHOICE(self, choice):
		if choice['label'] is not None:
			labelstmt = {'type': 'annotation', 'instruction': 'SECTION', 'section': choice['label'], 'params': []}
			self.compile_statement(labelstmt)
		self.add_paragraph("We are presented with a choice:", style='Actor Instruction')
		if choice['title'] is not None:
			self.add_paragraph(choice['title'][1], italic=False)
		for c in choice['choices']:
			self.add_paragraph(style='Choice')
			if c['condition'] is None:
				self.add_run(c['text'][1])
			else:
				self.add_run(c['text'][1] + "\n")
				if scp.typed_check(c['condition'], 'boolean', True):
					self.add_run('(always shown)', style='Choice Condition')
				elif scp.typed_check(c['condition'], 'boolean', False):
					self.add_run('(never shown)', style='Choice Condition')
				elif scp.typed_check(c['condition'], 'id'):
					cond_id = scp.to_words(c['condition'][1]).lower()
					if cond_id.startswith('have '):
						cond_ph = cond_id[len('have '):]
						self.add_run('(choice shown only if we have ' + cond_ph + ')', style='Choice Condition')
					else:
						self.add_run('(choice shown only if \'' + cond_id + '\' is set)', style='Choice Condition')
				else:
					self.add_run('(choice shown only if ' + scp.to_human_readable(c['condition'][1]) + ')', style='Choice Condition')
			if self.include_varsets:
				for v in c['sets']:
					self.add_paragraph(self.make_varset(v)[0], style='Choice Instruction')
			self.add_paragraph(style='Choice Instruction')
			go = self.make_goto({'destination': c['target']})
			self.add_run(go[0])
			self.add_internal_link(go[1], go[2])
			self.add_run('.')
Exemple #2
0
	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)
Exemple #3
0
	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
Exemple #4
0
	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