Skip to content

Commit

Permalink
Finish scanning
Browse files Browse the repository at this point in the history
  • Loading branch information
NeilKleistGao committed Oct 24, 2023
1 parent d8d3db0 commit 4882795
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## TODO
- [x] Add editor support
- [ ] Scan the project to get all `*.gd` files
- [x] Scan the project to get all `*.gd` files
- [ ] Translate `*.gd` to LLVM IR
- [ ] Compile LLVM IR
- [ ] Export the project
13 changes: 9 additions & 4 deletions editor/gd2cpp_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#ifdef TOOLS_ENABLED
#include "scene/gui/label.h"
#include "editor/editor_node.h"
#include "../gd2cpp.h"

String GD2CppDialog::task_name = "gd2cpp";

Expand All @@ -41,8 +42,8 @@ GD2CppDialog::GD2CppDialog() {

void GD2CppDialog::ok_pressed() {
EditorNode* singleton = EditorNode::get_singleton();
singleton->progress_add_task(task_name, "Copy Project", full_steps);
singleton->progress_task_step(task_name, "Copy Project", 0);
singleton->progress_add_task(task_name, "Scanning project...", full_steps);
singleton->progress_task_step(task_name, "Scanning project...", 0);
run();
}

Expand All @@ -52,13 +53,17 @@ GD2CppDialog::~GD2CppDialog() {

void GD2CppDialog::run() {
EditorNode* singleton = EditorNode::get_singleton();
print_line("Scanning project...");

progress = full_steps;
Array scripts = gd2cpp::scan();
print_line(String{"Got "} + String::num_int64(scripts.size()) + String{" script(s)."});

progress = full_steps; // TODO: full workflow
if (progress == full_steps) {
singleton->progress_end_task(task_name);
}
else {
singleton->progress_task_step(task_name, "Copy Project", progress);
singleton->progress_task_step(task_name, "Scanning project...", progress);
}
}

Expand Down
5 changes: 5 additions & 0 deletions editor/gd2cpp_menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ GD2CppMenu::GD2CppMenu(): shown_title("Export with GD2Cpp") {
GLOBAL_DEF("gd2cpp/template", "");
ProjectSettings::get_singleton()->save();
}

if (!ProjectSettings::get_singleton()->has_setting("gd2cpp/directory")) {
GLOBAL_DEF("gd2cpp/directory", "llvm");
ProjectSettings::get_singleton()->save();
}
}

GD2CppMenu::~GD2CppMenu() {
Expand Down
46 changes: 46 additions & 0 deletions gd2cpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,50 @@
#include "gd2cpp.h"

#ifdef TOOLS_ENABLED
#include "core/string/ustring.h"
#include "core/variant/variant.h"
#include "core/io/dir_access.h"

namespace gd2cpp {
namespace {
} // namespace

Array scan() {
Array scripts{}, queue{};
queue.push_back(String{"res://"});
Error err = Error::OK;

while (!queue.is_empty()) {
String cur = queue.pop_front();
print_line(String{"Scanning "} + cur);
Ref<DirAccess> dir = DirAccess::open(cur, &err);

if (err != Error::OK) {
ERR_PRINT("Failed when scanning project.");
scripts.clear();
break;
}

PackedStringArray files = dir->get_files();
PackedStringArray dirs = dir->get_directories();

for (int i = 0; i < files.size(); ++i) {
String filename = files[i];
if (filename.ends_with(".gd")) {
String fullpath = (cur.ends_with("/")) ? cur + filename : cur + "/" + filename;
print_line(String{"Found "} + fullpath);
scripts.push_back(fullpath);
}
}

for (int i = 0; i < dirs.size(); ++i) {
String next = dirs[i];
queue.push_back(DirAccess::get_full_path(next, DirAccess::ACCESS_RESOURCES));
}
}

return scripts;
}
} // namespace gd2cpp

#endif
7 changes: 7 additions & 0 deletions gd2cpp.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@
#define __GD2CPP__H__

#ifdef TOOLS_ENABLED

#include "core/variant/array.h"

namespace gd2cpp {
Array scan();
} // namespace gd2cpp

#endif

#endif // __GD2CPP__H__
11 changes: 11 additions & 0 deletions tests/sub/foo.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
extends Node


# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.


# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
pass

0 comments on commit 4882795

Please sign in to comment.