Skip to content

Commit c7b0427

Browse files
committed
feat: add ModClass registration to BindAPI
1 parent 6f1fc7f commit c7b0427

File tree

3 files changed

+86
-0
lines changed

3 files changed

+86
-0
lines changed

src/API/Mod/Mod.cc

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#include "API/Mod/Mod.h"
2+
#include "API/Logger/Logger.h"
3+
4+
using namespace Komomo;
5+
6+
ClassDefine<ModClass> modClassBuilder = defineClass<ModClass>("Mod")
7+
.constructor(nullptr)
8+
9+
.function("getName", &ModClass::getName)
10+
.function("getType", &ModClass::getType)
11+
.function("getModDir", &ModClass::getModDir)
12+
.function("getDataDir", &ModClass::getDataDir)
13+
.function("getConfigDir", &ModClass::getConfigDir)
14+
.function("getLangDir", &ModClass::getLangDir)
15+
.function("getLogger", &ModClass::getLogger)
16+
17+
.build();
18+
19+
ModClass::ModClass() : ScriptClass(ConstructFromCpp<ModClass>{}) {}
20+
21+
std::shared_ptr<ll::mod::Mod> ModClass::getMod() { return ENGINE_DATA()->mMod; };
22+
23+
24+
// LLNDAPI std::string const& getName() const;
25+
Local<Value> ModClass::getName() { return String::newString(ENGINE_DATA()->mMod->getName()); };
26+
27+
// LLNDAPI std::string const& getType() const;
28+
Local<Value> ModClass::getType() { return String::newString(ENGINE_DATA()->mMod->getType()); };
29+
30+
// LLNDAPI std::filesystem::path const& getModDir() const;
31+
Local<Value> ModClass::getModDir() { return String::newString(ENGINE_DATA()->mMod->getModDir().string()); };
32+
33+
// LLNDAPI std::filesystem::path const& getDataDir() const;
34+
Local<Value> ModClass::getDataDir() { return String::newString(ENGINE_DATA()->mMod->getDataDir().string()); };
35+
36+
// LLNDAPI std::filesystem::path const& getConfigDir() const;
37+
Local<Value> ModClass::getConfigDir() { return String::newString(ENGINE_DATA()->mMod->getConfigDir().string()); };
38+
39+
// LLNDAPI std::filesystem::path const& getLangDir() const;
40+
Local<Value> ModClass::getLangDir() { return String::newString(ENGINE_DATA()->mMod->getLangDir().string()); };
41+
42+
// LLNDAPI ll::io::Logger& getLogger() const;
43+
Local<Value> ModClass::getLogger() { return LoggerClass::newLoggerClass(ENGINE_DATA()->mMod->getLogger().getTitle()); };

src/API/Mod/Mod.h

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#pragma once
2+
3+
#include "API/APIHelper.h" // IWYU pragma: keep
4+
5+
#include <ll/api/mod/Mod.h>
6+
#include <memory>
7+
8+
class ModClass : public ScriptClass {
9+
public:
10+
11+
ModClass();
12+
public: /* Method */
13+
// LLNDAPI State getState() const; // TODO
14+
// LLNDAPI Manifest const& getManifest() const; // TODO
15+
static inline std::shared_ptr<ll::mod::Mod> getMod();
16+
17+
// LLNDAPI std::string const& getName() const;
18+
static Local<Value> getName();
19+
20+
// LLNDAPI std::string const& getType() const;
21+
static Local<Value> getType();
22+
23+
// LLNDAPI std::filesystem::path const& getModDir() const;
24+
static Local<Value> getModDir();
25+
26+
// LLNDAPI std::filesystem::path const& getDataDir() const;
27+
static Local<Value> getDataDir();
28+
29+
// LLNDAPI std::filesystem::path const& getConfigDir() const;
30+
static Local<Value> getConfigDir();
31+
32+
// LLNDAPI std::filesystem::path const& getLangDir() const;
33+
static Local<Value> getLangDir();
34+
35+
// LLNDAPI ll::io::Logger& getLogger() const;
36+
static Local<Value> getLogger();
37+
};
38+
39+
extern ClassDefine<ModClass> modClassBuilder;

src/Manager/BindAPI.h

+4
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,23 @@
2828
#include "API/Logger/Logger.h"
2929
#include "API/Math/Vec3.h"
3030
#include "API/Mob/Mob.h"
31+
#include "API/Mod/Mod.h"
3132
#include "API/Player/Gamemode.h"
3233
#include "API/Player/LayeredAbilities.h"
3334
#include "API/Player/Player.h"
3435
#include "API/Service/Service.h"
3536
#include "Utils/Using.h"
3637

3738

39+
3840
namespace Komomo {
3941

4042
inline void BindAPI(ScriptEngine* engine) {
4143

4244
EnumAPI::RegisterEnum(engine);
4345

46+
engine->registerNativeClass<ModClass>(modClassBuilder);
47+
4448
engine->registerNativeClass<PlayerClass>(playerClassBuilder);
4549
engine->registerNativeClass<GameModeClass>(gameModeClassBuilder);
4650
engine->registerNativeClass<LayeredAbilitiesClass>(layeredAbilitiesClassBuilder);

0 commit comments

Comments
 (0)