yaze 0.2.2
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
11namespace yaze {
12
13const std::string kRecentFilesFilename = "recent_files.txt";
14constexpr char kEndOfProjectFile[] = "EndOfProjectFile";
15
25struct Project {
26 absl::Status Create(const std::string& project_name) {
27 name = project_name;
28 project_opened_ = true;
29 return absl::OkStatus();
30 }
31 absl::Status CheckForEmptyFields() {
32 if (name.empty() || filepath.empty() || rom_filename_.empty() ||
33 code_folder_.empty() || labels_filename_.empty()) {
34 return absl::InvalidArgumentError(
35 "Project fields cannot be empty. Please load a rom file, set your "
36 "code folder, and set your labels file. See HELP for more details.");
37 }
38
39 return absl::OkStatus();
40 }
41 absl::Status Open(const std::string& project_path);
42 absl::Status Save();
43
44 bool project_opened_ = false;
45 std::string name;
46 std::string flags = "";
47 std::string filepath;
48 std::string rom_filename_ = "";
49 std::string code_folder_ = "";
50 std::string labels_filename_ = "";
51 std::string keybindings_file = "";
52};
53
54// Default types
55static constexpr absl::string_view kDefaultTypes[] = {
56 "Dungeon Names", "Dungeon Room Names", "Overworld Map Names"};
57
59 bool LoadLabels(const std::string& filename);
60 bool SaveLabels();
61 void DisplayLabels(bool* p_open);
62 void EditLabel(const std::string& type, const std::string& key,
63 const std::string& newValue);
64 void SelectableLabelWithNameEdit(bool selected, const std::string& type,
65 const std::string& key,
66 const std::string& defaultValue);
67 std::string GetLabel(const std::string& type, const std::string& key);
68 std::string CreateOrGetLabel(const std::string& type, const std::string& key,
69 const std::string& defaultValue);
70
71 bool labels_loaded_ = false;
72 std::string filename_;
73 struct ResourceType {
74 std::string key_name;
76 };
77
78 std::unordered_map<std::string, std::unordered_map<std::string, std::string>>
80};
81
83 public:
85 RecentFilesManager(const std::string& filename) : filename_(filename) {}
86
87 void AddFile(const std::string& file_path) {
88 // Add a file to the list, avoiding duplicates
89 auto it = std::find(recent_files_.begin(), recent_files_.end(), file_path);
90 if (it == recent_files_.end()) {
91 recent_files_.push_back(file_path);
92 }
93 }
94
95 void Save() {
96 std::ofstream file(filename_);
97 if (!file.is_open()) {
98 return; // Handle the error appropriately
99 }
100
101 for (const auto& file_path : recent_files_) {
102 file << file_path << std::endl;
103 }
104 }
105
106 void Load() {
107 std::ifstream file(filename_);
108 if (!file.is_open()) {
109 return;
110 }
111
112 recent_files_.clear();
113 std::string line;
114 while (std::getline(file, line)) {
115 if (!line.empty()) {
116 recent_files_.push_back(line);
117 }
118 }
119 }
120
121 const std::vector<std::string>& GetRecentFiles() const {
122 return recent_files_;
123 }
124
125 private:
126 std::string filename_;
127 std::vector<std::string> recent_files_;
128};
129
131 absl::Status Commit(const std::string& message);
132 absl::Status Pull();
133 absl::Status Push();
134
135 private:
136 std::string repository_path_;
137};
138
139} // namespace yaze
140
141#endif // YAZE_APP_CORE_PROJECT_H
std::string filename_
Definition project.h:126
std::vector< std::string > recent_files_
Definition project.h:127
RecentFilesManager(const std::string &filename)
Definition project.h:85
const std::vector< std::string > & GetRecentFiles() const
Definition project.h:121
void AddFile(const std::string &file_path)
Definition project.h:87
absl::Status Commit(const std::string &message)
std::string repository_path_
Definition project.h:136
Main namespace for the application.
Definition controller.cc:12
constexpr char kEndOfProjectFile[]
Definition project.h:14
const std::string kRecentFilesFilename
Definition project.h:13
Represents a project in the application.
Definition project.h:25
std::string flags
Definition project.h:46
std::string name
Definition project.h:45
absl::Status Open(const std::string &project_path)
Definition project.cc:13
absl::Status Create(const std::string &project_name)
Definition project.h:26
std::string code_folder_
Definition project.h:49
absl::Status Save()
Definition project.cc:42
absl::Status CheckForEmptyFields()
Definition project.h:31
std::string keybindings_file
Definition project.h:51
std::string rom_filename_
Definition project.h:48
std::string filepath
Definition project.h:47
std::string labels_filename_
Definition project.h:50
bool project_opened_
Definition project.h:44
std::unordered_map< std::string, std::unordered_map< std::string, std::string > > labels_
Definition project.h:79
void EditLabel(const std::string &type, const std::string &key, const std::string &newValue)
Definition project.cc:140
bool LoadLabels(const std::string &filename)
Definition project.cc:64
std::string GetLabel(const std::string &type, const std::string &key)
Definition project.cc:170
std::string CreateOrGetLabel(const std::string &type, const std::string &key, const std::string &defaultValue)
Definition project.cc:175
void DisplayLabels(bool *p_open)
Definition project.cc:111
void SelectableLabelWithNameEdit(bool selected, const std::string &type, const std::string &key, const std::string &defaultValue)
Definition project.cc:146