Skip to content

Commit

Permalink
Move evolution_description to dexlib
Browse files Browse the repository at this point in the history
Updates #118
  • Loading branch information
magical committed Jul 19, 2019
1 parent 95f980f commit 561a572
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 87 deletions.
86 changes: 0 additions & 86 deletions splinext/pokedex/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,92 +486,6 @@ def article(noun, _=_):
return _(u'an')
return _(u'a')

def evolution_description(evolution, _=_):
"""Crafts a human-readable description from a `pokemon_evolution` row
object.
"""
chunks = []

# Trigger
if evolution.trigger.identifier == u'level-up':
chunks.append(_(u'Level up'))
elif evolution.trigger.identifier == u'trade':
chunks.append(_(u'Trade'))
elif evolution.trigger.identifier == u'use-item':
chunks.append(h.literal(_(u"Use {article} {item}")).format(
article=article(evolution.trigger_item.name, _=_),
item=item_link(evolution.trigger_item, include_icon=False)))
elif evolution.trigger.identifier == u'shed':
chunks.append(
_(u"Evolve {from_pokemon} ({to_pokemon} will consume "
u"a Poké Ball and appear in a free party slot)").format(
from_pokemon=evolution.evolved_species.parent_species.name,
to_pokemon=evolution.evolved_species.name))
else:
chunks.append(_(u'Do something'))

# Conditions
if evolution.gender_id:
chunks.append(_(u"{0}s only").format(evolution.gender.identifier))
if evolution.time_of_day:
chunks.append(_(u"during the {0}").format(evolution.time_of_day))
if evolution.minimum_level:
chunks.append(_(u"starting at level {0}").format(evolution.minimum_level))
if evolution.location_id:
chunks.append(h.literal(_(u"around {0} ({1})")).format(
h.HTML.a(evolution.location.name,
href=url(controller='dex', action='locations',
name=evolution.location.name.lower())),
evolution.location.region.name))
if evolution.held_item_id:
chunks.append(h.literal(_(u"while holding {article} {item}")).format(
article=article(evolution.held_item.name),
item=item_link(evolution.held_item, include_icon=False)))
if evolution.known_move_id:
chunks.append(h.literal(_(u"knowing {0}")).format(
h.HTML.a(evolution.known_move.name,
href=url(controller='dex', action='moves',
name=evolution.known_move.name.lower()))))
if evolution.known_move_type_id:
chunks.append(h.literal(_(u'knowing a {0}-type move')).format(
h.HTML.a(evolution.known_move_type.name,
href=url(controller='dex', action='types',
name=evolution.known_move_type.name.lower()))))
if evolution.minimum_happiness:
chunks.append(_(u"with at least {0} happiness").format(
evolution.minimum_happiness))
if evolution.minimum_beauty:
chunks.append(_(u"with at least {0} beauty").format(
evolution.minimum_beauty))
if evolution.minimum_affection:
chunks.append(_(u'with at least {0} affection in Pokémon-Amie').format(
evolution.minimum_affection))
if evolution.relative_physical_stats is not None:
if evolution.relative_physical_stats < 0:
op = _(u'<')
elif evolution.relative_physical_stats > 0:
op = _(u'>')
else:
op = _(u'=')
chunks.append(_(u"when Attack {0} Defense").format(op))
if evolution.party_species_id:
chunks.append(h.literal(_(u"with {0} in the party")).format(
pokemon_link(evolution.party_species.default_pokemon, include_icon=False)))
if evolution.party_type_id:
chunks.append(h.literal(_(u"with a {0}-type Pokémon in the party")).format(
h.HTML.a(evolution.party_type.name,
href=url(controller='dex', action='types',
name=evolution.party_type.name.lower()))))
if evolution.trade_species_id:
chunks.append(h.literal(_(u"in exchange for {0}")).format(
pokemon_link(evolution.trade_species.default_pokemon, include_icon=False)))
if evolution.needs_overworld_rain:
chunks.append(_(u'while it is raining outside of battle'))
if evolution.turn_upside_down:
chunks.append(_(u'with the 3DS turned upside-down'))

return h.literal(u', ').join(chunks)


### Formatting

