Skip to content

Commit

Permalink
Merge pull request #91 from PipeRift/feature/allow-ctypes-editing
Browse files Browse the repository at this point in the history
Allow ctypes editing
  • Loading branch information
muit authored Feb 22, 2023
2 parents f503805 + 0d703c7 commit b49fb89
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 22 deletions.
1 change: 0 additions & 1 deletion Examples/Project/__module__.rf
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"CNamespace": "none",
"CModule": {
"target": "Executable",
"dependencies": [
Expand Down
2 changes: 1 addition & 1 deletion Libs/Editor/Src/Panels/FileExplorerPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ namespace rift::Editor
UI::BeginChild("Files");
if (UI::BeginPopupContextWindow())
{
String projectPath = p::ToString(AST::GetProjectPath(ast));
String projectPath{AST::GetProjectPath(ast)};
DrawContextMenu(ast, projectPath, AST::NoId);
UI::EndPopup();
}
Expand Down
20 changes: 9 additions & 11 deletions Libs/Editor/Src/Systems/EditorSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -394,10 +394,10 @@ namespace rift::Editor::EditorSystem
if (UI::MenuItem(ICON_FA_SAVE, "CTRL+S"))
{
auto& file = ast.Get<AST::CFileRef>(moduleId);
TPair<Path, String> fileData{file.path, ""};
AST::SerializeModule(ast, moduleId, fileData.second);
String data;
AST::SerializeModule(ast, moduleId, data);

files::SaveStringFile(fileData.first, fileData.second);
files::SaveStringFile(file.path, data);
ast.Remove<AST::CFileDirty>(moduleId);

UI::AddNotification({UI::ToastType::Success, 1.f,
Expand Down Expand Up @@ -444,9 +444,6 @@ namespace rift::Editor::EditorSystem

if (UI::BeginInspector("ModuleInspector"))
{
auto& ns = moduleEditors.GetOrAdd<AST::CNamespace>(moduleId);
UI::InspectStruct(&ns);

auto& module = moduleEditors.Get<AST::CModule>(moduleId);
UI::InspectStruct(&module);

Expand Down Expand Up @@ -504,15 +501,16 @@ namespace rift::Editor::EditorSystem
if (UI::MenuItem(ICON_FA_SAVE, "CTRL+S"))
{
auto& file = ast.Get<AST::CFileRef>(typeId);
TPair<Path, String> fileData{file.path, ""};
AST::SerializeType(ast, typeId, fileData.second);
String data;
AST::SerializeType(ast, typeId, data);

files::SaveStringFile(file.path, data);
ast.Remove<AST::CFileDirty>(typeId);

UI::AddNotification({UI::ToastType::Success, 1.f,
Strings::Format("Saved file {}", p::GetFilename(file.path))});

files::SaveStringFile(fileData.first, fileData.second);
ast.Remove<AST::CFileDirty>(typeId);
}

if (UI::BeginMenu("View"))
{
if (AST::HasFunctions(ast, typeId))
Expand Down
10 changes: 7 additions & 3 deletions Libs/Framework/Include/AST/Utils/Namespaces.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,15 @@ namespace rift::AST
}
Tag& Last()
{
return scopes[Size() - 1];
const i32 size = Size();
const i32 lastIndex = size > 0 ? (size - 1) : 0; // Is Size is 0, last is first
return scopes[lastIndex];
}
Tag Last() const
const Tag& Last() const
{
return scopes[Size() - 1];
const i32 size = Size();
const i32 lastIndex = size > 0 ? (size - 1) : 0; // Is Size is 0, last is first
return scopes[lastIndex];
}
bool operator==(const Namespace& other) const
{
Expand Down
11 changes: 7 additions & 4 deletions Libs/Framework/Src/AST/Systems/LoadSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ namespace rift::AST::LoadSystem
TSet<Path> modulePaths;

TAccess<CModule, CFileRef> access{ast};
auto modules = ecs::ListAll<CModule>(access);
auto modules = ecs::ListAll<CModule, CFileRef>(access);

modulePaths.Reserve(modules.Size());
for (Id moduleId : modules)
Expand Down Expand Up @@ -121,7 +121,8 @@ namespace rift::AST::LoadSystem
{
ZoneScoped;

TAccess<TWrite<CModule>, TWrite<CFileRef>, CProject, TWrite<CChild>, TWrite<CParent>>
TAccess<TWrite<CModule>, TWrite<CFileRef>, TWrite<CNamespace>, CProject, TWrite<CChild>,
TWrite<CParent>>
access{ast};

// Remove existing module paths
Expand All @@ -144,9 +145,11 @@ namespace rift::AST::LoadSystem

for (i32 i = 0; i < ids.Size(); ++i)
{
Id id = ids[i];
Id id = ids[i];
p::String& path = paths[i];
access.Add<CModule>(id);
access.Add(id, CFileRef{Move(paths[i])});
access.Add(id, CNamespace{p::GetFilename(p::GetParentPath(path))});
access.Add(id, CFileRef{Move(path)});
}

// Link modules to the project
Expand Down
4 changes: 4 additions & 0 deletions Libs/Framework/Src/AST/Utils/ModuleUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ namespace rift::AST
// Create project node (root module)
Id projectId = ast.Create();
ast.Add<CProject, CModule>(projectId);
ast.Add(projectId, CNamespace{p::GetFilename(p::GetParentPath(filePath))});
ast.Add(projectId, CFileRef{filePath});

// Load project module
Expand Down Expand Up @@ -125,6 +126,8 @@ namespace rift::AST

Id moduleId = ast.Create();
ast.Add<CModule>(moduleId);
ast.Add(moduleId, CNamespace{p::GetFilename(p::GetParentPath(filePath))});
ast.Add(moduleId, CFileRef{filePath});

p::String data;
SerializeModule(ast, moduleId, data);
Expand Down Expand Up @@ -202,6 +205,7 @@ namespace rift::AST
p::ecs::EntityWriter w{writer.GetWriter(), ast};
w.BeginObject();
w.SerializeSingleEntity(id, onWriteModulePools);

data = writer.ToString();
}

Expand Down
2 changes: 1 addition & 1 deletion Libs/Framework/Src/FrameworkModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ namespace rift
AST::RegisterFileType<AST::CDeclStatic>(
staticType, {.displayName = "Static", .hasVariables = true, .hasFunctions = true});

AST::RegisterSerializedModulePools<AST::CNamespace, AST::CModule>();
AST::RegisterSerializedModulePools<AST::CModule>();
}
} // namespace rift

0 comments on commit b49fb89

Please sign in to comment.