Skip to content

Commit

Permalink
Move conquest_{evolution,transformation}_description to conqlib
Browse files Browse the repository at this point in the history
Updates veekun#118
  • Loading branch information
magical committed Oct 28, 2018
1 parent f053eb9 commit a08bdad
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 106 deletions.
104 changes: 0 additions & 104 deletions splinext/pokedex/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -572,110 +572,6 @@ def evolution_description(evolution, _=_):

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

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

# Trigger
if evolution.recruiting_ko_required:
chunks.append('Score a KO that makes a warrior offer to join your army')
elif evolution.item_id is not None:
chunks.append('Win a battle')
else:
chunks.append('Perform any action')

# Conditions
if evolution.kingdom_id is not None:
chunks.append(h.literal(_(u'in {0}')).format(
h.HTML.a(evolution.kingdom.name,
href=url(controller='dex_conquest', action='kingdoms',
name=evolution.kingdom.name.lower()))))
if evolution.item_id is not None:
chunks.append(h.literal(_(u'with {article} {item} equipped')).format(
article=article(evolution.item.name),
item=item_link(evolution.item, include_icon=False)))
if evolution.required_stat_id is not None:
chunks.append(_(u'with at least {number} {stat} afterwards').format(
number=evolution.minimum_stat,
stat=evolution.stat.name))
if evolution.minimum_link is not None:
chunks.append(_(u'with at least {0}% link afterwards').format(
evolution.minimum_link))
if evolution.warrior_gender_id is not None:
chunks.append(_(u'{0} warriors only').format(evolution.gender.identifier))

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

def conquest_transformation_description(tform, _=_):
"""Crafts a human-readable description from a
`conquest_warrior_transformation' row object.
"""
# Dumb tricks for saving characters; this has a lot of big awkward lines
def link(thing):
return h.HTML.a(thing.name, href=make_thingy_url(thing,
controller='dex_conquest'))
lit = h.literal

chunks = []

# Triggers
if tform.is_automatic:
chunks.append(_(u'Automatically happens in-story'))
elif tform.required_link is not None:
if tform.pokemon[0].identifier == 'eevee':
pokemon = lit(_(u'{0} or any of its evolutions')).format(
link(tform.pokemon[0]))
else:
pokemon = lit(_(u' or ')).join(link(p) for p in tform.pokemon)

chunks.append(lit(_(u'Reach at least {link}% link with {pokemon}'))
.format(link=tform.required_link, pokemon=pokemon))

# Conditions
if tform.completed_episode_id is not None:
warrior = tform.completed_episode.warriors[0]
if warrior != tform.warrior_rank.warrior:
warrior = link(warrior)
else:
warrior = warrior.name

chunks.append(lit(_(u'after completing {warrior}\'s episode, "{name}"'))
.format(warrior=warrior, name=tform.completed_episode.name))
elif tform.current_episode_id is not None:
if tform.current_episode.warriors[0].identifier == 'player-m':
warrior = _(u'the player')
else:
warrior = tform.current_episode.warriors[0].name

chunks.append(_(u'during {warrior}\'s episode, "{name}"')
.format(
warrior=warrior,
name=tform.current_episode.name
))
elif tform.distant_warrior_id is not None:
chunks.append(lit(_(u'with {0} in the army but not in the same kingdom '
u'or any adjacent kingdom')).format(link(tform.distant_warrior)))
elif tform.present_warriors:
chunks.append(h.literal(_(u'with {0} in the same kingdom'))
.format(lit(_(u' and ')).join(link(warrior) for warrior in
tform.present_warriors)))
elif tform.female_warlord_count is not None:
chunks.append(_(u'with at least {0} female warlords in the same kingdom')
.format(tform.female_warlord_count))
elif tform.pokemon_count is not None:
chunks.append(_(u'with at least {0} Pokémon in the gallery')
.format(tform.pokemon_count))
elif tform.collection_type_id is not None:
chunks.append(_(u'with all {0}-type Pokémon in the gallery')
.format(tform.type.name))
elif tform.warrior_count is not None:
chunks.append(_(u'with at least {0} warriors in the gallery')
.format(tform.warrior_count))

return lit(u', ').join(chunks)


### Formatting

Expand Down
108 changes: 108 additions & 0 deletions splinext/pokedex/templates/pokedex/conquest/lib.mako
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<%! from splinext.pokedex import i18n %>
<%def name="pokemon_page_header()">
<div id="dex-header">
<a href="${url.current(name=c.prev_pokemon.name.lower(), form=None)}" id="dex-header-prev" class="dex-box-link">
Expand Down Expand Up @@ -291,3 +293,109 @@ ${warrior_table_stat_colgroup(stats)}
</tr>
</thead>
</%def>

