yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
project_manager.cc
Go to the documentation of this file.
1#include "project_manager.h"
2
3#include <filesystem>
4#include <fstream>
5
6#include "absl/strings/str_format.h"
8#include "core/project.h"
9
10namespace yaze {
11namespace editor {
12
14 : toast_manager_(toast_manager) {
15}
16
17absl::Status ProjectManager::CreateNewProject(const std::string& template_name) {
18 if (template_name.empty()) {
19 // Create default project
21 current_project_.name = "New Project";
23
24 if (toast_manager_) {
25 toast_manager_->Show("New project created", ToastType::kSuccess);
26 }
27 return absl::OkStatus();
28 }
29
30 return CreateFromTemplate(template_name, "New Project");
31}
32
33absl::Status ProjectManager::OpenProject(const std::string& filename) {
34 if (filename.empty()) {
35 // TODO: Show file dialog
36 return absl::InvalidArgumentError("No filename provided");
37 }
38
39 return LoadProjectFromFile(filename);
40}
41
42absl::Status ProjectManager::LoadProjectFromFile(const std::string& filename) {
43 if (!IsValidProjectFile(filename)) {
44 return absl::InvalidArgumentError(
45 absl::StrFormat("Invalid project file: %s", filename));
46 }
47
48 try {
49 // TODO: Implement actual project loading from JSON/YAML
50 // For now, create a basic project structure
51
53 current_project_.filepath = filename;
54 current_project_.name = std::filesystem::path(filename).stem().string();
55
56 if (toast_manager_) {
58 absl::StrFormat("Project loaded: %s", current_project_.name),
60 }
61
62 return absl::OkStatus();
63
64 } catch (const std::exception& e) {
65 if (toast_manager_) {
67 absl::StrFormat("Failed to load project: %s", e.what()),
69 }
70 return absl::InternalError(
71 absl::StrFormat("Failed to load project: %s", e.what()));
72 }
73}
74
76 if (!HasActiveProject()) {
77 return absl::FailedPreconditionError("No active project to save");
78 }
79
81}
82
83absl::Status ProjectManager::SaveProjectAs(const std::string& filename) {
84 if (filename.empty()) {
85 // TODO: Show save dialog
86 return absl::InvalidArgumentError("No filename provided for save as");
87 }
88
89 return SaveProjectToFile(filename);
90}
91
92absl::Status ProjectManager::SaveProjectToFile(const std::string& filename) {
93 try {
94 // TODO: Implement actual project saving to JSON/YAML
95 // For now, just update the filepath
96
97 current_project_.filepath = filename;
98
99 if (toast_manager_) {
101 absl::StrFormat("Project saved: %s", filename),
103 }
104
105 return absl::OkStatus();
106
107 } catch (const std::exception& e) {
108 if (toast_manager_) {
110 absl::StrFormat("Failed to save project: %s", e.what()),
112 }
113 return absl::InternalError(
114 absl::StrFormat("Failed to save project: %s", e.what()));
115 }
116}
117
118absl::Status ProjectManager::ImportProject(const std::string& project_path) {
119 if (project_path.empty()) {
120 return absl::InvalidArgumentError("No project path provided");
121 }
122
123 if (!std::filesystem::exists(project_path)) {
124 return absl::NotFoundError(
125 absl::StrFormat("Project path does not exist: %s", project_path));
126 }
127
128 // TODO: Implement project import logic
129 // This would typically copy project files and update paths
130
131 if (toast_manager_) {
133 absl::StrFormat("Project imported: %s", project_path),
135 }
136
137 return absl::OkStatus();
138}
139
140absl::Status ProjectManager::ExportProject(const std::string& export_path) {
141 if (!HasActiveProject()) {
142 return absl::FailedPreconditionError("No active project to export");
143 }
144
145 if (export_path.empty()) {
146 return absl::InvalidArgumentError("No export path provided");
147 }
148
149 // TODO: Implement project export logic
150 // This would typically create a package with all project files
151
152 if (toast_manager_) {
154 absl::StrFormat("Project exported: %s", export_path),
156 }
157
158 return absl::OkStatus();
159}
160
162 if (!HasActiveProject()) {
163 return absl::FailedPreconditionError("No active project to repair");
164 }
165
166 // TODO: Implement project repair logic
167 // This would check for missing files, broken references, etc.
168
169 if (toast_manager_) {
170 toast_manager_->Show("Project repair completed", ToastType::kSuccess);
171 }
172
173 return absl::OkStatus();
174}
175
177 if (!HasActiveProject()) {
178 return absl::FailedPreconditionError("No active project to validate");
179 }
180
181 auto result = current_project_.Validate();
182 if (!result.ok()) {
183 if (toast_manager_) {
185 absl::StrFormat("Project validation failed: %s", result.message()),
187 }
188 return result;
189 }
190
191 if (toast_manager_) {
192 toast_manager_->Show("Project validation passed", ToastType::kSuccess);
193 }
194
195 return absl::OkStatus();
196}
197
199 return current_project_.name;
200}
201
204}
205
206std::vector<std::string> ProjectManager::GetAvailableTemplates() const {
207 // TODO: Scan templates directory and return available templates
208 return {
209 "Empty Project",
210 "Dungeon Editor Project",
211 "Overworld Editor Project",
212 "Graphics Editor Project",
213 "Full Editor Project"
214 };
215}
216
217absl::Status ProjectManager::CreateFromTemplate(const std::string& template_name,
218 const std::string& project_name) {
219 if (template_name.empty() || project_name.empty()) {
220 return absl::InvalidArgumentError("Template name and project name required");
221 }
222
223 // TODO: Implement template-based project creation
224 // This would copy template files and customize them
225
227 current_project_.name = project_name;
229
230 if (toast_manager_) {
232 absl::StrFormat("Project created from template: %s", template_name),
234 }
235
236 return absl::OkStatus();
237}
238
239std::string ProjectManager::GenerateProjectFilename(const std::string& project_name) const {
240 // Convert project name to valid filename
241 std::string filename = project_name;
242 std::replace(filename.begin(), filename.end(), ' ', '_');
243 std::replace(filename.begin(), filename.end(), '/', '_');
244 std::replace(filename.begin(), filename.end(), '\\', '_');
245
246 return absl::StrFormat("%s.yaze", filename);
247}
248
249bool ProjectManager::IsValidProjectFile(const std::string& filename) const {
250 if (filename.empty()) {
251 return false;
252 }
253
254 if (!std::filesystem::exists(filename)) {
255 return false;
256 }
257
258 // Check file extension
259 std::string extension = std::filesystem::path(filename).extension().string();
260 return extension == ".yaze" || extension == ".json";
261}
262
263absl::Status ProjectManager::InitializeProjectStructure(const std::string& project_path) {
264 try {
265 // Create project directory structure
266 std::filesystem::create_directories(project_path);
267 std::filesystem::create_directories(project_path + "/assets");
268 std::filesystem::create_directories(project_path + "/scripts");
269 std::filesystem::create_directories(project_path + "/output");
270
271 return absl::OkStatus();
272
273 } catch (const std::exception& e) {
274 return absl::InternalError(
275 absl::StrFormat("Failed to create project structure: %s", e.what()));
276 }
277}
278
279} // namespace editor
280} // namespace yaze
std::string GenerateProjectFilename(const std::string &project_name) const
absl::Status SaveProjectAs(const std::string &filename="")
absl::Status ExportProject(const std::string &export_path)
std::vector< std::string > GetAvailableTemplates() const
std::string GetProjectPath() const
bool IsValidProjectFile(const std::string &filename) const
absl::Status CreateNewProject(const std::string &template_name="")
project::YazeProject current_project_
absl::Status OpenProject(const std::string &filename="")
ProjectManager(ToastManager *toast_manager)
absl::Status ImportProject(const std::string &project_path)
absl::Status LoadProjectFromFile(const std::string &filename)
absl::Status InitializeProjectStructure(const std::string &project_path)
absl::Status CreateFromTemplate(const std::string &template_name, const std::string &project_name)
absl::Status SaveProjectToFile(const std::string &filename)
std::string GetProjectName() const
void Show(const std::string &message, ToastType type=ToastType::kInfo, float ttl_seconds=3.0f)
Main namespace for the application.
Definition controller.cc:20
Modern project structure with comprehensive settings consolidation.
Definition project.h:78
absl::Status Validate() const
Definition project.cc:461