Skip to content

Commit

Permalink
Add "get move" function for the json
Browse files Browse the repository at this point in the history
  • Loading branch information
TLNBS2405 committed Nov 21, 2023
1 parent 2943dca commit 6de575a
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 20 deletions.
4 changes: 2 additions & 2 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -11,4 +11,4 @@ def initiate_characters(character_list_path: str):
character.export_movelist_as_json()


initiate_characters("resources/character_list.json")
create_all_character_json("resources/character_list.json")
9 changes: 5 additions & 4 deletions src/module/character_importer.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import os,sys
import os, sys

from src.module import character
from src.wavu import wavu_reader

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
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
38 changes: 25 additions & 13 deletions src/module/json_movelist_reader.py
Original file line number Diff line number Diff line change
@@ -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__)


Expand All @@ -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
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 {}
34 changes: 33 additions & 1 deletion src/module/test/test_json_movelist_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,43 @@

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")

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")

0 comments on commit 6de575a

Please sign in to comment.