From 9dce8988b3874fcdd12aec90126f532570952ec5 Mon Sep 17 00:00:00 2001 From: Tiger Date: Tue, 20 Jan 2026 09:34:24 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=AE=9E=E7=8E=B0=E8=B5=84=E6=BA=90(?= =?UTF-8?q?=E5=9B=BE=E7=89=87=E3=80=81=E9=9F=B3=E9=A2=91)=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2=EF=BC=8C=E5=AE=8C=E5=96=84README?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 69 +++++++++++++++++++++++++++---- app/__init__.py | 3 ++ app/routes/assets.py | 14 +++++++ app/utils/assets.py | 16 +++++++ app/utils/cards.py | 4 +- app/utils/matters.py | 7 +++- app/utils/reactions.py | 4 +- resources/assets/index.json | 2 +- resources/assets/pics/Oxygen.png | Bin 0 -> 1653 bytes resources/conditions/list.json | 0 10 files changed, 107 insertions(+), 12 deletions(-) create mode 100644 resources/assets/pics/Oxygen.png create mode 100644 resources/conditions/list.json diff --git a/README.md b/README.md index b221256..26d7d98 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,54 @@ -# 后端 +# 纸片化学社区版:数据后端 ## 项目介绍 +纸片化学社区版(Paper Chemis Community)是由 Tiger 开发的一款纸片化学游戏。该游戏使用纸片化学玩法,并带来了更高的自由度。 + +本项目为纸片化学社区版的数据后端,为游戏本体提供数据源服务。 + ## 项目结构 +```text +backend/ + +- run.py +- test/ + - test_*.py +- app/ + - __init__.py + - models/ + - routes/ + - assets.py + - cards.py + - matters.py + - pages.py + - reactions.py + - utils/ + - assets.py + - cards.py + - matters.py + - reactions.py +- resources/ + - assets/ + - index.json + - pics/ + - sounds/ + - cards/ + - list.json + - conditions/ + - list.json + - matters/ + - list.json + - reactions/ + - list.json + - match.json +``` + ## 部分文件格式 ### list.json -`cards` `matters` 和 `reactions` 下的 `list.json` 有相同的格式。每个文件中都只有一个对象。对象的键的内容均是字符串,代表 ID。对象的值的内容均是字符串,代表对应JSON文件的相对路径,不用加 `.json` 后缀名。例如: +`cards` `matters` 和 `reactions` `conditions` 下的 `list.json` 有相同的格式。每个文件中都只有一个对象。对象的键的内容均是字符串,代表 ID。对象的值的内容均是字符串,代表对应JSON文件的相对路径,不用加 `.json` 后缀名。例如: ```json { @@ -18,14 +58,29 @@ } ``` -### assets/index.json +### reactions/match.json -`assets` 目录下的 `index.json` 是资源文件的索引目录文件。该文件的内容是一个对象,每一个键值对对应一个资源文件。键对应的是资源的 ID,值对应的是资源的相对文件路径,不加 `.json` 后缀名。例如: +`reactions` 目录下的 `match.json` 支持通过反应物匹配反应。该文件的内容是一个对象。对象的键由反应物构成,每个反应物(包括最后一个)后面都有一个 `-` 以间隔开各项反应物。值是反应的 ID,即 `list.json` 中对象的键。例如: ```json { - "Carbon": "cards/carbon.png", - "Oxygen": "cards/Oxygen.png" + "Carbon-Oxygen-": "CarbonDioxide" +} +``` + +### assets/index.json + +`assets` 目录下的 `index.json` 是资源文件的索引目录文件。该文件的内容是一个对象,每一个键值对对应一个资源文件。键对应的是资源的 ID,值对应的是资源的相对文件路径,不加 `pics/` 或 `sounds/` 前缀。例如: + +```json +{ + "pics": { + "Carbon": "cards/Carbon.png", + "Oxygen": "cards/Oxygen.png" + }, + "sounds": { + // ... + } } ``` @@ -43,4 +98,4 @@ 对于路径和 ID,均应当使用英文字母、下划线和数字,不应当使用包括中文和短横杠在内的其他字符。由此引发的问题后果自负。 -所有 JSON 文件中的缩进均应当使用2个或4个空格,而非制表符(`\t`)。 +所有 JSON 文件中的缩进均应当使用 2 个或 4 个空格,而非制表符(`\t`)。 diff --git a/app/__init__.py b/app/__init__.py index 7c28da0..8fb305d 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -16,5 +16,8 @@ def create_app(config_class='config.Config'): from app.routes.matters import matter_bp app.register_blueprint(matter_bp, url_prefix="/matter") + + from app.routes.assets import asset_bp + app.register_blueprint(asset_bp, url_prefix="/asset") return app \ No newline at end of file diff --git a/app/routes/assets.py b/app/routes/assets.py index e69de29..965039a 100644 --- a/app/routes/assets.py +++ b/app/routes/assets.py @@ -0,0 +1,14 @@ +from flask import Blueprint, send_file +from ..utils import assets + +asset_bp = Blueprint("asset", __name__, "/asset") + +@asset_bp.route("/pic/") +def search_matter(id: str): + path = "../resources/assets/pics/" + assets.readPicPath(id) + return send_file(path) + +@asset_bp.route("/sound/") +def select_matter(id: str): + path = "../resources/assets/sounds/" + assets.readSoundPath(id) + return send_file(path) \ No newline at end of file diff --git a/app/utils/assets.py b/app/utils/assets.py index e69de29..038e4a3 100644 --- a/app/utils/assets.py +++ b/app/utils/assets.py @@ -0,0 +1,16 @@ +import json + +def readAssetsList() -> dict: + with open("resources/assets/index.json", "r", encoding="utf8") as f: + text = f.read() + result = json.loads(text) + + return result + +assets_list = readAssetsList() + +def readPicPath(id: str): + return assets_list["pics"][id] + +def readSoundPath(id: str): + return assets_list["sounds"][id] \ No newline at end of file diff --git a/app/utils/cards.py b/app/utils/cards.py index a57f4f9..6f7853d 100644 --- a/app/utils/cards.py +++ b/app/utils/cards.py @@ -7,8 +7,10 @@ def readCardList() -> dict: return result +card_list = readCardList() + def readCard(id: str): - path = readCardList().get(id, -1) + path = card_list.get(id, -1) if (path == -1): return {"message": f"No Card {id}"} with open(f"resources/cards/{path}.json", "r", encoding="utf8") as f: diff --git a/app/utils/matters.py b/app/utils/matters.py index 4cac723..0bf59a8 100644 --- a/app/utils/matters.py +++ b/app/utils/matters.py @@ -14,8 +14,11 @@ def readMatchList() -> dict: return result +matter_list = readMatterList() +match_list = readMatchList() + def readMatter(id: str): - path = readMatterList().get(id, -1) + path = matter_list.get(id, -1) if (path == -1): return {"message": f"No Matter {id}"} with open(f"resources/matters/{path}.json", "r", encoding="utf8") as f: @@ -25,7 +28,7 @@ def readMatter(id: str): return {"message": "OK", "content": result} def selectMatter(id: str): - matter_id = readMatchList().get(id, -1) + matter_id = match_list.get(id, -1) if (matter_id == -1): return {"message": f"No Matter {id}"} diff --git a/app/utils/reactions.py b/app/utils/reactions.py index 9762efb..34db0a3 100644 --- a/app/utils/reactions.py +++ b/app/utils/reactions.py @@ -7,8 +7,10 @@ def readReactionList() -> dict: return result +reaction_list = readReactionList() + def readReaction(id: str): - path = readReactionList().get(id, -1) + path = reaction_list.get(id, -1) if (path == -1): return {"message": f"No Reaction {id}"} with open(f"resources/reactions/{path}.json", "r", encoding="utf8") as f: diff --git a/resources/assets/index.json b/resources/assets/index.json index 5a6e25a..3e92e62 100644 --- a/resources/assets/index.json +++ b/resources/assets/index.json @@ -1,6 +1,6 @@ { "pics": { - + "Oxygen": "Oxygen.png" }, "sounds": { diff --git a/resources/assets/pics/Oxygen.png b/resources/assets/pics/Oxygen.png new file mode 100644 index 0000000000000000000000000000000000000000..3925e05c0dc0fc10503a8cc665c07cd085605c8a GIT binary patch literal 1653 zcmZ`)TT~K=76num&jb+z%L-J)*F@yCQZo%u9K8gk<@7Ktyylq2V2NwQQM-jXI*QIn zgAWuRQyJP|l3AK$Vwz^YwQ2Bemf{0*%o$%}>wexfAN%Z&z0WyoosWG|*eqWp%n}9w z0FZu6`q541eFg-)S^1;cftv*7Grx)k0N|L<00MIIZ~y?<&X4XL7@Iefcj{(P5bi~S zua(^~m&*|+*ganqnaE0gEIFp=VD@o(=E0ux-4ms|JiJZ4!r>TYmR`?R*+iT-xEy|eq-gZhJe!#DbKBG$Mn*`G^of6c88#obr;pImVSV$C`! zs@gvWNZ}eHQ5OArp&lku)>KbRVh>HH(m$iAYJ~F?lvL zqBY*^|D~osCF`19Tw^|rQuf#ix*fb;CT*WuV(6XDX0Q^2MCE|y3bqk zPk15!NHZP;UxL^Z1B*jIa+8X=k)bG%r&hl9BvIEpv!iWTrFk^96vzehp%k~tjmt(M zzzSnez2c!1UBsCy3`foxY2MT+BT;<(yh|Ul{n+FdWn6jD=@ZqzOCrXn{bsZ~!lRs( zam4x4>5m;X?#{~o;(%SWFEtLUKdR8vK&+OyaK^mf;*LU2O+wU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