nonebot-plugin-bugu 0.2.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. nonebot_plugin_bugu/__init__.py +31 -0
  2. nonebot_plugin_bugu/api.py +282 -0
  3. nonebot_plugin_bugu/collection.py +166 -0
  4. nonebot_plugin_bugu/commands.py +234 -0
  5. nonebot_plugin_bugu/config.py +91 -0
  6. nonebot_plugin_bugu/draw.py +406 -0
  7. nonebot_plugin_bugu/features/__init__.py +0 -0
  8. nonebot_plugin_bugu/features/collection.py +247 -0
  9. nonebot_plugin_bugu/features/common.py +100 -0
  10. nonebot_plugin_bugu/features/flowers/__init__.py +0 -0
  11. nonebot_plugin_bugu/features/flowers/data.py +167 -0
  12. nonebot_plugin_bugu/features/flowers/render.py +300 -0
  13. nonebot_plugin_bugu/features/flowers/reply.py +123 -0
  14. nonebot_plugin_bugu/features/neighbors/__init__.py +0 -0
  15. nonebot_plugin_bugu/features/neighbors/data.py +143 -0
  16. nonebot_plugin_bugu/features/neighbors/render.py +225 -0
  17. nonebot_plugin_bugu/features/neighbors/reply.py +149 -0
  18. nonebot_plugin_bugu/features/recipes/__init__.py +0 -0
  19. nonebot_plugin_bugu/features/recipes/data.py +313 -0
  20. nonebot_plugin_bugu/features/recipes/render.py +371 -0
  21. nonebot_plugin_bugu/features/recipes/reply.py +219 -0
  22. nonebot_plugin_bugu/features/recipes/search.py +151 -0
  23. nonebot_plugin_bugu/features/starsea/__init__.py +0 -0
  24. nonebot_plugin_bugu/features/starsea/data.py +267 -0
  25. nonebot_plugin_bugu/features/starsea/render.py +579 -0
  26. nonebot_plugin_bugu/features/starsea/reply.py +356 -0
  27. nonebot_plugin_bugu/features/starsea/search.py +271 -0
  28. nonebot_plugin_bugu/fonts.py +152 -0
  29. nonebot_plugin_bugu/runtime.py +109 -0
  30. nonebot_plugin_bugu/values.py +87 -0
  31. nonebot_plugin_bugu-0.2.0.dist-info/METADATA +257 -0
  32. nonebot_plugin_bugu-0.2.0.dist-info/RECORD +35 -0
  33. nonebot_plugin_bugu-0.2.0.dist-info/WHEEL +4 -0
  34. nonebot_plugin_bugu-0.2.0.dist-info/entry_points.txt +3 -0
  35. nonebot_plugin_bugu-0.2.0.dist-info/licenses/LICENSE +21 -0
