Skip to content

Commit 335a5f0

Browse files
committed
refactor: adapt to LeviLamina 1.0.0 (WIP)
1 parent 8fa5ba1 commit 335a5f0

File tree

18 files changed

+94
-97
lines changed

18 files changed

+94
-97
lines changed

docs/apis/ScriptAPI/i18n.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ As our community gets bigger and bigger, language becomes a barrier for users an
1111
- path: `String`
1212
The file[^1]/directory[^2] where the translation data is located
1313
- defaultLocaleName: `String`
14-
default locale name, in the form of `zh_CN` or `en` (this parameter will be used if the target language is not provided for the translation of `i18n.tr` or `i18n.get`)
14+
**This parameter is deprecated since 0.9.0, it will follows LeviLamina's language**. default locale name, in the form of `zh_CN` or `en` (this parameter will be used if the target language is not provided for the translation of `i18n.tr` or `i18n.get`)
1515
If an empty string is passed in, the default follows the system language
1616
- defaultLangData: `Object`
1717
This parameter will be used to complete or create translation files in the form of

docs/apis/ScriptAPI/i18n.zh.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
- path: `String`
1313
翻译数据所在的文件[^1]/目录[^2]
1414
- defaultLocaleName: `String`
15-
默认的语言名称,形如`zh_CN``en`(如果没有提供目标语言给`i18n.tr``i18n.get`的翻译,这个参数将被使用)
15+
**该参数在0.9.0中废弃,将使用LeviLamina的默认语言**默认的语言名称,形如`zh_CN``en`(如果没有提供目标语言给`i18n.tr``i18n.get`的翻译,这个参数将被使用)
1616
若传入空字符串,则默认跟随系统语言
1717
- defaultLangData: `Object`
1818
该参数将用于补全或创建翻译文件,形如

manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"type": "native",
55
"description": "A plugin engine for running LLSE plugins on LeviLamina",
66
"author": "LiteLDev",
7-
"version": "0.8.20",
7+
"version": "0.9.0-rc.1",
88
"dependencies": [
99
{
1010
"name": "LegacyMoney"

src/legacy/api/BlockAPI.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "mc/world/level/block/actor/BlockActor.h"
1919
#include "mc/world/level/block/components/BlockLiquidDetectionComponent.h"
2020
#include "mc/world/level/dimension/Dimension.h"
21+
#include "mc/world/level/block/block_serialization_utils/BlockSerializationUtils.h"
2122

2223
#include <exception>
2324

@@ -290,8 +291,6 @@ Local<Value> BlockClass::getNbt(const Arguments&) {
290291
CATCH("Fail in getNbt!");
291292
}
292293

293-
#include "mc/world/level/block/block_serialization_utils/BlockSerializationUtils.h"
294-
295294
Local<Value> BlockClass::setNbt(const Arguments& args) {
296295
CHECK_ARGS_COUNT(args, 1);
297296

src/legacy/api/EntityAPI.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -296,9 +296,7 @@ Local<Value> EntityClass::isOnHotBlock() {
296296
Actor* entity = get();
297297
if (!entity) return Local<Value>();
298298

299-
return Boolean::newBoolean(
300-
entity->getDimensionBlockSource().getBlock(entity->getFeetBlockPos()).getMaterial().isSuperHot()
301-
); // TODO: Unsure
299+
return Boolean::newBoolean(false); // todo: check IsOnHotBlockTest to get the correct value
302300
}
303301
CATCH("Fail in isOnHotBlock!")
304302
}

src/legacy/api/InternationalAPI.cpp

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -193,9 +193,10 @@ Local<Value> I18nClass::load(const Arguments& args) {
193193

194194
try {
195195
auto path = args[0].toStr();
196-
std::string defaultLocaleName;
196+
// Deprecated because it follows LeviLamina's default locale
197+
// std::string defaultLocaleName;
197198
if (args.size() > 1) {
198-
defaultLocaleName = args[1].toStr();
199+
// defaultLocaleName = args[1].toStr();
199200
}
200201

201202
if (args.size() > 2) {
@@ -216,22 +217,16 @@ Local<Value> I18nClass::load(const Arguments& args) {
216217
if (str.getKind() != ValueKind::kString) {
217218
throw Exception("Value in SubLangData must be a string");
218219
}
219-
ll::i18n::getInstance().set(localeName, objKeys[j].toString(), str.toStr());
220+
EngineOwnData().i18n->set(localeName, objKeys[j].toString(), str.toStr());
220221
}
221222
}
222223
}
223224

224-
auto& i18nInstance = ll::i18n::getInstance();
225-
auto result = i18nInstance.load(path);
226-
227-
if (result.has_value()) {
228-
if (!defaultLocaleName.empty()) {
229-
ll::i18n::getDefaultLocaleCode() = defaultLocaleName;
230-
}
231-
return Boolean::newBoolean(true);
225+
EngineOwnData().i18n = std::make_shared<ll::i18n::I18n>();;
226+
if (auto result = EngineOwnData().i18n->load(path); !result) {
227+
return Boolean::newBoolean(false);
232228
}
233-
234-
return Boolean::newBoolean(false);
229+
return Boolean::newBoolean(true);
235230
}
236231
CATCH_AND_THROW;
237232
}

src/legacy/engine/EngineOwnData.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ struct EngineOwnData {
7171
*/
7272

7373
// I18nAPI
74-
ll::i18n::I18n* i18n = nullptr;
74+
std::shared_ptr<ll::i18n::I18n> i18n = nullptr;
7575

7676
// 玩家绑定数据
7777
std::unordered_map<std::string, script::Global<Value>> playerDataDB;

src/legacy/legacyapi/db/Session.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "legacyapi/db/Session.h"
22

3+
#include "lse/Entry.h"
34
#include "legacyapi/db/impl/mysql/Session.h"
45
#include "legacyapi/db/impl/sqlite/Session.h"
56
#include "ll/api/io/LoggerRegistry.h"
@@ -26,12 +27,12 @@ ResultSet Session::query(const std::string& query) {
2627
});
2728
IF_ENDBG {
2829
if (result.valid()) {
29-
ll::io::LoggerRegistry::getInstance().getOrCreate("LLSEDB")->debug("Session::query: Results >");
30+
lse::getSelfPluginInstance().getLogger().debug("Session::query: Results >");
3031
for (auto& str : ll::string_utils::splitByPattern(result.toTableString(), "\n")) {
31-
ll::io::LoggerRegistry::getInstance().getOrCreate("LLSEDB")->debug(str);
32+
lse::getSelfPluginInstance().getLogger().debug(str);
3233
}
3334
} else {
34-
ll::io::LoggerRegistry::getInstance().getOrCreate("LLSEDB")->debug(
35+
lse::getSelfPluginInstance().getLogger().debug(
3536
"Session::query: Query returned no result"
3637
);
3738
}
@@ -43,7 +44,7 @@ std::string Session::getLastError() const { throw std::runtime_error("Session::g
4344

4445
std::weak_ptr<Session> Session::getOrSetSelf() {
4546
if (self.expired()) {
46-
IF_ENDBG ll::io::LoggerRegistry::getInstance().getOrCreate("LLSEDB")->debug(
47+
IF_ENDBG lse::getSelfPluginInstance().getLogger().debug(
4748
"Session::getOrSetSelf: `self` expired, trying fetching"
4849
);
4950
return self = getSession(this);

src/legacy/legacyapi/db/impl/mysql/Session.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// #include "lse/Entry.h"
12
// #include "legacyapi/db/impl/mysql/Session.h"
23

34
// #include "legacyapi/db/impl/mysql/Stmt.h"
@@ -7,16 +8,16 @@
78
// namespace DB {
89

910
// MySQLSession::MySQLSession() {
10-
// IF_ENDBG ll::io::LoggerRegistry::getInstance().getOrCreate("LLSEDB")->info("MySQLSession::MySQLSession:
11+
// IF_ENDBG lse::getSelfPluginInstance().getLogger().info("MySQLSession::MySQLSession:
1112
// Constructed! this: {}", (void*)this); conn = mysql_init(nullptr);
1213
// }
1314
// MySQLSession::MySQLSession(const ConnParams& params) {
14-
// IF_ENDBG ll::io::LoggerRegistry::getInstance().getOrCreate("LLSEDB")->info("MySQLSession::MySQLSession:
15+
// IF_ENDBG lse::getSelfPluginInstance().getLogger().info("MySQLSession::MySQLSession:
1516
// Constructed! this: {}", (void*)this); conn = mysql_init(nullptr); open(params);
1617
// }
1718

1819
// MySQLSession::~MySQLSession() {
19-
// IF_ENDBG ll::io::LoggerRegistry::getInstance().getOrCreate("LLSEDB")->info("MySQLSession::MySQLSession:
20+
// IF_ENDBG lse::getSelfPluginInstance().getLogger().info("MySQLSession::MySQLSession:
2021
// Destructor: this: {}", (void*)this); close();
2122
// }
2223

@@ -68,7 +69,7 @@
6869
// "true",
6970
// "utf8"
7071
// );
71-
// // IF_ENDBG ll::io::LoggerRegistry::getInstance().getOrCreate("LLSEDB")->debug("MySQLSession::open: MySQL default
72+
// // IF_ENDBG lse::getSelfPluginInstance().getLogger().debug("MySQLSession::open: MySQL default
7273
// charset name:
7374
// // {}", defaultCharset);
7475
// mysql_options(conn, MYSQL_SET_CHARSET_NAME, charset.c_str());
@@ -87,7 +88,7 @@
8788
// "MySQLSession::MySQLSession: Failed to open database: " + std::string(mysql_error(conn))
8889
// );
8990
// }
90-
// IF_ENDBG ll::io::LoggerRegistry::getInstance().getOrCreate("LLSEDB")->debug(
91+
// IF_ENDBG lse::getSelfPluginInstance().getLogger().debug(
9192
// "MySQLSession::open: Opened database: " + std::string(p.getHost()) + ":" + std::to_string(port) + "/" + db
9293
// );
9394
// #if defined(LLDB_DEBUG_MODE)
@@ -96,18 +97,18 @@
9697
// }
9798

9899
// bool MySQLSession::execute(const std::string& query) {
99-
// IF_ENDBG ll::io::LoggerRegistry::getInstance().getOrCreate("LLSEDB")->debug("MySQLSession::execute: Executing > "
100+
// IF_ENDBG lse::getSelfPluginInstance().getLogger().debug("MySQLSession::execute: Executing > "
100101
// + query); auto res = mysql_query(conn, query.c_str()); return res == OK;
101102
// }
102103

103104
// bool MySQLSession::relogin(const std::string& user, const std::string& password, const std::string& db) {
104-
// IF_ENDBG ll::io::LoggerRegistry::getInstance().getOrCreate("LLSEDB")->debug("MySQLSession::change: Changing user
105+
// IF_ENDBG lse::getSelfPluginInstance().getLogger().debug("MySQLSession::change: Changing user
105106
// to {} and database to {}", user, db); auto res = mysql_change_user(conn, user.c_str(), password.c_str(),
106107
// (db.empty() ? nullptr : db.c_str())); return res == OK;
107108
// }
108109

109110
// Session& MySQLSession::query(const std::string& query, std::function<bool(const Row&)> callback) {
110-
// IF_ENDBG ll::io::LoggerRegistry::getInstance().getOrCreate("LLSEDB")->debug("MySQLSession::query: Querying > " +
111+
// IF_ENDBG lse::getSelfPluginInstance().getLogger().debug("MySQLSession::query: Querying > " +
111112
// query); auto res = mysql_query(conn, query.c_str()); if (res != OK) {
112113
// throw std::runtime_error("MySQLSession::query: Failed to query database: " + std::string(mysql_error(conn)));
113114
// }
@@ -120,7 +121,7 @@
120121
// auto numFields = mysql_num_fields(result);
121122
// auto numRows = mysql_num_rows(result);
122123
// auto fields = mysql_fetch_fields(result);
123-
// IF_ENDBG ll::io::LoggerRegistry::getInstance().getOrCreate("LLSEDB")->debug("MySQLSession::query: Query returned
124+
// IF_ENDBG lse::getSelfPluginInstance().getLogger().debug("MySQLSession::query: Query returned
124125
// {} rows and {} fields", numRows, numFields);
125126
// // Fetch column names
126127
// RowHeader header;
@@ -204,7 +205,7 @@
204205
// if (conn) {
205206
// mysql_close(conn);
206207
// conn = nullptr;
207-
// IF_ENDBG ll::io::LoggerRegistry::getInstance().getOrCreate("LLSEDB")->debug("MySQLSession::close: Closed
208+
// IF_ENDBG lse::getSelfPluginInstance().getLogger().debug("MySQLSession::close: Closed
208209
// database");
209210
// }
210211
// }

src/legacy/legacyapi/db/impl/mysql/Stmt.cpp

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// #include "lse/Entry.h"
12
// #include "legacyapi/db/impl/mysql/Stmt.h"
23

34
// #include "legacyapi/db/impl/mysql/Session.h"
@@ -171,7 +172,7 @@
171172
// if (len) {
172173
// auto buffer = std::shared_ptr<char[]>(new char[len]);
173174
// #if defined(LLDB_DEBUG_MODE)
174-
// ll::io::LoggerRegistry::getInstance().getOrCreate("LLSEDB")->debug("AllocateBuffer: Allocated! Buffer size:
175+
// lse::getSelfPluginInstance().getLogger().debug("AllocateBuffer: Allocated! Buffer size:
175176
// {}", len);
176177
// #endif
177178
// return std::make_pair(buffer, len);
@@ -235,7 +236,7 @@
235236
// // case MYSQL_TYPE_GEOMETRY:
236237
// case MYSQL_TYPE_JSON:
237238
// #if defined(LLDB_DEBUG_MODE)
238-
// ll::io::LoggerRegistry::getInstance().getOrCreate("LLSEDB")->debug("ReceiverToAny: string: length: {}, buffer
239+
// lse::getSelfPluginInstance().getLogger().debug("ReceiverToAny: string: length: {}, buffer
239240
// {}", rec.length, rec.buffer.get());
240241
// #endif
241242
// return Any(std::string(rec.buffer.get()));
@@ -244,15 +245,15 @@
244245
// case MYSQL_TYPE_MEDIUM_BLOB:
245246
// case MYSQL_TYPE_LONG_BLOB:
246247
// #if defined(LLDB_DEBUG_MODE)
247-
// ll::io::LoggerRegistry::getInstance().getOrCreate("LLSEDB")->debug("ReceiverToAny: blob: length: {}, buffer
248+
// lse::getSelfPluginInstance().getLogger().debug("ReceiverToAny: blob: length: {}, buffer
248249
// {}", rec.length, rec.buffer.get());
249250
// #endif
250251
// // Unknown bug: rec.length is 0
251252
// return Any(ByteArray(rec.buffer.get(), rec.buffer.get() + rec.length));
252253
// case MYSQL_TYPE_DECIMAL:
253254
// case MYSQL_TYPE_NEWDECIMAL:
254255
// // TODO: Decimal
255-
// ll::io::LoggerRegistry::getInstance().getOrCreate("LLSEDB")->debug("MySQL_Decimal: {}",
256+
// lse::getSelfPluginInstance().getLogger().debug("MySQL_Decimal: {}",
256257
// std::string(rec.buffer.get(), rec.length)); return Any();
257258
// default:
258259
// throw std::runtime_error("ReceiverToAny: Unsupported MySQL data type: " + std::to_string(rec.field.type));
@@ -278,7 +279,7 @@
278279
// result++;
279280
// }
280281
// }
281-
// IF_ENDBG ll::io::LoggerRegistry::getInstance().getOrCreate("LLSEDB")->debug("MySQLStmt::getNextParamIndex: The
282+
// IF_ENDBG lse::getSelfPluginInstance().getLogger().debug("MySQLStmt::getNextParamIndex: The
282283
// next param index is {}", result + 1); return result + 1;
283284
// }
284285

@@ -290,7 +291,7 @@
290291
// );
291292
// }
292293
// if (!metadata) {
293-
// IF_ENDBG ll::io::LoggerRegistry::getInstance().getOrCreate("LLSEDB")->debug("MySQLStmt::bindResult: No result
294+
// IF_ENDBG lse::getSelfPluginInstance().getLogger().debug("MySQLStmt::bindResult: No result
294295
// metadata"); return;
295296
// }
296297
// // Set the attribute UPDATE_MAX_LENGTH to true
@@ -301,7 +302,7 @@
301302
// // later
302303
// mysql_stmt_store_result(stmt);
303304
// auto cnt = mysql_num_fields(metadata);
304-
// IF_ENDBG ll::io::LoggerRegistry::getInstance().getOrCreate("LLSEDB")->debug("MySQLStmt::bindResult:
305+
// IF_ENDBG lse::getSelfPluginInstance().getLogger().debug("MySQLStmt::bindResult:
305306
// mysql_num_fields: {}", cnt); auto fields = mysql_fetch_fields(metadata); result.reset(new MYSQL_BIND[cnt]);
306307
// // Allocate result bindings resultHeader.reset(new RowHeader); // Allocate result header for (auto i = 0U; i <
307308
// cnt; i++) {
@@ -398,7 +399,7 @@
398399
// params[index].buffer_length = sz;
399400
// params[index].is_null = 0;
400401
// params[index].length = (unsigned long*)&param.length;
401-
// IF_ENDBG ll::io::LoggerRegistry::getInstance().getOrCreate("LLSEDB")->debug("MySQLStmt::bind: Bound string
402+
// IF_ENDBG lse::getSelfPluginInstance().getLogger().debug("MySQLStmt::bind: Bound string
402403
// param at {}: {}", index, param.buffer.get()); break;
403404
// }
404405
// case Any::Type::Date:
@@ -490,17 +491,17 @@
490491
// if (fetched) {
491492
// throw std::runtime_error("MySQLStmt::_Fetch: No more rows");
492493
// }
493-
// IF_ENDBG ll::io::LoggerRegistry::getInstance().getOrCreate("LLSEDB")->debug("MySQLStmt::_Fetch: Fetching
494+
// IF_ENDBG lse::getSelfPluginInstance().getLogger().debug("MySQLStmt::_Fetch: Fetching
494495
// row..."); Row row(resultHeader); IF_ENDBG
495-
// ll::io::LoggerRegistry::getInstance().getOrCreate("LLSEDB")->debug("MySQLStmt::_Fetch: RowHeader size
496+
// lse::getSelfPluginInstance().getLogger().debug("MySQLStmt::_Fetch: RowHeader size
496497
// {}", row.header->size()); int i = 0; for (auto& col : resultValues) {
497498
// // Because of the inexplicable problems of MySQL C API,
498499
// // we must set the length of the field manually.
499500
// auto length = *(stmt->bind + i)->length;
500501
// col.length = length;
501502
// auto v = ReceiverToAny(col);
502503
// row.push_back(v);
503-
// IF_ENDBG ll::io::LoggerRegistry::getInstance().getOrCreate("LLSEDB")->debug(
504+
// IF_ENDBG lse::getSelfPluginInstance().getLogger().debug(
504505
// "MySQLStmt::_Fetch: Fetched column `{}`, type {}, value {}",
505506
// col.field.name,
506507
// Any::type2str(v.type),
@@ -590,11 +591,11 @@
590591
// auto query = sql;
591592
// auto params = ParseStmtParams(query);
592593
// if (raw->debugOutput && !params.empty()) {
593-
// ll::io::LoggerRegistry::getInstance().getOrCreate("LLSEDB")->debug("MySQLStmt::create: Parsed named
594+
// lse::getSelfPluginInstance().getLogger().debug("MySQLStmt::create: Parsed named
594595
// parameters in query: ");
595-
// ll::io::LoggerRegistry::getInstance().getOrCreate("LLSEDB")->debug("MySQLStmt::create: - SQL without named
596+
// lse::getSelfPluginInstance().getLogger().debug("MySQLStmt::create: - SQL without named
596597
// parameters: {}", query); for (auto& [k, v] : params) {
597-
// ll::io::LoggerRegistry::getInstance().getOrCreate("LLSEDB")->debug("MySQLStmt::create: - {}: {}", k, v);
598+
// lse::getSelfPluginInstance().getLogger().debug("MySQLStmt::create: - {}: {}", k, v);
598599
// }
599600
// }
600601
// auto res = mysql_stmt_prepare(stmt, query.c_str(), query.size());
@@ -605,7 +606,7 @@
605606
// result->query = sql;
606607
// result->paramIndexes = params;
607608
// result->setDebugOutput(raw->debugOutput);
608-
// if (raw->debugOutput) ll::io::LoggerRegistry::getInstance().getOrCreate("LLSEDB")->debug("MySQLStmt::create:
609+
// if (raw->debugOutput) lse::getSelfPluginInstance().getLogger().debug("MySQLStmt::create:
609610
// Prepared > " + query); auto shared = SharedPointer<Stmt>(result); result->self = shared; return shared;
610611
// }
611612

0 commit comments

Comments
 (0)