Exemple #1
0
def parse_item(sb, book):
    item = {
        'type': 'item',
        'source': book,
        'name': filter_name(sb.name.strip())
    }
    text = []
    for key, value in sb.keys:
        item_parse_function(key, sb.name.strip())(item, value)
    for detail in sb.details:
        if isinstance(
                detail,
                StatBlockSection) and detail.name.startswith("Construction"):
            for key, value in detail.keys:
                item_parse_function(key, detail.name.strip())(item, value)
        elif isinstance(detail, StatBlockSection):
            sections = item.setdefault('sections', [])
            sections.append(parse_section(detail, book))
        elif isinstance(detail, StatBlockHeading):
            sections.append(parse_stat_block(sb, book, no_sb=no_sb))
        else:
            if isinstance(detail, dict) or isinstance(detail, Heading):
                text.append(detail)
            else:
                text.append(unicode(detail))
    if len(text) > 0:
        collapse_text(item, text)
    return item
def parse_animal_companion(sb, book):
    ac = {
        'type': 'animal_companion',
        'subtype': 'base',
        'source': book,
        'name': filter_name(sb.name.strip()),
        'sections': []
    }
    text = []
    for key, value in sb.keys:
        animal_companion_parse_function(key)(ac, value)
    for detail in sb.details:
        if detail.__class__ == StatBlockSection and detail.name.endswith(
                'th-Level Advancement'):
            advancement = {
                'level': detail.name[:3],
                'source': book,
                'type': 'animal_companion',
                'name': filter_name(ac['name'])
            }
            for key, value in detail.keys:
                animal_companion_parse_function(key)(advancement, value)

            advancement['subtype'] = 'advancement'
            ac['sections'].append(advancement)
        else:
            text.append(detail)
    if ac["name"].endswith('th-Level Advancement'):
        ac['level'] = ac['name'][:3]
        ac['subtype'] = "advancement"
    if len(text) > 0:
        collapse_text(ac, text)
    return ac
Exemple #3
0
def parse_section(sb, book, no_sb=False, keys=True):
    section = {
        'type': 'section',
        'source': book,
        'name': filter_name(sb.name.strip())
    }
    text = []
    sections = []
    sectiontext = []
    ns = None
    if keys:
        for key in sb.keys:
            text.append("<p class='stat-block-1'><b>%s </b>%s</p>" % key)
    for detail in sb.details:
        if isinstance(detail, StatBlockSection):
            sections.append(parse_stat_block(detail, book, no_sb=no_sb))
        elif isinstance(detail, StatBlockHeading):
            sections.append(parse_stat_block(sb, book, no_sb=no_sb))
        elif isinstance(detail, dict):
            if len(sectiontext) > 0:
                section['text'] = ''.join(sectiontext)
                sectiontext = []
                ns = None
            sections.append(detail)
        elif detail.__class__ == Heading:
            if len(sectiontext) > 0:
                ns['text'] = ''.join(sectiontext)
                sectiontext = []
            ns = {
                'type': 'section',
                'source': book,
                'name': filter_name(detail.name)
            }
            sections.append(ns)
        else:
            if len(sections) == 0:
                if isinstance(detail, dict):
                    text.append(detail)
                else:
                    text.append(unicode(detail))
            else:
                if not ns:
                    ns = {'type': 'section', 'source': book}
                    sections.append(ns)
                if isinstance(detail, dict) or isinstance(detail, Heading):
                    sectiontext.append(detail)
                else:
                    sectiontext.append(unicode(detail))
    if len(text) > 0:
        collapse_text(section, text)
    if len(sectiontext) > 0:
        collapse_text(ns, sectiontext)
    if len(sections) > 0:
        section['sections'] = sections
    return section
Exemple #4
0
def parse_section(sb, book, no_sb=False, keys=True):
	section = {'type': 'section', 'source': book, 'name': filter_name(sb.name.strip())}
	text = []
	sections = []
	sectiontext = []
	ns = None
	if keys:
		for key in sb.keys:
			text.append("<p class='stat-block-1'><b>%s </b>%s</p>" % key)
	for detail in sb.details:
		if isinstance(detail, StatBlockSection):
			sections.append(parse_stat_block(detail, book, no_sb=no_sb))
		elif isinstance(detail, StatBlockHeading):
			sections.append(parse_stat_block(sb, book, no_sb=no_sb))
		elif isinstance(detail, dict):
			if len(sectiontext) > 0:
				section['text'] = ''.join(sectiontext)
				sectiontext = []
				ns = None
			sections.append(detail)
		elif detail.__class__ == Heading:
			if len(sectiontext) > 0:
				ns['text'] = ''.join(sectiontext)
				sectiontext = []
			ns = {'type': 'section', 'source': book, 'name': filter_name(detail.name)}
			sections.append(ns)
		else:
			if len(sections) == 0:
				if isinstance(detail, dict):
					text.append(detail)
				else:
					text.append(unicode(detail))
			else:
				if not ns:
					ns = {'type': 'section', 'source': book}
					sections.append(ns)
				if isinstance(detail, dict) or isinstance(detail, Heading):
					sectiontext.append(detail)
				else:
					sectiontext.append(unicode(detail))
	if len(text) > 0:
		collapse_text(section, text)
	if len(sectiontext) > 0:
		collapse_text(ns, sectiontext)
	if len(sections) > 0:
		section['sections'] = sections
	return section
