Ejemplo n.º 1
0
async def get_ingredients_for_item(
        ctx: Context,
        item_name: str,
        as_embed: bool = settings.USE_EMBEDS) -> Union[List[Embed], List[str]]:
    pss_assert.valid_entity_name(item_name, allowed_values=ALLOWED_ITEM_NAMES)

    items_data = await items_designs_retriever.get_data_dict3()
    item_infos = __get_item_infos_by_name(item_name,
                                          items_data,
                                          return_best_match=True)

    if not item_infos:
        raise NotFound(f'Could not find an item named `{item_name}`.')
    else:
        ingredients_details_collection = __create_ingredients_details_collection_from_infos(
            [item_infos[0]], items_data)
        if as_embed:
            return (
                await
                ingredients_details_collection.get_entities_details_as_embed(
                    ctx,
                    custom_footer_text=resources.get_resource(
                        'PRICE_NOTE_EMBED')))
        else:
            return (
                await
                ingredients_details_collection.get_entities_details_as_text(
                    custom_footer_text=resources.get_resource('PRICE_NOTE')))
Ejemplo n.º 2
0
	def init(self):
		flags = 0
		if not ANDROID:
			os.environ['SDL_VIDEO_CENTERED'] = '1'
			WINSIZE = 480, 800
		else:
			WINSIZE = 0, 0
			flags |= pygame.FULLSCREEN
		pygame.init()	
		mixer.init()
		
		# Map the back button to the escape key.
		if ANDROID:
			android.init()
			android.map_key(android.KEYCODE_BACK, pygame.K_b)

		self.clock = pygame.time.Clock()			
		if not ANDROID:
			self.icon = pygame.image.load(get_resource('android-icon.png'))
			pygame.display.set_icon(self.icon)
		screen = self.screen = pygame.display.set_mode(WINSIZE, flags)
		self.width, self.height = screen.get_width(), screen.get_height()		
		pygame.display.set_caption('Mazenum')
		
		self.score_font = pygame.font.Font(get_resource(join("fonts", "FreeSans.ttf")), 25)
		self.completed_font = pygame.font.Font(get_resource(join("fonts", "FreeSans.ttf")), 40)
		
		self.start_button = Button("Start game")
						
		self.playboard = PlayBoard(screen, 
				self.COLUMNS, self.ROWS, self.header_height)
		self._set_background()
		self.is_game_over = False						
Ejemplo n.º 3
0
def __get_footer_text_for_group(group_title: str, as_embed: bool) -> str:
    result = []
    if group_title and 'module' in group_title.lower():
        if as_embed:
            result.append(resources.get_resource('HERO_MODULE_NOTE_EMBED'))
        else:
            result.append(resources.get_resource('HERO_MODULE_NOTE'))
    if as_embed:
        result.append(resources.get_resource('PRICE_NOTE_EMBED'))
    else:
        result.append(resources.get_resource('PRICE_NOTE'))
    return '\n'.join(result)
Ejemplo n.º 4
0
def _get_item_price_as_text(item_name: str, items_designs_details) -> str:
    lines = []
    lines.append(f'**Item prices matching \'{item_name}\'**')
    for item_design_details in items_designs_details:
        lines.extend(item_design_details.get_details_as_text_long())

    lines.append(settings.EMPTY_LINE)
    lines.append(' '.join([
        resources.get_resource('MARKET_FAIR_PRICE_NOTE'),
        resources.get_resource('PRICE_NOTE')
    ]))

    return lines
Ejemplo n.º 5
0
def __get_can_sell(item_info: EntityInfo, items_data: EntitiesData, trainings_data: EntitiesData = None, **kwargs) -> Optional[str]:
    flags = int(item_info['Flags'])
    if flags & 1 == 0:
        result = resources.get_resource('CANNOT_BE_SOLD')
    else:
        result = None
    return result
Ejemplo n.º 6
0
def _get_item_ingredients_as_text(item_name, ingredients_dicts,
                                  item_design_data):
    lines = [f'**Ingredients for {item_name}**']
    ingredients_dicts = [d for d in ingredients_dicts if d]

    if ingredients_dicts:
        for ingredients_dict in ingredients_dicts:
            current_level_lines = []
            current_level_costs = 0
            for item_id, item_amount in ingredients_dict.items():
                item_info = item_design_data[item_id]
                item_name = item_info[ITEM_DESIGN_DESCRIPTION_PROPERTY_NAME]
                item_price = int(item_info['MarketPrice'])
                price_sum = item_price * item_amount
                current_level_costs += price_sum
                current_level_lines.append(
                    f'> {item_amount} x {item_name} ({item_price} bux ea): {price_sum} bux'
                )
            lines.extend(current_level_lines)
            lines.append(f'Crafting costs: {current_level_costs} bux')
            lines.append(settings.EMPTY_LINE)

        lines.append(resources.get_resource('PRICE_NOTE'))
    else:
        lines.append('This item can\'t be crafted')

    return lines
