yaze 0.2.0
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
project.h
Go to the documentation of this file.
1#ifndef YAZE_APP_CORE_PROJECT_H
2#define YAZE_APP_CORE_PROJECT_H
3
4#include <algorithm>
5#include <fstream>
6#include <string>
7#include <vector>
8
9#include "absl/status/status.h"
10#include "app/core/common.h"
12
13namespace yaze {
14namespace app {
15
16const std::string kRecentFilesFilename = "recent_files.txt";
17constexpr char kEndOfProjectFile[] = "EndOfProjectFile";
18
29 absl::Status Create(const std::string& project_name) {
30 name = project_name;
31 project_opened_ = true;
32 return absl::OkStatus();
33 }
34 absl::Status CheckForEmptyFields() {
35 if (name.empty() || filepath.empty() || rom_filename_.empty() ||
36 code_folder_.empty() || labels_filename_.empty()) {
37 return absl::InvalidArgumentError(
38 "Project fields cannot be empty. Please load a rom file, set your "
39 "code folder, and set your labels file. See HELP for more details.");
40 }
41
42 return absl::OkStatus();
43 }
44 absl::Status Open(const std::string &project_path);
45 absl::Status Save();
46
47 bool project_opened_ = false;
48 std::string name;
49 std::string flags = "";
50 std::string filepath;
51 std::string rom_filename_ = "";
52 std::string code_folder_ = "";
53 std::string labels_filename_ = "";
54 std::string keybindings_file = "";
55};
56
57// Default types
58static constexpr absl::string_view kDefaultTypes[] = {
59 "Dungeon Names", "Dungeon Room Names", "Overworld Map Names"};
60
62 bool LoadLabels(const std::string& filename);
63 bool SaveLabels();
64 void DisplayLabels(bool* p_open);
65 void EditLabel(const std::string& type, const std::string& key,
66 const std::string& newValue);
67 void SelectableLabelWithNameEdit(bool selected, const std::string& type,
68 const std::string& key,
69 const std::string& defaultValue);
70 std::string GetLabel(const std::string& type, const std::string& key);
71 std::string CreateOrGetLabel(const std::string& type, const std::string& key,
72 const std::string& defaultValue);
73
74 bool labels_loaded_ = false;
75 std::string filename_;
76 struct ResourceType {
77 std::string key_name;
79 };
80
81 std::unordered_map<std::string, std::unordered_map<std::string, std::string>>
83};
84
86 public:
88 RecentFilesManager(const std::string& filename) : filename_(filename) {}
89
90 void AddFile(const std::string& file_path) {
91 // Add a file to the list, avoiding duplicates
92 auto it = std::find(recent_files_.begin(), recent_files_.end(), file_path);
93 if (it == recent_files_.end()) {
94 recent_files_.push_back(file_path);
95 }
96 }
97
98 void Save() {
99 std::ofstream file(filename_);
100 if (!file.is_open()) {
101 return; // Handle the error appropriately
102 }
103
104 for (const auto& file_path : recent_files_) {
105 file << file_path << std::endl;
106 }
107 }
108
109 void Load() {
110 std::ifstream file(filename_);
111 if (!file.is_open()) {
112 return;
113 }
114
115 recent_files_.clear();
116 std::string line;
117 while (std::getline(file, line)) {
118 if (!line.empty()) {
119 recent_files_.push_back(line);
120 }
121 }
122 }
123
124 const std::vector<std::string>& GetRecentFiles() const {
125 return recent_files_;
126 }
127
128 private:
129 std::string filename_;
130 std::vector<std::string> recent_files_;
131};
132
133} // namespace app
134} // namespace yaze
135
136#endif // YAZE_APP_CORE_PROJECT_H
const std::vector< std::string > & GetRecentFiles() const
Definition project.h:124
RecentFilesManager(const std::string &filename)
Definition project.h:88
void AddFile(const std::string &file_path)
Definition project.h:90
std::vector< std::string > recent_files_
Definition project.h:130
A class to manage experimental feature flags.
Definition common.h:36
const std::string kRecentFilesFilename
Definition project.h:16
constexpr char kEndOfProjectFile[]
Definition project.h:17
Definition common.cc:22
Represents a project in the application.
Definition project.h:28
std::string name
Definition project.h:48
std::string filepath
Definition project.h:50
std::string code_folder_
Definition project.h:52
std::string flags
Definition project.h:49
absl::Status Open(const std::string &project_path)
Definition project.cc:14
std::string labels_filename_
Definition project.h:53
std::string keybindings_file
Definition project.h:54
absl::Status CheckForEmptyFields()
Definition project.h:34
absl::Status Create(const std::string &project_name)
Definition project.h:29
absl::Status Save()
Definition project.cc:43
std::string rom_filename_
Definition project.h:51
std::string CreateOrGetLabel(const std::string &type, const std::string &key, const std::string &defaultValue)
Definition project.cc:176
std::unordered_map< std::string, std::unordered_map< std::string, std::string > > labels_
Definition project.h:82
void DisplayLabels(bool *p_open)
Definition project.cc:112
void SelectableLabelWithNameEdit(bool selected, const std::string &type, const std::string &key, const std::string &defaultValue)
Definition project.cc:147
std::string GetLabel(const std::string &type, const std::string &key)
Definition project.cc:171
void EditLabel(const std::string &type, const std::string &key, const std::string &newValue)
Definition project.cc:141
bool LoadLabels(const std::string &filename)
Definition project.cc:65