-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GH-285 Add EditorDebugger support (Requires Godot 4.3)
- Loading branch information
Showing
26 changed files
with
1,168 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
// This file is part of the Godot Orchestrator project. | ||
// | ||
// Copyright (c) 2023-present Vahera Studios LLC and its contributors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
#include "editor/editor_cache.h" | ||
#include "plugins/orchestrator_editor_debugger_plugin.h" | ||
#include "plugins/orchestrator_editor_plugin.h" | ||
|
||
#include <godot_cpp/classes/editor_paths.hpp> | ||
|
||
#if GODOT_VERSION >= 0x040300 | ||
PackedInt64Array OrchestratorEditorCache::_get_breakpoints_for_path(const String& p_path, bool p_disabled) const | ||
{ | ||
return _cache->get_value(p_path, p_disabled ? "disabled_breakpoints" : "breakpoints", PackedInt64Array()); | ||
} | ||
#endif | ||
|
||
Error OrchestratorEditorCache::load() | ||
{ | ||
const EditorInterface* ei = OrchestratorPlugin::get_singleton()->get_editor_interface(); | ||
|
||
_cache = Ref<ConfigFile>(memnew(ConfigFile)); | ||
|
||
Error result = _cache->load(ei->get_editor_paths()->get_project_settings_dir().path_join(CACHE_FILE)); | ||
if (result != OK) | ||
return result; | ||
|
||
#if GODOT_VERSION >= 0x040300 | ||
if (OrchestratorEditorDebuggerPlugin* debugger = OrchestratorEditorDebuggerPlugin::get_singleton()) | ||
{ | ||
for (const String& section : _cache->get_sections()) | ||
{ | ||
if (_cache->has_section_key(section, "breakpoints")) | ||
{ | ||
PackedInt64Array breakpoints = _get_breakpoints_for_path(section, false); | ||
for (int i = 0; i < breakpoints.size(); i++) | ||
debugger->set_breakpoint(section, breakpoints[i], true); | ||
} | ||
if (_cache->has_section_key(section, "disabled_breakpoints")) | ||
{ | ||
PackedInt64Array disabled_breakpoints = _get_breakpoints_for_path(section, true); | ||
for (int i = 0; i < disabled_breakpoints.size(); i++) | ||
debugger->set_breakpoint(section, disabled_breakpoints[i], true); | ||
} | ||
} | ||
} | ||
#endif | ||
|
||
return OK; | ||
} | ||
|
||
Error OrchestratorEditorCache::save() | ||
{ | ||
if (_cache.is_valid()) | ||
{ | ||
const EditorInterface* ei = OrchestratorPlugin::get_singleton()->get_editor_interface(); | ||
return _cache->save(ei->get_editor_paths()->get_project_settings_dir().path_join(CACHE_FILE)); | ||
} | ||
|
||
return ERR_FILE_CANT_WRITE; | ||
} | ||
|
||
#if GODOT_VERSION >= 0x040300 | ||
void OrchestratorEditorCache::clear_all_breakpoints() | ||
{ | ||
for (const String& section : _cache->get_sections()) | ||
{ | ||
PackedInt64Array breakpoints = _get_breakpoints_for_path(section, false); | ||
if (!breakpoints.is_empty()) | ||
_cache->set_value(section, "breakpoints", Variant()); | ||
|
||
PackedInt64Array disabled_breakpoints = _get_breakpoints_for_path(section, true); | ||
if (!disabled_breakpoints.is_empty()) | ||
_cache->set_value(section, "disabled_breakpoints", Variant()); | ||
} | ||
} | ||
|
||
bool OrchestratorEditorCache::is_node_breakpoint(const String& p_path, int p_node_id) const | ||
{ | ||
return _get_breakpoints_for_path(p_path, false).has(p_node_id); | ||
} | ||
|
||
bool OrchestratorEditorCache::is_node_disabled_breakpoint(const String& p_path, int p_node_id) const | ||
{ | ||
return _get_breakpoints_for_path(p_path, true).has(p_node_id); | ||
} | ||
|
||
void OrchestratorEditorCache::set_breakpoint(const String& p_path, int p_node_id, bool p_enabled) | ||
{ | ||
PackedInt64Array breakpoints = _get_breakpoints_for_path(p_path, false); | ||
if (p_enabled && !breakpoints.has(p_node_id)) | ||
{ | ||
breakpoints.push_back(p_node_id); | ||
_cache->set_value(p_path, "breakpoints", breakpoints); | ||
} | ||
else if (!p_enabled && breakpoints.has(p_node_id)) | ||
{ | ||
breakpoints.remove_at(breakpoints.find(p_node_id)); | ||
_cache->set_value(p_path, "breakpoints", breakpoints); | ||
} | ||
} | ||
|
||
void OrchestratorEditorCache::set_disabled_breakpoint(const String& p_path, int p_node_id, bool p_remove) | ||
{ | ||
PackedInt64Array breakpoints = _get_breakpoints_for_path(p_path, true); | ||
if (p_remove && breakpoints.has(p_node_id)) | ||
{ | ||
breakpoints.remove_at(breakpoints.find(p_node_id)); | ||
_cache->set_value(p_path, "disabled_breakpoints", breakpoints); | ||
} | ||
else if (!p_remove && !breakpoints.has(p_node_id)) | ||
{ | ||
breakpoints.push_back(p_node_id); | ||
_cache->set_value(p_path, "disabled_breakpoints", breakpoints); | ||
} | ||
} | ||
#endif | ||
|
||
void OrchestratorEditorCache::_bind_methods() | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
// This file is part of the Godot Orchestrator project. | ||
// | ||
// Copyright (c) 2023-present Vahera Studios LLC and its contributors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
#ifndef ORCHESTRATOR_EDITOR_CACHE_H | ||
#define ORCHESTRATOR_EDITOR_CACHE_H | ||
|
||
#include "common/version.h" | ||
|
||
#include <godot_cpp/classes/config_file.hpp> | ||
#include <godot_cpp/classes/ref_counted.hpp> | ||
|
||
using namespace godot; | ||
|
||
/// A simple cache that maintains editor state details for Orchestrator. | ||
class OrchestratorEditorCache : public RefCounted | ||
{ | ||
GDCLASS(OrchestratorEditorCache, RefCounted); | ||
static void _bind_methods(); | ||
|
||
protected: | ||
const String CACHE_FILE = "orchestrator_editor_cache.cfg"; //! The cache file name | ||
Ref<ConfigFile> _cache; //! Cache file | ||
|
||
#if GODOT_VERSION >= 0x040300 | ||
/// Get breakpoints for the specified path | ||
/// @param p_path the path | ||
/// @param p_disabled when true, returns disabled breakpoints, false returns enabled breakpoints | ||
/// @return array of breakpoints | ||
PackedInt64Array _get_breakpoints_for_path(const String& p_path, bool p_disabled) const; | ||
#endif | ||
|
||
public: | ||
/// Loads the script editor cache from disk. | ||
/// @return the error code based on the load operation | ||
Error load(); | ||
|
||
/// Saves the script editor cache to disk. | ||
/// @return the error code based on the save operation | ||
Error save(); | ||
|
||
#if GODOT_VERSION >= 0x040300 | ||
/// Clears all breakpoints | ||
void clear_all_breakpoints(); | ||
|
||
/// Check whether the node in a script is a breakpoint | ||
/// @param p_path the script path | ||
/// @param p_node_id the node id | ||
/// @return true if the node is a breakpoint, false otherwise | ||
bool is_node_breakpoint(const String& p_path, int p_node_id) const; | ||
|
||
/// Check whether the node in a script is a breakpoint and is disabled | ||
/// @param p_path the script path | ||
/// @param p_node_id the node id | ||
/// @return true if the node is a breakpoint that is disabled, false otherwise | ||
bool is_node_disabled_breakpoint(const String& p_path, int p_node_id) const; | ||
|
||
/// Set whether a breakpoint is enabled | ||
/// @param p_path the script path | ||
/// @param p_node_id the node id | ||
/// @param p_enabled whether the breakpoint is enabled or disabled | ||
void set_breakpoint(const String& p_path, int p_node_id, bool p_enabled); | ||
|
||
/// Set the breakpoint as disabled | ||
/// @param p_path the script path | ||
/// @param p_node_id the node id | ||
/// @param p_remove whether to remove the disabled entry | ||
void set_disabled_breakpoint(const String& p_path, int p_node_id, bool p_remove = false); | ||
#endif | ||
|
||
}; | ||
|
||
#endif // ORCHESTRATOR_EDITOR_CACHE_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.