Sort data exported to the api.json file for GDNative

(cherry picked from commit 0d2f3f4f50)
This commit is contained in:
Bastiaan Olij 2019-04-07 21:26:31 +10:00 committed by Rémi Verschelde
parent e802da4e81
commit b2b112d703
1 changed files with 34 additions and 0 deletions

View File

@ -138,6 +138,34 @@ static String get_type_name(const PropertyInfo &info) {
return Variant::get_type_name(info.type); return Variant::get_type_name(info.type);
} }
/*
* Some comparison helper functions we need
*/
struct MethodInfoComparator {
StringName::AlphCompare compare;
bool operator()(const MethodInfo &p_a, const MethodInfo &p_b) const {
return compare(p_a.name, p_b.name);
}
};
struct PropertyInfoComparator {
StringName::AlphCompare compare;
bool operator()(const PropertyInfo &p_a, const PropertyInfo &p_b) const {
return compare(p_a.name, p_b.name);
}
};
struct ConstantAPIComparator {
NoCaseComparator compare;
bool operator()(const ConstantAPI &p_a, const ConstantAPI &p_b) const {
return compare(p_a.constant_name, p_b.constant_name);
}
};
/* /*
* Reads the entire Godot API to a list * Reads the entire Godot API to a list
*/ */
@ -147,6 +175,7 @@ List<ClassAPI> generate_c_api_classes() {
List<StringName> classes; List<StringName> classes;
ClassDB::get_class_list(&classes); ClassDB::get_class_list(&classes);
classes.sort_custom<StringName::AlphCompare>();
// Register global constants as a fake GlobalConstants singleton class // Register global constants as a fake GlobalConstants singleton class
{ {
@ -162,6 +191,7 @@ List<ClassAPI> generate_c_api_classes() {
constant_api.constant_value = GlobalConstants::get_global_constant_value(i); constant_api.constant_value = GlobalConstants::get_global_constant_value(i);
global_constants_api.constants.push_back(constant_api); global_constants_api.constants.push_back(constant_api);
} }
global_constants_api.constants.sort_custom<ConstantAPIComparator>();
api.push_back(global_constants_api); api.push_back(global_constants_api);
} }
@ -193,6 +223,7 @@ List<ClassAPI> generate_c_api_classes() {
{ {
List<String> constant; List<String> constant;
ClassDB::get_integer_constant_list(class_name, &constant, true); ClassDB::get_integer_constant_list(class_name, &constant, true);
constant.sort_custom<NoCaseComparator>();
for (List<String>::Element *c = constant.front(); c != NULL; c = c->next()) { for (List<String>::Element *c = constant.front(); c != NULL; c = c->next()) {
ConstantAPI constant_api; ConstantAPI constant_api;
constant_api.constant_name = c->get(); constant_api.constant_name = c->get();
@ -206,6 +237,7 @@ List<ClassAPI> generate_c_api_classes() {
{ {
List<MethodInfo> signals_; List<MethodInfo> signals_;
ClassDB::get_signal_list(class_name, &signals_, true); ClassDB::get_signal_list(class_name, &signals_, true);
signals_.sort_custom<MethodInfoComparator>();
for (int i = 0; i < signals_.size(); i++) { for (int i = 0; i < signals_.size(); i++) {
SignalAPI signal; SignalAPI signal;
@ -245,6 +277,7 @@ List<ClassAPI> generate_c_api_classes() {
{ {
List<PropertyInfo> properties; List<PropertyInfo> properties;
ClassDB::get_property_list(class_name, &properties, true); ClassDB::get_property_list(class_name, &properties, true);
properties.sort_custom<PropertyInfoComparator>();
for (List<PropertyInfo>::Element *p = properties.front(); p != NULL; p = p->next()) { for (List<PropertyInfo>::Element *p = properties.front(); p != NULL; p = p->next()) {
PropertyAPI property_api; PropertyAPI property_api;
@ -272,6 +305,7 @@ List<ClassAPI> generate_c_api_classes() {
{ {
List<MethodInfo> methods; List<MethodInfo> methods;
ClassDB::get_method_list(class_name, &methods, true); ClassDB::get_method_list(class_name, &methods, true);
methods.sort_custom<MethodInfoComparator>();
for (List<MethodInfo>::Element *m = methods.front(); m != NULL; m = m->next()) { for (List<MethodInfo>::Element *m = methods.front(); m != NULL; m = m->next()) {
MethodAPI method_api; MethodAPI method_api;