Exemple #5
0
def parse_animal_companion(sb, book):
	ac = {'type': 'animal_companion', 'subtype': 'base', 'source': book, 'name': filter_name(sb.name.strip()), 'sections': []}
	text = []
	for key, value in sb.keys:
		animal_companion_parse_function(key)(ac, value)
	for detail in sb.details:
		if detail.__class__ == StatBlockSection and detail.name.endswith('th-Level Advancement'):
			advancement = {'level': detail.name[:3], 'source': book, 'type': 'animal_companion', 'name': filter_name(ac['name'])}
			for key, value in detail.keys:
				animal_companion_parse_function(key)(advancement, value)

			advancement['subtype'] = 'advancement'
			ac['sections'].append(advancement)
		else:
			text.append(detail)
	if ac["name"].endswith('th-Level Advancement'):
		ac['level'] = ac['name'][:3]
		ac['subtype'] = "advancement"
	if len(text) > 0:
		collapse_text(ac, text)
	return ac
Exemple #6
0
def parse_item(sb, book):
	item = {'type': 'item', 'source': book, 'name': filter_name(sb.name.strip())}
	text = []
	for key, value in sb.keys:
		item_parse_function(key, sb.name.strip())(item, value)
	for detail in sb.details:
		if isinstance(detail, StatBlockSection) and detail.name.startswith("Construction"):
			for key, value in detail.keys:
				item_parse_function(key, detail.name.strip())(item, value)
		elif isinstance(detail, StatBlockSection):
			sections = item.setdefault('sections', [])
			sections.append(parse_section(detail, book))
		elif isinstance(detail, StatBlockHeading):
			sections.append(parse_stat_block(sb, book, no_sb=no_sb))
		else:
			if isinstance(detail, dict) or isinstance(detail, Heading):
				text.append(detail)
			else:
				text.append(unicode(detail))
	if len(text) > 0:
		collapse_text(item, text)
	return item
Exemple #7
0
def parse_creature(sb, book):
	name = sb.name
	cr = None
	if name.find('CR') > -1:
		name, cr = name.split('CR')
	creature = {'type': 'creature', 'source': book, 'name': filter_name(name)}
	if cr:
		creature['cr'] = cr.strip()
	sections = []
	text = []
	descriptors = []
	for tup in sb.keys:
		if tup[0] == 'descriptor':
			descriptors.append(tup)
	for tup in descriptors:
		sb.keys.remove(tup)
	if len(descriptors) > 0:
		parse_creature_descriptors(creature, descriptors)
	
	for key, value in sb.keys:
		creature_parse_function(key)(creature, value)
	for detail in sb.details:
		if detail.name.lower() == 'base statistics':
			detail.name = 'Statistics'
		if detail.name.lower() == 'environment':
			detail.name = 'Ecology'
		if detail.__class__ == StatBlockSection and detail.name.lower() in ['defense', 'offense', 'statistics', 'ecology']:
			for key, value in detail.keys:
				creature_parse_function(key)(creature, value)
			for subd in detail.details:
				if isinstance(subd, dict) or isinstance(subd, Heading):
					sections.append(subd)
				else:
					newsec = {'type': 'section', 'source': book, 'text': unicode(subd)}
					sections.append(newsec)
		elif detail.__class__ == StatBlockSection and detail.name.lower() in ['special abilities']:
			special_abilities = {'type': 'section', 'subtype': 'special_abilities', 'source': book, 'name': 'Special Abilities', 'sections': []}
			for key in detail.keys:
				newsec = {'type': 'section', 'source': book, 'name': key[0], 'text': key[1]}
				special_abilities['sections'].append(newsec)
			sections.append(special_abilities)
			for subd in detail.details:
				if isinstance(subd, dict) or isinstance(subd, Heading):
					sections.append(subd)
				else:
					newsec = {'type': 'section', 'source': book, 'text': unicode(subd)}
					sections.append(newsec)
		elif detail.__class__ == StatBlockSection and detail.name.lower() in ['tactics']:
			sections.append(parse_stat_block(detail, book, no_sb=True))
		else:
			if isinstance(detail, dict) or isinstance(detail, Heading):
				text.append(detail)
			else:
				text.append(unicode(detail))
	if len(text) > 0:
		collapse_text(creature, text)
	if len(sections) > 0:
		level = has_heading(sections)
		while level:
			sections = title_collapse_pass(sections, level)
			level = level - 1
		if level == 0:
			sections = sections_pass(sections, creature['source'])
		creature['sections'] = sections
	return creature