def _pformat_object( self, tables, pformat_config = _PrettyFormatConfig( ) ): """ Nicely formats the object for display. """ # TODO: Lookup monster name from monsters table. return self.monster_number
def pformat_object( self, tables, pformat_config = _PrettyFormatConfig( ) ): """ Nicely formats the object for display. """ template = pformat_config.indent args = { } if pformat_config.render_title: template += "{title}" args[ "title" ] = self.TITLE( ) if pformat_config.render_key_with_object: template += " [{attribute_number}]: " args[ "attribute_number" ] = self.attribute_number else: template += ": " else: if pformat_config.render_key_with_object: template += "{attribute_number}" args[ "attribute_number" ] = self.attribute_number template += "{value}" args[ "value" ] = self._pformat_object( tables, pformat_config = pformat_config ) return template.format( **args )
def pprint( self, dump_files_path = None, pformat_config = _PrettyFormatConfig( ) ): """ Dumps all loaded data to stdout or to files in a directory. """ if not _path_exists( dump_files_path ): _os.mkdir( dump_files_path, 0o700 ) else: if not _path_is_directory( dump_files_path ): raise IOError( "Not a directory: {0}".format( dump_files_path ) ) if not _os.access( dump_files_path, _os.R_OK | _os.W_OK | _os.X_OK ): raise IOError( "Could not access directory: {0}".format( dump_files_path ) ) tables = self._tables for table in tables.values( ): if None is dump_files_path: table.pprint( tables, pformat_config ) else: dump_file_path = _path_join( dump_files_path, table.FILE_NAME_BASE( ) + _path_extsep + "txt" ) with open( dump_file_path, "w" ) as dump_file: stream_print \ = _functools.partial( print, file = dump_file ) table.pprint( tables, pformat_config, stream_print )
def pformat_object( self, tables, pformat_config = _PrettyFormatConfig( ) ): """ Nicely formats the object for display. """ template = "{value}" args = { "value": self._pformat_object( tables, pformat_config = pformat_config ) } if pformat_config.render_title: template = "{title}: " + template args[ "title" ] = self._TITLE if pformat_config.render_key_with_object: template += " [{key}]" args[ "key" ] = self.pformat_key( tables, pformat_config = pformat_config.clone( key_format = self._KEY_FORMAT ) ) template = pformat_config.indent + template return template.format( **args )
def pformat_table_lookup( self, key, tables, pformat_config = _PrettyFormatConfig( ) ): """ Nicely formats a table lookup for display. """ pformat_config_row = pformat_config.clone( ) if pformat_config.render_title: pformat_config_row.indent = pformat_config.indent + " " * 4 pformat_config_row.render_title = False template = "{values}" args = { "values": "\n".join( [ row.pformat_object( tables, pformat_config = pformat_config_row ) for row in self._table.values( ) if key & row.bit_value ] ) } if pformat_config.render_title: args[ "title" ] = self._TITLE if pformat_config.render_key_with_object: template = "{title} [Total: {key}]:\n" + template args[ "key" ] = key else: template = "{title}:\n" + template return template.format( **args )
def pprint_table_rows(self, tables, pformat_config=_PrettyFormatConfig(), stream_print=print): """ Nicely formats and prints the table rows to an output stream. """ stream_print(self.pformat_table_rows(tables, pformat_config))
def pformat_table_lookup(self, key, tables, pformat_config=_PrettyFormatConfig()): """ Nicely formats a table lookup for display. """ pformat_config_row = pformat_config.clone() if pformat_config.render_title: pformat_config_row.indent = pformat_config.indent + " " * 4 pformat_config_row.render_title = False template = "{values}" args = { "values": "\n".join([ row.pformat_object(tables, pformat_config=pformat_config_row) for row in self._table.values() if key & row.bit_value ]) } if pformat_config.render_title: args["title"] = self._TITLE if pformat_config.render_key_with_object: template = "{title} [Total: {key}]:\n" + template args["key"] = key else: template = "{title}:\n" + template return template.format(**args)
def pprint_key(self, tables, pformat_config=_PrettyFormatConfig(), stream_print=print): """ Prints a nicely-formatted row key to an output stream. """ stream_print(self.pformat_key(tables, pformat_config))
def _pformat_object( self, tables, pformat_config = _PrettyFormatConfig( ) ): """ Nicely formats the object for display. (Internal version - override as necessary.) """ return str( self )
def pformat_object( self, tables, pformat_config = _PrettyFormatConfig( ) ): """ Nicely formats the object for display. """ pformat_config_1 = pformat_config.clone( indent = pformat_config.indent + 4 * " " ) pformat_config_title = pformat_config.clone( indent = "" ) template = "{value}" args = { "value": self._pformat_object( tables, pformat_config = pformat_config_1 ) } if pformat_config.render_title: args[ "title" ] \ = tables[ EffectsInfo_DataTable.LABEL( ) ].pformat_table_lookup( self.effect_number, tables, pformat_config = pformat_config_title ) template = "{title}\n" + template template = pformat_config.indent + template return template.format( **args )
def pformat_table_lookup( self, key, tables, pformat_config = _PrettyFormatConfig( ) ): """ Nicely formats a table lookup for display. """ return self._table[ key ].pformat_object( tables, pformat_config = pformat_config )
def pformat_object( self, tables, pformat_config = _PrettyFormatConfig( ) ): """ Nicely formats the object for display. """ return self.value.pformat_object( tables, pformat_config = pformat_config )
def pformat_key( self, tables, pformat_config = _PrettyFormatConfig( ) ): """ Nicely formats the row key for display. """ return ("{key:" + pformat_config.key_format + "}").format( key = getattr( self, self._KEY_NAME ) )
def pformat_object( self, tables, pformat_config = _PrettyFormatConfig( ) ): """ Nicely formats the object for display. """ return pformat_config.indent + "{title}: <Unimplemented>".format( title = self.TITLE( ) )
def pformat_table_lookup(self, key, tables, pformat_config=_PrettyFormatConfig()): """ Nicely formats a table lookup for display. """ return self._table[key].pformat_object(tables, pformat_config=pformat_config)
def pformat_object( self, tables, pformat_config = _PrettyFormatConfig( ) ): """ Nicely formats the object for display. """ return \ tables[ EffectModifierBits_DataTable.LABEL( ) ].pformat_table_lookup( self.bit_value, tables, pformat_config = pformat_config )
def pformat_table_rows(self, tables, pformat_config=_PrettyFormatConfig()): """ Nicely formats the table rows for display. """ pformat_config_row = pformat_config.clone( key_format=self._generated_key_format()) return "\n".join([ row.pformat_row(tables, pformat_config=pformat_config_row) for row in self._table.values() ])
def pformat_object(self, tables, pformat_config=_PrettyFormatConfig()): """ Nicely formats the object for display. """ template = "<Unknown> [Offset: {offset}]: {value}" args = {"offset": self.offset, "value": self.value} template = pformat_config.indent + template return template.format(**args)
def pformat_row(self, tables, pformat_config=_PrettyFormatConfig()): """ Nicely formats the table row for display. """ pformat_config_row = pformat_config.clone(indent="", render_title=False, render_key_with_object=False) return (pformat_config.indent + "{key}: {value}").format( key=self.pformat_key(tables, pformat_config_row), value=self.pformat_object(tables, pformat_config_row))
def pformat_row( self, tables, pformat_config = _PrettyFormatConfig( ) ): """ Nicely formats the table row for display. """ pformat_config_row = pformat_config.clone( indent = "", render_title = False, render_key_with_object = False ) return (pformat_config.indent + "{key}: {value}").format( key = self.pformat_key( tables, pformat_config_row ), value = self.pformat_object( tables, pformat_config_row ) )
def pformat_row(self, tables, pformat_config=_PrettyFormatConfig()): """ Nicely formats the table row for display. """ output = [] pformat_config_no_key_padding = pformat_config.clone( key_format=self._KEY_FORMAT) pformat_config_1 = pformat_config.clone(indent=pformat_config.indent + 4 * " ") pformat_config_2 = pformat_config_1.clone( indent=pformat_config_1.indent + 4 * " ") indent = pformat_config.indent + 4 * " " output.append( (pformat_config.indent + "{title} #{number}: {name}").format( title=self._TITLE, number=self.pformat_key( tables, pformat_config=pformat_config_no_key_padding), name=self.name)) if pformat_config.render_compactly: return output[0] output.append( tables[ArmorTypes_DataTable.LABEL()].pformat_table_lookup( self.armor_type, tables, pformat_config=pformat_config_1)) # TODO: Output actual protection. if self.protections: output.append(indent + "Protection by Zone") for protection in self.protections: output.append( protection.pformat_object(tables, pformat_config=pformat_config_2)) output.append(indent + "Defense {{Arm: #def}}: {defense}".format( defense=self.defense)) output.append(indent + "Encumbrance {{Arm: #enc}}: {encumbrance}".format( encumbrance=self.encumbrance)) output.append(indent + "Resource Cost {{Arm: #rcost}}: {resource_cost}".format( resource_cost=self.resource_cost)) if self.attributes: for attribute in self.attributes: output.append( attribute.pformat_object(tables, pformat_config=pformat_config_1)) if not pformat_config.suppress_unknowns and self.unknown_fields: output.append(indent + "Unknowns") for unknown_field in self.unknown_fields: output.append( unknown_field.pformat_object( tables, pformat_config=pformat_config_2)) return "\n".join(output) + "\n"
def pformat_object( self, tables, pformat_config = _PrettyFormatConfig( ) ): """ Nicely formats the object for display. """ template = "{title}: {healing}" args = { "title": self.TITLE( ), "healing": self.healing } template = pformat_config.indent + template return template.format( **args )
def pformat_table_rows( self, tables, pformat_config = _PrettyFormatConfig( ) ): """ Nicely formats the table rows for display. """ pformat_config_row = pformat_config.clone( key_format = self._generated_key_format( ) ) return "\n".join( [ row.pformat_row( tables, pformat_config = pformat_config_row ) for row in self._table.values( ) ] )
def pformat_object( self, tables, pformat_config = _PrettyFormatConfig( ) ): """ Nicely formats the object for display. """ template = "<Unknown> [Offset: {offset}]: {value}" args = { "offset": self.offset, "value": self.value } template = pformat_config.indent + template return template.format( **args )
def pformat(self, tables, pformat_config=_PrettyFormatConfig()): """ Nicely formats table for display. """ indent = pformat_config.indent line_width = pformat_config.line_width output_format = \ (indent + "\n{{title:-^{line_width}}}\n\n{{table_rows}}\n").format( line_width = line_width - len( indent ) ) return output_format.format(title=" Table: {0} ".format(self._TITLE), table_rows=self.pformat_table_rows( tables, pformat_config))
def pformat_object( self, tables, pformat_config = _PrettyFormatConfig( ) ): """ Nicely formats the object for display. """ template = "{title}" args = { "title": self.TITLE( ) } if self.value: template = "{title}: {value}" args[ "value" ] = self.value template = pformat_config.indent + template return template.format( **args )
def pformat_object(self, tables, pformat_config=_PrettyFormatConfig()): """ Nicely formats the object for display. """ pformat_config_zone = pformat_config.clone(render_title=False) template = "{zone_name}: {protection}" args = { "zone_name": tables[ ArmorProtectionZones_DataTable.LABEL( ) ]\ .pformat_table_lookup( self.zone_number, tables, pformat_config = pformat_config_zone ), "protection": self.protection } return template.format(**args)
def pformat( self, tables, pformat_config = _PrettyFormatConfig( ) ): """ Nicely formats table for display. """ indent = pformat_config.indent line_width = pformat_config.line_width output_format = \ (indent + "\n{{title:-^{line_width}}}\n\n{{table_rows}}\n").format( line_width = line_width - len( indent ) ) return output_format.format( title = " Table: {0} ".format( self._TITLE ), table_rows = self.pformat_table_rows( tables, pformat_config ) )
def pformat_object( self, tables, pformat_config = _PrettyFormatConfig( ) ): """ Nicely formats the object for display. """ pformat_config_zone = pformat_config.clone( render_title = False ) template = "{zone_name}: {protection}" args = { "zone_name": tables[ ArmorProtectionZones_DataTable.LABEL( ) ]\ .pformat_table_lookup( self.zone_number, tables, pformat_config = pformat_config_zone ), "protection": self.protection } return template.format( **args )
def pformat_object( self, tables, pformat_config = _PrettyFormatConfig( ) ): """ Nicely formats the object for display. """ template = "{title}: " args = { "title": self.TITLE( ) } if self.totally_damage: template = template + "{message} [{value}]" args[ "message" ] = self._MESSAGE_TOTALLY_DAMAGE args[ "value" ] = self._SPECIAL_VALUE_TOTALLY_DAMAGE else: template = template + "{damage_base}" args[ "damage_base" ] = self.damage_base if self.damage_per_level: template = template + " + {damage_per_level} per caster level" args[ "damage_per_level" ] = self.damage_per_level template = pformat_config.indent + template return template.format( **args )
def pformat_object( self, tables, pformat_config = _PrettyFormatConfig( ) ): """ Nicely formats the object for display. """ template = "" args = { } if None is not self.monster_number: template += pformat_config.indent + "{title}: {monster_number}" args[ "title" ] = self.TITLE( ) args[ "monster_number" ] = self.monster_number else: template += "{monster_group_summary}" args[ "monster_group_summary" ] \ = tables[ MonsterTags_DataTable.LABEL( ) ].pformat_table_lookup( self.monster_group_tag, tables, pformat_config = pformat_config ) return template.format( **args )
def pformat_object(self, tables, pformat_config=_PrettyFormatConfig()): """ Nicely formats the object for display. """ template = "{value}" args = { "value": self._pformat_object(tables, pformat_config=pformat_config) } if pformat_config.render_title: template = "{title}: " + template args["title"] = self._TITLE if pformat_config.render_key_with_object: template += " [{key}]" args["key"] = self.pformat_key(tables, pformat_config=pformat_config.clone( key_format=self._KEY_FORMAT)) template = pformat_config.indent + template return template.format(**args)
def _pformat_object( self, tables, pformat_config = _PrettyFormatConfig( ) ): """ Nicely formats the object data for display. """ return self.bit_name
def pformat_row( self, tables, pformat_config = _PrettyFormatConfig( ) ): """ Nicely formats the table row for display. """ output = [ ] pformat_config_no_key_padding = pformat_config.clone( key_format = self._KEY_FORMAT ) pformat_config_1 = pformat_config.clone( indent = pformat_config.indent + 4 * " " ) pformat_config_2 = pformat_config_1.clone( indent = pformat_config_1.indent + 4 * " " ) indent = pformat_config.indent + 4 * " " output.append( (pformat_config.indent + "{title} #{number}: {name}").format( title = self._TITLE, number = self.pformat_key( tables, pformat_config = pformat_config_no_key_padding ), name = self.name ) ) if pformat_config.render_compactly: return output[ 0 ] output.append( tables[ ArmorTypes_DataTable.LABEL( ) ].pformat_table_lookup( self.armor_type, tables, pformat_config = pformat_config_1 ) ) # TODO: Output actual protection. if self.protections: output.append( indent + "Protection by Zone" ) for protection in self.protections: output.append( protection.pformat_object( tables, pformat_config = pformat_config_2 ) ) output.append( indent + "Defense {{Arm: #def}}: {defense}".format( defense = self.defense ) ) output.append( indent + "Encumbrance {{Arm: #enc}}: {encumbrance}".format( encumbrance = self.encumbrance ) ) output.append( indent + "Resource Cost {{Arm: #rcost}}: {resource_cost}".format( resource_cost = self.resource_cost ) ) if self.attributes: for attribute in self.attributes: output.append( attribute.pformat_object( tables, pformat_config = pformat_config_1 ) ) if not pformat_config.suppress_unknowns and self.unknown_fields: output.append( indent + "Unknowns" ) for unknown_field in self.unknown_fields: output.append( unknown_field.pformat_object( tables, pformat_config = pformat_config_2 ) ) return "\n".join( output ) + "\n"
def pformat_row( self, tables, pformat_config = _PrettyFormatConfig( ) ): """ Nicely formats the table row for display. """ output = [ ] pformat_config_no_key_padding = pformat_config.clone( key_format = self._KEY_FORMAT ) pformat_config_1 = pformat_config.clone( indent = pformat_config.indent + 4 * " " ) pformat_config_2 = pformat_config_1.clone( indent = pformat_config_1.indent + 4 * " " ) indent = pformat_config.indent + 4 * " " output.append( (pformat_config.indent + "{title} #{number}: {name}").format( title = self._TITLE, number = self.pformat_key( tables, pformat_config = pformat_config_no_key_padding ), name = self.name ) ) if pformat_config.render_compactly: return output[ 0 ] if self.epithet: output.append( indent + "Epithet: {epithet}".format( epithet = self.epithet ) ) if self.abbreviation: output.append( indent + "Abbreviation: {abbreviation}".format( abbreviation = self.abbreviation ) ) if self.file_name_base: output.append( indent + "File Name Base: {file_name_base}".format( file_name_base = self.file_name_base ) ) if self.initial_scout: # TODO: Fill out via table lookup. output.append( indent + "Initial Scout {{#startscout}}: " "{initial_scout}".format( initial_scout = self.initial_scout ) ) if self.initial_leader: # TODO: Fill out via table lookup. output.append( indent + "Initial Leader {{#startcom}}: " "{initial_leader}".format( initial_leader = self.initial_leader ) ) # TODO: Fill out via table lookup. output.append( indent + "Initial Troops (Type I) {{#startunittype1}}: " "{initial_troops_type} " "(Count {{#startunitnbs1}}: {initial_troops_count})".format( initial_troops_type = self.initial_troops_type_1, initial_troops_count = self.initial_troops_count_1 ) ) # TODO: Fill out via table lookup. output.append( indent + "Initial Troops (Type II) {{#startunittype2}}: " "{initial_troops_type} " "(Count {{#startunitnbs2}}: {initial_troops_count})".format( initial_troops_type = self.initial_troops_type_2, initial_troops_count = self.initial_troops_count_2 ) ) indent_1 = indent + 4 * " " if self.unpretender_types: output.append( indent + "Excluded Pretenders {#delgod}" ) for troop_type in self.unpretender_types: # TODO: Fill out via table lookup. output.append( indent_1 + str( troop_type.monster_number ) ) if self.pretender_types: output.append( indent + "Pretenders {#addgod}" ) for troop_type in self.pretender_types: # TODO: Fill out via table lookup. output.append( indent_1 + str( troop_type.monster_number ) ) if self.fort_leader_types: output.append( indent + "Recruitable Leaders (Fortification) {#addreccom}" ) for troop_type in self.fort_leader_types: # TODO: Fill out via table lookup. output.append( indent_1 + str( troop_type.monster_number ) ) if self.fort_troop_types: output.append( indent + "Recruitable Troops (Fortification) {#addrecunit}" ) for troop_type in self.fort_troop_types: # TODO: Fill out via table lookup. output.append( indent_1 + str( troop_type.monster_number ) ) if self.nonfort_leader_types: output.append( indent + "Recruitable Leaders (Foreign) {#addforeigncom}" ) for troop_type in self.nonfort_leader_types: # TODO: Fill out via table lookup. output.append( indent_1 + str( troop_type.monster_number ) ) if self.nonfort_troop_types: output.append( indent + "Recruitable Troops (Foreign) {#addforeignunit}" ) for troop_type in self.nonfort_troop_types: # TODO: Fill out via table lookup. output.append( indent_1 + str( troop_type.monster_number ) ) if self.attributes: for attribute in self.attributes: output.append( attribute.pformat_object( tables, pformat_config = pformat_config_1 ) ) if not pformat_config.suppress_unknowns and self.unknown_fields: output.append( indent + "Unknowns" ) for unknown_field in self.unknown_fields: output.append( unknown_field.pformat_object( tables, pformat_config = pformat_config_2 ) ) return "\n".join( output ) + "\n"
def _pformat_object(self, tables, pformat_config=_PrettyFormatConfig()): """ Nicely formats the object for display. (Internal version - override as necessary.) """ return str(self)
def _pformat_object( self, tables, pformat_config = _PrettyFormatConfig( ) ): """ Nicely formats the object for display. (Internal version - override as necessary.) """ pformat_config_list = pformat_config.clone( indent = pformat_config.indent + 4 * " ", render_title = False ) output = [ ] indent = pformat_config.indent if self.ritual: output.append( indent + "Ritual [{effect_number}]".format( effect_number = self.effect_number + 10000 ) ) if self.duration: output.append( indent + "Duration (?): {duration} [{effect_number}]".format( duration = self.duration, effect_number = self.effect_number + 1000 * self.duration ) ) output.append( self.argument.pformat_object( tables, pformat_config = pformat_config ) ) if self.modifiers: output.append( indent + "Modifiers {{Spl: #spec}}: [Total Mask: {mask}]".format( mask = self.modifiers_mask ) ) for modifier in self.modifiers: output.append( modifier.pformat_object( tables, pformat_config = pformat_config_list ) ) template = indent + "Range {{Spl: #range, Wpn: #range}}: " args = { } if self.range_base: template += "{range_base} squares" args[ "range_base" ] = self.range_base if self.range_per_level: template += " + {range_per_level} per caster level" args[ "range_per_level" ] = self.range_per_level output.append( template.format( **args ) ) elif self.range_strength_divisor: template += "wielder's strength, " template += "divided by {range_strength_divisor}" args[ "range_strength_divisor" ] = self.range_strength_divisor output.append( template.format( **args ) ) template = indent + "Area {{Spl: #aoe, Wpn: #aoe}}: " args = { } if self.area_base: template += "{area_base} squares" args [ "area_base" ] = self.area_base if self.area_per_level: template += " + {area_per_level} per caster level" args[ "area_per_level" ] = self.area_per_level output.append( template.format( **args ) ) elif self.area_battlefield_pct: template += "{area_battlefield_pct}% of battlefield" args [ "area_battlefield_pct" ] = self.area_battlefield_pct output.append( template.format( **args ) ) if self.sound_number: output.append( tables[ Sounds_DataTable.LABEL( ) ].pformat_table_lookup( self.sound_number, tables, pformat_config = pformat_config ) ) if self.flight_sprite_number: output.append( tables[ FlightSprites_DataTable.LABEL( ) ]\ .pformat_table_lookup( self.flight_sprite_number, tables, pformat_config = pformat_config ) + " (Length: {length})".format( length = self.flight_sprite_length ) ) if self.explosion_sprite_number: output.append( tables[ ExplosionSprites_DataTable.LABEL( ) ]\ .pformat_table_lookup( self.explosion_sprite_number, tables, pformat_config = pformat_config ) + " (Length: {length})".format( length = self.explosion_sprite_length ) ) return "\n".join( output )
def pformat_row( self, tables, pformat_config = _PrettyFormatConfig( ) ): """ Nicely formats the table row for display. """ output = [ ] pformat_config_no_key_padding = pformat_config.clone( key_format = self._KEY_FORMAT ) pformat_config_1 = pformat_config.clone( indent = pformat_config.indent + 4 * " " ) pformat_config_2 = pformat_config_1.clone( indent = pformat_config_1.indent + 4 * " " ) pformat_config_compact = pformat_config.clone( indent = "", render_title = False, render_compactly = True ) pformat_config_compact_no_key = pformat_config.clone( indent = "", render_title = False, render_key_with_object = False, render_compactly = True ) indent = pformat_config.indent + 4 * " " output.append( (pformat_config.indent + "{title} #{number}: {name}").format( title = self._TITLE, number = self.pformat_key( tables, pformat_config = pformat_config_no_key_padding ), name = self.name ) ) if pformat_config.render_compactly: return output[ 0 ] template = indent + "Research Requirement {{Spl: #school}}" args = { "school": tables[ MagicSchools_DataTable.LABEL( ) ].pformat_table_lookup( self.school, tables, pformat_config = pformat_config_compact_no_key ) } if 0 > self.school: template += ": {school}" else: template += " {{Spl: #researchlevel}}: {school} {level}" args[ "level" ] = self.research_level output.append( template.format( **args ) ) for idx in range( 2 ): path = eval( "self.path_{idx}".format( idx = idx ) ) if 0 <= path: output.append( indent + "Magic Path #{idx_plus_1} " "{{Spl: #path {idx}}} {{Spl: #pathlevel {idx}}}: " "{path} {level}".format( idx = idx, idx_plus_1 = idx + 1, path = tables[ MagicPaths_DataTable.LABEL( ) ]\ .pformat_table_lookup( path, tables, pformat_config = pformat_config_compact_no_key ), level = eval( "self.path_level_{idx}".format( idx = idx ) ) ) ) output.append( self.effect.pformat_object( tables, pformat_config = pformat_config_1 ) ) output.append( indent + "Number of Effects {{Spl: #nreff}}: " "{effects_count}".format( effects_count = self.effects_count ) ) if self.precision: output.append( indent + "Precision {{Spl: #precision}}: {precision}".format( precision = self.precision ) ) if self.fatigue: output.append( indent + "Fatigue {{Spl: #fatiguecost}}: {fatigue}".format( fatigue = self.fatigue ) ) elif self.gem_cost: output.append( indent + "Gem Cost {{Spl: #fatiguecost}}: {gem_cost}".format( gem_cost = self.gem_cost ) ) if self.next_spell: output.append( indent + "Next Spell {{Spl: #nextspell}}: " "{next_spell}".format( next_spell = tables[ Spells_DataTable.LABEL( ) ]\ .pformat_table_lookup( self.next_spell, tables, pformat_config = pformat_config_compact ) ) ) if self.attributes: for attribute in self.attributes: output.append( attribute.pformat_object( tables, pformat_config = pformat_config_1 ) ) if not pformat_config.suppress_unknowns and self.unknown_fields: output.append( indent + "Unknowns" ) for unknown_field in self.unknown_fields: output.append( unknown_field.pformat_object( tables, pformat_config = pformat_config_2 ) ) if self.description: output.append( "" ) text_wrapper = _TextWrapper( width = pformat_config.line_width, initial_indent = pformat_config_1.indent, subsequent_indent = pformat_config_1.indent ) output.extend( text_wrapper.wrap( self.description ) ) return "\n".join( output ) + "\n"
def pformat_row( self, tables, pformat_config = _PrettyFormatConfig( ) ): """ Nicely formats the table row for display. """ output = [ ] pformat_config_no_key_padding = pformat_config.clone( key_format = self._KEY_FORMAT ) pformat_config_1 = pformat_config.clone( indent = pformat_config.indent + 4 * " " ) pformat_config_2 = pformat_config_1.clone( indent = pformat_config_1.indent + 4 * " " ) pformat_config_compact = pformat_config.clone( indent = "", render_title = False, render_compactly = True ) indent = pformat_config.indent + 4 * " " output.append( (pformat_config.indent + "{title} #{number}: {name}").format( title = self._TITLE, number = self.pformat_key( tables, pformat_config = pformat_config_no_key_padding ), name = self.name ) ) if pformat_config.render_compactly: return output[ 0 ] output.append( self.effect.pformat_object( tables, pformat_config = pformat_config_1 ) ) output.append( indent + "Attack {{Wpn: #att}}: {attack}".format( attack = self.attack ) ) output.append( indent + "Defense {{Wpn: #def}}: {defense}".format( defense = self.defense ) ) # TODO: Handle negative rates. output.append( indent + "Attack Rate {{Wpn: #nratt}}: {attack_rate}".format( attack_rate = self.attack_rate ) ) if self.attacks_total: output.append( indent + "Attacks per Battle {{Wpn: #ammo}}: " "{attacks_total}".format( attacks_total = self.attacks_total ) ) output.append( indent + "Length {{Wpn: #len}}: {length}".format( length = self.length ) ) if self.secondary_effect_on_hit: output.append( indent + "On-Hit Secondary Effect {Wpn: #secondaryeffect}: " + tables[ Weapons_DataTable.LABEL( ) ].pformat_table_lookup( self.secondary_effect_on_hit, tables, pformat_config = pformat_config_compact ) ) if self.secondary_effect_always: output.append( indent + "Always Secondary Effect " "{Wpn: #secondaryeffectalways}: " + tables[ Weapons_DataTable.LABEL( ) ].pformat_table_lookup( self.secondary_effect_always, tables, pformat_config = pformat_config_compact ) ) output.append( indent + "Resource Cost {{Wpn: #rcost}}: {resource_cost}".format( resource_cost = self.resource_cost ) ) if self.attributes: for attribute in self.attributes: output.append( attribute.pformat_object( tables, pformat_config = pformat_config_1 ) ) if not pformat_config.suppress_unknowns and self.unknown_fields: output.append( indent + "Unknowns" ) for unknown_field in self.unknown_fields: output.append( unknown_field.pformat_object( tables, pformat_config = pformat_config_2 ) ) return "\n".join( output ) + "\n"
def pprint_row( self, tables, pformat_config = _PrettyFormatConfig( ), stream_print = print ): """ Prints a nicely-formatted table row to an output stream. """ stream_print( self.pformat_row( tables, pformat_config ) )
def pprint_table_rows( self, tables, pformat_config = _PrettyFormatConfig( ), stream_print = print ): """ Nicely formats and prints the table rows to an output stream. """ stream_print( self.pformat_table_rows( tables, pformat_config ) )
def _pformat_object(self, tables, pformat_config=_PrettyFormatConfig()): """ Nicely formats the object data for display. """ return self.bit_name
def pformat_row(self, tables, pformat_config=_PrettyFormatConfig()): """ Nicely formats the table row for display. """ output = [] pformat_config_no_key_padding = pformat_config.clone( key_format=self._KEY_FORMAT) pformat_config_1 = pformat_config.clone(indent=pformat_config.indent + 4 * " ") pformat_config_2 = pformat_config_1.clone( indent=pformat_config_1.indent + 4 * " ") pformat_config_compact = pformat_config.clone(indent="", render_title=False, render_compactly=True) indent = pformat_config.indent + 4 * " " output.append( (pformat_config.indent + "{title} #{number}: {name}").format( title=self._TITLE, number=self.pformat_key( tables, pformat_config=pformat_config_no_key_padding), name=self.name)) if pformat_config.render_compactly: return output[0] output.append( self.effect.pformat_object(tables, pformat_config=pformat_config_1)) output.append(indent + "Attack {{Wpn: #att}}: {attack}".format( attack=self.attack)) output.append(indent + "Defense {{Wpn: #def}}: {defense}".format( defense=self.defense)) # TODO: Handle negative rates. output.append(indent + "Attack Rate {{Wpn: #nratt}}: {attack_rate}".format( attack_rate=self.attack_rate)) if self.attacks_total: output.append(indent + "Attacks per Battle {{Wpn: #ammo}}: " "{attacks_total}".format( attacks_total=self.attacks_total)) output.append(indent + "Length {{Wpn: #len}}: {length}".format( length=self.length)) if self.secondary_effect_on_hit: output.append( indent + "On-Hit Secondary Effect {Wpn: #secondaryeffect}: " + tables[Weapons_DataTable.LABEL()].pformat_table_lookup( self.secondary_effect_on_hit, tables, pformat_config=pformat_config_compact)) if self.secondary_effect_always: output.append( indent + "Always Secondary Effect " "{Wpn: #secondaryeffectalways}: " + tables[Weapons_DataTable.LABEL()].pformat_table_lookup( self.secondary_effect_always, tables, pformat_config=pformat_config_compact)) output.append(indent + "Resource Cost {{Wpn: #rcost}}: {resource_cost}".format( resource_cost=self.resource_cost)) if self.attributes: for attribute in self.attributes: output.append( attribute.pformat_object(tables, pformat_config=pformat_config_1)) if not pformat_config.suppress_unknowns and self.unknown_fields: output.append(indent + "Unknowns") for unknown_field in self.unknown_fields: output.append( unknown_field.pformat_object( tables, pformat_config=pformat_config_2)) return "\n".join(output) + "\n"
def pformat_row(self, tables, pformat_config=_PrettyFormatConfig()): """ Nicely formats the table row for display. """ output = [] pformat_config_no_key_padding = pformat_config.clone( key_format=self._KEY_FORMAT) pformat_config_1 = pformat_config.clone(indent=pformat_config.indent + 4 * " ") pformat_config_2 = pformat_config_1.clone( indent=pformat_config_1.indent + 4 * " ") indent = pformat_config.indent + 4 * " " output.append( (pformat_config.indent + "{title} #{number}: {name}").format( title=self._TITLE, number=self.pformat_key( tables, pformat_config=pformat_config_no_key_padding), name=self.name)) if pformat_config.render_compactly: return output[0] if self.epithet: output.append(indent + "Epithet: {epithet}".format(epithet=self.epithet)) if self.abbreviation: output.append(indent + "Abbreviation: {abbreviation}".format( abbreviation=self.abbreviation)) if self.file_name_base: output.append(indent + "File Name Base: {file_name_base}".format( file_name_base=self.file_name_base)) if self.initial_scout: # TODO: Fill out via table lookup. output.append(indent + "Initial Scout {{#startscout}}: " "{initial_scout}".format( initial_scout=self.initial_scout)) if self.initial_leader: # TODO: Fill out via table lookup. output.append(indent + "Initial Leader {{#startcom}}: " "{initial_leader}".format( initial_leader=self.initial_leader)) # TODO: Fill out via table lookup. output.append( indent + "Initial Troops (Type I) {{#startunittype1}}: " "{initial_troops_type} " "(Count {{#startunitnbs1}}: {initial_troops_count})".format( initial_troops_type=self.initial_troops_type_1, initial_troops_count=self.initial_troops_count_1)) # TODO: Fill out via table lookup. output.append( indent + "Initial Troops (Type II) {{#startunittype2}}: " "{initial_troops_type} " "(Count {{#startunitnbs2}}: {initial_troops_count})".format( initial_troops_type=self.initial_troops_type_2, initial_troops_count=self.initial_troops_count_2)) indent_1 = indent + 4 * " " if self.unpretender_types: output.append(indent + "Excluded Pretenders {#delgod}") for troop_type in self.unpretender_types: # TODO: Fill out via table lookup. output.append(indent_1 + str(troop_type.monster_number)) if self.pretender_types: output.append(indent + "Pretenders {#addgod}") for troop_type in self.pretender_types: # TODO: Fill out via table lookup. output.append(indent_1 + str(troop_type.monster_number)) if self.fort_leader_types: output.append(indent + "Recruitable Leaders (Fortification) {#addreccom}") for troop_type in self.fort_leader_types: # TODO: Fill out via table lookup. output.append(indent_1 + str(troop_type.monster_number)) if self.fort_troop_types: output.append(indent + "Recruitable Troops (Fortification) {#addrecunit}") for troop_type in self.fort_troop_types: # TODO: Fill out via table lookup. output.append(indent_1 + str(troop_type.monster_number)) if self.nonfort_leader_types: output.append(indent + "Recruitable Leaders (Foreign) {#addforeigncom}") for troop_type in self.nonfort_leader_types: # TODO: Fill out via table lookup. output.append(indent_1 + str(troop_type.monster_number)) if self.nonfort_troop_types: output.append(indent + "Recruitable Troops (Foreign) {#addforeignunit}") for troop_type in self.nonfort_troop_types: # TODO: Fill out via table lookup. output.append(indent_1 + str(troop_type.monster_number)) if self.coast_troop_types: output.append(indent + "Coast Troops {#coastunit}") for troop_type in self.coast_troop_types: # TODO: Fill out via table lookup. output.append(indent_1 + str(troop_type.monster_number)) if self.coast_leader_types: output.append(indent + "Coast Leaders {#coastcom}") for troop_type in self.coast_leader_types: # TODO: Fill out via table lookup. output.append(indent_1 + str(troop_type.monster_number)) if self.attributes: for attribute in self.attributes: output.append( attribute.pformat_object(tables, pformat_config=pformat_config_1)) if not pformat_config.suppress_unknowns and self.unknown_fields: output.append(indent + "Unknowns") for unknown_field in self.unknown_fields: output.append( unknown_field.pformat_object( tables, pformat_config=pformat_config_2)) return "\n".join(output) + "\n"
def pformat_key(self, tables, pformat_config=_PrettyFormatConfig()): """ Nicely formats the row key for display. """ return ("{key:" + pformat_config.key_format + "}").format(key=getattr(self, self._KEY_NAME))
def pformat_row( self, tables, pformat_config = _PrettyFormatConfig( ) ): """ Nicely formats the table row for display. """ output = [ ] pformat_config_no_key_padding = pformat_config.clone( key_format = self._KEY_FORMAT ) pformat_config_1 = pformat_config.clone( indent = pformat_config.indent + 4 * " " ) pformat_config_2 = pformat_config_1.clone( indent = pformat_config_1.indent + 4 * " " ) pformat_config_compact = pformat_config.clone( indent = "", render_title = False, render_compactly = True ) pformat_config_compact_no_key = pformat_config.clone( indent = "", render_title = False, render_key_with_object = False, render_compactly = True ) indent = pformat_config.indent + 4 * " " output.append( (pformat_config.indent + "{title} #{number}: {name}").format( title = self._TITLE, number = self.pformat_key( tables, pformat_config = pformat_config_no_key_padding ), name = self.name ) ) if pformat_config.render_compactly: return output[ 0 ] template = indent + "Research Requirement {{Spl: #school}}" args = { "school": tables[ MagicSchools_DataTable.LABEL( ) ].pformat_table_lookup( self.school, tables, pformat_config = pformat_config_compact_no_key ) } if 0 > self.school: template += ": {school}" else: template += " {{Spl: #researchlevel}}: {school} {level}" args[ "level" ] = self.research_level output.append( template.format( **args ) ) for idx in range( 2 ): path = eval( "self.path_{idx}".format( idx = idx ) ) if 0 <= path: output.append( indent + "Magic Path #{idx_plus_1} " "{{Spl: #path {idx}}} {{Spl: #pathlevel {idx}}}: " "{path} {level}".format( idx = idx, idx_plus_1 = idx + 1, path = tables[ MagicPaths_DataTable.LABEL( ) ]\ .pformat_table_lookup( path, tables, pformat_config = pformat_config_compact_no_key ), level = eval( "self.path_level_{idx}".format( idx = idx ) ) ) ) output.append( self.effect.pformat_object( tables, pformat_config = pformat_config_1 ) ) output.append( indent + "Number of Effects {{Spl: #nreff}}: " "{effects_count}".format( effects_count = self.effects_count ) ) if self.precision: output.append( indent + "Precision {{Spl: #precision}}: {precision}".format( precision = self.precision ) ) if self.fatigue: output.append( indent + "Fatigue {{Spl: #fatiguecost}}: {fatigue}".format( fatigue = self.fatigue ) ) elif self.gem_cost: output.append( indent + "Gem Cost {{Spl: #fatiguecost}}: {gem_cost}".format( gem_cost = self.gem_cost ) ) if self.next_spell: output.append( indent + "Next Spell {{Spl: #nextspell}}: " "{next_spell}".format( next_spell = tables[ Spells_DataTable.LABEL( ) ]\ .pformat_table_lookup( self.next_spell, tables, pformat_config = pformat_config_compact ) ) ) if self.attributes: for attribute in self.attributes: output.append( attribute.pformat_object( tables, pformat_config = pformat_config_1 ) ) if not pformat_config.suppress_unknowns and self.unknown_fields: output.append( indent + "Unknowns" ) for unknown_field in self.unknown_fields: output.append( unknown_field.pformat_object( tables, pformat_config = pformat_config_2 ) ) if self.description: output.append( "" ) text_wrapper = _TextWrapper( width = pformat_config.line_width, initial_indent = pformat_config_1.indent, subsequent_indent = pformat_config_1.indent ) output.extend( text_wrapper.wrap( self.description ) ) return "\n".join( output ) + "\n"