def _solution(request, char_id, is_guest, encoded_char_id=None): char = get_object_or_404(Char, pk=char_id) inclusions = get_all_inclusions_en_names(char) exclusions = get_all_exclusions_en_names(char) solution = get_solution(char) solution_result = SolutionResult(solution, inclusions, exclusions) params = {'char_id': char_id, 'lock_item': static('chardata/lock-icon.png'), 'switch_item': static('chardata/1412645636_Left-right.png'), 'delete_item': static('chardata/delete-icon.png'), 'add_item': static('chardata/add-icon.png'), 'ajax_loader': json.dumps(get_ajax_loader_URL(request)), 'link_external_image': json.dumps(get_external_image_URL(request)), 'is_guest': is_guest, 'is_guest_json': json.dumps(is_guest), 'encoded_char_id': encoded_char_id, 'link_shared': char.link_shared, 'owner_alias': get_alias(char.owner), 'is_dueler': chardata.smart_build.char_has_aspect(char, 'duel')} if char.link_shared: params['initial_link'] = generate_link(char) params.update(solution_result.get_params()) response = set_response(request, 'chardata/solution.html', params, char) return response
def get_external_image_URL(request): theme = get_theme(request) if theme == 'auto': external_image = {} external_image['lighttheme'] = static('chardata/link-external-%s.png' % ('lighttheme')) external_image['darktheme'] = static('chardata/link-external-%s.png' % ('darktheme')) else: external_image = static('chardata/link-external-%s.png' % (theme)) return external_image
def get_ajax_loader_URL(request): theme = get_theme(request) if theme == 'auto': loader_pic = {} loader_pic['lighttheme'] = static('chardata/ajax-loader-%s-2.gif' % ('lighttheme')) loader_pic['darktheme'] = static('chardata/ajax-loader-%s-2.gif' % ('darktheme')) else: loader_pic = static('chardata/ajax-loader-%s-2.gif' % (theme)) return loader_pic
def get_needle_URL(request): theme = get_theme(request) if theme == 'auto': needle_pic = {} needle_pic['lighttheme'] = static('chardata/needle-%s.png' % ('lighttheme')) needle_pic['darktheme'] = static('chardata/needle-%s.png' % ('darktheme')) else: needle_pic = static('chardata/needle-%s.png' % (theme)) return needle_pic
def get_triangle_URL(request): theme = get_theme(request) if theme == 'auto': triangle_pic = {} triangle_pic['lighttheme'] = static('chardata/triangle-%s.png' % ('lighttheme')) triangle_pic['darktheme'] = static('chardata/triangle-%s.png' % ('darktheme')) else: triangle_pic = static('chardata/triangle-%s.png' % (theme)) return triangle_pic
def get_questionmark_URL(request): theme = get_theme(request) if theme == 'auto': questionmark = {} questionmark['lighttheme'] = static('chardata/QuestionMark-%s.png' % ('lighttheme')) questionmark['darktheme'] = static('chardata/QuestionMark-%s.png' % ('darktheme')) else: questionmark = static('chardata/QuestionMark-%s.png' % (theme)) return questionmark
def get_css_static_for_theme(theme, request): theme_css = {} if theme == 'auto': for css in CSS_NAMES: if 'current_auto' in request.COOKIES: auto_theme = request.COOKIES['current_auto'] theme_css[css] = static("chardata/%s_%s.css" % (css, auto_theme)) else: theme_css[css] = static("chardata/%s_%s.css" % (css, 'darktheme')) theme_css['%s%s' % (css, 'lighttheme')] = static("chardata/%s_%s.css" % (css, 'lighttheme')) theme_css['%s%s' % (css, 'darktheme')] = static("chardata/%s_%s.css" % (css, 'darktheme')) else: for css in CSS_NAMES: theme_css[css] = static("chardata/%s_%s.css" % (css, theme)) return theme_css
def _create_weapon_web_digest(weapon): web_digest = {} if weapon.is_mageable: web_digest['type'] = 'weapon' web_digest['element_maged'] = weapon.element_maged else: web_digest['type'] = 'weapon_non_mageable' web_digest['name'] = weapon.localized_name web_digest['level'] = weapon.level web_digest['image_url'] = static('chardata/items/' + weapon.or_name + '.png') web_digest['hit_number'] = len(weapon.non_crit_hits) web_digest['non_crit_dams'] = _convert_weapon_damage(weapon.non_crit_hits) web_digest['crit_dams'] = _convert_weapon_damage(weapon.crit_hits) damage_indexes = []; healing_indexes = []; for i, hit_instance in enumerate(weapon.non_crit_hits[NEUTRAL]): if hit_instance.heals: healing_indexes.append(i) else: damage_indexes.append(i) aggregates = [] if damage_indexes: aggregates.append(('', damage_indexes)) if healing_indexes: aggregates.append(('', healing_indexes)) web_digest['aggregates'] = convert_aggregates(aggregates) return web_digest
def get_all_images_URLs(request): images = {} images['lighttheme'] = {} images['darktheme'] = {} images['lighttheme']['triangle'] = static('chardata/triangle-%s.png' % ('lighttheme')) images['lighttheme']['loader'] = static('chardata/ajax-loader-%s-2.gif' % ('lighttheme')) images['lighttheme']['external'] = static('chardata/link-external-%s.png' % ('lighttheme')) images['lighttheme']['needle'] = static('chardata/needle-%s.png' % ('lighttheme')) images['lighttheme']['questionmark'] = static('chardata/QuestionMark-%s.png' % ('lighttheme')) images['darktheme']['triangle'] = static('chardata/triangle-%s.png' % ('darktheme')) images['darktheme']['loader'] = static('chardata/ajax-loader-%s-2.gif' % ('darktheme')) images['darktheme']['external'] = static('chardata/link-external-%s.png' % ('darktheme')) images['darktheme']['needle'] = static('chardata/needle-%s.png' % ('darktheme')) images['darktheme']['questionmark'] = static('chardata/QuestionMark-%s.png' % ('darktheme')) return images
def get_item_details(request): item_id = request.POST.get('item', None) info = {} if item_id is not None: structure = get_structure() item = structure.get_item_by_id(int(item_id)) info['level'] = item.level info['file'] = static( get_image_url(structure.get_type_name_by_id(item.type), item.name)) json_response = jsonpickle.encode(info, unpicklable=False) return HttpResponseJson(json_response)
def inclusions(request, char_id): char = get_char_or_raise(request, char_id) structure = get_structure() types_list = structure.get_types_list() items_by_type = {} items_by_type_and_name = {} for item_type in types_list: items_by_type[item_type] = {} items_by_type_and_name[item_type] = {} for item_type in items_by_type: for item in structure.get_unique_items_by_type_and_level( item_type, char.level): item_name = structure.get_item_name_in_language( item, get_supported_language()) items_by_type[item_type][item.id] = item_name items_by_type_and_name[item_type][item_name] = item.id images_urls = {} for item_slot in SLOT_NAME_TO_TYPE: images_urls[item_slot] = static('chardata/%s.png' % SLOT_NAME_TO_TYPE[item_slot]) inclusions = get_inclusions_dict(char) for slot in SLOTS: inclusions.setdefault(slot, '') return set_response( request, 'chardata/inclusions.html', { 'char_id': char_id, 'advanced': True, 'types': items_by_type, 'types_json': jsonpickle.encode(items_by_type, unpicklable=False), 'names_and_types_json': jsonpickle.encode(items_by_type_and_name, unpicklable=False), 'inclusions_json': json.dumps(inclusions), 'images_json': json.dumps(images_urls), 'slot_to_type_json': json.dumps(SLOT_NAME_TO_TYPE), 'ajax_loader': json.dumps(get_ajax_loader_URL(request)) }, char)
def _create_spell_web_digest(spell): web_digest = {} digest = spell.get_effects_digest() web_digest['type'] = 'spell' web_digest['name'] = _(spell.name) web_digest['level'] = spell.level_req web_digest['stacks'] = spell.stacks web_digest['image_url'] = static('chardata/spells/' + spell.name + '.png') web_digest['hit_number'] = digest.hit_number web_digest['non_crit_dams'] = _convert_spell_damage(digest.non_crit_dams) web_digest['crit_dams'] = _convert_spell_damage(digest.crit_dams) web_digest['aggregates'] = convert_aggregates(digest.aggregates) web_digest['is_linked'] = (spell.is_linked[0], _(spell.is_linked[1])) if spell.is_linked else None web_digest['special'] = spell.special return web_digest
def __init__(self, char, slots): structure = get_structure() self.items_by_type = {} self.items_by_type_and_name = {} for slot in slots: item_type = SLOT_NAME_TO_TYPE[slot] self.items_by_type[item_type] = {} self.items_by_type_and_name[item_type] = {} for item in structure.get_unique_items_by_type_and_level( item_type, char.level): item_name = structure.get_item_name_in_language( item, get_supported_language()) self.items_by_type[item_type][item.id] = item_name self.items_by_type_and_name[item_type][item_name] = item.id self.images_urls = {} self.images_urls[slot] = static('chardata/' + item_type + '.png') self.slot_to_type = SLOT_NAME_TO_TYPE
def evolve_result_item(result_item, r=None): if result_item.slot: result_item.file = static('chardata/%s.png' % SLOT_NAME_TO_TYPE[result_item.slot]) if not result_item.item_added: if not result_item.file: print 'No item and no slot for picture.' return stats_from_result_item = sorted(result_item.stats.iteritems(), key=lambda x: STAT_ORDER[x[0]]) result_item.stats_lines = [] for stat_key, stat_value in stats_from_result_item: stat_name = get_structure().get_stat_by_key(stat_key).name result_item.stats_lines.append(AttributeLine(stat_value, stat_name)) for extra in result_item.extras: result_item.stats_lines.append(ExtraLine(extra)) result_item.condition_lines = [] if hasattr(result_item, 'min_stats_to_equip'): min_from_result_item = sorted( result_item.min_stats_to_equip.iteritems(), key=lambda x: STAT_ORDER[x[0]]) for stat_key, stat_value in min_from_result_item: stat_name = get_structure().get_stat_by_key(stat_key).name result_item.condition_lines.append( MinConditionLine(stat_value, stat_name, r)) if hasattr(result_item, 'max_stats_to_equip'): max_from_result_item = sorted( result_item.max_stats_to_equip.iteritems(), key=lambda x: STAT_ORDER[x[0]]) for stat_key, stat_value in max_from_result_item: stat_name = get_structure().get_stat_by_key(stat_key).name result_item.condition_lines.append( MaxConditionLine(stat_value, stat_name, r)) if result_item.weird_conditions['light_set']: result_item.condition_lines.append(LightSetConditionLine(r)) if hasattr(result_item, 'non_crit_hits'): damage_lines = [] if result_item.crit_chance is not None and result_item.crit_bonus is not None: damage_lines.append( _('(%(weapon_type)s) AP: %(AP)d / CH: %(crit_chance)d%% (+%(crit_bonus)d)' ) % { 'weapon_type': LOCALIZED_WEAPON_TYPES[result_item.weapon_type], 'AP': result_item.ap, 'crit_chance': result_item.crit_chance, 'crit_bonus': result_item.crit_bonus }) else: damage_lines.append( _('(%(weapon_type)s) AP: %(AP)d') % { 'weapon_type': result_item.weapon_type, 'AP': result_item.ap }) for hit in result_item.non_crit_hits[NEUTRAL]: if hit.steals: line = _('%(min)d to %(max)d (%(element)s steal)') % { 'min': hit.min_dam, 'max': hit.max_dam, 'element': LOCALIZED_ELEMENTS[hit.element] } elif hit.heals: line = _('%(min)d to %(max)d (HP restored)') % { 'min': hit.min_dam, 'max': hit.max_dam } else: line = _('%(min)d to %(max)d (%(element)s)') % { 'min': hit.min_dam, 'max': hit.max_dam, 'element': LOCALIZED_ELEMENTS[hit.element] } damage_lines.append(line) result_item.damage_text = '<br>'.join(damage_lines) result_item.file = static(get_image_url(result_item.type, result_item.name)) if settings.EXPERIMENTS['ITEM_LINKS']: result_item.link = get_item_link(result_item.ankama_type, result_item.ankama_id, result_item.localized_name)
def home(request, char_id=0): items = [] for unused in xrange(12): item_row = [] for unused in xrange(13): item_obj = get_structure().get_random_item() item = {} item['name'] = item_obj.localized_names[get_supported_language()] item['file'] = static( get_image_url( get_structure().get_type_name_by_id(item_obj.type), item_obj.name)) item_row.append(item) items.append(item_row) buttons = [] if not is_anon_cant_create(request) and not has_too_many_projects( request) and len(buttons) < 3: button = {} button['pic'] = static('chardata/LoadProj2.png') button['label'] = _('Create a Project') button['link'] = reverse('chardata.create_project_view.setup') button['class'] = get_button_pos(buttons) buttons.append(button) if user_has_projects(request) and len(buttons) < 3: button = {} button['pic'] = static('chardata/NewProj1.png') button['label'] = _('Load a Project') button['link'] = reverse('chardata.views.load_projects') button['class'] = get_button_pos(buttons) buttons.append(button) if request.user.is_anonymous() and len(buttons) < 3: button = {} button['pic'] = static('chardata/Login1.png') button['label'] = _('Login') button['link'] = reverse('chardata.login_view.login_page') button['class'] = get_button_pos(buttons) buttons.append(button) if len(buttons) < 3: button = {} button['pic'] = static('chardata/Faq2.png') button['label'] = _('FAQ') button['link'] = reverse('chardata.views.faq') button['class'] = get_button_pos(buttons) buttons.append(button) if len(buttons) < 3: button = {} button['pic'] = static('chardata/About2.png') button['label'] = _('Help & About') button['link'] = reverse('chardata.views.about') button['class'] = get_button_pos(buttons) buttons.append(button) return set_response( request, 'chardata/home.html', { 'request': request, 'home': True, 'items': items, 'buttons': buttons, 'user': request.user, 'char_id': char_id })