forked from TLNBS2405/heihachi
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
315ea77
commit d5ae240
Showing
22 changed files
with
338 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,6 +35,7 @@ dev = [ | |
"pre-commit", | ||
"mypy", | ||
"pytest", | ||
"types-requests" | ||
] | ||
|
||
[tool.ruff] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
from .json_directory import JsonDirectory | ||
from .wavu import Wavu | ||
from .json_directory import JsonDirectory as JsonDirectory | ||
from .wavu import Wavu as Wavu |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .json_directory import JsonDirectory as JsonDirectory |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import json | ||
import logging | ||
import os | ||
|
||
import requests | ||
|
||
from framedb import Character, CharacterName, FrameService, Move | ||
|
||
logger = logging.getLogger("main") | ||
|
||
|
||
class JsonDirectory(FrameService): | ||
def __init__(self, char_meta_dir: str, movelist_dir: str) -> None: | ||
self.name = f"JSON Directory ({movelist_dir})" | ||
self.icon = None | ||
self.movelist_dir = movelist_dir | ||
|
||
try: | ||
with open(char_meta_dir, "r") as f: | ||
self.character_meta = json.load(f) | ||
except Exception as e: | ||
raise Exception(f"Could not load character meta data from {char_meta_dir}") from e | ||
|
||
def get_frame_data(self, character: CharacterName, session: requests.Session | None = None) -> Character: | ||
# TODO: duplicated across wavu and json_directory -> refactor | ||
target_char_meta = None | ||
for char_meta in self.character_meta: | ||
if char_meta["name"] == character.value: | ||
target_char_meta = char_meta | ||
break | ||
if target_char_meta is None: | ||
raise Exception(f"Could not find character meta data for {character.value}") | ||
|
||
name = CharacterName(target_char_meta["name"]) | ||
portrait = target_char_meta["portrait"] | ||
page = target_char_meta["page"] | ||
|
||
filepath = os.path.abspath(os.path.join(self.movelist_dir, f"{character.value}.json")) | ||
with open(filepath, encoding="utf-8") as move_file: | ||
move_file_contents = json.load(move_file) | ||
movelist = {move["id"]: Move(**move) for move in move_file_contents} | ||
char = Character(name, portrait, movelist, page) | ||
return char |
162 changes: 162 additions & 0 deletions
162
src/frame_service/json_directory/tests/static/character_list.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
[ | ||
{ | ||
"name": "alisa", | ||
"portrait": "https://i.imgur.com/5uhzI8W.png", | ||
"page": "https://wavu.wiki/t/Alisa" | ||
}, | ||
{ | ||
"name": "asuka", | ||
"portrait": "https://i.imgur.com/yl6wb3s.png", | ||
"page": "https://wavu.wiki/t/Asuka" | ||
}, | ||
{ | ||
"name": "azucena", | ||
"portrait": "https://i.imgur.com/fjMRO7I.png", | ||
"page": "https://wavu.wiki/t/Azucena" | ||
}, | ||
{ | ||
"name": "bryan", | ||
"portrait": "https://i.imgur.com/2pZOovW.png", | ||
"page": "https://wavu.wiki/t/Bryan" | ||
}, | ||
{ | ||
"name": "claudio", | ||
"portrait": "https://i.imgur.com/kBtrwM6.png", | ||
"page": "https://wavu.wiki/t/Claudio" | ||
}, | ||
{ | ||
"name": "devil_jin", | ||
"portrait": "https://i.imgur.com/Y0pez4V.png", | ||
"page": "https://wavu.wiki/t/Devil_Jin" | ||
}, | ||
{ | ||
"name": "dragunov", | ||
"portrait": "https://i.imgur.com/MZClYKp.png", | ||
"page": "https://wavu.wiki/t/Dragunov" | ||
}, | ||
{ | ||
"name": "feng", | ||
"portrait": "https://i.imgur.com/kuBCcMo.png", | ||
"page": "https://wavu.wiki/t/Feng" | ||
}, | ||
{ | ||
"name": "hwoarang", | ||
"portrait": "https://i.imgur.com/21UCjZ0.png", | ||
"page": "https://wavu.wiki/t/Hwoarang" | ||
}, | ||
{ | ||
"name": "jack-8", | ||
"portrait": "https://i.imgur.com/YZgpYIf.png", | ||
"page": "https://wavu.wiki/t/Jack-8" | ||
}, | ||
{ | ||
"name": "jin", | ||
"portrait": "https://i.imgur.com/ucx6sUa.png", | ||
"page": "https://wavu.wiki/t/Jin" | ||
}, | ||
{ | ||
"name": "jun", | ||
"portrait": "https://i.imgur.com/J1nIsFj.png", | ||
"page": "https://wavu.wiki/t/Jun" | ||
}, | ||
{ | ||
"name": "kazuya", | ||
"portrait": "https://i.imgur.com/HhPyKVn.png", | ||
"page": "https://wavu.wiki/t/Kazuya" | ||
}, | ||
{ | ||
"name": "king", | ||
"portrait": "https://i.imgur.com/rJfQwwz.png", | ||
"page": "https://wavu.wiki/t/King" | ||
}, | ||
{ | ||
"name": "kuma", | ||
"portrait": "https://i.imgur.com/HhPyKVn.png", | ||
"page": "https://wavu.wiki/t/Kuma" | ||
}, | ||
{ | ||
"name": "lars", | ||
"portrait": "https://i.imgur.com/gt5tF85.png", | ||
"page": "https://wavu.wiki/t/Lars" | ||
}, | ||
{ | ||
"name": "law", | ||
"portrait": "https://i.imgur.com/GmE9yOG.png", | ||
"page": "https://wavu.wiki/t/Law" | ||
}, | ||
{ | ||
"name": "lee", | ||
"portrait": "https://i.imgur.com/ARAtm1t.png", | ||
"page": "https://wavu.wiki/t/Lee" | ||
}, | ||
{ | ||
"name": "leo", | ||
"portrait": "https://i.imgur.com/fAIdWfw.png", | ||
"page": "https://wavu.wiki/t/Leo" | ||
}, | ||
{ | ||
"name": "leroy", | ||
"portrait": "https://i.imgur.com/wUttHKT.png", | ||
"page": "https://wavu.wiki/t/Leroy" | ||
}, | ||
{ | ||
"name": "lili", | ||
"portrait": "https://i.imgur.com/UWKqF0v.png", | ||
"page": "https://wavu.wiki/t/Lili" | ||
}, | ||
{ | ||
"name": "nina", | ||
"portrait": "https://i.imgur.com/PAUToyh.png", | ||
"page": "https://wavu.wiki/t/Nina" | ||
}, | ||
{ | ||
"name": "panda", | ||
"portrait": "https://i.imgur.com/IgAKZwR.png", | ||
"page": "https://wavu.wiki/t/Panda" | ||
}, | ||
{ | ||
"name": "paul", | ||
"portrait": "https://i.imgur.com/44jv2IR.png", | ||
"page": "https://wavu.wiki/t/Paul" | ||
}, | ||
{ | ||
"name": "raven", | ||
"portrait": "https://i.imgur.com/r1CYJOr.png", | ||
"page": "https://wavu.wiki/t/Raven" | ||
}, | ||
{ | ||
"name": "reina", | ||
"portrait": "https://i.imgur.com/WaiMf45.png", | ||
"page": "https://wavu.wiki/t/Reina" | ||
}, | ||
{ | ||
"name": "shaheen", | ||
"portrait": "https://i.imgur.com/Z0uYuBp.png", | ||
"page": "https://wavu.wiki/t/Shaheen" | ||
}, | ||
{ | ||
"name": "steve", | ||
"portrait": "https://i.imgur.com/97msjwy.png", | ||
"page": "https://wavu.wiki/t/Steve" | ||
}, | ||
{ | ||
"name": "victor", | ||
"portrait": "https://i.imgur.com/3gXDki2.png", | ||
"page": "https://wavu.wiki/t/Victor" | ||
}, | ||
{ | ||
"name": "xiaoyu", | ||
"portrait": "https://i.imgur.com/tnZ4qby.png", | ||
"page": "https://wavu.wiki/t/Xiaoyu" | ||
}, | ||
{ | ||
"name": "yoshimitsu", | ||
"portrait": "https://i.imgur.com/414HXeL.png", | ||
"page": "https://wavu.wiki/t/Yoshimitsu" | ||
}, | ||
{ | ||
"name": "zafina", | ||
"portrait": "https://i.imgur.com/36rN3ZO.png", | ||
"page": "https://wavu.wiki/t/Zafina" | ||
} | ||
] |
21 changes: 21 additions & 0 deletions
21
src/frame_service/json_directory/tests/test_json_directory.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import os | ||
|
||
import pytest | ||
|
||
from frame_service import JsonDirectory | ||
from framedb import CharacterName | ||
|
||
STATIC_BASE = os.path.join(os.path.dirname(__file__), "static") | ||
|
||
|
||
@pytest.fixture | ||
def json_directory() -> JsonDirectory: | ||
return JsonDirectory( | ||
char_meta_dir=os.path.join(STATIC_BASE, "character_list.json"), | ||
movelist_dir=os.path.join(STATIC_BASE, "json_movelist"), # TODO: add static movelists to test dir | ||
) | ||
|
||
|
||
def test_get_movelist_from_json(json_directory: JsonDirectory) -> None: | ||
char = json_directory.get_frame_data(CharacterName.AZUCENA, None) | ||
assert char is not None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
from .wavu import Wavu | ||
from .wavu import Wavu as Wavu |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.