Ejemplo n.º 7
0
	def __init__(self, screen, columns, rows, header_height=None):		
		self.rows = rows
		self.columns = columns		
		# Create two dimentional array using list comprehension
		# This array stores data for the static pieces on the game board
		self._board = [x[:] for x in [[0]*rows]*columns]
		# List of (animated) falling pieces 
		# Items on the list = (column, ypos, bubble_id)
		self.falling_pieces = []	
		# Max random id that can be assigned to a board piece
		self.max_rand_id = 5
		self.header_height = header_height
		
		self.screen = screen
		width, height = screen.get_width(), screen.get_height()
		
		# Dimension for the pieces		
		horizontal_size = width / self.columns
		vertical_size = (height-self.header_height) / self.rows
		self.piece_w = self.piece_h = vertical_size if vertical_size < horizontal_size else horizontal_size
		self.h_border = (width-(self.piece_w*self.columns))/2
		if self.h_border < 0: 
			self.h_border = 0
		self.surfaces  = []
		self.mini_surfaces  = []
		self.width = self.piece_w * self.columns
		self.height = self.piece_h * self.rows
		self.my_surface = pygame.Surface((self.width, self.height))
		self.tmp_surface = pygame.Surface((self.width, self.height))
		self.needs_static_redraw = True		
		
		surface  = pygame.image.load(get_resource('gfx/lightning.png'))
		self.lighthing_surface = pygame.transform.scale(surface, (self.piece_w, self.piece_h))
Ejemplo n.º 8
0
def load_image(name, colorkey=None):
    fullname = os.path.join('gfx', 'buttons', name)
    try:
        image = pygame.image.load(get_resource(fullname))
    except pygame.error, message:
        print 'Cannot load image:', fullname
        raise SystemExit, message
Ejemplo n.º 9
0
def __get_pretty_market_price(item_info: EntityInfo, items_data: EntitiesData, trainings_data: EntitiesData = None, **kwargs) -> Optional[str]:
    flags = int(item_info['Flags'])
    if flags & 1 == 0:
        result = resources.get_resource('CANNOT_BE_SOLD')
    else:
        market_price = item_info['MarketPrice']
        result = f'{market_price} bux'
    return result
Ejemplo n.º 10
0
	def _set_theme(self):
		WINSIZE = self.width, self.height
		fn = join('gfx', 'themes', self.theme , 'background.jpg')
		background = pygame.image.load(get_resource(fn))							
		self.background = pygame.transform.scale(background, (WINSIZE))
		surfaces = self._load_pieces()
		self.playboard.set_surfaces(surfaces)
		self.playboard.set_background(self.background)
Ejemplo n.º 11
0
	def _load_pieces(self):
		""" Load pieces image files """		
		pieces = []
		for n in range(5):
			fn = join('gfx', 'themes', self.theme, 'piece-%d.png' % (n+1))
			piece = pygame.image.load(get_resource(fn))
			pieces.append(piece)			
			
		return pieces
Ejemplo n.º 12
0
def display_version():
    deb_version = get_resource("DEB_VERSION").decode().rstrip()
    print("Debian package version:", deb_version)

    git_version = get_git_version()
    print("Git commit hash:", git_version)

    apt_branch = get_apt_branch()
    print("Apt branch:", apt_branch)
Ejemplo n.º 13
0
 def create_index_if_not_exists(self):
     if self.es.indices.exists(self.index_name):
         return
     configuration = {
         "mappings": {
             self.doc_type: get_resource('elasticsearch/index_mapping.json')
         }
     }
     self.es.indices.create(index=self.index_name, body=configuration)
     self.logger.debug("Elasticsearch index %s created." % self.index_name)
Ejemplo n.º 14
0
def __get_best_items_error(slot: str, stat: str) -> Optional[str]:
    if not stat:
        return f'You must specify a stat! {__STATS_AVAILABLE}'
    if slot:
        slot = slot.lower()
        if slot not in lookups.EQUIPMENT_SLOTS_LOOKUP.keys() and slot not in resources.get_resource('ANY_SLOT_NAMES'):
            return f'The specified equipment slot is not valid! {__SLOTS_AVAILABLE}'
    if stat.lower() not in lookups.STAT_TYPES_LOOKUP.keys():
        return f'The specified stat is not valid! {__STATS_AVAILABLE}'

    return None
Ejemplo n.º 15
0
async def get_item_price(ctx: Context, item_name: str, as_embed: bool = settings.USE_EMBEDS) -> Union[List[Embed], List[str]]:
    pss_assert.valid_entity_name(item_name, allowed_values=ALLOWED_ITEM_NAMES)

    items_data = await items_designs_retriever.get_data_dict3()
    item_infos = __get_item_infos_by_name(item_name, items_data)

    if not item_infos:
        raise NotFound(f'Could not find an item named `{item_name}`.')
    else:
        get_best_match = utils.is_str_in_list(item_name, ALLOWED_ITEM_NAMES, case_sensitive=False) and len(item_name) < settings.MIN_ENTITY_NAME_LENGTH - 1
        if get_best_match:
            item_infos = [item_infos[0]]

        item_infos = entity.sort_entities_by(item_infos, [(ITEM_DESIGN_DESCRIPTION_PROPERTY_NAME, None, False)])
        items_details_collection = __create_price_details_collection_from_infos(item_infos, items_data)

        if as_embed:
            custom_footer = '\n'.join([resources.get_resource('MARKET_FAIR_PRICE_NOTE_EMBED'), resources.get_resource('PRICE_NOTE_EMBED')])
            return (await items_details_collection.get_entities_details_as_embed(ctx, custom_footer_text=custom_footer))
        else:
            custom_footer = '\n'.join([resources.get_resource('MARKET_FAIR_PRICE_NOTE'), resources.get_resource('PRICE_NOTE')])
            return (await items_details_collection.get_entities_details_as_text())
