diff --git a/src/main.py b/src/main.py index 9f557c5..9c18d4a 100644 --- a/src/main.py +++ b/src/main.py @@ -2,7 +2,7 @@ from src.module import character_importer -def initiate_characters(character_list_path: str): +def create_all_character_json(character_list_path: str): with open(character_list_path) as file: characters = json.load(file) @@ -11,4 +11,4 @@ def initiate_characters(character_list_path: str): character.export_movelist_as_json() -initiate_characters("resources/character_list.json") \ No newline at end of file +create_all_character_json("resources/character_list.json") \ No newline at end of file diff --git a/src/module/character_importer.py b/src/module/character_importer.py index 34d6d5a..6ed9bb7 100644 --- a/src/module/character_importer.py +++ b/src/module/character_importer.py @@ -1,4 +1,4 @@ -import os,sys +import os, sys from src.module import character from src.wavu import wavu_reader @@ -6,11 +6,12 @@ sys.path.insert(1, (os.path.dirname(os.path.dirname(__file__)))) base_path = os.path.dirname(__file__) + def import_character(character_meta: dict) -> character.Character: name = character_meta["name"] portrait = character_meta["portrait"] move_list = wavu_reader.get_character_movelist(name) - move_list_path = os.path.abspath(os.path.join(base_path,".." ,"json_movelist", name+".json")) - cha = character.Character(name,portrait,move_list,move_list_path) - return cha \ No newline at end of file + move_list_path = os.path.abspath(os.path.join(base_path, "..", "json_movelist", name + ".json")) + cha = character.Character(name, portrait, move_list, move_list_path) + return cha diff --git a/src/module/json_movelist_reader.py b/src/module/json_movelist_reader.py index 3806e97..c85db3f 100644 --- a/src/module/json_movelist_reader.py +++ b/src/module/json_movelist_reader.py @@ -1,6 +1,7 @@ from src.resources import const -from src.module import character_importer,character +from src.module import character_importer, character import os, json + base_path = os.path.dirname(__file__) @@ -15,28 +16,39 @@ def _correct_character_name(alias: str): return None -def get_movelist_from_json(character_name :str) -> dict: +def get_movelist_from_json(character_name: str) -> dict: character_name = _correct_character_name(character_name) - os.path.abspath(os.path.join(base_path, "..", "json_movelist", character_name+".json")) - filepath = os.path.abspath(os.path.join(base_path, "..", "json_movelist", character_name+".json")) + os.path.abspath(os.path.join(base_path, "..", "json_movelist", character_name + ".json")) + filepath = os.path.abspath(os.path.join(base_path, "..", "json_movelist", character_name + ".json")) with open(filepath) as move_file: move_file_contents = json.loads(move_file.read()) return move_file_contents -def _simplify_input(input :str) -> str: +def _simplify_input(input: str) -> str: """Removes bells and whistles from the move_input""" - short_input = input.strip().lower() - short_input = short_input.replace("in rage", "") + input = input.strip().lower() + input = input.replace("rage", "r.") + input = input.replace("heat", "h.") for old, new in const.REPLACE.items(): - short_input = short_input.replace(old, new) + input = input.replace(old, new) # cd works, ewgf doesn't, for some reason - if short_input[:2].lower() == 'cd' and short_input[:3].lower() != 'cds': - short_input = short_input.lower().replace('cd', 'fnddf') - if short_input[:2].lower() == 'wr': - short_input = short_input.lower().replace('wr', 'fff') - return short_input \ No newline at end of file + if input[:2].lower() == 'cd' and input[:3].lower() != 'cds': + input = input.lower().replace('cd', 'fnddf') + if input[:2].lower() == 'wr': + input = input.lower().replace('wr', 'fff') + return input + +def get_move(input :str, character_movelist :dict): + + result = [entry for entry in character_movelist if _simplify_input(entry["input"]) == _simplify_input(input)] + + if result: + result[0]['input'] = result[0]['input'].replace("\\","") + return result[0] + else: + return {} diff --git a/src/module/test/test_json_movelist_reader.py b/src/module/test/test_json_movelist_reader.py index 0c2bd82..eb688e4 100644 --- a/src/module/test/test_json_movelist_reader.py +++ b/src/module/test/test_json_movelist_reader.py @@ -3,7 +3,7 @@ class MyTestCase(unittest.TestCase): - def test_get_movelist_from(self): + def test_get_movelist_from_json(self): result = json_movelist_reader.get_movelist_from_json("azucena") self.assertEqual(result[0]["id"],"Azucena-1") @@ -11,3 +11,35 @@ def test_get_movelist_from(self): result = json_movelist_reader.get_movelist_from_json("azu") self.assertEqual(result[0]["id"],"Azucena-1") + def test_get_move(self): + + azu_move_list = json_movelist_reader.get_movelist_from_json("azucena") + move = json_movelist_reader.get_move("d/f+1",azu_move_list) + self.assertEqual(move["id"],"Azucena-df+1") + move = json_movelist_reader.get_move("LIB 2",azu_move_list) + self.assertEqual(move["id"],"Azucena-LIB.2") + move = json_movelist_reader.get_move("LIB.2",azu_move_list) + self.assertEqual(move["id"],"Azucena-LIB.2") + + move = json_movelist_reader.get_move("wr3",azu_move_list) + self.assertEqual(move["id"],"Azucena-f,f,F+3") + + move = json_movelist_reader.get_move("f214",azu_move_list) + self.assertEqual(move["id"],"Azucena-f+2,1,4") + + move = json_movelist_reader.get_move("rage d/f+1+2",azu_move_list) + self.assertEqual(move["id"],"Azucena-R.df+1+2") + + move = json_movelist_reader.get_move("R.d/f+1+2",azu_move_list) + self.assertEqual(move["id"],"Azucena-R.df+1+2") + + move = json_movelist_reader.get_move("H.LIB.2,F",azu_move_list) + self.assertEqual(move["id"],"Azucena-H.LIB.2,F") + move = json_movelist_reader.get_move("Heat LIB.2,F",azu_move_list) + self.assertEqual(move["id"],"Azucena-H.LIB.2,F") + + move = json_movelist_reader.get_move("Heat lib2f",azu_move_list) + self.assertEqual(move["id"],"Azucena-H.LIB.2,F") + + move = json_movelist_reader.get_move("ws41",azu_move_list) + self.assertEqual(move["id"],"Azucena-ws4,1") \ No newline at end of file