📝 迁移部分代码结构,使文件名和代码功能更加匹配

This commit is contained in:
Art_Sakura 2025-05-07 17:04:08 +08:00
parent 8243a1e1c8
commit 0cd9b9d8db
9 changed files with 140 additions and 115 deletions

View File

@ -9,6 +9,8 @@
方法一(推荐):在小真寻后台的插件商店下载即可<br>
方法二:下载源码放在小真寻`plugin`目录下
---
## 使用指令
| 指令 | 描述 | Tip |
@ -25,17 +27,21 @@
| 出售作物 [作物名称] [数量] | 从仓库里向系统售卖作物 | 不填写作物名将售卖仓库种全部作物 填作物名不填数量将指定作物全部出售 |
| @美波理 偷菜 | 偷别人的菜 | 每人每天只能偷5次 |
| 购买农场币 | 将真寻金币兑换成农场币 | 兑换比例默认为1:2 手续费默认20% |
| 更改农场名 [新的农场名] | 改名 |
---
## 更新日志[详细](./log/log.md)
- 感谢[quanquan1014](https://github.com/quanquan1014)对农场名称中包含特殊字符的处理。
- 更正数据库写法但是会导致V1.0用户的作物和种子丢失
- 完善我的农场图片资源,现在会在左上角显示经验、等级、金币等详细信息了
- 完善出售作物逻辑,现在可以空置作物名称来一键出售全部作物了,也可以选择空置数量来一键出售仓库种指定作物
- 完善播种逻辑,现在可以空置数量来一键播种指定作物了
- 新增更改农场名指令
- 改进对土地开垦条件判断
## 更新日志[(详细)](./log/log.md)
用户方面
---
- 修复重大BUG该BUG会导致用户经验等级计算异常
- 修正种子价格,现在不会以单价的形式购买种子了,而是新增的种子价格
代码方面
---
- 彻底重构数据库但是不会像V1.1一样导致用户数据丢失
- 迁移部分代码结构,使文件名和代码功能更加匹配
- 加入事件机制采用类似Qt信号槽机制
---
## 待办事宜 `Todo` 列表

View File

@ -6,11 +6,11 @@ from zhenxun.services.log import logger
from zhenxun.utils.message import MessageUtils
from .command import diuse_farm, diuse_register, reclamation
from .config import g_pJsonManager
from .database.database import g_pSqlManager
from .dbService import g_pDBService
from .farm.farm import g_pFarmManager
from .farm.shop import g_pShopManager
from .json import g_pJsonManager
from .request import g_pRequestManager
__plugin_meta__ = PluginMetadata(

View File

@ -7,7 +7,6 @@ from nonebot_plugin_uninfo import Uninfo
from nonebot_plugin_waiter import waiter
from zhenxun.services.log import logger
from zhenxun.utils.depends import UserName
from zhenxun.utils.message import MessageUtils
from .dbService import g_pDBService

View File

@ -1,106 +1,8 @@
import json
from pathlib import Path
from zhenxun.configs.path_config import DATA_PATH
from zhenxun.services.log import logger
g_sDBPath = DATA_PATH / "farm_db"
g_sDBFilePath = DATA_PATH / "farm_db/farm.db"
g_sResourcePath = Path(__file__).resolve().parent / "resource"
class CJsonManager:
def __init__(self):
self.m_pItem = {}
self.m_pPlant = {}
self.m_pLevel = {}
self.m_pSoil = {}
async def init(self) -> bool:
if not await self.initItem():
return False
if not await self.initPlant():
return False
if not await self.initLevel():
return False
if not await self.initSoil():
return False
return True
async def initItem(self) -> bool:
current_file_path = Path(__file__)
try:
with open(
current_file_path.resolve().parent / "config/item.json",
encoding="utf-8",
) as file:
self.m_pItem = json.load(file)
return True
except FileNotFoundError:
logger.warning("item.json 打开失败")
return False
except json.JSONDecodeError as e:
logger.warning(f"item.json JSON格式错误: {e}")
return False
async def initPlant(self) -> bool:
current_file_path = Path(__file__)
try:
with open(
current_file_path.resolve().parent / "config/plant.json",
encoding="utf-8",
) as file:
self.m_pPlant = json.load(file)
return True
except FileNotFoundError:
logger.warning("plant.json 打开失败")
return False
except json.JSONDecodeError as e:
logger.warning(f"plant.json JSON格式错误: {e}")
return False
async def initLevel(self) -> bool:
current_file_path = Path(__file__)
try:
with open(
current_file_path.resolve().parent / "config/level.json",
encoding="utf-8",
) as file:
self.m_pLevel = json.load(file)
return True
except FileNotFoundError:
logger.warning("level.json 打开失败")
return False
except json.JSONDecodeError as e:
logger.warning(f"level.json JSON格式错误: {e}")
return False
async def initSoil(self) -> bool:
current_file_path = Path(__file__)
try:
with open(
current_file_path.resolve().parent / "config/soil.json",
encoding="utf-8",
) as file:
self.m_pSoil = json.load(file)
return True
except FileNotFoundError:
logger.warning("soil.json 打开失败")
return False
except json.JSONDecodeError as e:
logger.warning(f"soil.json JSON格式错误: {e}")
return False
g_pJsonManager = CJsonManager()

View File

@ -3,8 +3,8 @@ from typing import Optional
from zhenxun.services.log import logger
from ..config import g_pJsonManager
from ..dbService import g_pDBService
from ..json import g_pJsonManager
from .database import CSqlManager

View File

@ -13,9 +13,10 @@ from zhenxun.utils.enum import GoldHandle
from zhenxun.utils.image_utils import ImageTemplate
from zhenxun.utils.platform import PlatformUtils
from ..config import g_pJsonManager, g_sResourcePath
from ..config import g_sResourcePath
from ..dbService import g_pDBService
from ..event.event import g_pEventManager
from ..json import g_pJsonManager
class CFarmManager:

View File

@ -1,12 +1,12 @@
import math
from re import I
from zhenxun.services.log import logger
from zhenxun.utils._build_image import BuildImage
from zhenxun.utils.image_utils import ImageTemplate
from ..config import g_pJsonManager, g_sResourcePath
from ..config import g_sResourcePath
from ..dbService import g_pDBService
from ..json import g_pJsonManager
class CShopManager:

101
json.py Normal file
View File

@ -0,0 +1,101 @@
import json
from pathlib import Path
from zhenxun.services.log import logger
class CJsonManager:
def __init__(self):
self.m_pItem = {}
self.m_pPlant = {}
self.m_pLevel = {}
self.m_pSoil = {}
async def init(self) -> bool:
if not await self.initItem():
return False
if not await self.initPlant():
return False
if not await self.initLevel():
return False
if not await self.initSoil():
return False
return True
async def initItem(self) -> bool:
current_file_path = Path(__file__)
try:
with open(
current_file_path.resolve().parent / "config/item.json",
encoding="utf-8",
) as file:
self.m_pItem = json.load(file)
return True
except FileNotFoundError:
logger.warning("item.json 打开失败")
return False
except json.JSONDecodeError as e:
logger.warning(f"item.json JSON格式错误: {e}")
return False
async def initPlant(self) -> bool:
current_file_path = Path(__file__)
try:
with open(
current_file_path.resolve().parent / "config/plant.json",
encoding="utf-8",
) as file:
self.m_pPlant = json.load(file)
return True
except FileNotFoundError:
logger.warning("plant.json 打开失败")
return False
except json.JSONDecodeError as e:
logger.warning(f"plant.json JSON格式错误: {e}")
return False
async def initLevel(self) -> bool:
current_file_path = Path(__file__)
try:
with open(
current_file_path.resolve().parent / "config/level.json",
encoding="utf-8",
) as file:
self.m_pLevel = json.load(file)
return True
except FileNotFoundError:
logger.warning("level.json 打开失败")
return False
except json.JSONDecodeError as e:
logger.warning(f"level.json JSON格式错误: {e}")
return False
async def initSoil(self) -> bool:
current_file_path = Path(__file__)
try:
with open(
current_file_path.resolve().parent / "config/soil.json",
encoding="utf-8",
) as file:
self.m_pSoil = json.load(file)
return True
except FileNotFoundError:
logger.warning("soil.json 打开失败")
return False
except json.JSONDecodeError as e:
logger.warning(f"soil.json JSON格式错误: {e}")
return False
g_pJsonManager = CJsonManager()

View File

@ -1,15 +1,31 @@
# 真寻农场更新日志
## V1.1
## V1.2
用户方面
---
- 修复重大BUG该BUG会导致用户经验等级计算异常
- 修正种子价格,现在不会以单价的形式购买种子了,而是新增的种子价格
- 感谢[quanquan1014](https://github.com/quanquan1014)对农场名称中包含特殊字符的处理。
- 更正数据库写法但是会导致V1.0用户的作物和种子丢失
代码方面
---
- 彻底重构数据库但是不会像V1.1一样导致用户数据丢失
- 迁移部分代码结构,使文件名和代码功能更加匹配
- 加入事件机制采用类似Qt信号槽机制
## V1.1
用户方面
---
- 完善我的农场图片资源,现在会在左上角显示经验、等级、金币等详细信息了
- 完善出售作物逻辑,现在可以空置作物名称来一键出售全部作物了,也可以选择空置数量来一键出售仓库种指定作物
- 完善播种逻辑,现在可以空置数量来一键播种指定作物了
- 新增更改农场名指令
- 改进对土地开垦条件判断
代码方面
---
- 感谢[quanquan1014](https://github.com/quanquan1014)对农场名称中包含特殊字符的处理。
- 更正数据库写法但是会导致V1.0用户的作物和种子丢失
## V1.0
世界的起源。