类式插件的数据文件
ToolDelta 类式插件为生成数据文件路径提供了一些实用方法。
以下的方法均为 Plugin 类中的函数。
生成此插件的数据文件文件夹
python
def make_data_path()
1
- 根据该插件主类的
name: str
生成数据文件的文件夹。 - 例如:
name = "test"
,则会创建插件数据文件/test/
文件夹。 - 示例:
python
class MyPlugin(Plugin):
name = "我的插件"
def __init__(self):
# 创建 `插件数据文件/我的插件/` 文件夹
self.make_data_path()
1
2
3
4
5
6
2
3
4
5
6
获取该插件的数据文件文件夹路径
python
data_path: str
1
- 等价于
os.path.join("插件数据文件", self.name)
- 在获取
data_path
时,会自动创建数据文件夹。 - 示例:
python
class MyPlugin(Plugin):
name = "我的插件"
def __init__(self):
print(self.data_path)
# 插件数据文件/我的插件
1
2
3
4
5
6
2
3
4
5
6
获取格式化的数据文件路径
python
def format_data_path(*path: str) -> str
1
- 等价于
os.path.join(self.data_path, *path)
- 示例:
python
class MyPlugin(Plugin):
name = "我的插件"
def __init__(self):
# 会生成 "插件数据文件/我的插件/商店.json"
path1 = self.format_data_path("商店.json")
# 会生成 "插件数据文件/我的插件/玩家数据/Steve.json"
path2 = self.format_data_path("玩家数据", "Steve.json")
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8