Skip to content

Commit

Permalink
style: format all code
Browse files Browse the repository at this point in the history
  • Loading branch information
futrime committed Jan 25, 2024
1 parent 3eb24b4 commit 8ffca8a
Show file tree
Hide file tree
Showing 13 changed files with 72 additions and 65 deletions.
3 changes: 2 additions & 1 deletion src/api/BlockAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,8 @@ Local<Value> 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();
Expand Down
8 changes: 4 additions & 4 deletions src/api/CommandAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ class CommandClass : public ScriptClass {
bool registered = false;
inline DynamicCommandInstance* get() { return ptr; }
inline std::vector<std::string> parseStringList(Local<Array> arr) {
if (arr.size() == 0 || !arr.get(0).isString()) return {};
if (arr.size() == 0 || !arr.get(0).isString()) return {};
std::vector<std::string> 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<Value> getStringArray(std::vector<std::string> values) {
Local<Array> arr = Array::newArray(values.size());
Expand Down
9 changes: 6 additions & 3 deletions src/api/EntityAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1665,7 +1665,8 @@ Local<Value> 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<Value>();
Expand Down Expand Up @@ -1726,7 +1727,8 @@ Local<Value> 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<Value>();
Expand Down Expand Up @@ -1790,7 +1792,8 @@ Local<Value> 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<Value>();
Expand Down
4 changes: 2 additions & 2 deletions src/api/FileSystemAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -740,7 +740,7 @@ Local<Value> OpenFile(const Arguments& args) {

bool isBinary = false;
if (args.size() >= 3 && args[2].asBoolean().value()) {
isBinary = true;
isBinary = true;
mode |= std::ios_base::binary;
}

Expand Down
3 changes: 2 additions & 1 deletion src/api/ItemAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,8 @@ Local<Value> 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<Value>();
Expand Down
26 changes: 13 additions & 13 deletions src/api/NetworkAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,16 +116,15 @@ void WSClientClass::initListeners() {
}
});

ws->OnBinaryReceived(
[nowList{&listeners[int(WSClientEvents::onBinaryReceived)]}](WebSocketClient& client, vector<uint8_t> 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<uint8_t> 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())
Expand All @@ -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;
Expand Down Expand Up @@ -390,7 +389,8 @@ using namespace httplib;
EngineScope::currentEngine(), \
script::Global<Function>{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) \
Expand Down
8 changes: 4 additions & 4 deletions src/api/ParticleAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@

#define GETVEC3(v, d, u) \
if (IsInstanceOf<IntPos>(u)) { \
auto pos2 = EngineScope::currentEngine()->getNativeInstance<IntPos>(u); \
v = Vec3(pos2->x, pos2->y, pos2->z); \
auto pos2 = EngineScope::currentEngine() -> getNativeInstance<IntPos>(u); \
v = Vec3(pos2->x, pos2->y, pos2->z); \
v += 0.5f; \
d = pos2->dim; \
d = pos2->dim; \
} else if (IsInstanceOf<FloatPos>(u)) { \
auto pos2 = EngineScope::currentEngine()->getNativeInstance<FloatPos>(u); \
auto pos2 = EngineScope::currentEngine() -> getNativeInstance<FloatPos>(u); \
v = Vec3(pos2->x, pos2->y, pos2->z); \
d = pos2->dim; \
} else { \
Expand Down
30 changes: 15 additions & 15 deletions src/api/SimulatedPlayerAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,12 +256,12 @@ Local<Value> PlayerClass::simulateLocalMove(const Arguments& args) {
float speed = 1.0f;
size_t index = 0;
if (IsInstanceOf<IntPos>(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<FloatPos>(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
Expand All @@ -270,7 +270,7 @@ Local<Value> 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
Expand Down Expand Up @@ -300,12 +300,12 @@ Local<Value> PlayerClass::simulateWorldMove(const Arguments& args) {
float speed = 1.0f;
size_t index = 0;
if (IsInstanceOf<IntPos>(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<FloatPos>(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
Expand All @@ -314,7 +314,7 @@ Local<Value> 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
Expand Down Expand Up @@ -344,12 +344,12 @@ Local<Value> PlayerClass::simulateMoveTo(const Arguments& args) {
float speed = 1.0f;
size_t index = 0;
if (IsInstanceOf<IntPos>(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<FloatPos>(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
Expand All @@ -358,7 +358,7 @@ Local<Value> 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
Expand Down
2 changes: 1 addition & 1 deletion src/engine/OperationCount.h
Original file line number Diff line number Diff line change
Expand Up @@ -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(); }
Expand Down
4 changes: 2 additions & 2 deletions src/legacyapi/Base64.h
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
Expand All @@ -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<uint8_t>(c);
i = (i << 8) + static_cast<uint8_t>(c);
j += 8;
while (j >= 0) {
result += _base64_table[(i >> j) & 0x3F];
Expand Down
18 changes: 9 additions & 9 deletions src/legacyapi/db/ConnParams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
19 changes: 10 additions & 9 deletions src/main/PythonHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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<std::string>& elem) {
std::optional<std::string> depend = *elem;
std::optional<std::string> depend = *elem;
dependsAdded += "\n" + *depend;
});
}
Expand Down
3 changes: 2 additions & 1 deletion src/utils/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 8ffca8a

Please sign in to comment.