Expand Down
90 changes: 90 additions & 0 deletions splinext/pokedex/templates/pokedex/lib.mako
Original file line number Diff line number Diff line change
Expand Up @@ -362,3 +362,93 @@ cry_url = url(controller='dex', action='media',
% endfor
</dl>
</%def>


###### Evolution descriptions

<%def name="evolution_description(evolution)"><%
"""Crafts a human-readable description from a `pokemon_evolution` row
object.
"""
chunks = []
# Trigger
if evolution.trigger.identifier == u'level-up':
chunks.append(_(u'Level up'))
elif evolution.trigger.identifier == u'trade':
chunks.append(_(u'Trade'))
elif evolution.trigger.identifier == u'use-item':
chunks.append(h.literal(_(u"Use {article} {item}")).format(
article=h.pokedex.article(evolution.trigger_item.name, _=_),
item=h.pokedex.item_link(evolution.trigger_item, include_icon=False)))
elif evolution.trigger.identifier == u'shed':
chunks.append(
_(u"Evolve {from_pokemon} ({to_pokemon} will consume "
u"a Poké Ball and appear in a free party slot)").format(
from_pokemon=evolution.evolved_species.parent_species.name,
to_pokemon=evolution.evolved_species.name))
else:
chunks.append(_(u'Do something'))
# Conditions
if evolution.gender_id:
chunks.append(_(u"{0}s only").format(evolution.gender.identifier))
if evolution.time_of_day:
chunks.append(_(u"during the {0}").format(evolution.time_of_day))
if evolution.minimum_level:
chunks.append(_(u"starting at level {0}").format(evolution.minimum_level))
if evolution.location_id:
chunks.append(h.literal(_(u"around {0} ({1})")).format(
h.HTML.a(evolution.location.name,
href=url(controller='dex', action='locations',
name=evolution.location.name.lower())),
evolution.location.region.name))
if evolution.held_item_id:
chunks.append(h.literal(_(u"while holding {article} {item}")).format(
article=h.pokedex.article(evolution.held_item.name),
item=h.pokedex.item_link(evolution.held_item, include_icon=False)))
if evolution.known_move_id:
chunks.append(h.literal(_(u"knowing {0}")).format(
h.HTML.a(evolution.known_move.name,
href=url(controller='dex', action='moves',
name=evolution.known_move.name.lower()))))
if evolution.known_move_type_id:
chunks.append(h.literal(_(u'knowing a {0}-type move')).format(
h.HTML.a(evolution.known_move_type.name,
href=url(controller='dex', action='types',
name=evolution.known_move_type.name.lower()))))
if evolution.minimum_happiness:
chunks.append(_(u"with at least {0} happiness").format(
evolution.minimum_happiness))
if evolution.minimum_beauty:
chunks.append(_(u"with at least {0} beauty").format(
evolution.minimum_beauty))
if evolution.minimum_affection:
chunks.append(_(u'with at least {0} affection in Pokémon-Amie').format(
evolution.minimum_affection))
if evolution.relative_physical_stats is not None:
if evolution.relative_physical_stats < 0:
op = _(u'<')
elif evolution.relative_physical_stats > 0:
op = _(u'>')
else:
op = _(u'=')
chunks.append(_(u"when Attack {0} Defense").format(op))
if evolution.party_species_id:
chunks.append(h.literal(_(u"with {0} in the party")).format(
h.pokedex.pokemon_link(evolution.party_species.default_pokemon, include_icon=False)))
if evolution.party_type_id:
chunks.append(h.literal(_(u"with a {0}-type Pokémon in the party")).format(
h.HTML.a(evolution.party_type.name,
href=url(controller='dex', action='types',
name=evolution.party_type.name.lower()))))
if evolution.trade_species_id:
chunks.append(h.literal(_(u"in exchange for {0}")).format(
h.pokedex.pokemon_link(evolution.trade_species.default_pokemon, include_icon=False)))
if evolution.needs_overworld_rain:
chunks.append(_(u'while it is raining outside of battle'))
if evolution.turn_upside_down:
chunks.append(_(u'with the 3DS turned upside-down'))
return h.literal(u', ').join(chunks)
%></%def>
2 changes: 1 addition & 1 deletion splinext/pokedex/templates/pokedex/pokemon.mako
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ ${h.h1(_('Evolution'))}
% endif
% for evolution in col['species'].evolutions:
<span class="dex-evolution-chain-method">
${h.pokedex.evolution_description(evolution, _=_)}
${dexlib.evolution_description(evolution)}
</span>
% endfor
% if col['species'].is_baby and c.pokemon.species.evolution_chain.baby_trigger_item:
Expand Down

0 comments on commit 561a572

Please sign in to comment.