Merge branch 'develop' into 'master'
基本完成数据后端功能 See merge request paper-chemis-community/backend!2
This commit is contained in:
@@ -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`)。
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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/<id>")
|
||||
def find_pic(id: str):
|
||||
|
||||
+4
-4
@@ -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/<id>")
|
||||
def search_card(id):
|
||||
return cards.readCard(id)
|
||||
return jsonify(cards.readCard(id))
|
||||
@@ -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/<id>")
|
||||
def search_matter(id):
|
||||
return matters.readMatter(id)
|
||||
return jsonify(matters.readMatter(id))
|
||||
+8
-3
@@ -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"})
|
||||
def index_page():
|
||||
return jsonify({"code": "200", "message": "Service normal"})
|
||||
|
||||
@page_bp.route("/index")
|
||||
def description():
|
||||
return jsonify(index.readIndex())
|
||||
@@ -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/<id>")
|
||||
def search_reaction(id):
|
||||
return reactions.readReaction(id)
|
||||
return jsonify(reactions.readReaction(id))
|
||||
|
||||
@reaction_bp.route("/match/<id>")
|
||||
def select_reaction(id):
|
||||
return reactions.selectReaction(id)
|
||||
return jsonify(reactions.selectReaction(id))
|
||||
@@ -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
|
||||
@@ -3,6 +3,7 @@
|
||||
"en-US": "Carbon",
|
||||
"zh-CN": "碳"
|
||||
},
|
||||
"type": "Element/Solid",
|
||||
"number": 6,
|
||||
"mass": 12
|
||||
}
|
||||
@@ -3,6 +3,7 @@
|
||||
"en-US": "Oxygen",
|
||||
"zh-CN": "氧"
|
||||
},
|
||||
"type": "Element/Solid",
|
||||
"number": 8,
|
||||
"mass": 16
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
{
|
||||
"name": {
|
||||
"en-US": "Ignite",
|
||||
"zh-CN": "点燃"
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
{
|
||||
"Ignite": "Ignite"
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"name": "Offical Example",
|
||||
"author": "Paper Chemis Community Team",
|
||||
"uuid": "6b3d2702c1c345499fc8617d664b3627",
|
||||
|
||||
"rules": {
|
||||
"common": true
|
||||
}
|
||||
}
|
||||
@@ -3,5 +3,6 @@
|
||||
"en-US": "Carbon Dioxide",
|
||||
"zh-CN": "二氧化碳"
|
||||
},
|
||||
"type": "Compound/Gas",
|
||||
"mass": 44
|
||||
}
|
||||
@@ -3,6 +3,7 @@
|
||||
"en-US": "Carbon",
|
||||
"zh-CN": "碳"
|
||||
},
|
||||
"type": "Element/Solid",
|
||||
"number": 6,
|
||||
"mass": 12
|
||||
}
|
||||
@@ -3,6 +3,7 @@
|
||||
"en-US": "Oxygen",
|
||||
"zh-CN": "氧"
|
||||
},
|
||||
"type": "Element/Solid",
|
||||
"number": 8,
|
||||
"mass": 16
|
||||
}
|
||||
Reference in New Issue
Block a user