add # 新增开垦、升级土地功能

This commit is contained in:
2026-10-21 14:07:18 +08:00
parent e5bec1a2b6
commit 4a484bfde6
13 changed files with 709 additions and 33 deletions
+20 -20
View File
@@ -8282,46 +8282,46 @@
"x": 1352,
"y": 552
},
{
"x": 1462,
"y": 611
},
{
"x": 1572,
"y": 670
},
{
"x": 1682,
"y": 729
},
{
"x": 1792,
"y": 788
},
{
"x": 1902,
"y": 847
},
{
"x": 1237,
"y": 606
},
{
"x": 1462,
"y": 611
},
{
"x": 1350,
"y": 665
},
{
"x": 1572,
"y": 670
},
{
"x": 1457,
"y": 724
},
{
"x": 1682,
"y": 729
},
{
"x": 1567,
"y": 783
},
{
"x": 1792,
"y": 788
},
{
"x": 1677,
"y": 842
},
{
"x": 1902,
"y": 847
},
{
"x": 1787,
"y": 901
+4 -1
View File
@@ -14,8 +14,11 @@ class RenderOptions:
quality: int = 75 # 有损编码质量,不代表分辨率。
method: int = 2 # WebP 编码力度,0最快,6最慢。
theme: str = "default" # 显式主题,不读取隐含季节或全局配置。
show_plot_ids: bool = False # 编号图显示全部地块及开垦状态。
def __post_init__(self):
if type(self.show_plot_ids) is not bool:
raise ValueError("Invalid plot ID option")
for value, low, high in (
(self.width, 256, 3072), (self.quality, 1, 95),
(self.method, 0, 6),
@@ -48,7 +51,7 @@ class RenderOptions:
@dataclass(frozen=True)
class PlotView:
slot: int # 旧布局的1到30地块编号。
slot: int # 1到30地块编号,对应统一位置表的slot-1项。
state: str # empty/growing/ripe/withered。
sprite: str = "" # 包内受控素材名,不来自用户路径。
stage: int = 0 # 本季展示阶段。
+39
View File
@@ -70,6 +70,8 @@ class FarmRenderer:
self._pests(canvas, scene, options)
self._decorations(canvas, options, "foreground")
self._panel(canvas, scene, options, avatar)
if options.show_plot_ids:
self._plot_ids(canvas, scene, options)
composed = perf_counter()
content = canvas.encode(codec, options.quality, options.method)
encoded = perf_counter()
@@ -92,6 +94,43 @@ class FarmRenderer:
def _scale(value, options):
return round(value * options.width / 3072)
def _plot_ids(self, canvas, scene, options):
s = lambda n: self._scale(n, options)
owned = {plot.slot for plot in scene.plots}
soil_w, soil_h = self.assets.metadata['soil_size']
size = max(1, s(40))
for slot, pos in enumerate(self.assets.metadata['positions'], 1):
x = s(pos['x'] + soil_w/2)
y = s(pos['y'] + soil_h/2)
color = '#fff2ca' if slot in owned else '#d5e8bc'
canvas.rectangle(
(x-s(38), y-s(30), x+s(38), y+s(30)),
'#493b22', radius=s(30),
)
canvas.rectangle(
(x-s(36), y-s(28), x+s(36), y+s(28)),
color, radius=s(28),
)
label = str(slot)
width = canvas.measure_text(label, self.font_path, size)
box = font(self.font_path, size).getbbox(label)
canvas.text(
(round(x-width/2), round(y-(box[1]+box[3])/2)),
label, self.font_path, size, '#392917',
)
canvas.rectangle(
(s(76), s(1676), s(2996), s(1836)),
'#fff2ca', radius=s(24),
)
for y, text, text_size in (
(1694, '地块编号 · 浅色:已开垦 | 绿色:待开垦', 46),
(1760, '前两排交错编号,之后逐排推进。作物信息:农场详述', 40),
):
canvas.text(
(s(116), s(y)), text, self.font_path,
max(1, s(text_size)), '#392917',
)
def _base(self, scene, options):
slots = frozenset(p.slot for p in scene.plots)
key = ("base", options.theme, options.width, slots)