<%def name="conquest_evolution_description(evolution)"><%
"""Crafts a human-readable description from a `conquest_pokemon_evolution`
row object.
"""
chunks = []
# Trigger
if evolution.recruiting_ko_required:
chunks.append('Score a KO that makes a warrior offer to join your army')
elif evolution.item_id is not None:
chunks.append('Win a battle')
else:
chunks.append('Perform any action')
# Conditions
if evolution.kingdom_id is not None:
chunks.append(h.literal(_(u'in {0}')).format(
h.HTML.a(evolution.kingdom.name,
href=url(controller='dex_conquest', action='kingdoms',
name=evolution.kingdom.name.lower()))))
if evolution.item_id is not None:
chunks.append(h.literal(_(u'with {article} {item} equipped')).format(
article=h.pokedex.article(evolution.item.name),
item=h.pokedex.item_link(evolution.item, include_icon=False)))
if evolution.required_stat_id is not None:
chunks.append(_(u'with at least {number} {stat} afterwards').format(
number=evolution.minimum_stat,
stat=evolution.stat.name))
if evolution.minimum_link is not None:
chunks.append(_(u'with at least {0}% link afterwards').format(
evolution.minimum_link))
if evolution.warrior_gender_id is not None:
chunks.append(_(u'{0} warriors only').format(evolution.gender.identifier))
return h.literal(u', ').join(chunks)
%></%def>

<%def name="conquest_transformation_description(tform)"><%
"""Crafts a human-readable description from a
`conquest_warrior_transformation' row object.
"""
# Dumb tricks for saving characters; this has a lot of big awkward lines
def link(thing):
return h.HTML.a(thing.name,
href=h.pokedex.make_thingy_url(thing, controller='dex_conquest'))
lit = h.literal
chunks = []
# Triggers
if tform.is_automatic:
chunks.append(_(u'Automatically happens in-story'))
elif tform.required_link is not None:
if tform.pokemon[0].identifier == 'eevee':
pokemon = lit(_(u'{0} or any of its evolutions')).format(
link(tform.pokemon[0]))
else:
pokemon = lit(_(u' or ')).join(link(p) for p in tform.pokemon)
chunks.append(lit(_(u'Reach at least {link}% link with {pokemon}'))
.format(link=tform.required_link, pokemon=pokemon))
# Conditions
if tform.completed_episode_id is not None:
warrior = tform.completed_episode.warriors[0]
if warrior != tform.warrior_rank.warrior:
warrior = link(warrior)
else:
warrior = warrior.name
chunks.append(lit(_(u'after completing {warrior}\'s episode, "{name}"'))
.format(warrior=warrior, name=tform.completed_episode.name))
elif tform.current_episode_id is not None:
if tform.current_episode.warriors[0].identifier == 'player-m':
warrior = _(u'the player')
else:
warrior = tform.current_episode.warriors[0].name
chunks.append(_(u'during {warrior}\'s episode, "{name}"')
.format(
warrior=warrior,
name=tform.current_episode.name
))
elif tform.distant_warrior_id is not None:
chunks.append(lit(_(u'with {0} in the army but not in the same kingdom '
u'or any adjacent kingdom')).format(link(tform.distant_warrior)))
elif tform.present_warriors:
chunks.append(h.literal(_(u'with {0} in the same kingdom'))
.format(lit(_(u' and ')).join(link(warrior) for warrior in
tform.present_warriors)))
elif tform.female_warlord_count is not None:
chunks.append(_(u'with at least {0} female warlords in the same kingdom')
.format(tform.female_warlord_count))
elif tform.pokemon_count is not None:
chunks.append(_(u'with at least {0} Pokémon in the gallery')
.format(tform.pokemon_count))
elif tform.collection_type_id is not None:
chunks.append(_(u'with all {0}-type Pokémon in the gallery')
.format(tform.type.name))
elif tform.warrior_count is not None:
chunks.append(_(u'with at least {0} warriors in the gallery')
.format(tform.warrior_count))
return lit(u', ').join(chunks)
%></%def>
2 changes: 1 addition & 1 deletion splinext/pokedex/templates/pokedex/conquest/pokemon.mako
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ ${h.h1(_('Evolution'))}
% if absent:
Not present in Pokémon Conquest
% elif col['species'].conquest_evolution is not None:
${h.pokedex.conquest_evolution_description(col['species'].conquest_evolution, _=_)}
${conqlib.conquest_evolution_description(col['species'].conquest_evolution)}
% endif
</span>
</td>
Expand Down
2 changes: 1 addition & 1 deletion splinext/pokedex/templates/pokedex/conquest/warrior.mako
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ ${h.h1(_('Essentials'))}
% for rank in c.warrior.ranks:
% if rank.transformation:
<dt>${_(u'Rank {0}').format(h.pokedex.conquest_rank_label[rank.rank])}</dt>
<dd>${h.pokedex.conquest_transformation_description(rank.transformation)}.</dd>
<dd>${conqlib.conquest_transformation_description(rank.transformation)}.</dd>
% endif
% endfor
</dl>
Expand Down

0 comments on commit a08bdad

Please sign in to comment.