From 710d105b63548f16eaead9233f06505be1f45ece Mon Sep 17 00:00:00 2001 From: lxgr-linux Date: Wed, 3 Aug 2022 22:15:41 +0200 Subject: [PATCH 1/2] did a lot of linting --- pokete.py | 107 ++++++++++++++------------ pokete_classes/achievements.py | 2 +- pokete_classes/attack.py | 6 +- pokete_classes/attack_actions.py | 41 ++++++---- pokete_classes/audio.py | 3 +- pokete_classes/detail.py | 5 +- pokete_classes/dummy_playsound.py | 8 -- pokete_classes/effects.py | 3 +- pokete_classes/fightmap.py | 42 ++++++---- pokete_classes/generic_map_handler.py | 8 +- pokete_classes/health_bar.py | 2 +- pokete_classes/hotkeys.py | 21 +++-- pokete_classes/input.py | 6 +- pokete_classes/inv_items.py | 4 +- pokete_classes/loops.py | 1 - pokete_classes/mods.py | 6 +- pokete_classes/movemap.py | 41 ++++++---- pokete_classes/moves.py | 3 +- pokete_classes/nature.py | 7 +- pokete_classes/npcs.py | 35 ++++----- pokete_classes/poke.py | 10 +-- pokete_classes/pokete_care.py | 2 +- pokete_classes/providers.py | 26 +++---- pokete_classes/side_loops.py | 52 +++++++++---- pokete_classes/timer.py | 8 +- pokete_classes/ui_elements.py | 6 +- 26 files changed, 259 insertions(+), 196 deletions(-) delete mode 100644 pokete_classes/dummy_playsound.py diff --git a/pokete.py b/pokete.py index 2fd0fd92..9dd7d04a 100755 --- a/pokete.py +++ b/pokete.py @@ -69,12 +69,12 @@ class NPCActions: npc: The NPC the method belongs to""" @staticmethod - def swap_poke(npc): + def swap_poke(_): """Swap_poke wrapper""" swap_poke() @staticmethod - def heal(npc): + def heal(_): """Heal wrapper""" figure.heal() @@ -275,8 +275,10 @@ def action(self, ob): elif action.triggers(Action.ACT_2): figure.heal() time.sleep(SPEED_OF_TIME * 0.5) - mvp.movemap.text(int(mvp.movemap.width / 2), 3, - ["...", "Your Poketes are now healed!"]) + mvp.movemap.text( + int(mvp.movemap.width / 2), 3, + ["...", "Your Poketes are now healed!"] + ) break elif action.triggers(Action.CANCEL, Action.ACT_3): break @@ -550,7 +552,7 @@ def __call__(self): ask_ok(self.map, f"{poke.name} reached level " f"{poke.lvl()}!") - elif type(obj) is LearnDisc: + elif isinstance(obj, LearnDisc): if ask_bool(self.map, f"Do you want to teach '\ {obj.attack_dict['name']}'?"): ex_cond = True @@ -566,10 +568,13 @@ def __call__(self): obj.attack_dict['types'][0])\ in poke.types: break - else: - ex_cond = ask_bool(self.map, - f"You cant't \ -teach '{obj.attack_dict['name']}' to '{poke.name}'! \nDo you want to continue?") + ex_cond = ask_bool( + self.map, + "You cant't teach " + f"'{obj.attack_dict['name']}' to " + f"'{poke.name}'! \n" + "Do you want to continue?" + ) if not ex_cond: break if LearnAttack(poke, self.map)\ @@ -697,7 +702,7 @@ def __call__(self, pevm): time.sleep(SPEED_OF_TIME * 1.5) elif i == self.exit_label: save() - exit() + sys.exit() elif i == self.about_label: about() elif i == self.ach_label: @@ -818,7 +823,6 @@ def exiter(): print("\033[?1049l\033[1A") if audio.curr is not None: audio.kill() - #sys.exit() # Functions needed for mvp.movemap @@ -839,7 +843,7 @@ def codes(string): print(exc) return elif i == "q": - exit() + sys.exit() # Playmap extra action functions @@ -895,13 +899,14 @@ def teleport(poke): poke: The Poke shown in the animation""" if (obj := roadmap(mvp.movemap, choose=True)) is None: return - else: - if settings("animations").val: - animations.transition(mvp.movemap, poke) - cen_d = p_data.map_data[obj.name]["hard_obs"]["pokecenter"] - Door("", state="float", arg_proto={"map": obj.name, - "x": cen_d["x"] + 5, - "y": cen_d["y"] + 6}).action(figure) + if settings("animations").val: + animations.transition(mvp.movemap, poke) + cen_d = p_data.map_data[obj.name]["hard_obs"]["pokecenter"] + Door("", state="float", arg_proto={ + "map": obj.name, + "x": cen_d["x"] + 5, + "y": cen_d["y"] + 6 + }).action(figure) def swap_poke(): @@ -1008,13 +1013,16 @@ def _game(_map): # Directions are not being used yet action = get_action() if action.triggers(*ACTION_DIRECTIONS): - figure.direction = '' #TODO - figure.set(figure.x + action.get_X_strength(), figure.y + action.get_Y_strength()) + figure.direction = '' + figure.set( + figure.x + action.get_x_strength(), + figure.y + action.get_y_strength() + ) elif action.triggers(*inp_dict): audio_before = settings("audio").val - for key in inp_dict: + for key, option in inp_dict.items(): if action.triggers(key): - inp_dict[key][0](*inp_dict[key][1]) + option[0](*option[1]) _ev.clear() if audio_before != settings("audio").val: audio.switch(_map.song) @@ -1022,7 +1030,7 @@ def _game(_map): elif action.triggers(Action.CANCEL, Action.EXIT_GAME): if ask_bool(mvp.movemap, "Do you really wish to exit?"): save() - exit() + sys.exit() elif action.triggers(Action.CONSOLE): inp = text_input(mvp.movemap.code_label, mvp.movemap, ":", mvp.movemap.width, @@ -1092,48 +1100,47 @@ def gen_obs(): trainers = p_data.trainers # adding all trainer to map - for i in trainers: + for i, trainer_list in trainers.items(): _map = obmp.ob_maps[i] - for j in trainers[i]: + for j in trainer_list: args = j["args"] trainer = Trainer([Poke(*p, player=False) for p in j["pokes"]], *args[:-2]) trainer.add(_map, args[-2], args[-1]) _map.trainers.append(trainer) # generating objects from map_data - for ob_map in map_data: + for ob_map, single_map in map_data.items(): _map = obmp.ob_maps[ob_map] - for hard_ob in map_data[ob_map]["hard_obs"]: + for hard_ob, single_hard_ob in single_map["hard_obs"].items(): parse_obj(_map, hard_ob, - se.Text(map_data[ob_map]["hard_obs"][hard_ob]["txt"], + se.Text(single_hard_ob["txt"], ignore=" "), - map_data[ob_map]["hard_obs"][hard_ob]) - for soft_ob in map_data[ob_map]["soft_obs"]: + single_hard_ob) + for soft_ob, single_soft_ob in single_map["soft_obs"].items(): cls = { "sand": Sand, "meadow": Meadow, "water": Water, - }[map_data[ob_map]["soft_obs"][soft_ob].get("cls", "meadow")] + }[single_soft_ob.get("cls", "meadow")] parse_obj(_map, soft_ob, - cls(map_data[ob_map]["soft_obs"][soft_ob]["txt"], + cls(single_soft_ob["txt"], _map.poke_args if cls != Water else _map.w_poke_args), - map_data[ob_map]["soft_obs"][soft_ob]) - for door in map_data[ob_map]["dors"]: + single_soft_ob) + for door, single_door in single_map["dors"].items(): parse_obj(_map, door, Door(" ", state="float", - arg_proto=map_data[ob_map]["dors"][door]["args"]), - map_data[ob_map]["dors"][door]) - for ball in map_data[ob_map]["balls"]: + arg_proto=single_door["args"]), + single_door) + for ball, single_ball in single_map["balls"].items(): if f'{ob_map}.{ball}' not in figure.used_npcs or not \ settings("save_trainers").val: parse_obj(_map, ball, Poketeball(f"{ob_map}.{ball}"), - map_data[ob_map]["balls"][ball]) + single_ball) # NPCs - for npc in npcs: - _npc = npcs[npc] - NPC(npc, _npc["texts"], fn=_npc["fn"], + for npc, _npc in npcs.items(): + NPC(npc, _npc["texts"], _fn=_npc["fn"], chat=_npc.get("chat", None)).add(obmp.ob_maps[_npc["map"]], _npc["x"], _npc["y"]) @@ -1143,8 +1150,7 @@ def gen_maps(): RETURNS: Dict of all PlayMaps""" maps = {} - for ob_map in p_data.maps: - args = p_data.maps[ob_map] + for ob_map, args in p_data.maps.items(): args["extra_actions"] = (getattr(ExtraActions, args["extra_actions"], None) if args["extra_actions"] is not None @@ -1159,15 +1165,14 @@ def check_version(sinfo): sinfo: session_info dict""" if "ver" not in sinfo: return False - else: - ver = sinfo["ver"] + ver = sinfo["ver"] if VERSION != ver and sort_vers([VERSION, ver])[-1] == ver: if not ask_bool(loading_screen.map, liner(f"The save file was created \ on version '{ver}', the current version is '{VERSION}', \ such a downgrade may result in data loss! \ Do you want to continue?", int(width * 2 / 3))): - exit() + sys.exit() return VERSION != ver @@ -1467,8 +1472,8 @@ def recogniser(): if settings("load_mods").val: try: import mods - except ModError as err: - error_box = InfoBox(str(err), "Mod-loading Error") + except ModError as mod_err: + error_box = InfoBox(str(mod_err), "Mod-loading Error") error_box.center_add(loading_screen.map) loading_screen.map.show() sys.exit(1) @@ -1533,8 +1538,8 @@ def recogniser(): # Achievements achievements.set_achieved(session_info.get("achievements", [])) - for identifier, args in p_data.achievements.items(): - achievements.add(identifier, **args) + for identifier, achievement_args in p_data.achievements.items(): + achievements.add(identifier, **achievement_args) # objects relevant for fm.fight() fm.fightmap = fm.FightMap(height - 1, width) diff --git a/pokete_classes/achievements.py b/pokete_classes/achievements.py index ea033c99..10ef7a40 100644 --- a/pokete_classes/achievements.py +++ b/pokete_classes/achievements.py @@ -109,7 +109,7 @@ def __call__(self, _map): else: if action.triggers(Action.CANCEL): break - elif action.triggers(Action.ACCEPT): + if action.triggers(Action.ACCEPT): ach = achievements.achievements[ self.get_item(*self.index).ind ] diff --git a/pokete_classes/attack.py b/pokete_classes/attack.py index fb55c112..95ce58c6 100644 --- a/pokete_classes/attack.py +++ b/pokete_classes/attack.py @@ -3,10 +3,10 @@ import time import scrap_engine as se from pokete_data.attacks import attacks +from release import SPEED_OF_TIME from .effects import effects from .types import types from .color import Color -from release import SPEED_OF_TIME class Attack: @@ -59,12 +59,12 @@ def give_effect(self, enem): time.sleep(SPEED_OF_TIME * 1.5) getattr(effects, self.effect)().add(enem) - def set_ap(self, ap): + def set_ap(self, _ap): """Sets attack points ARGS: ap: Attack points""" if ap != "SKIP": - self.ap = min(ap, self.max_ap) + self.ap = min(_ap, self.max_ap) self.label.rechar("") self.label += self.make_label() diff --git a/pokete_classes/attack_actions.py b/pokete_classes/attack_actions.py index fcbf5f73..b1626c14 100644 --- a/pokete_classes/attack_actions.py +++ b/pokete_classes/attack_actions.py @@ -10,55 +10,70 @@ class AttackActions: pattern: ARGS: obj: The Poke object that attacks - enem: The Poke object that is attacked""" + enem: The Poke object that is attacked + providers: List of the current providers""" - def cry(self, obj, enem, _): + def cry(self, _, enem, __): + """Cry attack action""" enem.miss_chance += 1 - def eye_pick(self, obj, enem, _): + def eye_pick(self, _, enem, __): + """Eye pick attack action""" enem.miss_chance += 2 - def chocer(self, obj, enem, _): + def chocer(self, _, enem, __): + """Chocer attack action""" enem.atc -= 1 - def snooze(self, obj, enem, _): + def snooze(self, _, enem, __): + """Snooze attack action""" enem.miss_chance += 0.5 enem.atc -= 1 enem.defense -= 1 - def politure(self, obj, enem, _): + def politure(self, obj, _, __): + """Politure attack action""" obj.defense += 1 obj.atc += 1 - def bark_hardening(self, obj, enem, _): + def bark_hardening(self, obj, _, __): + """Bark hardening attack action""" obj.defense += 1 - def dick_energy(self, obj, enem, _): + def dick_energy(self, obj, _, __): + """Dick energy attack action""" obj.atc += 2 - def hiding(self, obj, enem, _): + def hiding(self, obj, _, __): + """Hiding attack action""" obj.defense += 2 - def brooding(self, obj, enem, _): + def brooding(self, obj, _, __): + """Brooding attack action""" obj.hp += 2 if obj.hp + 2 <= obj.full_hp else 0 - def heart_touch(self, obj, enem, _): + def heart_touch(self, _, enem, __): + """Heart touch attack action""" enem.defense -= 4 def super_sucker(self, obj, enem, _): + """Super sucker attack action""" enem.hp -= 2 obj.hp += 2 if obj.hp+2 <= obj.full_hp else 0 - def sucker(self, obj, enem, _): + def sucker(self, obj, enem, __): + """Sucker attack action""" enem.hp -= 1 obj.hp += 1 if obj.hp+1 <= obj.full_hp else 0 - def rain_dance(self, obj, enem, providers): + def rain_dance(self, obj, _, providers): + """Rain dance attack action""" providers[0].map.weather = Weather("rain") obj.ico.map.outp.outp("It started raining!") time.sleep(2) def encouragement(self, obj, _, providers): + """Encouragement attack action""" for poke in next( prov for prov in providers if prov.curr == obj ).pokes[:6]: diff --git a/pokete_classes/audio.py b/pokete_classes/audio.py index 09381503..8efc64f9 100644 --- a/pokete_classes/audio.py +++ b/pokete_classes/audio.py @@ -11,6 +11,8 @@ def audio_fn(song, play_audio): """plays a song in loop""" import playsound + + while play_audio: playsound.playsound(str(MUSIC_PATH / song)) @@ -43,4 +45,3 @@ def kill(self): self.curr.terminate() audio = Audio() - diff --git a/pokete_classes/detail.py b/pokete_classes/detail.py index 224ee2d0..44c2e280 100644 --- a/pokete_classes/detail.py +++ b/pokete_classes/detail.py @@ -1,6 +1,5 @@ """Contains classes needed for the detail-view of a Pokete""" -import logging import scrap_engine as se import pokete_classes.game_map as gm from pokete_classes.hotkeys import Action, get_action @@ -136,9 +135,8 @@ def __call__(self, poke, abb=True): atc.label_desc, atc.label_type]: obj.remove() del atc.temp_i, atc.temp_j - logging.info("2"+repr(ret_action)) return ret_action - elif action.triggers(Action.NATURE_INFO): + if action.triggers(Action.NATURE_INFO): poke.nature.info(self.map) elif action.triggers(Action.ABILITIES): if abb_obs != [] and abb: @@ -153,7 +151,6 @@ def __call__(self, poke, abb=True): self.map.show() elif action.triggers(Action.ACCEPT): ret_action = abb_obs[box.index.index].world_action - logging.info("1"+repr(ret_action)) _ev.set(Action.CANCEL.mapping) break elif action.triggers(Action.CANCEL): diff --git a/pokete_classes/dummy_playsound.py b/pokete_classes/dummy_playsound.py deleted file mode 100644 index b845f68d..00000000 --- a/pokete_classes/dummy_playsound.py +++ /dev/null @@ -1,8 +0,0 @@ -"""Dummy fallback sound module""" - -import time -from release import SPEED_OF_TIME - -def playsound(song): - """Dummy fallback playsound function""" - time.sleep(SPEED_OF_TIME * 5) diff --git a/pokete_classes/effects.py b/pokete_classes/effects.py index f8a906e3..c2659a09 100644 --- a/pokete_classes/effects.py +++ b/pokete_classes/effects.py @@ -4,8 +4,9 @@ import random import logging import scrap_engine as se -from .color import Color from release import SPEED_OF_TIME +from .color import Color + class Effect(): """An effect that can be given to a Pokete and that effects the Pokete diff --git a/pokete_classes/fightmap.py b/pokete_classes/fightmap.py index 40a17dd4..9692679d 100644 --- a/pokete_classes/fightmap.py +++ b/pokete_classes/fightmap.py @@ -8,6 +8,7 @@ from pokete_general_use_fns import liner from pokete_classes import animations, ob_maps as obmp, movemap as mvp, \ deck, game_map as gm +from release import SPEED_OF_TIME from .hotkeys import ACTION_UP_DOWN, Action, get_action from .audio import audio from .loops import std_loop @@ -19,7 +20,6 @@ from .achievements import achievements from .inv_items import invitems from .settings import settings -from release import SPEED_OF_TIME class FightMap(gm.GameMap): @@ -112,7 +112,7 @@ def add_1(self, player, enem): ARGS: player: The player Poke object enemy: The enemy Poke object that the labels belong to""" - for obj, x, y in zip( + for obj, _x, _y in zip( ( enem.curr.tril, enem.curr.trir, @@ -125,7 +125,7 @@ def add_1(self, player, enem): (7, 16, 1, 1, 1, self.width - 14, 8), (3, 3, 1, 2, 3, 2, 3) ): - obj.add(self, x, y) + obj.add(self, _x, _y) if enem.curr.identifier in player.caught_pokes: enem.curr.pball_small.add(self, len(self.e_underline.text) - 1, 1) @@ -163,6 +163,9 @@ def fast_change(self, arr, setob): time.sleep(SPEED_OF_TIME * 0.1) def rechar_atk_info_box(self, attack_obs): + """Rechars the attack info box + ARGS: + attack_obs: The current attack obs""" self.atk_info_box.label.rechar( liner(attack_obs[self.box.index.index].desc, 37) ) @@ -267,7 +270,17 @@ def get_figure_attack(self, figure, enem): or not ask_bool(self, "Do you really want to run away?") ): continue - if (random.randint(0, 100) < max(5, min(50 - (figure.curr.initiative - enem.curr.initiative), 95))): + if ( + random.randint(0, 100) < max( + 5, + min( + 50 - ( + figure.curr.initiative - enem.curr.initiative + ), + 95 + ) + ) + ): self.outp.outp("You failed to run away!") time.sleep(SPEED_OF_TIME * 1) return "" @@ -281,7 +294,7 @@ def get_figure_attack(self, figure, enem): elif action.triggers(Action.CHOOSE_ITEM): items = [getattr(invitems, i) for i in figure.inv - if getattr(invitems, i).fn is not None + if getattr(invitems, i).func is not None and figure.inv[i] > 0] if not items: self.outp.outp( @@ -293,9 +306,9 @@ def get_figure_attack(self, figure, enem): if item == "": continue # I hate you python for not having switch statements - if (i := getattr(fightitems, item.fn)(figure, enem)) == 1: + if (i := getattr(fightitems, item.func)(figure, enem)) == 1: continue - elif i == 2: + if i == 2: logging.info("[Fight] Ended, fightitem") time.sleep(SPEED_OF_TIME * 2) audio.switch(figure.map.song) @@ -352,7 +365,7 @@ def fight(self, providers): time.sleep(SPEED_OF_TIME * 0.3) if attack == "won": return player - elif attack != "": + if attack != "": player.curr.attack(attack, enem.curr, self, providers) self.show() time.sleep(SPEED_OF_TIME * 0.5) @@ -498,11 +511,10 @@ def throw(self, obj, enem, chance, name): logging.info("[Fighitem][%s] Missed", name) return None - def potion(self, obj, enem, hp, name): + def potion(self, obj, hp, name): """Potion function ARGS: obj: The players Poke object - enem: The enemys Poke object hp: The hp that will be given to the Poke name: The potions name""" @@ -512,13 +524,13 @@ def potion(self, obj, enem, hp, name): obj.curr.hp_bar.update(obj.curr.oldhp) logging.info("[Fighitem][%s] Used", name) - def heal_potion(self, obj, enem): + def heal_potion(self, obj, _): """Healing potion function""" - return self.potion(obj, enem, 5, "healing_potion") + return self.potion(obj, 5, "healing_potion") - def super_potion(self, obj, enem): + def super_potion(self, obj, _): """Super potion function""" - return self.potion(obj, enem, 15, "super_potion") + return self.potion(obj, 15, "super_potion") def poketeball(self, obj, enem): """Poketeball function""" @@ -532,7 +544,7 @@ def hyperball(self, obj, enem): """Hyperball function""" return self.throw(obj, enem, 1000, "hyperball") - def ap_potion(self, obj, enem): + def ap_potion(self, obj, _): """AP potion function""" obj.remove_item("ap_potion") for atc in obj.curr.attack_obs: diff --git a/pokete_classes/generic_map_handler.py b/pokete_classes/generic_map_handler.py index edf16bc8..2ffdf5cb 100644 --- a/pokete_classes/generic_map_handler.py +++ b/pokete_classes/generic_map_handler.py @@ -32,8 +32,8 @@ def add_grass(self): """Adds a Meadow to the map""" self.grass_raw = "" - for l in self.string_map: - for i in l: + for j in self.string_map: + for i in j: if i == ";": self.grass_raw += i else: @@ -46,8 +46,8 @@ def add_solid(self): """Adds all solid objects to the map""" self.solid_raw = "" - for l in self.string_map: - for i in l: + for j in self.string_map: + for i in j: if i not in [";", "~", "."]: self.solid_raw += i else: diff --git a/pokete_classes/health_bar.py b/pokete_classes/health_bar.py index 63c8428e..6acf537e 100644 --- a/pokete_classes/health_bar.py +++ b/pokete_classes/health_bar.py @@ -2,8 +2,8 @@ import time import scrap_engine as se -from .color import Color from release import SPEED_OF_TIME +from .color import Color class HealthBar(se.Text): diff --git a/pokete_classes/hotkeys.py b/pokete_classes/hotkeys.py index 77b71246..dd30bbc5 100644 --- a/pokete_classes/hotkeys.py +++ b/pokete_classes/hotkeys.py @@ -1,3 +1,6 @@ +"""Contains everything related to input processing""" + +import sys from enum import Enum, auto from collections import defaultdict from pokete_general_use_fns import liner @@ -72,19 +75,19 @@ def get_number(self): return action.value - Action.ACT_1.value return -1 - def get_Y_strength(self) -> int: + def get_y_strength(self) -> int: """Gets move in Y direction""" if self.triggers(Action.UP): - return -1 - elif self.triggers(Action.DOWN): + return -1 + if self.triggers(Action.DOWN): return 1 return 0 - def get_X_strength(self) -> int: + def get_x_strength(self) -> int: """Gets move in X direction""" if self.triggers(Action.RIGHT): return 1 - elif self.triggers(Action.LEFT): + if self.triggers(Action.LEFT): return -1 return 0 @@ -159,8 +162,9 @@ def hotkeys_save(): def hotkeys_from_save(save, _map, version_change): """Sets hotkey_mappings from save""" - global hotkey_mappings from .input import ask_bool + global hotkey_mappings + if save == {}: return @@ -187,11 +191,12 @@ def hotkeys_from_save(save, _map, version_change): key = action.mapping new_hotkey_mappings[key].append(action) else: - exit() + sys.exit() hotkey_mappings = new_hotkey_mappings -# Exists maybe for performance so references to new actionlists don't have to always be cleaned up when the following function returns nothing +# Exists maybe for performance so references to new actionlists don't have +# to always be cleaned up when the following function returns nothing # I don't trust python to be smart enough to do this itself EMPTY_ACTIONLIST = ActionList() diff --git a/pokete_classes/input.py b/pokete_classes/input.py index 787b9570..3f9829ab 100644 --- a/pokete_classes/input.py +++ b/pokete_classes/input.py @@ -21,12 +21,12 @@ def text_input(obj, _map, name, wrap_len, max_len=1000000): _map.show() while True: # Use lower level ev.get() methods because we need to handle typed text, not game actions - if _ev.get() in ["Key.enter", "Key.esc"]: + if _ev.get() in ("Key.enter", "Key.esc"): _ev.clear() obj.rechar(hard_liner(wrap_len, name)) _map.show() return name - elif _ev.get() == "Key.backspace": + if _ev.get() == "Key.backspace": if len(name) <= 0: _ev.clear() obj.rechar(bname) @@ -61,7 +61,7 @@ def ask_bool(_map, text): if action.triggers(Action.ACCEPT): ret = True break - elif action.triggers(Action.CANCEL): + if action.triggers(Action.CANCEL): ret = False break std_loop(_map.name == "movemap") diff --git a/pokete_classes/inv_items.py b/pokete_classes/inv_items.py index 58350a79..8f1690fa 100644 --- a/pokete_classes/inv_items.py +++ b/pokete_classes/inv_items.py @@ -26,12 +26,12 @@ class InvItem: price: The item's price in the shop fn: The associated method name in FightItems""" - def __init__(self, name, pretty_name, desc, price, fn=None): + def __init__(self, name, pretty_name, desc, price, _fn=None): self.name = name self.pretty_name = pretty_name self.desc = desc self.price = price - self.fn = fn + self.func = _fn class LearnDisc(InvItem): diff --git a/pokete_classes/loops.py b/pokete_classes/loops.py index 610887ac..6bcfe596 100644 --- a/pokete_classes/loops.py +++ b/pokete_classes/loops.py @@ -4,7 +4,6 @@ from pokete_classes.hotkeys import Action, get_action import release from .notify import notifier -from release import SPEED_OF_TIME def easy_exit_loop(on_mvmp=True): diff --git a/pokete_classes/mods.py b/pokete_classes/mods.py index d540363a..02c0f002 100644 --- a/pokete_classes/mods.py +++ b/pokete_classes/mods.py @@ -1,6 +1,6 @@ """This file contains all classes related to mods""" -from .side_loops import About +from .side_loops import LoopBox from .ui_elements import InfoBox from .settings import settings @@ -27,7 +27,7 @@ def __init__(self, name, err): super().__init__(f"The mod '{name}' lacks attributes!\n{err}") -class ModInfo(About): +class ModInfo(LoopBox): """Gives information about mods ARGS: _map: The se.Map the info is shown on @@ -41,7 +41,7 @@ def __init__(self, _map, mod_info): Currently {len(mod_info)} mod{"s are" if len(mod_info) != 1 else " is"} loaded: """ + "\n ".join(f"{i}-{mod_info[i]}" for i in mod_info) + "\n" - self.box = InfoBox(self.text, name="Mods", _map=_map) + super().__init__(InfoBox(self.text, name="Mods", _map=_map)) if __name__ == "__main__": diff --git a/pokete_classes/movemap.py b/pokete_classes/movemap.py index 2cfac1e0..0f119a49 100644 --- a/pokete_classes/movemap.py +++ b/pokete_classes/movemap.py @@ -5,12 +5,12 @@ from pokete_general_use_fns import liner import pokete_classes.ob_maps as obmp import pokete_classes.game_map as gm +from release import SPEED_OF_TIME from .loops import std_loop from .classes import OutP from .color import Color from .event import _ev from .hotkeys import Action -from release import SPEED_OF_TIME class Movemap(gm.GameSubmap): @@ -49,15 +49,15 @@ def add_obs(self): self.label_bg.add(self, 0, self.height - 1) self.label.add(self, 0, self.height - 1) - def assure_distance(self, x, y, width, height): + def assure_distance(self, _x, _y, width, height): """This ensures the game does not crash when big chunks of text are displayed ARGS: - x: The x coordinate the distance should be assured from - y: The y coordinate the distance should be assured from + _x: The x coordinate the distance should be assured from + _y: The y coordinate the distance should be assured from width: The distances width height: The distances height""" - for _c, i, j, _k in zip([x, y], ["x", "y"], + for _c, i, j, _k in zip([_x, _y], ["x", "y"], [self.width, self.height], [width, height]): while _c - getattr(self, i) + _k >= j: self.set(self.x + (1 if i == "x" else 0), @@ -65,30 +65,41 @@ def assure_distance(self, x, y, width, height): self.show() time.sleep(SPEED_OF_TIME * 0.045) - def text(self, x, y, inp_arr): + def text(self, _x, _y, inp_arr): """Shows dialog text on movemap ARGS: - x: The message's X - y: And y-coordinate + _x: The message's X + _y: And y-coordinate inp_arr: List of messages that will be displayed""" - self.assure_distance(x, y, 17, 10) + self.assure_distance(_x, _y, 17, 10) self.multitext.rechar("") - self.multitext.add(self, x - self.x + 1, y - self.y) + self.multitext.add(self, _x - self.x + 1, _y - self.y) arr = [" < " + i + (" >" if j != len(inp_arr) - 1 else "") for j, i in enumerate(inp_arr)] for text in arr: - # Clear events and animate text appearing until any key is pressed. Then wait until another key is pressed to close dialogue. + # Clear events and animate text appearing until any key is pressed. + # Then wait until another key is pressed to close dialogue. _ev.clear() self.multitext.rechar("") for i in range(len(text) + 1): - self.multitext.outp(liner(text[:i], - self.width - (x - self.x + 1), " ")) + self.multitext.outp( + liner( + text[:i], + self.width - (_x - self.x + 1), + " " + ) + ) std_loop() if _ev.get() != "": _ev.clear() break - self.multitext.outp(liner(text, - self.width - (x - self.x + 1), " ")) + self.multitext.outp( + liner( + text, + self.width - (_x - self.x + 1), + " " + ) + ) while _ev.get() == "": std_loop() self.multitext.remove() diff --git a/pokete_classes/moves.py b/pokete_classes/moves.py index e5ca9d9e..d44cb19a 100644 --- a/pokete_classes/moves.py +++ b/pokete_classes/moves.py @@ -3,8 +3,9 @@ import time import random import scrap_engine as se -from .color import Color from release import SPEED_OF_TIME +from .color import Color + class Moves: """This class contains all attack moves diff --git a/pokete_classes/nature.py b/pokete_classes/nature.py index 00b5f058..698dd5d5 100644 --- a/pokete_classes/nature.py +++ b/pokete_classes/nature.py @@ -37,7 +37,10 @@ class PokeNature: nature: The Nature of the Pokete grade: The Nature's grade, 1 or 2""" - natures = {name: Nature(name, **_dict) for name, _dict in p_data.natures.items()} + natures = { + name: Nature(name, **_dict) + for name, _dict in p_data.natures.items() + } def __init__(self, nature, grade): self.nature = nature @@ -103,7 +106,7 @@ def get_amount(val): """Gets the amount denominator for a value""" if val == 1: return "the same" - elif val < 1: + if val < 1: return "less" return "more" diff --git a/pokete_classes/npcs.py b/pokete_classes/npcs.py index bad13889..6beb1f0d 100644 --- a/pokete_classes/npcs.py +++ b/pokete_classes/npcs.py @@ -5,8 +5,9 @@ import random import scrap_engine as se import pokete_classes.fightmap as fm +from release import SPEED_OF_TIME from pokete_classes.hotkeys import ACTION_UP_DOWN, Action, get_action -import pokete_classes.movemap as mvp +from . import movemap as mvp from .providers import Provider from .loops import std_loop from .input import ask_bool @@ -14,7 +15,6 @@ from .settings import settings from .ui_elements import ChooseBox from .general import check_walk_back -from release import SPEED_OF_TIME class NPCTrigger(se.Object): @@ -53,11 +53,11 @@ def get(cls, name): name: The NPCs name""" return cls.registry[name] - def __init__(self, name, texts, fn=None, chat=None, side_trigger=True): + def __init__(self, name, texts, _fn=None, chat=None, side_trigger=True): super().__init__(0, 0) self.name = name self.texts = texts - self.__fn = fn + self.__fn = _fn if chat is None: self.q_a = {} else: @@ -96,40 +96,40 @@ def action(self): time.sleep(SPEED_OF_TIME * 0.7) self.exclamate() self.text(self.texts) - self.fn() + self.func() - def fn(self): + def func(self): """The function that's executed after the interaction""" if self.__fn is not None: getattr(self.npcactions, self.__fn)(self) - def check_walk(self, x, y): + def check_walk(self, _x, _y): """Checks whether the NPC can walk to a point or not ARGS: - x: X-coordinate - y: Y-coordinate + _x: X-coordinate + _y: Y-coordinate RETURNS: bool: Whether or not the walk is possible""" - vec = se.Line(" ", x - self.x, y - self.y) + vec = se.Line(" ", _x - self.x, _y - self.y) ret = not any([any(j.state == "solid" for j in self.map.obmap[i.ry + self.y][i.rx + self.x]) for i in vec.obs][1:]) logging.info("[NPC][%s] %s walk check to (%d|%d)", - self.name, 'Succeeded' if ret else 'Failed', x, y) + self.name, 'Succeeded' if ret else 'Failed', _x, _y) return ret - def walk_point(self, x, y): + def walk_point(self, _x, _y): """Walks the NPC tp a certain point ARGS: - x: X-coordinate - y: Y-coordinate + _x: X-coordinate + _y: Y-coordinate RETURNS: bool: Whether or not the walk succeeded""" o_x = self.x o_y = self.y - vec = se.Line(" ", x - o_x, y - o_y) - if not self.check_walk(x, y): + vec = se.Line(" ", _x - o_x, _y - o_y) + if not self.check_walk(_x, _y): return False for i in vec.obs: self.set(i.rx + o_x, i.ry + o_y) @@ -169,7 +169,7 @@ def chat(self): return while True: self.text(q_a["q"]) - while get_action() == None: + while get_action() is None: std_loop() if q_a["a"] == {}: break @@ -301,4 +301,3 @@ def handle_defeat(self, fightmap, winner): fightmap.show() time.sleep(SPEED_OF_TIME * 2) return True - diff --git a/pokete_classes/poke.py b/pokete_classes/poke.py index c45c77d8..52845b56 100644 --- a/pokete_classes/poke.py +++ b/pokete_classes/poke.py @@ -7,6 +7,7 @@ import scrap_engine as se import pokete_data as p_data from pokete_general_use_fns import liner +from release import SPEED_OF_TIME from .attack_actions import AttackActions from .attack import Attack from .health_bar import HealthBar @@ -17,20 +18,19 @@ from .effects import effects from .learnattack import LearnAttack from .nature import PokeNature -from release import SPEED_OF_TIME class Poke: """The Pokete class ARGS: poke: The Pokes generic name - xp: Initial xp + _xp: Initial xp _hp: Initial hp ('SKIP' sets to max hp) _attacks: List of attack names learned player: Bool whether or not the Poke belongs to the player shiny: Bool whether or not the Poke is shiny (is extra strong)""" - def __init__(self, poke, xp, _hp="SKIP", _ap=None, _attacks=None, + def __init__(self, poke, _xp, _hp="SKIP", _ap=None, _attacks=None, _effects=None, player=True, shiny=False, nature=None): self.nature = PokeNature.random() if nature is None \ else PokeNature.from_dict(nature) @@ -40,7 +40,7 @@ def __init__(self, poke, xp, _hp="SKIP", _ap=None, _attacks=None, self.night_active = self.inf.get("night_active", None) self.enem = None self.oldhp = 0 - self.xp = xp + self.xp = _xp self.identifier = poke self.shiny = shiny self.atc = 0 @@ -177,7 +177,7 @@ def attack(self, attack, enem, fightmap, providers): for eff in self.effects: if eff.effect() == 1: return - if any(type(i) is effects.confusion for i in self.effects): + if any(isinstance(i, effects.confusion) for i in self.effects): self.enem = enem = self else: self.enem = enem diff --git a/pokete_classes/pokete_care.py b/pokete_classes/pokete_care.py index 85925956..4aa4d287 100644 --- a/pokete_classes/pokete_care.py +++ b/pokete_classes/pokete_care.py @@ -8,7 +8,7 @@ class DummyFigure: """A dummy Figure to use in Pokete-Care ARGS: poke: The poke to contain""" - + def __init__(self, poke): self.pokes = [poke] self.caught_pokes = [] diff --git a/pokete_classes/providers.py b/pokete_classes/providers.py index 2f463255..4284e365 100644 --- a/pokete_classes/providers.py +++ b/pokete_classes/providers.py @@ -1,3 +1,5 @@ +"""Providers are any instance that is able to paticipate in a fight""" + import random import time from abc import ABC, abstractmethod @@ -17,15 +19,16 @@ def __init__(self, pokes, escapable, xp_multiplier): def heal(self): """Heals all poketes""" - for poke in self.pokes: - poke.hp = poke.full_hp - poke.effects = [] - poke.miss_chance = poke.full_miss_chance - poke.text_hp.rechar(f"HP:{poke.hp}") - poke.set_vars() - poke.hp_bar.make(poke.hp) - if poke.player: - mvp.movemap.balls_label_rechar(self.pokes) + if self.pokes: + for poke in self.pokes: + poke.hp = poke.full_hp + poke.effects = [] + poke.miss_chance = poke.full_miss_chance + poke.text_hp.rechar(f"HP:{poke.hp}") + poke.set_vars() + poke.hp_bar.make(poke.hp) + if poke.player: + mvp.movemap.balls_label_rechar(self.pokes) @property def curr(self): @@ -44,14 +47,12 @@ def get_attack(self, fightmap, enem): ARGS: fightmap: fightmap object anem: The enemy Provider""" - pass @abstractmethod def greet(self, fightmap): """Outputs a greeting text at the fights start: ARGS: fightmap: fightmap object""" - pass @abstractmethod def handle_defeat(self, fightmap, winner): @@ -61,7 +62,6 @@ def handle_defeat(self, fightmap, winner): winner: the defeating provider RETURNS: bool: whether or not a Pokete was choosen""" - pass class NatureProvider(Provider): """The Natures Provider @@ -133,5 +133,3 @@ def handle_defeat(self, fightmap, winner): time.sleep(2) fightmap.choose_poke(self, False) return True - - diff --git a/pokete_classes/side_loops.py b/pokete_classes/side_loops.py index 751c4e1a..08b208f4 100644 --- a/pokete_classes/side_loops.py +++ b/pokete_classes/side_loops.py @@ -8,7 +8,21 @@ from .ui_elements import InfoBox, StdFrame -class About: +class LoopBox: + """Provides an easy_exit_loop call function + ARGS: + box: The box to display""" + + def __init__(self, box): + self.box = box + + def __call__(self): + """Shows the about text""" + with self.box: + easy_exit_loop() + + +class About(LoopBox): """The about text, that can be triggered in the menu ARGS: ver: Version @@ -16,29 +30,35 @@ class About: _map: se.Map this will be displayed on""" def __init__(self, ver, cname, _map): - self.box = InfoBox(liner(f"""Pokete v{ver} -- {cname} + super().__init__( + InfoBox( + liner( + f"""Pokete v{ver} -- {cname} by lxgr-linux -This software is licensed under the GPL3, you should have gotten a copy of the GPL3 license alongside this software. -Feel free to contribute what ever you want to this game, new Pokete contributions are especially welcome. +This software is licensed under the GPL3, you should have gotten a \ +copy of the GPL3 license alongside this software. +Feel free to contribute what ever you want to this game, \ +new Pokete contributions are especially welcome. For this see the comments in the definations area. You can contribute here: https://github.com/lxgr-linux/pokete""", - 60, pre=""), name="About", _map=_map) - - def __call__(self): - """Shows the about text""" - with self.box: - easy_exit_loop() + 60, pre="" + ), + name="About", + _map=_map + ) + ) -class Help(About): +class Help(LoopBox): """Helptext that can be displayed by pressing '?' ARGS: _map: se.Map this will be displayed on""" def __init__(self, _map): - self.map = _map - self.box = InfoBox("""Controls: + super().__init__( + InfoBox( + """Controls: 'w':up, 'a':left, 's':down, 'd':right, 'e':menu @@ -47,7 +67,11 @@ def __init__(self, _map): by wild Poketes, those can be killed or weakened and caught. NPCs will talk to you when walking up to them. For more information about how to play this game, check out -https://git.io/JRRqe""", name="Help", _map=self.map) +https://git.io/JRRqe""", + name="Help", + _map=_map + ) + ) class ResizeScreen(): diff --git a/pokete_classes/timer.py b/pokete_classes/timer.py index 58be13d4..2c5502f6 100644 --- a/pokete_classes/timer.py +++ b/pokete_classes/timer.py @@ -3,11 +3,11 @@ import logging import time as time_mod import scrap_engine as se - +from release import SPEED_OF_TIME from .hotkeys import Action, get_action from .ui_elements import Box from .loops import std_loop -from release import SPEED_OF_TIME + time = None clock = None @@ -102,8 +102,8 @@ class Clock(Box): ARGS: time: Time object""" - def __init__(self, time): - self.time = time + def __init__(self, time_ob): + self.time = time_ob super().__init__(9, 28, "Clock", f"{Action.CANCEL.mapping}:close") def __call__(self, _map): diff --git a/pokete_classes/ui_elements.py b/pokete_classes/ui_elements.py index 400cada1..c66cddc7 100644 --- a/pokete_classes/ui_elements.py +++ b/pokete_classes/ui_elements.py @@ -119,8 +119,8 @@ def input(self, inp: ActionList): """Moves the cursor in the box ARGS: inp: Inputted action""" - assert(inp.triggers(*ACTION_UP_DOWN)) - y_str = inp.get_Y_strength() + assert inp.triggers(*ACTION_UP_DOWN) + y_str = inp.get_y_strength() if inp.triggers(Action.UP): inp = Action.UP else: @@ -228,7 +228,7 @@ def input(self, inp: Action): """Evaluates user input ARGS: inp: Inputted string""" - assert(inp.triggers(*ACTION_DIRECTIONS)) + assert inp.triggers(*ACTION_DIRECTIONS) if inp.triggers(Action.UP): inp = Action.UP elif inp.triggers(Action.LEFT): From 8d84bce3c30b4637c80d3bc96599aa01fee77559 Mon Sep 17 00:00:00 2001 From: lxgr-linux Date: Wed, 3 Aug 2022 22:16:48 +0200 Subject: [PATCH 2/2] Fixed set_ap --- pokete_classes/attack.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pokete_classes/attack.py b/pokete_classes/attack.py index 95ce58c6..2d23c39f 100644 --- a/pokete_classes/attack.py +++ b/pokete_classes/attack.py @@ -63,7 +63,7 @@ def set_ap(self, _ap): """Sets attack points ARGS: ap: Attack points""" - if ap != "SKIP": + if _ap != "SKIP": self.ap = min(_ap, self.max_ap) self.label.rechar("") self.label += self.make_label()