Skip to content

Commit cb0cf4a

Browse files
committed
fix: fix block.name #130
fix: fix getAllPluginInfo #128
1 parent 2889266 commit cb0cf4a

File tree

4 files changed

+34
-29
lines changed

4 files changed

+34
-29
lines changed

docs/apis/ScriptAPI/Ll.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ Some interfaces related to loader operations are provided here.
4040
| ----------------- | ----------------------- | -------------------------------- |
4141
| plugin.name | Plugin name | `String` |
4242
| plugin.desc | Plugin description | `String` |
43+
| plugin.type | Plugin type | `String` |
4344
| plugin.version | Plugin version (array) | `Array<Integer,Integer,Integer>` |
4445
| plugin.versionStr | Plugin version (string) | `String` |
4546
| plugin.filePath | Path to plugin | `String` |

docs/apis/ScriptAPI/Ll.zh.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
| ----------------- | -------------------- | -------------------------------- |
4343
| plugin.name | 插件名称 | `String` |
4444
| plugin.desc | 插件描述 | `String` |
45+
| plugin.type | 插件类型 | `String` |
4546
| plugin.version | 插件版本(数组形式) | `Array<Integer,Integer,Integer>` |
4647
| plugin.versionStr | 插件版本 | `String` |
4748
| plugin.filePath | 插件路径 | `String` |

src/legacy/api/BlockAPI.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@ Block* BlockClass::extract(Local<Value> v) {
112112

113113
// member function
114114
void BlockClass::preloadData(BlockPos bp, int dim) {
115-
name = block->getName().getString(); // TODO
116-
type = block->getName().getString();
115+
name = block->buildDescriptionName();
116+
type = block->getTypeName();
117117
id = block->getBlockItemId();
118118
pos = {bp.x, bp.y, bp.z, dim};
119119
}

src/legacy/api/LlAPI.cpp

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -167,36 +167,39 @@ Local<Value> LlClass::requireVersion(const Arguments& args) { return Boolean::ne
167167
Local<Value> LlClass::getAllPluginInfo(const Arguments& args) {
168168
try {
169169
Local<Array> plugins = Array::newArray();
170-
lse::getPluginManager().forEachPlugin([&](std::string_view name, ll::plugin::Plugin& plugin) {
171-
// Create plugin object
172-
auto pluginObject = Object::newObject();
173-
174-
pluginObject.set("name", plugin.getManifest().name);
175-
if (plugin.getManifest().description.has_value()) {
176-
pluginObject.set("desc", plugin.getManifest().description.value());
177-
}
178-
179-
auto ver = Array::newArray();
180-
ver.add(Number::newNumber(plugin.getManifest().version->major));
181-
ver.add(Number::newNumber(plugin.getManifest().version->minor));
182-
ver.add(Number::newNumber(plugin.getManifest().version->patch));
183-
184-
pluginObject.set("version", ver);
185-
pluginObject.set("versionStr", plugin.getManifest().version->to_string());
186-
pluginObject.set("filePath", plugin.getManifest().entry);
170+
ll::plugin::PluginManagerRegistry::getInstance().forEachPluginWithType(
171+
[&](std::string_view type, std::string_view name, ll::plugin::Plugin& plugin) {
172+
// Create plugin object
173+
auto pluginObject = Object::newObject();
187174

188-
if (plugin.getManifest().extraInfo.has_value()) {
189-
auto others = Object::newObject();
190-
for (const auto& [k, v] : plugin.getManifest().extraInfo.value()) {
191-
others.set(k, v);
175+
pluginObject.set("name", plugin.getManifest().name);
176+
if (plugin.getManifest().description.has_value()) {
177+
pluginObject.set("desc", plugin.getManifest().description.value());
178+
}
179+
pluginObject.set("type", type);
180+
181+
auto ver = Array::newArray();
182+
ver.add(Number::newNumber(plugin.getManifest().version->major));
183+
ver.add(Number::newNumber(plugin.getManifest().version->minor));
184+
ver.add(Number::newNumber(plugin.getManifest().version->patch));
185+
186+
pluginObject.set("version", ver);
187+
pluginObject.set("versionStr", plugin.getManifest().version->to_string());
188+
pluginObject.set("filePath", plugin.getManifest().entry);
189+
190+
if (plugin.getManifest().extraInfo.has_value()) {
191+
auto others = Object::newObject();
192+
for (const auto& [k, v] : plugin.getManifest().extraInfo.value()) {
193+
others.set(k, v);
194+
}
195+
pluginObject.set("others", others);
192196
}
193-
pluginObject.set("others", others);
194-
}
195197

196-
// Add plugin object to list
197-
plugins.add(pluginObject);
198-
return true;
199-
});
198+
// Add plugin object to list
199+
plugins.add(pluginObject);
200+
return true;
201+
}
202+
);
200203
return plugins;
201204
}
202205
CATCH("Fail in LLAPI");

0 commit comments

Comments
 (0)