Skip to content

Commit

Permalink
refactor: refactoring the api file architecture
Browse files Browse the repository at this point in the history
  • Loading branch information
zimuya4153 committed Jan 11, 2025
1 parent a11a877 commit 8fd0bed
Show file tree
Hide file tree
Showing 36 changed files with 90 additions and 147 deletions.
5 changes: 1 addition & 4 deletions src/API/APIHelper.cc
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
#include "APIHelper.h"
#include "Entry.h"
#include "Utils/Util.h"
#include "fmt/core.h"
#include "fmt/format.h"
#include <fmt/core.h>
#include <iostream>


namespace jse {


bool IsFloat(Local<Value> const& num) {
try {
return fabs(num.asNumber().toDouble() - num.asNumber().toInt64()) >= 1e-15;
Expand Down
1 change: 0 additions & 1 deletion src/API/APIHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#include "Manager/EngineData.h"
#include "Utils/Using.h"


namespace jse {

bool IsFloat(Local<Value> const& num);
Expand Down
2 changes: 1 addition & 1 deletion src/API/ActorAPI.cc → src/API/Actor/ActorAPI.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "ActorAPI.h"
#include "API/APIHelper.h"
#include "APIHelper.h"
#include "API/APIHelper.h"
#include "Utils/Convert.h"
#include "Utils/Using.h"
#include <cstddef>
Expand Down
3 changes: 1 addition & 2 deletions src/API/ActorAPI.h → src/API/Actor/ActorAPI.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#pragma once

#include "API/CommandSenderAPI.h"
#include "API/Command/CommandSenderAPI.h"
#include "Utils/Defines.h"
#include "Utils/Using.h"
#include "endstone/actor/actor.h"
Expand Down
6 changes: 1 addition & 5 deletions src/API/MobAPI.cc → src/API/Actor/MobAPI.cc
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
#include "MobAPI.h"
#include "API/APIHelper.h"
#include "APIHelper.h"
#include "API/Actor/MobAPI.h"
#include "Utils/Convert.h"
#include "Utils/Using.h"
#include <cstddef>
#include <sstream>

namespace jse {

Expand Down
5 changes: 2 additions & 3 deletions src/API/MobAPI.h → src/API/Actor/MobAPI.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#pragma once

#include "API/ActorAPI.h"
#include "API/Actor/ActorAPI.h"
#include "Utils/Defines.h"
#include "Utils/Using.h"
#include "endstone/actor/mob.h"
#include <endstone/actor/mob.h>

namespace jse {

Expand Down
7 changes: 3 additions & 4 deletions src/API/CommandAPI.cc → src/API/Command/CommandAPI.cc
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
#include "CommandAPI.h"
#include "API/Command/CommandAPI.h"
#include "API/APIHelper.h"
#include "API/CommandSenderAPI.h"
#include "API/Command/CommandSenderAPI.h"
#include "Utils/Convert.h"
#include "Utils/Defines.h"
#include "Utils/Using.h"
#include "endstone/command/command.h"
#include <vector>
#include <endstone/command/command.h>

namespace jse {

Expand Down
5 changes: 2 additions & 3 deletions src/API/CommandAPI.h → src/API/Command/CommandAPI.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
#pragma once

#include "API/APIHelper.h"
#include "Utils/Defines.h"
#include "Utils/Using.h"
#include "endstone/command/command.h"
namespace jse {
#include <endstone/command/command.h>

namespace jse {

class CommandAPI : public ScriptClass {
endstone::Command* mCommand;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
#include "CommandSenderAPI.h"
#include "ActorAPI.h"
#include "PlayerAPI.h"
#include "API/Command/CommandSenderAPI.h"
#include "API/PlayerAPI.h"
#include "API/APIHelper.h"
#include "Utils/Convert.h"
#include "Utils/Using.h"
#include <cstddef>
#include <sstream>


namespace jse {

ClassDefine<CommandSenderAPI> CommandSenderAPI::builder =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
#pragma once

#include "API/PermissibleAPI.h"
#include "API/Permissions/PermissibleAPI.h"
#include "Utils/Defines.h"
#include "Utils/Using.h"
#include "endstone/command/command_sender.h"
namespace jse {
#include <endstone/command/command_sender.h>

namespace jse {

class CommandSenderAPI : public PermissibleAPI {
endstone::CommandSender* mSender;
Expand Down
10 changes: 6 additions & 4 deletions src/API/EnumAPI.cc → src/API/JSE/EnumAPI.cc
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#include "EnumAPI.h"
#include "APIHelper.h"
#include "API/JSE/EnumAPI.h"
#include "Utils/Using.h"
#include "Utils/Convert.h"
#include <endstone/game_mode.h>
#include <endstone/logger.h>
#include <endstone/permissions/permission_default.h>
#include <string>
#include <unordered_map>
#include <endstone/plugin/plugin_load_order.h>
#include <magic_enum/magic_enum.hpp>

#define REGISTER_ENUM_MACRO(ENUM, NAME) \
for (auto [value, key] : magic_enum::enum_entries<ENUM>()) { \
Expand Down
1 change: 0 additions & 1 deletion src/API/EnumAPI.h → src/API/JSE/EnumAPI.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#pragma once

#include "Utils/Using.h"

namespace jse::EnumAPI {
Expand Down
5 changes: 2 additions & 3 deletions src/API/FileAPI.cc → src/API/JSE/FileAPI.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "FileAPI.h"
#include "APIHelper.h"
#include "Manager/EngineData.h"
#include "API/JSE/FileAPI.h"
#include "API/APIHelper.h"
#include "Utils/FileUtils.h"
#include <filesystem>

Expand Down
1 change: 0 additions & 1 deletion src/API/FileAPI.h → src/API/JSE/FileAPI.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#pragma once

#include "Utils/Defines.h"
#include "Utils/Using.h"

Expand Down
9 changes: 2 additions & 7 deletions src/API/JSEAPI.cc → src/API/JSE/JSEAPI.cc
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
#include "JSEAPI.h"
#include "APIHelper.h"
#include "Entry.h"
#include "API/JSE/JSEAPI.h"
#include "API/APIHelper.h"
#include "Manager/EngineData.h"
#include "Manager/NodeManager.h"
#include "PluginAPI.h"
#include "Utils/Using.h"
#include "fmt/core.h"
#include <iostream>



namespace jse {

ClassDefine<void> JSEAPI::builder = defineClass("JSE")
Expand Down
File renamed without changes.
8 changes: 3 additions & 5 deletions src/API/PluginAPI.cc → src/API/JSE/PluginAPI.cc
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
#include "PluginAPI.h"
#include "API/JSE/PluginAPI.h"
#include "API/JSE/PluginDescriptionAPI.h"
#include "API/APIHelper.h"
#include "API/LoggerAPI.h"
#include "API/PluginDescriptionAPI.h"
#include "APIHelper.h"
#include "Manager/EngineData.h"
#include "Utils/Using.h"
#include <cstddef>


namespace jse {

Expand Down
1 change: 0 additions & 1 deletion src/API/PluginAPI.h → src/API/JSE/PluginAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#include "Utils/Defines.h"
#include "Utils/Using.h"


namespace jse {


Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
#include "PluginDescriptionAPI.h"
#include "API/JSE/PluginDescriptionAPI.h"
#include "API/APIHelper.h"
#include "API/CommandAPI.h"
#include "API/PermissionAPI.h"
#include "API/Command/CommandAPI.h"
#include "API/Permissions/PermissionAPI.h"
#include "Manager/EngineData.h"
#include "Utils/Convert.h"
#include "Utils/Using.h"


namespace jse {

ClassDefine<PluginDescriptionAPI> PluginDescriptionAPI::builder =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@
#include "Utils/Defines.h"
#include "Utils/Using.h"


namespace jse {


class PluginDescriptionAPI : public ScriptClass {
public:
explicit PluginDescriptionAPI() : ScriptClass(ScriptClass::ConstructFromCpp<PluginDescriptionAPI>{}) {}
Expand Down
10 changes: 2 additions & 8 deletions src/API/LoggerAPI.cc
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
#include "LoggerAPI.h"
#include "APIHelper.h"
#include "Entry.h"
#include "API/LoggerAPI.h"
#include "API/APIHelper.h"
#include "Manager/EngineData.h"
#include "Manager/NodeManager.h"
#include "fmt/args.h"
#include "fmt/format.h"



namespace jse {

Expand Down
1 change: 0 additions & 1 deletion src/API/LoggerAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace jse {


class LoggerAPI : public ScriptClass {
public:
explicit LoggerAPI() : ScriptClass(ScriptClass::ConstructFromCpp<LoggerAPI>{}){};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
#include "PermissibleAPI.h"
#include "API/CommandSenderAPI.h"
#include "API/PermissionAPI.h"
#include "API/PluginAPI.h"
#include "APIHelper.h"
#include "Loader/JavaScriptPlugin.h"
#include "API/Permissions/PermissibleAPI.h"
#include "API/APIHelper.h"
#include "API/Command/CommandSenderAPI.h"
#include "API/JSE/PluginAPI.h"
#include "API/Permissions/PermissionAPI.h"
#include "Utils/Convert.h"
#include "Utils/Defines.h"
#include "Utils/Using.h"
#include "endstone/permissions/permissible.h"
#include "endstone/plugin/plugin.h"
#include "endstone/util/result.h"
#include "fmt/core.h"
#include <endstone/permissions/permissible.h>
#include <endstone/plugin/plugin.h>
#include <endstone/util/result.h>
#include <stdexcept>


namespace jse {

ClassDefine<PermissibleAPI> PermissibleAPI::builder =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
#pragma once
#include "Utils/Defines.h"
#include "Utils/Using.h"
#include "endstone/permissions/permissible.h"

#include <endstone/permissions/permissible.h>

namespace jse {


class PermissibleAPI : public ScriptClass {
endstone::Permissible* mPermissible;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#include "PermissionAPI.h"
#include "API/Permissions/PermissionAPI.h"
#include "API/APIHelper.h"
#include "API/PermissibleAPI.h"
#include "API/Permissions/PermissibleAPI.h"
#include "Utils/Convert.h"
#include "Utils/Defines.h"
#include "endstone/permissions/permission_default.h"
#include <endstone/permissions/permission_default.h>

namespace jse {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
#pragma once
#include "API/APIHelper.h"
#include "Utils/Defines.h"
#include "Utils/Using.h"
#include "endstone/permissions/permission.h"

#include <endstone/permissions/permission.h>

namespace jse {


class PermissionAPI : public ScriptClass {
endstone::Permission* mPermission;

Expand Down
6 changes: 1 addition & 5 deletions src/API/PlayerAPI.cc
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
#include "PlayerAPI.h"
#include "API/PlayerAPI.h"
#include "API/APIHelper.h"
#include "APIHelper.h"
#include "Utils/Convert.h"
#include "Utils/Using.h"
#include <cstddef>
#include <sstream>
#include <unordered_map>


namespace jse {

Expand Down
5 changes: 2 additions & 3 deletions src/API/PlayerAPI.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#pragma once

#include "API/MobAPI.h"
#include "API/Actor/MobAPI.h"
#include "Utils/Defines.h"
#include "Utils/Using.h"
#include "endstone/player.h"
#include <endstone/player.h>

namespace jse {

Expand Down
11 changes: 5 additions & 6 deletions src/Loader/JavaScriptPlugin.cc
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
#include "JavaScriptPlugin.h"
#include "Loader/JavaScriptPlugin.h"
#include "API/APIHelper.h"
#include "API/CommandAPI.h"
#include "API/CommandSenderAPI.h"
#include "API/Command/CommandAPI.h"
#include "API/Command/CommandSenderAPI.h"
#include "Entry.h"
#include "Manager/EngineData.h"
#include "Manager/NodeManager.h"
#include "Utils/Convert.h"
#include "Utils/Using.h"
#include "endstone/command/command.h"
#include "endstone/logger.h"
#include <endstone/command/command.h>
#include <endstone/logger.h>
#include <iostream>


namespace jse {


Expand Down
7 changes: 3 additions & 4 deletions src/Loader/JavaScriptPlugin.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
#pragma once
#include "endstone/detail/plugin/plugin_description_builder.h"
#include "endstone/plugin/plugin.h"
#include "endstone/plugin/plugin_description.h"
#include <endstone/detail/plugin/plugin_description_builder.h>
#include <endstone/plugin/plugin.h>
#include <endstone/plugin/plugin_description.h>
#include <cstdint>


namespace jse {

class JsPluginDescriptionBuilder : public endstone::detail::PluginDescriptionBuilder {
Expand Down
Loading

0 comments on commit 8fd0bed

Please sign in to comment.