feat: modules moved and engine moved to submodule

This commit is contained in:
Jan van der Weide 2025-04-12 18:40:44 +02:00
parent dfb5e645cd
commit c33d2130cc
5136 changed files with 225275 additions and 64485 deletions

View file

@ -29,6 +29,7 @@
/**************************************************************************/
#include "jsonrpc.h"
#include "jsonrpc.compat.inc"
#include "core/io/json.h"
@ -39,7 +40,7 @@ JSONRPC::~JSONRPC() {
}
void JSONRPC::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_scope", "scope", "target"), &JSONRPC::set_scope);
ClassDB::bind_method(D_METHOD("set_method", "name", "callback"), &JSONRPC::set_method);
ClassDB::bind_method(D_METHOD("process_action", "action", "recurse"), &JSONRPC::process_action, DEFVAL(false));
ClassDB::bind_method(D_METHOD("process_string", "action"), &JSONRPC::process_string);
@ -99,9 +100,6 @@ Variant JSONRPC::process_action(const Variant &p_action, bool p_process_arr_elem
if (p_action.get_type() == Variant::DICTIONARY) {
Dictionary dict = p_action;
String method = dict.get("method", "");
if (method.begins_with("$/")) {
return ret;
}
Array args;
if (dict.has("params")) {
@ -113,14 +111,11 @@ Variant JSONRPC::process_action(const Variant &p_action, bool p_process_arr_elem
}
}
Object *object = this;
if (method_scopes.has(method.get_base_dir())) {
object = method_scopes[method.get_base_dir()];
method = method.get_file();
}
/// A Notification is a Request object without an "id" member.
bool is_notification = !dict.has("id");
Variant id;
if (dict.has("id")) {
if (!is_notification) {
id = dict["id"];
// Account for implementations that discern between int and float on the json serialization level, by using an int if there is a .0 fraction. See #100914
@ -129,25 +124,35 @@ Variant JSONRPC::process_action(const Variant &p_action, bool p_process_arr_elem
}
}
if (object == nullptr || !object->has_method(method)) {
ret = make_response_error(JSONRPC::METHOD_NOT_FOUND, "Method not found: " + method, id);
if (methods.has(method)) {
Variant call_ret = methods[method].callv(args);
ret = make_response(call_ret, id);
} else {
Variant call_ret = object->callv(method, args);
if (id.get_type() != Variant::NIL) {
ret = make_response(call_ret, id);
}
ret = make_response_error(JSONRPC::METHOD_NOT_FOUND, "Method not found: " + method, id);
}
/// The Server MUST NOT reply to a Notification
if (is_notification) {
ret = Variant();
}
} else if (p_action.get_type() == Variant::ARRAY && p_process_arr_elements) {
Array arr = p_action;
int size = arr.size();
if (size) {
if (!arr.is_empty()) {
Array arr_ret;
for (int i = 0; i < size; i++) {
const Variant &var = arr.get(i);
arr_ret.push_back(process_action(var));
for (const Variant &var : arr) {
Variant res = process_action(var);
if (res.get_type() != Variant::NIL) {
arr_ret.push_back(res);
}
}
/// If there are no Response objects contained within the Response array as it is to be sent to the client, the server MUST NOT return an empty Array and should return nothing at all.
if (!arr_ret.is_empty()) {
ret = arr_ret;
}
ret = arr_ret;
} else {
/// If the batch rpc call itself fails to be recognized ... as an Array with at least one value, the response from the Server MUST be a single Response object.
ret = make_response_error(JSONRPC::INVALID_REQUEST, "Invalid Request");
}
} else {
@ -175,6 +180,6 @@ String JSONRPC::process_string(const String &p_input) {
return ret.to_json_string();
}
void JSONRPC::set_scope(const String &p_scope, Object *p_obj) {
method_scopes[p_scope] = p_obj;
void JSONRPC::set_method(const String &p_name, const Callable &p_callback) {
methods[p_name] = p_callback;
}