Ejemplo n.º 16
0
	def init(self):
		flags = 0
		if not ANDROID:
			os.environ['SDL_VIDEO_CENTERED'] = '1'
			WINSIZE = 480, 800
		else:
			WINSIZE = 0, 0
			flags |= pygame.FULLSCREEN
		pygame.init()	
		if USE_MIXER:
			mixer.init()
		
		# Map the back button to the escape key.
		if ANDROID:
			android.init()
			android.map_key(android.KEYCODE_BACK, pygame.K_ESCAPE)

		self.clock = pygame.time.Clock()			
		if not (ANDROID or PYTHON4ANDROID):
			self.icon = pygame.image.load(get_resource('android-icon.png'))
			pygame.display.set_icon(self.icon)
		screen = self.screen = pygame.display.set_mode(WINSIZE, flags)
		self.width, self.height = screen.get_width(), screen.get_height()
		pygame.display.set_caption('Popzi')

		if USE_MIXER:
			self.pop_sound = mixer.Sound(get_resource("sfx/pop.ogg"))
		
		self.score_font = pygame.font.Font(get_resource(join("fonts", "FreeSans.ttf")), 25)
		self.completed_font = pygame.font.Font(get_resource(join("fonts", "FreeSans.ttf")), 40)
		
		self.start_button = Button("Start game")				
		self.themes_button = Button("Select theme")
						
		self.playboard = PlayBoard(screen, 
				self.COLUMNS, self.ROWS, self.header_height)
		
		self._read_theme_config()
Ejemplo n.º 17
0
async def get_item_details_by_name(
        ctx: Context,
        item_name: str,
        as_embed: bool = settings.USE_EMBEDS) -> Union[List[Embed], List[str]]:
    pss_assert.valid_entity_name(item_name, allowed_values=ALLOWED_ITEM_NAMES)

    items_data = await items_designs_retriever.get_data_dict3()
    item_infos = __get_item_infos_by_name(item_name, items_data)

    if not item_infos:
        raise NotFound(f'Could not find an item named `{item_name}`.')
    else:
        trainings_data = await training.trainings_designs_retriever.get_data_dict3(
        )
        items_data_for_sort = {
            item_info.get(ITEM_DESIGN_KEY_NAME): item_info
            for item_info in item_infos
        }
        item_infos = sorted(
            item_infos,
            key=lambda item_info:
            (__get_key_for_base_items_sort(item_info, items_data_for_sort)))
        items_details_collection = __create_base_details_collection_from_infos(
            item_infos, items_data, trainings_data)

        if as_embed:
            return (await
                    items_details_collection.get_entities_details_as_embed(
                        ctx,
                        custom_footer_text=resources.get_resource(
                            'PRICE_NOTE_EMBED')))
        else:
            return (await
                    items_details_collection.get_entities_details_as_text(
                        custom_footer_text=resources.get_resource('PRICE_NOTE')
                    ))
Ejemplo n.º 18
0
def _get_best_items_as_text_all(
    stat: str,
    items_designs_details_groups: Dict[str,
                                       List[ItemDesignDetails]]) -> List[str]:
    result = []

    for group_name, group in items_designs_details_groups.items():
        slot = _get_pretty_slot(group_name)
        result.append(settings.EMPTY_LINE)
        result.append(_get_best_title(stat, slot))
        for item_design_details in group:
            result.extend(item_design_details.get_details_as_text_long())

    result.append(settings.EMPTY_LINE)
    result.append(resources.get_resource('PRICE_NOTE'))

    return result
Ejemplo n.º 19
0
	def _set_background(self):
		WINSIZE = self.width, self.height
		fn = join('gfx', 'background.jpg')
		background = pygame.image.load(get_resource(fn))							
		self.background = pygame.transform.scale(background, (WINSIZE))
		self.playboard.set_background(self.background)
Ejemplo n.º 20
0
def get_apt_branch():
    return get_resource("APT_BRANCH").decode().rstrip()
Ejemplo n.º 21
0
 def __init__(self, text=None):
     self.image, self.rect = load_image('dark.png')
     font = pygame.font.Font(get_resource(join("fonts", "FreeSans.ttf")), 25)
     text_img = font.render(text, True, THECOLORS["white"])
     self.image.blit(text_img, (self.rect.width/2-text_img.get_width()/2, 0))
     self.text = text
Ejemplo n.º 22
0
def get_git_version():
    return get_resource("GIT_VERSION").decode().rstrip()
Ejemplo n.º 23
0
def copy_to(name: str, fileout: str) -> None:
    util.writefile(fileout, get_resource(name))