diff --git a/app/__init__.py b/app/__init__.py index 55c8024..7601292 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -10,6 +10,9 @@ def create_app(config_class='config.DevelopmentConfig'): app.register_blueprint(page_bp) from app.routes.cards import card_bp - app.register_blueprint(card_bp) + app.register_blueprint(card_bp, url_prefix="/card") + + from app.routes.reactions import reaction_bp + app.register_blueprint(reaction_bp, url_prefix="/reaction") return app \ No newline at end of file diff --git a/app/routes/reactions.py b/app/routes/reactions.py index e69de29..e6fedde 100644 --- a/app/routes/reactions.py +++ b/app/routes/reactions.py @@ -0,0 +1,8 @@ +from flask import Blueprint +from ..services import reactions + +reaction_bp = Blueprint("reaction", __name__, "/reaction") + +@reaction_bp.route("/") +def search_card(id): + return reactions.readReaction(id) \ No newline at end of file diff --git a/app/services/cards.py b/app/services/cards.py index 84ad27f..d224b74 100644 --- a/app/services/cards.py +++ b/app/services/cards.py @@ -8,4 +8,11 @@ def readCardList() -> dict: return result def readCard(id: str): - return readCardList().get(id, f"No Card {id}") \ No newline at end of file + path = readCardList().get(id, -1) + if (path == -1): + return {"message": f"No Card {id}"} + with open(f"cards/{path}.json", "r", encoding="utf8") as f: + text = f.read() + result = json.loads(text) + + return {"message": "OK", "content": result} \ No newline at end of file diff --git a/app/services/reactions.py b/app/services/reactions.py index e99a22c..ba77511 100644 --- a/app/services/reactions.py +++ b/app/services/reactions.py @@ -8,4 +8,11 @@ def readReactionList() -> dict: return result def readReaction(id: str): - return readReactionList().get(id, -1) \ No newline at end of file + path = readReactionList().get(id, -1) + if (path == -1): + return {"message": f"No Reaction {id}"} + with open(f"reactions/{path}.json", "r", encoding="utf8") as f: + text = f.read() + result = json.loads(text) + + return {"message": "OK", "content": result} \ No newline at end of file diff --git a/cards/NonMetal/Carbon.json b/cards/NonMetal/Carbon.json new file mode 100644 index 0000000..116e77f --- /dev/null +++ b/cards/NonMetal/Carbon.json @@ -0,0 +1,8 @@ +{ + "name": { + "en-US": "Carbon", + "zh-CN": "碳" + }, + "number": 6, + "mass": 12 +} \ No newline at end of file diff --git a/cards/NonMetal/Oxygen.json b/cards/NonMetal/Oxygen.json new file mode 100644 index 0000000..0ac441c --- /dev/null +++ b/cards/NonMetal/Oxygen.json @@ -0,0 +1,8 @@ +{ + "name": { + "en-US": "Oxygen", + "zh-CN": "氧" + }, + "number": 8, + "mass": 16 +} \ No newline at end of file diff --git a/cards/list.json b/cards/list.json index 544b7b4..c567560 100644 --- a/cards/list.json +++ b/cards/list.json @@ -1,3 +1,4 @@ { - + "Carbon": "NonMetal/Carbon", + "Oxygen": "NonMetal/Oxygen" } \ No newline at end of file diff --git a/conditions/Ignite.json b/conditions/Ignite.json new file mode 100644 index 0000000..6cdc519 --- /dev/null +++ b/conditions/Ignite.json @@ -0,0 +1,6 @@ +{ + "name": { + "en-US": "Ignite", + "zh-CN": "点燃" + } +} \ No newline at end of file diff --git a/config/local.json b/config/local.json deleted file mode 100644 index 544b7b4..0000000 --- a/config/local.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - -} \ No newline at end of file diff --git a/matters/Compound/Carbon_Dioxide.json b/matters/Compound/Carbon_Dioxide.json new file mode 100644 index 0000000..b430ccb --- /dev/null +++ b/matters/Compound/Carbon_Dioxide.json @@ -0,0 +1,7 @@ +{ + "name": { + "en-US": "Carbon Dioxide", + "zh-CN": "二氧化碳" + }, + "mass": 44 +} \ No newline at end of file diff --git a/matters/NonMetal/Carbon.json b/matters/NonMetal/Carbon.json new file mode 100644 index 0000000..116e77f --- /dev/null +++ b/matters/NonMetal/Carbon.json @@ -0,0 +1,8 @@ +{ + "name": { + "en-US": "Carbon", + "zh-CN": "碳" + }, + "number": 6, + "mass": 12 +} \ No newline at end of file diff --git a/matters/NonMetal/Oxygen.json b/matters/NonMetal/Oxygen.json new file mode 100644 index 0000000..0ac441c --- /dev/null +++ b/matters/NonMetal/Oxygen.json @@ -0,0 +1,8 @@ +{ + "name": { + "en-US": "Oxygen", + "zh-CN": "氧" + }, + "number": 8, + "mass": 16 +} \ No newline at end of file diff --git a/matters/list.json b/matters/list.json index 544b7b4..429e067 100644 --- a/matters/list.json +++ b/matters/list.json @@ -1,3 +1,6 @@ { + "Carbon": "NonMetal/Carbon", + "Oxygen": "NonMetal/Oxygen", + "Carbon_Dioxide": "Compound/Carbon_Dioxide" } \ No newline at end of file diff --git a/reactions/Oxidation/CarbonDioxide.json b/reactions/Oxidation/CarbonDioxide.json new file mode 100644 index 0000000..70f9f62 --- /dev/null +++ b/reactions/Oxidation/CarbonDioxide.json @@ -0,0 +1,12 @@ +{ + "reactants": [ + "NonMetal/Carbon", + "NonMetal/Oxygen" + ], + "conditions": [ + "Ignite" + ], + "products": [ + "Compound/Carbon_Dioxide" + ] +} \ No newline at end of file diff --git a/reactions/list.json b/reactions/list.json index 544b7b4..9775ae9 100644 --- a/reactions/list.json +++ b/reactions/list.json @@ -1,3 +1,3 @@ { - + "CarbonDioxide": "Oxidation/CarbonDioxide" } \ No newline at end of file diff --git a/test/test_cards.py b/test/test_cards.py new file mode 100644 index 0000000..0bbbca9 --- /dev/null +++ b/test/test_cards.py @@ -0,0 +1,5 @@ +''' +检查卡牌信息,包括: +卡牌列表中的路径是否存在 +卡牌配置文件是否符合规范 +''' \ No newline at end of file