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