diff --git a/README.md b/README.md index ec3764e..4f5e921 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,7 @@ backend/ - matters.py - reactions.py - resources/ + - description.json - assets/ - index.json - pics/ @@ -46,6 +47,22 @@ backend/ ## 部分文件格式 +### description.json + +`resources` 目录下的 `description.json` 是整个源的介绍文件,应当包含源的名字、作者和唯一UUID以及规则。其中UUID不带横杠(`-`)。下面给出一个示例: + +```json +{ + "name": "Offical Example", + "author": "Paper Chemis Community Team", + "uuid": "6b3d2702c1c345499fc8617d664b3627", + + "rules": { + "common": true + } +} +``` + ### list.json `cards` `matters` 和 `reactions` `conditions` 下的 `list.json` 有相同的格式。每个文件中都只有一个对象。对象的键的内容均是字符串,代表 ID。对象的值的内容均是字符串,代表对应JSON文件的相对路径,不用加 `.json` 后缀名。例如: @@ -100,6 +117,10 @@ backend/ ## 最佳实践 -对于路径和 ID,均应当使用英文字母、下划线和数字,不应当使用包括中文和短横杠在内的其他字符。由此引发的问题后果自负。 +不遵守此部分内容引发的问题后果自负。 + +对于同一物质/卡牌,其在各处的 ID 应该相同,即在 `cards` `matters` `reactions` `assets` 中的 ID 都应该相同,否则游戏本体将无法读取。 + +对于路径和 ID,均应当使用英文字母、下划线和数字,不应当使用包括中文和短横杠在内的其他字符。 所有 JSON 文件中的缩进均应当使用 2 个或 4 个空格,而非制表符(`\t`)。 diff --git a/app/__init__.py b/app/__init__.py index 8fb305d..4e31aec 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -3,6 +3,7 @@ from flask import Flask def create_app(config_class='config.Config'): app = Flask(__name__) app.config.from_object(config_class) + app.json.ensure_ascii = False # type: ignore # 注册蓝图 from app.routes.pages import page_bp diff --git a/app/models/__Init__.py b/app/models/__Init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/app/routes/assets.py b/app/routes/assets.py index 9255fde..4491531 100644 --- a/app/routes/assets.py +++ b/app/routes/assets.py @@ -1,14 +1,14 @@ ''' 资源文件读取路由 ''' -from flask import Blueprint, send_file +from flask import Blueprint, send_file, jsonify from ..utils import assets -asset_bp = Blueprint("asset", __name__, "/asset") +asset_bp = Blueprint("asset", __name__, url_prefix="/asset") @asset_bp.route("/list") def asset_list(): - return assets.readAssetsList() + return jsonify(assets.readAssetsList()) @asset_bp.route("/pic/") def find_pic(id: str): diff --git a/app/routes/cards.py b/app/routes/cards.py index fd92f42..edd3864 100644 --- a/app/routes/cards.py +++ b/app/routes/cards.py @@ -1,15 +1,15 @@ ''' 卡牌定义文件读取路由 ''' -from flask import Blueprint +from flask import Blueprint, jsonify from ..utils import cards -card_bp = Blueprint("card", __name__, "/card") +card_bp = Blueprint("card", __name__, url_prefix="/card") @card_bp.route("/list") def card_list(): - return cards.readCardList() + return jsonify(cards.readCardList()) @card_bp.route("/id/") def search_card(id): - return cards.readCard(id) \ No newline at end of file + return jsonify(cards.readCard(id)) \ No newline at end of file diff --git a/app/routes/matters.py b/app/routes/matters.py index 7d17378..ebd107d 100644 --- a/app/routes/matters.py +++ b/app/routes/matters.py @@ -1,15 +1,15 @@ ''' 物质定义文件读取路由 ''' -from flask import Blueprint +from flask import Blueprint, jsonify from ..utils import matters -matter_bp = Blueprint("matter", __name__, "/matter") +matter_bp = Blueprint("matter", __name__, url_prefix="/matter") @matter_bp.route("/list") def matter_list(): - return matters.readMatterList() + return jsonify(matters.readMatterList()) @matter_bp.route("/id/") def search_matter(id): - return matters.readMatter(id) \ No newline at end of file + return jsonify(matters.readMatter(id)) \ No newline at end of file diff --git a/app/routes/pages.py b/app/routes/pages.py index 2d54d4a..c3f6a36 100644 --- a/app/routes/pages.py +++ b/app/routes/pages.py @@ -2,9 +2,14 @@ 网页路由 ''' from flask import Blueprint, jsonify +from ..utils import index -page_bp = Blueprint("page", __name__, "/") +page_bp = Blueprint("page", __name__, url_prefix="/") @page_bp.route("/") -def index(): - return jsonify({"code": "200", "message": "Service normal"}) \ No newline at end of file +def index_page(): + return jsonify({"code": "200", "message": "Service normal"}) + +@page_bp.route("/index") +def description(): + return jsonify(index.readIndex()) \ No newline at end of file diff --git a/app/routes/reactions.py b/app/routes/reactions.py index aa5ab5d..0395e8f 100644 --- a/app/routes/reactions.py +++ b/app/routes/reactions.py @@ -1,23 +1,23 @@ ''' 反应定义文件读取路由 ''' -from flask import Blueprint +from flask import Blueprint, jsonify from ..utils import reactions -reaction_bp = Blueprint("reaction", __name__, "/reaction") +reaction_bp = Blueprint("reaction", __name__, url_prefix="/reaction") @reaction_bp.route("list") def reaction_list(): - return reactions.readReactionList() + return jsonify(reactions.readReactionList()) @reaction_bp.route("/match") def match_list(): - return reactions.readMatchList() + return jsonify(reactions.readMatchList()) @reaction_bp.route("/id/") def search_reaction(id): - return reactions.readReaction(id) + return jsonify(reactions.readReaction(id)) @reaction_bp.route("/match/") def select_reaction(id): - return reactions.selectReaction(id) \ No newline at end of file + return jsonify(reactions.selectReaction(id)) \ No newline at end of file diff --git a/app/utils/index.py b/app/utils/index.py new file mode 100644 index 0000000..4b6e846 --- /dev/null +++ b/app/utils/index.py @@ -0,0 +1,12 @@ +''' +读取 description.json 的内容 +''' +import json + +def readIndex() -> dict: + + with open("resources/description.json", "r", encoding="utf8") as f: + text = f.read() + result = json.loads(text) + + return result \ No newline at end of file diff --git a/resources/cards/NonMetal/Carbon.json b/resources/cards/NonMetal/Carbon.json index 116e77f..51c43ca 100644 --- a/resources/cards/NonMetal/Carbon.json +++ b/resources/cards/NonMetal/Carbon.json @@ -3,6 +3,7 @@ "en-US": "Carbon", "zh-CN": "碳" }, + "type": "Element/Solid", "number": 6, "mass": 12 } \ No newline at end of file diff --git a/resources/cards/NonMetal/Oxygen.json b/resources/cards/NonMetal/Oxygen.json index 0ac441c..f3bd5c1 100644 --- a/resources/cards/NonMetal/Oxygen.json +++ b/resources/cards/NonMetal/Oxygen.json @@ -3,6 +3,7 @@ "en-US": "Oxygen", "zh-CN": "氧" }, + "type": "Element/Solid", "number": 8, "mass": 16 } \ No newline at end of file diff --git a/resources/conditions/Ignite.json b/resources/conditions/Ignite.json deleted file mode 100644 index 6cdc519..0000000 --- a/resources/conditions/Ignite.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "name": { - "en-US": "Ignite", - "zh-CN": "点燃" - } -} \ No newline at end of file diff --git a/resources/conditions/list.json b/resources/conditions/list.json deleted file mode 100644 index f61b33b..0000000 --- a/resources/conditions/list.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "Ignite": "Ignite" -} \ No newline at end of file diff --git a/resources/description.json b/resources/description.json new file mode 100644 index 0000000..446350e --- /dev/null +++ b/resources/description.json @@ -0,0 +1,9 @@ +{ + "name": "Offical Example", + "author": "Paper Chemis Community Team", + "uuid": "6b3d2702c1c345499fc8617d664b3627", + + "rules": { + "common": true + } +} \ No newline at end of file diff --git a/resources/matters/Compound/Carbon_Dioxide.json b/resources/matters/Compound/Carbon_Dioxide.json index b430ccb..47dfee2 100644 --- a/resources/matters/Compound/Carbon_Dioxide.json +++ b/resources/matters/Compound/Carbon_Dioxide.json @@ -3,5 +3,6 @@ "en-US": "Carbon Dioxide", "zh-CN": "二氧化碳" }, + "type": "Compound/Gas", "mass": 44 } \ No newline at end of file diff --git a/resources/matters/NonMetal/Carbon.json b/resources/matters/NonMetal/Carbon.json index 116e77f..51c43ca 100644 --- a/resources/matters/NonMetal/Carbon.json +++ b/resources/matters/NonMetal/Carbon.json @@ -3,6 +3,7 @@ "en-US": "Carbon", "zh-CN": "碳" }, + "type": "Element/Solid", "number": 6, "mass": 12 } \ No newline at end of file diff --git a/resources/matters/NonMetal/Oxygen.json b/resources/matters/NonMetal/Oxygen.json index 0ac441c..f3bd5c1 100644 --- a/resources/matters/NonMetal/Oxygen.json +++ b/resources/matters/NonMetal/Oxygen.json @@ -3,6 +3,7 @@ "en-US": "Oxygen", "zh-CN": "氧" }, + "type": "Element/Solid", "number": 8, "mass": 16 } \ No newline at end of file