@@ -0,0 +1,313 @@
1
+ """菜谱(``/api/bootstrap``)的数据模型。"""
2
+
3
+ from __future__ import annotations
4
+
5
+ from dataclasses import dataclass, field
6
+ from typing import Any, Dict, List, Optional, Tuple
7
+
8
+ from ...values import absolute_url, as_int, as_optional_int, as_str, as_str_list, clean_text
9
+
10
+
11
+ @dataclass
12
+ class Ingredient:
13
+ """一个食材槽;``icons`` 有两个时表示「A/B 二选一」。"""
14
+
15
+ names: List[str]
16
+ label: str
17
+ quality: str
18
+ icons: List[str]
19
+ note: str
20
+ placeholder: bool
21
+
22
+ @property
23
+ def is_pair(self) -> bool:
24
+ return len(self.icons) > 1
25
+
26
+
27
+ @dataclass
28
+ class Kitchen:
29
+ name: str
30
+ icon: str
31
+ specified: bool
32
+
33
+
34
+ @dataclass
35
+ class Buff:
36
+ name: str
37
+ tier: str
38
+ label: str
39
+ icon: str
40
+ description: str
41
+ effect_label: str
42
+ effect_text: str
43
+ effect_raw: str
44
+ tiers: List[str]
45
+ tier_values: List[Tuple[str, str, str]]
46
+
47
+
48
+ @dataclass
49
+ class NeighborRef:
50
+ name: str
51
+ icon: str
52
+
53
+
54
+ @dataclass
55
+ class Recipe:
56
+ number: int
57
+ name: str
58
+ specified: bool
59
+ description: str
60
+ sources: List[str]
61
+ quality: str
62
+ panel_color: str
63
+ type: str
64
+ type_icon: str
65
+ level: Optional[int]
66
+ level_text: str
67
+ food_tags: List[str]
68
+ cuisine: str
69
+ kitchen: Optional[Kitchen]
70
+ strength: Optional[int]
71
+ buff: Optional[Buff]
72
+ neighbor: Optional[NeighborRef]
73
+ is_miracle: bool
74
+ miracle_label: str
75
+ dish: str
76
+ dish_placeholder: bool
77
+ dish_tint: str
78
+ ingredients: List[Ingredient]
79
+ incomplete: bool
80
+ incomplete_notice: str
81
+ search_name: str
82
+ search_number: str
83
+ ingredient_tokens: List[str]
84
+
85
+ @property
86
+ def display_name(self) -> str:
87
+ return self.name or "???"
88
+
89
+ @property
90
+ def number_text(self) -> str:
91
+ return f"{self.number:03d}"
92
+
93
+
94
+ @dataclass
95
+ class FilterOption:
96
+ value: str
97
+ count: int
98
+ icon: str
99
+
100
+
101
+ @dataclass
102
+ class RecipeBook:
103
+ recipes: List[Recipe]
104
+ filters: Dict[str, List[FilterOption]] = field(default_factory=dict)
105
+ aliases: Dict[str, str] = field(default_factory=dict)
106
+ ingredient_notes: Dict[str, str] = field(default_factory=dict)
107
+ buffs: Dict[str, Buff] = field(default_factory=dict)
108
+ quality_colors: Dict[str, str] = field(default_factory=dict)
109
+ assets: Dict[str, Any] = field(default_factory=dict)
110
+ version: str = ""
111
+
112
+ def by_number(self, number: int) -> Optional[Recipe]:
113
+ for recipe in self.recipes:
114
+ if recipe.number == number:
115
+ return recipe
116
+ return None
117
+
118
+ def find_exact(self, query: str) -> Optional[Recipe]:
119
+ """按菜名或编号精确找。"""
120
+ text = (query or "").strip()
121
+ if not text:
122
+ return None
123
+ if text.isdigit():
124
+ found = self.by_number(int(text))
125
+ if found is not None:
126
+ return found
127
+ folded = text.casefold()
128
+ for recipe in self.recipes:
129
+ if recipe.display_name.casefold() == folded:
130
+ return recipe
131
+ return None
132
+
133
+ def filter_options(self) -> Dict[str, List[FilterOption]]:
134
+ return self.filters
135
+
136
+ def filter_value(self, token: str) -> Optional[Tuple[str, str]]:
137
+ """判断一个词是不是筛选值,返回 ``(筛选器 key, 值)``。"""
138
+ text = (token or "").strip()
139
+ if not text:
140
+ return None
141
+ for key, options in self.filters.items():
142
+ for option in options:
143
+ if option.value == text:
144
+ return key, option.value
145
+ return None
146
+
147
+ @property
148
+ def count(self) -> int:
149
+ return len(self.recipes)
150
+
151
+
152
+ def _parse_buff(raw: Any, base: str) -> Optional[Buff]:
153
+ if not isinstance(raw, dict) or not raw.get("name"):
154
+ return None
155
+ detail = raw.get("detail") if isinstance(raw.get("detail"), dict) else {}
156
+ tier_values = []
157
+ for item in detail.get("tierValues") or []:
158
+ if isinstance(item, dict):
159
+ tier_values.append(
160
+ (as_str(item.get("tier")), as_str(item.get("value")), as_str(item.get("suffix")))
161
+ )
162
+ return Buff(
163
+ name=as_str(raw.get("name")),
164
+ tier=as_str(raw.get("tier")),
165
+ label=as_str(raw.get("label")) or as_str(raw.get("name")),
166
+ icon=absolute_url(base, as_str(raw.get("icon"))),
167
+ description=clean_text(detail.get("description")),
168
+ effect_label=as_str(detail.get("effectLabel")),
169
+ effect_text=as_str(detail.get("effectText")),
170
+ effect_raw=as_str(detail.get("effectRaw")),
171
+ tiers=as_str_list(detail.get("tiers")),
172
+ tier_values=tier_values,
173
+ )
174
+
175
+
176
+ def _parse_ingredient(raw: Dict[str, Any], base: str) -> Ingredient:
177
+ icons = [absolute_url(base, icon) for icon in as_str_list(raw.get("icons"))]
178
+ names = as_str_list(raw.get("names")) or [as_str(raw.get("label"))]
179
+ return Ingredient(
180
+ names=names,
181
+ label=as_str(raw.get("label")) or (names[0] if names else ""),
182
+ quality=as_str(raw.get("quality")).upper(),
183
+ icons=icons,
184
+ note=clean_text(raw.get("note")),
185
+ placeholder=bool(raw.get("placeholder")),
186
+ )
187
+
188
+
189
+ def parse_recipe(raw: Dict[str, Any], base: str) -> Recipe:
190
+ kitchen_raw = raw.get("kitchen")
191
+ kitchen = None
192
+ if isinstance(kitchen_raw, dict) and kitchen_raw.get("name"):
193
+ kitchen = Kitchen(
194
+ name=as_str(kitchen_raw.get("name")),
195
+ icon=absolute_url(base, as_str(kitchen_raw.get("icon"))),
196
+ specified=bool(kitchen_raw.get("specified")),
197
+ )
198
+
199
+ neighbor_raw = raw.get("neighbor")
200
+ neighbor = None
201
+ if isinstance(neighbor_raw, dict) and neighbor_raw.get("name"):
202
+ neighbor = NeighborRef(
203
+ name=as_str(neighbor_raw.get("name")),
204
+ icon=absolute_url(base, as_str(neighbor_raw.get("icon"))),
205
+ )
206
+
207
+ search = raw.get("search") if isinstance(raw.get("search"), dict) else {}
208
+
209
+ return Recipe(
210
+ number=as_int(raw.get("number")),
211
+ name=as_str(raw.get("name")),
212
+ specified=bool(raw.get("nameSpecified", True)),
213
+ description=clean_text(raw.get("descriptionText")) or clean_text(raw.get("description")),
214
+ sources=[clean_text(s) for s in raw.get("sources") or [] if clean_text(s)],
215
+ quality=as_str(raw.get("quality")).upper(),
216
+ panel_color=as_str(raw.get("panelColor")) or "#9CC2C2",
217
+ type=as_str(raw.get("type")),
218
+ type_icon=absolute_url(base, as_str(raw.get("typeIcon"))),
219
+ level=as_optional_int(raw.get("level")),
220
+ level_text=as_str(raw.get("levelText")),
221
+ food_tags=as_str_list(raw.get("foodTags")),
222
+ cuisine=as_str(raw.get("cuisine")),
223
+ kitchen=kitchen,
224
+ strength=as_optional_int(raw.get("strength")),
225
+ buff=_parse_buff(raw.get("buff"), base),
226
+ neighbor=neighbor,
227
+ is_miracle=bool(raw.get("isMiracle")),
228
+ miracle_label=as_str(raw.get("miracleLabel")),
229
+ dish=absolute_url(base, as_str(raw.get("dish"))),
230
+ dish_placeholder=bool(raw.get("dishPlaceholder")),
231
+ dish_tint=as_str(raw.get("dishTint")) or "#9CC2C2",
232
+ ingredients=[
233
+ _parse_ingredient(item, base)
234
+ for item in raw.get("ingredients") or []
235
+ if isinstance(item, dict)
236
+ ],
237
+ incomplete=bool(raw.get("incomplete")),
238
+ incomplete_notice=clean_text(raw.get("incompleteNotice")),
239
+ search_name=as_str(search.get("name")) or as_str(raw.get("nameText")),
240
+ search_number=as_str(search.get("number")) or str(as_int(raw.get("number"))),
241
+ ingredient_tokens=as_str_list(search.get("ingredientTokens")),
242
+ )
243
+
244
+
245
+ def _parse_filters(raw: Any, base: str) -> Dict[str, List[FilterOption]]:
246
+ out: Dict[str, List[FilterOption]] = {}
247
+ if not isinstance(raw, dict):
248
+ return out
249
+ for key, options in raw.items():
250
+ items: List[FilterOption] = []
251
+ for option in options or []:
252
+ if not isinstance(option, dict):
253
+ continue
254
+ items.append(
255
+ FilterOption(
256
+ value=as_str(option.get("value")),
257
+ count=as_int(option.get("count")),
258
+ icon=absolute_url(base, as_str(option.get("icon"))),
259
+ )
260
+ )
261
+ out[key] = items
262
+ return out
263
+
264
+
265
+ def parse_recipes(payload: Dict[str, Any], base: str) -> RecipeBook:
266
+ """解析 ``/api/bootstrap``。"""
267
+ if not isinstance(payload, dict):
268
+ raise ValueError("接口返回的不是 JSON 对象")
269
+ raw_recipes = payload.get("recipes")
270
+ if not isinstance(raw_recipes, list) or not raw_recipes:
271
+ raise ValueError("接口没有返回任何菜谱")
272
+
273
+ reference = payload.get("reference") if isinstance(payload.get("reference"), dict) else {}
274
+ design = payload.get("design") if isinstance(payload.get("design"), dict) else {}
275
+
276
+ ingredient_notes: Dict[str, str] = {}
277
+ for key, value in (reference.get("ingredientNotes") or {}).items():
278
+ ingredient_notes[as_str(key)] = clean_text(value)
279
+
280
+ aliases: Dict[str, str] = {}
281
+ for key, value in (reference.get("searchAliases") or {}).items():
282
+ aliases[as_str(key)] = as_str(value)
283
+
284
+ buffs: Dict[str, Buff] = {}
285
+ for key, value in (reference.get("buffs") or {}).items():
286
+ parsed = _parse_buff({"name": key, **value} if isinstance(value, dict) else value, base)
287
+ if parsed is not None:
288
+ buffs[parsed.name] = parsed
289
+
290
+ quality_colors = {
291
+ as_str(key): as_str(value)
292
+ for key, value in (reference.get("qualityColors") or {}).get("ingredient", {}).items()
293
+ } if isinstance((reference.get("qualityColors") or {}).get("ingredient"), dict) else {}
294
+
295
+ assets: Dict[str, Any] = {}
296
+ for key, value in (design.get("assets") or {}).items():
297
+ if isinstance(value, str):
298
+ assets[as_str(key)] = absolute_url(base, value)
299
+ elif isinstance(value, dict):
300
+ assets[as_str(key)] = {
301
+ k: absolute_url(base, as_str(v)) for k, v in value.items() if isinstance(v, str)
302
+ }
303
+
304
+ return RecipeBook(
305
+ recipes=[parse_recipe(r, base) for r in raw_recipes if isinstance(r, dict)],
306
+ filters=_parse_filters(payload.get("filters"), base),
307
+ aliases=aliases,
308
+ ingredient_notes=ingredient_notes,
309
+ buffs=buffs,
310
+ quality_colors=quality_colors,
311
+ assets=assets,
312
+ version=as_str(payload.get("version")),
313
+ )
@@ -0,0 +1,371 @@
1
+ """菜谱卡片。
2
+
3
+ 版式照站点详情页改:左边一张品质色菜图,右边菜名 / 编号 / 类型 / 等级,
4
+ 下面是食材、厨具、标签行,最后是获取途径与描述。
5
+ """
6
+
7
+ from __future__ import annotations
8
+
9
+ from typing import Dict, List, Optional, Tuple
10
+
11
+ from ...draw import (
12
+ BG_BOTTOM,
13
+ CREAM,
14
+ DIM,
15
+ FAINT,
16
+ LINE,
17
+ TILE_BG,
18
+ TYPE_CHIP_INK,
19
+ YELLOW,
20
+ Draw,
21
+ bold_text,
22
+ chip,
23
+ chip_row,
24
+ draw_paragraph,
25
+ finish,
26
+ fit_text,
27
+ icon_disc,
28
+ open_image,
29
+ require_pillow,
30
+ resize,
31
+ resolve_fontset,
32
+ text_width,
33
+ )
34
+ from ...fonts import FontSet
35
+ from ...values import grade_text
36
+ from .data import Ingredient, Recipe, RecipeBook
37
+
38
+ QUALITY_PREFIX = {
39
+ "S": ("金色", (198, 158, 58)),
40
+ "A": ("紫色", (156, 134, 162)),
41
+ }
42
+ TIER_NUM = {"一阶": "1", "二阶": "2", "三阶": "3"}
43
+
44
+
45
+ def hex_to_rgb(value: str, default: Tuple[int, int, int] = (156, 194, 194)) -> Tuple[int, int, int]:
46
+ text = (value or "").lstrip("#")
47
+ if len(text) == 3:
48
+ text = "".join(ch * 2 for ch in text)
49
+ if len(text) != 6:
50
+ return default
51
+ try:
52
+ return tuple(int(text[i : i + 2], 16) for i in (0, 2, 4)) # type: ignore[return-value]
53
+ except ValueError:
54
+ return default
55
+
56
+
57
+ def mix(color: Tuple[int, int, int], other: Tuple[int, int, int], ratio: float) -> Tuple[int, int, int]:
58
+ return tuple(int(a + (b - a) * ratio) for a, b in zip(color, other)) # type: ignore[return-value]
59
+
60
+
61
+ def _section_title(draw: Draw, x: int, y: int, text: str, fonts: FontSet) -> int:
62
+ bold_text(draw, (x, y), text, fonts.get(20, True), fonts, fill=YELLOW)
63
+ return y + 34
64
+
65
+
66
+ def _draw_ingredient_row(
67
+ canvas,
68
+ draw: Draw,
69
+ ingredient: Ingredient,
70
+ x: int,
71
+ y: int,
72
+ images: Dict[str, Optional[bytes]],
73
+ fonts: FontSet,
74
+ slot_colors: Dict[str, Tuple[int, int, int]],
75
+ row_height: int = 52,
76
+ ) -> None:
77
+ radius = 22
78
+ cy = y + row_height // 2
79
+ label_x = x + radius * 2 + 16
80
+
81
+ if ingredient.is_pair:
82
+ icons = [
83
+ open_image(images.get(url), "食材图标") for url in ingredient.icons[:2]
84
+ ]
85
+ pill_w, pill_h = 92, 46
86
+ draw.rounded_rectangle(
87
+ [x, cy - pill_h // 2, x + pill_w, cy + pill_h // 2],
88
+ pill_h // 2,
89
+ fill=slot_colors.get(ingredient.quality, TILE_BG),
90
+ outline=(120, 130, 160),
91
+ width=2,
92
+ )
93
+ for index, icon in enumerate(icons):
94
+ cx = x + 24 + index * 44
95
+ if icon is not None:
96
+ scale = 34 / max(1, max(icon.width, icon.height))
97
+ scaled = resize(
98
+ icon, (max(1, round(icon.width * scale)), max(1, round(icon.height * scale)))
99
+ )
100
+ canvas.alpha_composite(
101
+ scaled, (round(cx - scaled.width / 2), round(cy - scaled.height / 2))
102
+ )
103
+ draw.text((x + 46, cy), "/", font=fonts.get(18, True), fill=DIM, anchor="mm")
104
+ label_x = x + pill_w + 16
105
+ else:
106
+ icon = open_image(images.get(ingredient.icons[0]) if ingredient.icons else None, "食材图标")
107
+ icon_disc(
108
+ canvas,
109
+ draw,
110
+ icon,
111
+ x + radius,
112
+ cy,
113
+ radius,
114
+ ring=(110, 125, 160),
115
+ fill=slot_colors.get(ingredient.quality, TILE_BG),
116
+ placeholder="?",
117
+ font=fonts.get(20, True),
118
+ placeholder_fill=CREAM,
119
+ )
120
+
121
+ prefix = QUALITY_PREFIX.get(ingredient.quality)
122
+ cursor_x = label_x
123
+ label = ingredient.label
124
+ if prefix and not ingredient.placeholder:
125
+ word, color = prefix
126
+ draw.text((cursor_x, cy), word, font=fonts.get(18), fill=color, anchor="lm")
127
+ cursor_x += text_width(draw, word, fonts.get(18)) + 2
128
+ label = "品质" + label
129
+ draw.text(
130
+ (cursor_x, cy),
131
+ fit_text(draw, label, fonts.get(18), canvas.width - cursor_x - 40),
132
+ font=fonts.get(18),
133
+ fill=CREAM if not ingredient.placeholder else DIM,
134
+ anchor="lm",
135
+ )
136
+
137
+
138
+ def render_recipe_card(
139
+ book: RecipeBook,
140
+ recipe: Recipe,
141
+ images: Dict[str, Optional[bytes]],
142
+ *,
143
+ fonts: Optional[FontSet] = None,
144
+ width: int = 1000,
145
+ unlocked: bool = False,
146
+ ) -> bytes:
147
+ require_pillow()
148
+ font_set = resolve_fontset(fonts)
149
+
150
+ from PIL import Image, ImageDraw
151
+
152
+ pad = 36
153
+ art = 190
154
+ quality = hex_to_rgb(recipe.panel_color, (156, 194, 194))
155
+
156
+ ingredient_rows = 0 if recipe.is_miracle else len(recipe.ingredients)
157
+ estimate = pad + art + 30 + 40 + ingredient_rows * 52 + 60 + 120 + 300 + 200
158
+ content = Image.new("RGBA", (width, estimate), (0, 0, 0, 0))
159
+ draw = ImageDraw.Draw(content)
160
+
161
+ # ---- 左侧菜图
162
+ draw.rounded_rectangle(
163
+ [pad, pad, pad + art, pad + art],
164
+ 18,
165
+ fill=mix(quality, BG_BOTTOM, 0.78),
166
+ outline=quality,
167
+ width=3,
168
+ )
169
+ dish = open_image(images.get(recipe.dish) if recipe.dish else None, "菜品图")
170
+ if dish is not None:
171
+ box = art - 34
172
+ scale = min(box / dish.width, box / dish.height)
173
+ dish = resize(dish, (max(1, round(dish.width * scale)), max(1, round(dish.height * scale))))
174
+ content.alpha_composite(
175
+ dish, (pad + (art - dish.width) // 2, pad + (art - dish.height) // 2)
176
+ )
177
+ else:
178
+ draw.text(
179
+ (pad + art / 2, pad + art / 2),
180
+ "???" if recipe.incomplete else "菜",
181
+ font=font_set.get(40, True),
182
+ fill=DIM,
183
+ anchor="mm",
184
+ )
185
+
186
+ if unlocked:
187
+ chip(
188
+ draw,
189
+ pad + 12,
190
+ pad + art - 42,
191
+ "已解锁",
192
+ font_set.get(14, True),
193
+ fill=(76, 175, 98),
194
+ ink=(255, 255, 255),
195
+ pad_x=12,
196
+ height=26,
197
+ radius=13,
198
+ )
199
+
200
+ avatar = open_image(images.get(recipe.neighbor.icon) if recipe.neighbor else None, "友邻头像")
201
+ if avatar is not None:
202
+ cx, cy, r = pad + art - 8, pad + art - 8, 26
203
+ disc = Image.new("RGBA", (r * 2, r * 2), (0, 0, 0, 0))
204
+ mask = Image.new("L", (r * 2, r * 2), 0)
205
+ ImageDraw.Draw(mask).ellipse([0, 0, r * 2 - 1, r * 2 - 1], fill=255)
206
+ scaled = resize(avatar, (r * 2, r * 2))
207
+ scaled.putalpha(mask)
208
+ disc.alpha_composite(scaled)
209
+ content.alpha_composite(disc, (cx - r, cy - r))
210
+ draw.ellipse([cx - r, cy - r, cx + r, cy + r], outline=quality, width=2)
211
+
212
+ # ---- 右侧头部
213
+ text_x = pad + art + 26
214
+ name_font = font_set.get(38, True)
215
+ name = fit_text(draw, recipe.display_name, name_font, width - text_x - pad - 90)
216
+ bold_text(draw, (text_x, pad), name, name_font, font_set)
217
+ draw.text(
218
+ (width - pad, pad + 12),
219
+ f"#{recipe.number_text}",
220
+ font=font_set.get(17),
221
+ fill=DIM,
222
+ anchor="rt",
223
+ )
224
+
225
+ cursor = pad + 54
226
+ chips: List[Tuple[str, Tuple[int, int, int], Tuple[int, int, int]]] = []
227
+ if recipe.type:
228
+ chips.append((recipe.type, quality, TYPE_CHIP_INK))
229
+ if recipe.is_miracle and recipe.miracle_label and recipe.miracle_label != recipe.type:
230
+ chips.append((recipe.miracle_label, (246, 204, 82), TYPE_CHIP_INK))
231
+ if chips:
232
+ chip_row(draw, text_x, cursor, chips, font_set.get(15, True), width - text_x - pad, height=28, line_gap=34)
233
+ cursor += 40
234
+
235
+ meta_parts: List[str] = []
236
+ if recipe.quality:
237
+ meta_parts.append(f"{grade_text(recipe.quality)}品质")
238
+ if recipe.level_text:
239
+ meta_parts.append(recipe.level_text)
240
+ if recipe.strength is not None:
241
+ meta_parts.append(f"力气 +{recipe.strength}")
242
+ if recipe.cuisine:
243
+ meta_parts.append(recipe.cuisine)
244
+ draw.text(
245
+ (text_x, cursor),
246
+ fit_text(draw, " · ".join(meta_parts), font_set.get(17), width - text_x - pad),
247
+ font=font_set.get(17),
248
+ fill=DIM,
249
+ )
250
+
251
+ # ---- 分隔线
252
+ cursor = pad + art + 22
253
+ draw.line([(pad, cursor), (width - pad, cursor)], fill=LINE, width=1)
254
+ cursor += 24
255
+
256
+ # ---- 食材
257
+ if recipe.is_miracle:
258
+ draw.text(
259
+ (pad, cursor),
260
+ "奇迹盛宴:不消耗食材,也不需要用厨具。",
261
+ font=font_set.get(17),
262
+ fill=DIM,
263
+ )
264
+ cursor += 36
265
+ elif recipe.ingredients:
266
+ cursor = _section_title(draw, pad, cursor, "食材", font_set)
267
+ slot_colors = {key: hex_to_rgb(value, TILE_BG) for key, value in book.quality_colors.items()}
268
+ for ingredient in recipe.ingredients:
269
+ _draw_ingredient_row(
270
+ content, draw, ingredient, pad, cursor, images, font_set, slot_colors
271
+ )
272
+ cursor += 52
273
+ cursor += 8
274
+
275
+ # ---- 厨具
276
+ if recipe.kitchen is not None:
277
+ kitchen = recipe.kitchen
278
+ radius = 22
279
+ cy = cursor + 26
280
+ icon = open_image(images.get(kitchen.icon) if kitchen.icon else None, "厨具图标")
281
+ icon_disc(
282
+ content,
283
+ draw,
284
+ icon,
285
+ pad + radius,
286
+ cy,
287
+ radius,
288
+ ring=(110, 125, 160),
289
+ fill=TILE_BG,
290
+ placeholder="?",
291
+ font=font_set.get(20, True),
292
+ placeholder_fill=DIM,
293
+ )
294
+ draw.text((pad + radius * 2 + 16, cy), "厨具", font=font_set.get(16), fill=FAINT, anchor="lm")
295
+ draw.text(
296
+ (pad + radius * 2 + 16 + text_width(draw, "厨具", font_set.get(16)) + 10, cy),
297
+ kitchen.name,
298
+ font=font_set.get(19, True),
299
+ fill=CREAM if kitchen.specified else DIM,
300
+ anchor="lm",
301
+ )
302
+ cursor += 56
303
+
304
+ # ---- 标签行
305
+ tags: List[Tuple[str, Tuple[int, int, int], Tuple[int, int, int]]] = []
306
+ if recipe.buff is not None:
307
+ tags.append((recipe.buff.label, (86, 130, 90), (255, 255, 255)))
308
+ if recipe.strength is not None:
309
+ tags.append((f"力气 +{recipe.strength}", (52, 62, 96), CREAM))
310
+ for tag in recipe.food_tags:
311
+ tags.append((tag, (52, 62, 96), CREAM))
312
+ if recipe.cuisine:
313
+ tags.append((recipe.cuisine, (70, 58, 92), CREAM))
314
+ if tags:
315
+ used = chip_row(
316
+ draw,
317
+ pad,
318
+ cursor,
319
+ tags,
320
+ font_set.get(15),
321
+ width - pad * 2,
322
+ height=32,
323
+ line_gap=40,
324
+ )
325
+ cursor += used + 18
326
+
327
+ # ---- 描述
328
+ if recipe.description:
329
+ cursor += draw_paragraph(
330
+ draw,
331
+ recipe.description,
332
+ font_set.get(17),
333
+ pad,
334
+ cursor,
335
+ width - pad * 2,
336
+ line_height=27,
337
+ fill=(206, 212, 226),
338
+ max_lines=8,
339
+ )
340
+ cursor += 10
341
+
342
+ # ---- 获取途径
343
+ for source in recipe.sources:
344
+ cursor += draw_paragraph(
345
+ draw,
346
+ f"获取途径:{source}",
347
+ font_set.get(15),
348
+ pad,
349
+ cursor,
350
+ width - pad * 2,
351
+ line_height=23,
352
+ fill=FAINT,
353
+ max_lines=3,
354
+ )
355
+ cursor += 4
356
+
357
+ if recipe.incomplete_notice:
358
+ cursor += draw_paragraph(
359
+ draw,
360
+ recipe.incomplete_notice,
361
+ font_set.get(15),
362
+ pad,
363
+ cursor,
364
+ width - pad * 2,
365
+ line_height=23,
366
+ fill=(226, 182, 92),
367
+ max_lines=2,
368
+ )
369
+
370
+ right = f"#{recipe.number_text}" + (f" · {recipe.type}" if recipe.type else "")
371
+ return finish(content, width, fonts=font_set, pad=pad, right_text=right)