Skip to content

Commit b49fb89

Browse files
authored
Merge pull request #91 from PipeRift/feature/allow-ctypes-editing
Allow ctypes editing
2 parents f503805 + 0d703c7 commit b49fb89

File tree

8 files changed

+30
-22
lines changed

8 files changed

+30
-22
lines changed

Examples/Project/__module__.rf

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
{
2-
"CNamespace": "none",
32
"CModule": {
43
"target": "Executable",
54
"dependencies": [

Libs/Editor/Src/Panels/FileExplorerPanel.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ namespace rift::Editor
7979
UI::BeginChild("Files");
8080
if (UI::BeginPopupContextWindow())
8181
{
82-
String projectPath = p::ToString(AST::GetProjectPath(ast));
82+
String projectPath{AST::GetProjectPath(ast)};
8383
DrawContextMenu(ast, projectPath, AST::NoId);
8484
UI::EndPopup();
8585
}

Libs/Editor/Src/Systems/EditorSystem.cpp

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -394,10 +394,10 @@ namespace rift::Editor::EditorSystem
394394
if (UI::MenuItem(ICON_FA_SAVE, "CTRL+S"))
395395
{
396396
auto& file = ast.Get<AST::CFileRef>(moduleId);
397-
TPair<Path, String> fileData{file.path, ""};
398-
AST::SerializeModule(ast, moduleId, fileData.second);
397+
String data;
398+
AST::SerializeModule(ast, moduleId, data);
399399

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

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

445445
if (UI::BeginInspector("ModuleInspector"))
446446
{
447-
auto& ns = moduleEditors.GetOrAdd<AST::CNamespace>(moduleId);
448-
UI::InspectStruct(&ns);
449-
450447
auto& module = moduleEditors.Get<AST::CModule>(moduleId);
451448
UI::InspectStruct(&module);
452449

@@ -504,15 +501,16 @@ namespace rift::Editor::EditorSystem
504501
if (UI::MenuItem(ICON_FA_SAVE, "CTRL+S"))
505502
{
506503
auto& file = ast.Get<AST::CFileRef>(typeId);
507-
TPair<Path, String> fileData{file.path, ""};
508-
AST::SerializeType(ast, typeId, fileData.second);
504+
String data;
505+
AST::SerializeType(ast, typeId, data);
506+
507+
files::SaveStringFile(file.path, data);
508+
ast.Remove<AST::CFileDirty>(typeId);
509509

510510
UI::AddNotification({UI::ToastType::Success, 1.f,
511511
Strings::Format("Saved file {}", p::GetFilename(file.path))});
512-
513-
files::SaveStringFile(fileData.first, fileData.second);
514-
ast.Remove<AST::CFileDirty>(typeId);
515512
}
513+
516514
if (UI::BeginMenu("View"))
517515
{
518516
if (AST::HasFunctions(ast, typeId))

Libs/Framework/Include/AST/Utils/Namespaces.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,15 @@ namespace rift::AST
5656
}
5757
Tag& Last()
5858
{
59-
return scopes[Size() - 1];
59+
const i32 size = Size();
60+
const i32 lastIndex = size > 0 ? (size - 1) : 0; // Is Size is 0, last is first
61+
return scopes[lastIndex];
6062
}
61-
Tag Last() const
63+
const Tag& Last() const
6264
{
63-
return scopes[Size() - 1];
65+
const i32 size = Size();
66+
const i32 lastIndex = size > 0 ? (size - 1) : 0; // Is Size is 0, last is first
67+
return scopes[lastIndex];
6468
}
6569
bool operator==(const Namespace& other) const
6670
{

Libs/Framework/Src/AST/Systems/LoadSystem.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ namespace rift::AST::LoadSystem
8787
TSet<Path> modulePaths;
8888

8989
TAccess<CModule, CFileRef> access{ast};
90-
auto modules = ecs::ListAll<CModule>(access);
90+
auto modules = ecs::ListAll<CModule, CFileRef>(access);
9191

9292
modulePaths.Reserve(modules.Size());
9393
for (Id moduleId : modules)
@@ -121,7 +121,8 @@ namespace rift::AST::LoadSystem
121121
{
122122
ZoneScoped;
123123

124-
TAccess<TWrite<CModule>, TWrite<CFileRef>, CProject, TWrite<CChild>, TWrite<CParent>>
124+
TAccess<TWrite<CModule>, TWrite<CFileRef>, TWrite<CNamespace>, CProject, TWrite<CChild>,
125+
TWrite<CParent>>
125126
access{ast};
126127

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

145146
for (i32 i = 0; i < ids.Size(); ++i)
146147
{
147-
Id id = ids[i];
148+
Id id = ids[i];
149+
p::String& path = paths[i];
148150
access.Add<CModule>(id);
149-
access.Add(id, CFileRef{Move(paths[i])});
151+
access.Add(id, CNamespace{p::GetFilename(p::GetParentPath(path))});
152+
access.Add(id, CFileRef{Move(path)});
150153
}
151154

152155
// Link modules to the project

Libs/Framework/Src/AST/Utils/ModuleUtils.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ namespace rift::AST
8686
// Create project node (root module)
8787
Id projectId = ast.Create();
8888
ast.Add<CProject, CModule>(projectId);
89+
ast.Add(projectId, CNamespace{p::GetFilename(p::GetParentPath(filePath))});
8990
ast.Add(projectId, CFileRef{filePath});
9091

9192
// Load project module
@@ -125,6 +126,8 @@ namespace rift::AST
125126

126127
Id moduleId = ast.Create();
127128
ast.Add<CModule>(moduleId);
129+
ast.Add(moduleId, CNamespace{p::GetFilename(p::GetParentPath(filePath))});
130+
ast.Add(moduleId, CFileRef{filePath});
128131

129132
p::String data;
130133
SerializeModule(ast, moduleId, data);
@@ -202,6 +205,7 @@ namespace rift::AST
202205
p::ecs::EntityWriter w{writer.GetWriter(), ast};
203206
w.BeginObject();
204207
w.SerializeSingleEntity(id, onWriteModulePools);
208+
205209
data = writer.ToString();
206210
}
207211

Libs/Framework/Src/FrameworkModule.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@ namespace rift
3131
AST::RegisterFileType<AST::CDeclStatic>(
3232
staticType, {.displayName = "Static", .hasVariables = true, .hasFunctions = true});
3333

34-
AST::RegisterSerializedModulePools<AST::CNamespace, AST::CModule>();
34+
AST::RegisterSerializedModulePools<AST::CModule>();
3535
}
3636
} // namespace rift

0 commit comments

Comments
 (0)