Skip to content

Commit

Permalink
Fix code template generation.
Browse files Browse the repository at this point in the history
  • Loading branch information
fuzzybinary committed Sep 4, 2024
1 parent 6c43a05 commit 9b590fc
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 5 deletions.
2 changes: 1 addition & 1 deletion example/2d_tutorial/src/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ packages:
path: "../../../src/dart/godot_dart"
relative: true
source: path
version: "0.1.0"
version: "0.1.1"
godot_dart_build:
dependency: "direct dev"
description:
Expand Down
4 changes: 4 additions & 0 deletions example/2d_tutorial/src/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,7 @@ dev_dependencies:
build_runner: ^2.3.3
godot_dart_build:
path: ../../../src/dart/godot_dart_build

dependency_overrides:
godot_dart:
path: ../../../src/dart/godot_dart
2 changes: 1 addition & 1 deletion src/cpp/editor/dart_templates.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const char *dart_script = "import 'dart:ffi';\n"
"\n"
"import 'package:godot_dart/godot_dart.dart';\n"
"\n"
"part '__CLASS_NAME__.g.dart';\n"
"part '__FILE_NAME__.g.dart';\n"
"\n"
"@GodotScript()\n"
"class __CLASS_NAME__ extends __BASE_CLASS__ {\n"
Expand Down
15 changes: 13 additions & 2 deletions src/cpp/script/dart_script_language.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,14 @@ godot::PackedStringArray DartScriptLanguage::_get_string_delimiters() const {
godot::Ref<godot::Script> DartScriptLanguage::_make_template(const godot::String &_template,
const godot::String &class_name,
const godot::String &base_class_name) const {
static godot::String space(" ");

godot::String source_template(dart_script);
godot::String source =
source_template.replace("__CLASS_NAME__", class_name).replace("__BASE_CLASS__", base_class_name);
godot::String actual_class_name = class_name.capitalize().replace(space, godot::String());

godot::String source = source_template.replace("__FILE_NAME__", class_name)
.replace("__CLASS_NAME__", actual_class_name)
.replace("__BASE_CLASS__", base_class_name);

godot::Ref<DartScript> script;
script.instantiate();
Expand All @@ -122,6 +127,12 @@ godot::Ref<godot::Script> DartScriptLanguage::_make_template(const godot::String
return script;
}

godot::TypedArray<godot::Dictionary> DartScriptLanguage::_get_built_in_templates(
const godot::StringName &object) const {
// Won't be called for now because _is_using_templates returns false, but look into maybe supporting them?
return godot::TypedArray<godot::Dictionary>();
}

godot::Dictionary DartScriptLanguage::_validate(const godot::String &script, const godot::String &path,
bool validate_functions, bool validate_errors, bool validate_warnings,
bool validate_safe_lines) const {
Expand Down
6 changes: 5 additions & 1 deletion src/cpp/script/dart_script_language.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ class DartScriptLanguage : public godot::ScriptLanguageExtension {
godot::Ref<godot::Script> _make_template(const godot::String &_template, const godot::String &class_name,
const godot::String &base_class_name) const override;
bool _is_using_templates() override {
return true;
return false;
}
godot::TypedArray<godot::Dictionary> _get_built_in_templates(const godot::StringName &object) const override;
godot::Dictionary _validate(const godot::String &script, const godot::String &path, bool validate_functions,
bool validate_errors, bool validate_warnings, bool validate_safe_lines) const override;
godot::String _validate_path(const godot::String &path) const override;
Expand All @@ -41,6 +42,9 @@ class DartScriptLanguage : public godot::ScriptLanguageExtension {
bool _supports_builtin_mode() const override {
return false;
}
bool _can_inherit_from_file() const override {
return false;
}
int _find_function(const godot::String &class_name, const godot::String &funciton_name) const override;
bool _overrides_external_editor() override {
return false;
Expand Down

0 comments on commit 9b590fc

Please sign in to comment.