⚡️ 优化我的农场资源图片
@ -8,6 +8,7 @@ from nonebot_plugin_uninfo import Uninfo
|
|||||||
from nonebot_plugin_waiter import waiter
|
from nonebot_plugin_waiter import waiter
|
||||||
|
|
||||||
from zhenxun.services.log import logger
|
from zhenxun.services.log import logger
|
||||||
|
from zhenxun.utils.depends import UserName
|
||||||
from zhenxun.utils.message import MessageUtils
|
from zhenxun.utils.message import MessageUtils
|
||||||
|
|
||||||
from .database import g_pSqlManager
|
from .database import g_pSqlManager
|
||||||
@ -68,13 +69,13 @@ diuse_farm = on_alconna(
|
|||||||
)
|
)
|
||||||
|
|
||||||
@diuse_farm.assign("$main")
|
@diuse_farm.assign("$main")
|
||||||
async def _(session: Uninfo):
|
async def _(session: Uninfo, nickname: str = UserName()):
|
||||||
uid = str(session.user.id)
|
uid = str(session.user.id)
|
||||||
|
|
||||||
if await isRegisteredByUid(uid) == False:
|
if await isRegisteredByUid(uid) == False:
|
||||||
return
|
return
|
||||||
|
|
||||||
image = await g_pFarmManager.drawFarmByUid(uid)
|
image = await g_pFarmManager.drawFarmByUid(uid, nickname)
|
||||||
await MessageUtils.build_message(image).send(reply_to=True)
|
await MessageUtils.build_message(image).send(reply_to=True)
|
||||||
|
|
||||||
diuse_farm.shortcut(
|
diuse_farm.shortcut(
|
||||||
|
|||||||
56
farm/farm.py
@ -13,6 +13,7 @@ from zhenxun.services.log import logger
|
|||||||
from zhenxun.utils._build_image import BuildImage
|
from zhenxun.utils._build_image import BuildImage
|
||||||
from zhenxun.utils.enum import GoldHandle
|
from zhenxun.utils.enum import GoldHandle
|
||||||
from zhenxun.utils.image_utils import ImageTemplate
|
from zhenxun.utils.image_utils import ImageTemplate
|
||||||
|
from zhenxun.utils.platform import PlatformUtils
|
||||||
|
|
||||||
from ..config import g_pJsonManager, g_sResourcePath
|
from ..config import g_pJsonManager, g_sResourcePath
|
||||||
from ..database import g_pSqlManager
|
from ..database import g_pSqlManager
|
||||||
@ -50,7 +51,7 @@ class CFarmManager:
|
|||||||
return f"充值{point}农场币成功,手续费{tax}金币,当前农场币:{number}"
|
return f"充值{point}农场币成功,手续费{tax}金币,当前农场币:{number}"
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
async def drawFarmByUid(cls, uid: str) -> bytes:
|
async def drawFarmByUid(cls, uid: str, name: str) -> bytes:
|
||||||
"""绘制用户农场
|
"""绘制用户农场
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@ -59,7 +60,7 @@ class CFarmManager:
|
|||||||
Returns:
|
Returns:
|
||||||
bytes: 返回绘制结果
|
bytes: 返回绘制结果
|
||||||
"""
|
"""
|
||||||
img = BuildImage(background = g_sResourcePath / "background/background.png")
|
img = BuildImage(background = g_sResourcePath / "background/background.jpg")
|
||||||
|
|
||||||
soilSize = g_pJsonManager.m_pSoil['size']
|
soilSize = g_pJsonManager.m_pSoil['size']
|
||||||
|
|
||||||
@ -113,34 +114,31 @@ class CFarmManager:
|
|||||||
await img.paste(expansion, (x + soilSize[0] // 2 - expansion.width // 2,
|
await img.paste(expansion, (x + soilSize[0] // 2 - expansion.width // 2,
|
||||||
y + soilSize[1] // 2 - expansion.height))
|
y + soilSize[1] // 2 - expansion.height))
|
||||||
|
|
||||||
#绘制背景信息
|
|
||||||
#小屋
|
|
||||||
hut = BuildImage(background = g_sResourcePath / "background/hut.png")
|
|
||||||
await hut.resize(0, 600, 661)
|
|
||||||
await img.paste(hut, (1700, 100))
|
|
||||||
|
|
||||||
#犬舍
|
|
||||||
kennel = BuildImage(background = g_sResourcePath / "background/kennel.png")
|
|
||||||
await img.paste(kennel, (300, 750))
|
|
||||||
|
|
||||||
#交易
|
|
||||||
trade = BuildImage(background = g_sResourcePath / "background/trade.png")
|
|
||||||
await img.paste(trade, (555, 510))
|
|
||||||
|
|
||||||
#魔法
|
|
||||||
magic = BuildImage(background = g_sResourcePath / "background/magic.png")
|
|
||||||
await img.paste(magic, (850, 450))
|
|
||||||
|
|
||||||
#信箱
|
|
||||||
mailbox = BuildImage(background = g_sResourcePath / "background/mailbox.png")
|
|
||||||
await img.paste(mailbox, (800, 550))
|
|
||||||
|
|
||||||
#渔场
|
|
||||||
fisheries = BuildImage(background = g_sResourcePath / "background/fisheries.png")
|
|
||||||
await img.paste(fisheries, (1120, 1000))
|
|
||||||
|
|
||||||
#左上角绘制用户信息
|
#左上角绘制用户信息
|
||||||
await img.resize(0.5)
|
#头像
|
||||||
|
image = await PlatformUtils.get_user_avatar(uid, "qq")
|
||||||
|
|
||||||
|
if image:
|
||||||
|
avatar = BuildImage(background = image)
|
||||||
|
|
||||||
|
await img.paste(avatar, (125, 85))
|
||||||
|
|
||||||
|
#头像框
|
||||||
|
frame = BuildImage(background = g_sResourcePath / "background/frame.png")
|
||||||
|
await img.paste(frame, (75, 44))
|
||||||
|
|
||||||
|
#用户名
|
||||||
|
nameImg = await BuildImage.build_text_image(name)
|
||||||
|
await img.paste(nameImg, (300, 100))
|
||||||
|
|
||||||
|
#经验值
|
||||||
|
|
||||||
|
#金币
|
||||||
|
|
||||||
|
#点券
|
||||||
|
|
||||||
|
|
||||||
|
# await img.resize(0.4)
|
||||||
return img.pic2bytes()
|
return img.pic2bytes()
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|||||||
@ -1,6 +1,5 @@
|
|||||||
import math
|
import math
|
||||||
|
|
||||||
from Python311.Lib._pytest.mark.structures import istestfunc
|
|
||||||
from zhenxun.services.log import logger
|
from zhenxun.services.log import logger
|
||||||
from zhenxun.utils._build_image import BuildImage
|
from zhenxun.utils._build_image import BuildImage
|
||||||
from zhenxun.utils.image_utils import ImageTemplate
|
from zhenxun.utils.image_utils import ImageTemplate
|
||||||
|
|||||||
BIN
resource/background/background.jpg
Normal file
|
After Width: | Height: | Size: 797 KiB |
|
Before Width: | Height: | Size: 912 KiB After Width: | Height: | Size: 5.5 MiB |
|
Before Width: | Height: | Size: 160 KiB |
|
Before Width: | Height: | Size: 551 KiB |
|
Before Width: | Height: | Size: 46 KiB |
|
Before Width: | Height: | Size: 25 KiB |
|
Before Width: | Height: | Size: 100 KiB |
|
Before Width: | Height: | Size: 9.2 KiB |
|
Before Width: | Height: | Size: 49 KiB |