From 8ffca8ad03089350ea248cd43b87102a675c7b8a Mon Sep 17 00:00:00 2001 From: Zijian Zhang Date: Thu, 25 Jan 2024 17:25:59 +0800 Subject: [PATCH] style: format all code --- src/api/BlockAPI.cpp | 3 ++- src/api/CommandAPI.h | 8 ++++---- src/api/EntityAPI.cpp | 9 ++++++--- src/api/FileSystemAPI.cpp | 4 ++-- src/api/ItemAPI.cpp | 3 ++- src/api/NetworkAPI.cpp | 26 +++++++++++++------------- src/api/ParticleAPI.cpp | 8 ++++---- src/api/SimulatedPlayerAPI.cpp | 30 +++++++++++++++--------------- src/engine/OperationCount.h | 2 +- src/legacyapi/Base64.h | 4 ++-- src/legacyapi/db/ConnParams.cpp | 18 +++++++++--------- src/main/PythonHelper.cpp | 19 ++++++++++--------- src/utils/Utils.cpp | 3 ++- 13 files changed, 72 insertions(+), 65 deletions(-) diff --git a/src/api/BlockAPI.cpp b/src/api/BlockAPI.cpp index df665f12..3bc64835 100644 --- a/src/api/BlockAPI.cpp +++ b/src/api/BlockAPI.cpp @@ -576,7 +576,8 @@ Local McClass::spawnParticle(const Arguments& args) { args[0].asNumber().toFloat(), args[1].asNumber().toFloat(), args[2].asNumber().toFloat(), - args[3].toInt()}; + args[3].toInt() + }; type = args[4]; } else { LOG_WRONG_ARGS_COUNT(); diff --git a/src/api/CommandAPI.h b/src/api/CommandAPI.h index cf8b3d34..04575cbd 100644 --- a/src/api/CommandAPI.h +++ b/src/api/CommandAPI.h @@ -14,12 +14,12 @@ class CommandClass : public ScriptClass { bool registered = false; inline DynamicCommandInstance* get() { return ptr; } inline std::vector parseStringList(Local arr) { - if (arr.size() == 0 || !arr.get(0).isString()) return {}; + if (arr.size() == 0 || !arr.get(0).isString()) return {}; std::vector strs; - for (size_t i = 0; i < arr.size(); ++i) { - strs.push_back(arr.get(i).toStr()); + for (size_t i = 0; i < arr.size(); ++i) { + strs.push_back(arr.get(i).toStr()); } - return std::move(strs); + return std::move(strs); } inline Local getStringArray(std::vector values) { Local arr = Array::newArray(values.size()); diff --git a/src/api/EntityAPI.cpp b/src/api/EntityAPI.cpp index d2f55604..482cb5bc 100644 --- a/src/api/EntityAPI.cpp +++ b/src/api/EntityAPI.cpp @@ -1665,7 +1665,8 @@ Local McClass::cloneMob(const Arguments& args) { args[1].asNumber().toFloat(), args[2].asNumber().toFloat(), args[3].asNumber().toFloat(), - args[4].toInt()}; + args[4].toInt() + }; } else { LOG_WRONG_ARGS_COUNT(); return Local(); @@ -1726,7 +1727,8 @@ Local McClass::spawnMob(const Arguments& args) { args[1].asNumber().toFloat(), args[2].asNumber().toFloat(), args[3].asNumber().toFloat(), - args[4].toInt()}; + args[4].toInt() + }; } else { LOG_WRONG_ARGS_COUNT(); return Local(); @@ -1790,7 +1792,8 @@ Local McClass::explode(const Arguments& args) { args[0].asNumber().toFloat(), args[1].asNumber().toFloat(), args[2].asNumber().toFloat(), - args[3].toInt()}; + args[3].toInt() + }; } else { LOG_WRONG_ARGS_COUNT(); return Local(); diff --git a/src/api/FileSystemAPI.cpp b/src/api/FileSystemAPI.cpp index 6f82c9ff..43a5b5ee 100644 --- a/src/api/FileSystemAPI.cpp +++ b/src/api/FileSystemAPI.cpp @@ -137,7 +137,7 @@ FileClass* FileClass::constructor(const Arguments& args) { bool isBinary = false; if (args.size() >= 3 && args[2].asBoolean().value()) { - isBinary = true; + isBinary = true; mode |= std::ios_base::binary; } @@ -740,7 +740,7 @@ Local OpenFile(const Arguments& args) { bool isBinary = false; if (args.size() >= 3 && args[2].asBoolean().value()) { - isBinary = true; + isBinary = true; mode |= std::ios_base::binary; } diff --git a/src/api/ItemAPI.cpp b/src/api/ItemAPI.cpp index 67f14e13..a6b9aea0 100644 --- a/src/api/ItemAPI.cpp +++ b/src/api/ItemAPI.cpp @@ -482,7 +482,8 @@ Local McClass::spawnItem(const Arguments& args) { args[1].asNumber().toFloat(), args[2].asNumber().toFloat(), args[3].asNumber().toFloat(), - args[4].toInt()}; + args[4].toInt() + }; } else { LOG_WRONG_ARGS_COUNT(); return Local(); diff --git a/src/api/NetworkAPI.cpp b/src/api/NetworkAPI.cpp index add66641..0906c895 100644 --- a/src/api/NetworkAPI.cpp +++ b/src/api/NetworkAPI.cpp @@ -116,16 +116,15 @@ void WSClientClass::initListeners() { } }); - ws->OnBinaryReceived( - [nowList{&listeners[int(WSClientEvents::onBinaryReceived)]}](WebSocketClient& client, vector data) { - if (!nowList->empty()) - for (auto& listener : *nowList) { - if (!EngineManager::isValid(listener.engine)) return; - EngineScope enter(listener.engine); - NewTimeout(listener.func.get(), {ByteBuffer::newByteBuffer(data.data(), data.size())}, 1); - } - } - ); + ws->OnBinaryReceived([nowList{&listeners[int(WSClientEvents::onBinaryReceived)] + }](WebSocketClient& client, vector data) { + if (!nowList->empty()) + for (auto& listener : *nowList) { + if (!EngineManager::isValid(listener.engine)) return; + EngineScope enter(listener.engine); + NewTimeout(listener.func.get(), {ByteBuffer::newByteBuffer(data.data(), data.size())}, 1); + } + }); ws->OnError([nowList{&listeners[int(WSClientEvents::onError)]}](WebSocketClient& client, string msg) { if (!nowList->empty()) @@ -136,8 +135,8 @@ void WSClientClass::initListeners() { } }); - ws->OnLostConnection([nowList{ - &listeners[int(WSClientEvents::onLostConnection)]}](WebSocketClient& client, int code) { + ws->OnLostConnection([nowList{&listeners[int(WSClientEvents::onLostConnection)] + }](WebSocketClient& client, int code) { if (!nowList->empty()) for (auto& listener : *nowList) { if (!EngineManager::isValid(listener.engine)) return; @@ -390,7 +389,8 @@ using namespace httplib; EngineScope::currentEngine(), \ script::Global{func}, \ HttpRequestType::method, \ - path} \ + path \ + } \ )); \ svr->##method##(path.c_str(), [this, engine = EngineScope::currentEngine()](const Request& req, Response& resp) { \ if ((ll::getServerStatus() != ll::ServerStatus::Running) || !EngineManager::isValid(engine) \ diff --git a/src/api/ParticleAPI.cpp b/src/api/ParticleAPI.cpp index 05532136..70ff5852 100644 --- a/src/api/ParticleAPI.cpp +++ b/src/api/ParticleAPI.cpp @@ -8,12 +8,12 @@ #define GETVEC3(v, d, u) \ if (IsInstanceOf(u)) { \ - auto pos2 = EngineScope::currentEngine()->getNativeInstance(u); \ - v = Vec3(pos2->x, pos2->y, pos2->z); \ + auto pos2 = EngineScope::currentEngine() -> getNativeInstance(u); \ + v = Vec3(pos2->x, pos2->y, pos2->z); \ v += 0.5f; \ - d = pos2->dim; \ + d = pos2->dim; \ } else if (IsInstanceOf(u)) { \ - auto pos2 = EngineScope::currentEngine()->getNativeInstance(u); \ + auto pos2 = EngineScope::currentEngine() -> getNativeInstance(u); \ v = Vec3(pos2->x, pos2->y, pos2->z); \ d = pos2->dim; \ } else { \ diff --git a/src/api/SimulatedPlayerAPI.cpp b/src/api/SimulatedPlayerAPI.cpp index 04f3fb4b..df12ff62 100644 --- a/src/api/SimulatedPlayerAPI.cpp +++ b/src/api/SimulatedPlayerAPI.cpp @@ -256,12 +256,12 @@ Local PlayerClass::simulateLocalMove(const Arguments& args) { float speed = 1.0f; size_t index = 0; if (IsInstanceOf(args[0])) { - auto pos = IntPos::extractPos(args[0]); - target = pos->getBlockPos(); + auto pos = IntPos::extractPos(args[0]); + target = pos->getBlockPos(); index += 1; } else if (IsInstanceOf(args[0])) { - auto pos = FloatPos::extractPos(args[0]); - target = pos->getVec3(); + auto pos = FloatPos::extractPos(args[0]); + target = pos->getVec3(); index += 1; } #ifdef ENABLE_NUMBERS_AS_POS @@ -270,7 +270,7 @@ Local PlayerClass::simulateLocalMove(const Arguments& args) { CHECK_ARG_TYPE(args[0], ValueKind::kNumber); CHECK_ARG_TYPE(args[1], ValueKind::kNumber); CHECK_ARG_TYPE(args[2], ValueKind::kNumber); - Vec3 pos = Vec3(args[0].asNumber().toFloat(), args[1].asNumber().toFloat(), args[2].asNumber().toFloat()); + Vec3 pos = Vec3(args[0].asNumber().toFloat(), args[1].asNumber().toFloat(), args[2].asNumber().toFloat()); index += 3; } #endif // ENABLE_NUMBERS_AS_POS @@ -300,12 +300,12 @@ Local PlayerClass::simulateWorldMove(const Arguments& args) { float speed = 1.0f; size_t index = 0; if (IsInstanceOf(args[0])) { - auto pos = IntPos::extractPos(args[0]); - target = pos->getBlockPos(); + auto pos = IntPos::extractPos(args[0]); + target = pos->getBlockPos(); index += 1; } else if (IsInstanceOf(args[0])) { - auto pos = FloatPos::extractPos(args[0]); - target = pos->getVec3(); + auto pos = FloatPos::extractPos(args[0]); + target = pos->getVec3(); index += 1; } #ifdef ENABLE_NUMBERS_AS_POS @@ -314,7 +314,7 @@ Local PlayerClass::simulateWorldMove(const Arguments& args) { CHECK_ARG_TYPE(args[0], ValueKind::kNumber); CHECK_ARG_TYPE(args[1], ValueKind::kNumber); CHECK_ARG_TYPE(args[2], ValueKind::kNumber); - Vec3 pos = Vec3(args[0].asNumber().toFloat(), args[1].asNumber().toFloat(), args[2].asNumber().toFloat()); + Vec3 pos = Vec3(args[0].asNumber().toFloat(), args[1].asNumber().toFloat(), args[2].asNumber().toFloat()); index += 3; } #endif // ENABLE_NUMBERS_AS_POS @@ -344,12 +344,12 @@ Local PlayerClass::simulateMoveTo(const Arguments& args) { float speed = 1.0f; size_t index = 0; if (IsInstanceOf(args[0])) { - auto pos = IntPos::extractPos(args[0]); - target = pos->getBlockPos(); + auto pos = IntPos::extractPos(args[0]); + target = pos->getBlockPos(); index += 1; } else if (IsInstanceOf(args[0])) { - auto pos = FloatPos::extractPos(args[0]); - target = pos->getVec3(); + auto pos = FloatPos::extractPos(args[0]); + target = pos->getVec3(); index += 1; } #ifdef ENABLE_NUMBERS_AS_POS @@ -358,7 +358,7 @@ Local PlayerClass::simulateMoveTo(const Arguments& args) { CHECK_ARG_TYPE(args[0], ValueKind::kNumber); CHECK_ARG_TYPE(args[1], ValueKind::kNumber); CHECK_ARG_TYPE(args[2], ValueKind::kNumber); - Vec3 pos = Vec3(args[0].asNumber().toFloat(), args[1].asNumber().toFloat(), args[2].asNumber().toFloat()); + Vec3 pos = Vec3(args[0].asNumber().toFloat(), args[1].asNumber().toFloat(), args[2].asNumber().toFloat()); index += 3; } #endif // ENABLE_NUMBERS_AS_POS diff --git a/src/engine/OperationCount.h b/src/engine/OperationCount.h index 4d212c34..4d70384b 100644 --- a/src/engine/OperationCount.h +++ b/src/engine/OperationCount.h @@ -11,7 +11,7 @@ class OperationCount { static OperationCount create(const string& name); static bool exists(const string& name); bool remove(); - operator bool() { return exists(name); } + operator bool() { return exists(name); } bool done(); inline bool finish() { return done(); } diff --git a/src/legacyapi/Base64.h b/src/legacyapi/Base64.h index 01894064..d372bdd4 100644 --- a/src/legacyapi/Base64.h +++ b/src/legacyapi/Base64.h @@ -40,7 +40,7 @@ inline size_t getDecodeLength(const std::string& in) { ++count; } input_size -= count; // remove padding size - count = 0; // reset padding counter + count = 0; // reset padding counter while (input_size % 4) { // redo padding input_size++; count++; @@ -65,7 +65,7 @@ inline std::string Encode(const std::string& text_input) { int j = -6; for (auto c : text_input) { - i = (i << 8) + static_cast(c); + i = (i << 8) + static_cast(c); j += 8; while (j >= 0) { result += _base64_table[(i >> j) & 0x3F]; diff --git a/src/legacyapi/db/ConnParams.cpp b/src/legacyapi/db/ConnParams.cpp index 1efc1ba4..22b0b9a8 100644 --- a/src/legacyapi/db/ConnParams.cpp +++ b/src/legacyapi/db/ConnParams.cpp @@ -79,15 +79,15 @@ URL ParseURL(const std::string& url) { extern ll::Logger dbLogger; void PrintURL(const URL& url) { - dbLogger.debug("Parsed URL"); - dbLogger.debug("scheme: {}", url.scheme); - dbLogger.debug("user: {}", url.user); - dbLogger.debug("password: {}", url.password); - dbLogger.debug("host: {}", url.host); - dbLogger.debug("port: {}", url.port); - dbLogger.debug("path: {}", url.path); - dbLogger.debug("query:"); - for (auto& pair : url.query) dbLogger.debug("- {}: {}", pair.first, pair.second); + dbLogger.debug("Parsed URL"); + dbLogger.debug("scheme: {}", url.scheme); + dbLogger.debug("user: {}", url.user); + dbLogger.debug("password: {}", url.password); + dbLogger.debug("host: {}", url.host); + dbLogger.debug("port: {}", url.port); + dbLogger.debug("path: {}", url.path); + dbLogger.debug("query:"); + for (auto& pair : url.query) dbLogger.debug("- {}: {}", pair.first, pair.second); dbLogger.debug("fragment: {}", url.fragment); } diff --git a/src/main/PythonHelper.cpp b/src/main/PythonHelper.cpp index 1cebf12f..06da3392 100644 --- a/src/main/PythonHelper.cpp +++ b/src/main/PythonHelper.cpp @@ -30,14 +30,15 @@ extern bool isInConsoleDebugMode; extern ScriptEngine* debugEngine; struct PyConfig; -typedef PyObject* (*create_stdio_func_type -)(const PyConfig* config, - PyObject* io, - int fd, - int write_mode, - const char* name, - const wchar_t* encoding, - const wchar_t* errors); +typedef PyObject* (*create_stdio_func_type)( + const PyConfig* config, + PyObject* io, + int fd, + int write_mode, + const char* name, + const wchar_t* encoding, + const wchar_t* errors +); namespace PythonHelper { @@ -305,7 +306,7 @@ std::string getPluginPackDependencyFilePath(const std::string& dirPath) { if (projectNode["dependencies"]) { toml::array* arr = projectNode["dependencies"].as_array(); arr->for_each([&dependsAdded](toml::value& elem) { - std::optional depend = *elem; + std::optional depend = *elem; dependsAdded += "\n" + *depend; }); } diff --git a/src/utils/Utils.cpp b/src/utils/Utils.cpp index acffb4d4..c344fdaa 100644 --- a/src/utils/Utils.cpp +++ b/src/utils/Utils.cpp @@ -74,7 +74,8 @@ unsigned long long GetCurrentTimeStampMS() { currentTime.wHour, currentTime.wDay, currentTime.wMonth - 1, - currentTime.wYear - 1900}; + currentTime.wYear - 1900 + }; unsigned long long nNow = mktime(&currTm) * 1000 + currentTime.wMilliseconds; return nNow;