Make various instance stuff to take references to other instance objs
[lsnes.git] / include / core / project.hpp
blob6ced2c60eaf49d0915fbc5149f4ea7a2cf0986f0
1 #ifndef _project__hpp__included__
2 #define _project__hpp__included__
4 #include <string>
5 #include <map>
6 #include <list>
7 #include <vector>
8 #include "library/json.hpp"
9 #include "core/controller.hpp"
10 #include "core/rom.hpp"
12 class voice_commentary;
13 class memwatch_set;
14 class controller_state;
15 namespace command
17 class group;
19 namespace settingvar
21 class cache;
24 //A branch.
25 struct project_branch_info
27 //Parent branch ID.
28 uint64_t pbid;
29 //Name.
30 std::string name;
33 //Information about project.
34 struct project_info
36 //Internal ID of the project.
37 std::string id;
38 //Name of the project.
39 std::string name;
40 //Bundle ROM used.
41 std::string rom;
42 //ROMs used.
43 std::string roms[ROM_SLOT_COUNT];
44 //Last savestate.
45 std::string last_save;
46 //Directory for save/load dialogs.
47 std::string directory;
48 //Prefix for save/load dialogs.
49 std::string prefix;
50 //List of Lua scripts to run at startup.
51 std::list<std::string> luascripts;
52 //Memory watches.
53 std::map<std::string, std::string> watches;
54 //Macros.
55 std::map<std::string, JSON::node> macros;
56 //Branches.
57 std::map<uint64_t, project_branch_info> branches;
58 uint64_t active_branch;
59 uint64_t next_branch;
60 //Filename this was loaded from.
61 std::string filename;
62 //Stub movie data.
63 std::string gametype;
64 std::map<std::string, std::string> settings;
65 std::string coreversion;
66 std::string gamename;
67 std::string projectid;
68 std::string romimg_sha256[ROM_SLOT_COUNT];
69 std::string romxml_sha256[ROM_SLOT_COUNT];
70 std::string namehint[ROM_SLOT_COUNT];
71 std::vector<std::pair<std::string, std::string>> authors;
72 std::map<std::string, std::vector<char>> movie_sram;
73 std::vector<char> anchor_savestate;
74 int64_t movie_rtc_second;
75 int64_t movie_rtc_subsecond;
76 /**
77 * Obtain parent of branch.
79 * Parameter bid: The branch ID.
80 * Returns: The parent branch ID.
81 * Throws std::runtime_error: Invalid branch ID.
83 * Note: bid 0 is root. Calling this on root always gives 0.
85 uint64_t get_parent_branch(uint64_t bid);
86 /**
87 * Get current branch id.
89 * Returns: The branch id.
91 uint64_t get_current_branch() { return active_branch; }
92 /**
93 * Set current branch.
95 * Parameter bid: The branch id.
96 * Throws std::runtime_error: Invalid branch ID.
98 void set_current_branch(uint64_t bid);
99 /**
100 * Get name of branch.
102 * Parameter bid: The branch id.
103 * Throws std::runtime_error: Invalid branch ID.
104 * Note: The name of ROOT branch is always empty string.
106 const std::string& get_branch_name(uint64_t bid);
108 * Set name of branch.
110 * Parameter bid: The branch id.
111 * Parameter name: The new name
112 * Throws std::runtime_error: Invalid branch ID.
113 * Note: The name of ROOT branch can't be changed.
115 void set_branch_name(uint64_t bid, const std::string& name);
117 * Set parent branch of branch.
119 * Parameter bid: The branch id.
120 * Parameter pbid: The new parent branch id.
121 * Throws std::runtime_error: Invalid branch ID, or cyclic dependency.
122 * Note: The parent of ROOT branch can't be set.
124 void set_parent_branch(uint64_t bid, uint64_t pbid);
126 * Enumerate child branches of specified branch.
128 * Parameter bid: The branch id.
129 * Returns: The set of chilid branch IDs.
130 * Throws std::runtime_error: Invalid branch ID.
132 std::set<uint64_t> branch_children(uint64_t bid);
134 * Create a new branch.
136 * Parameter pbid: Parent of the new branch.
137 * Parameter name: Name of new branch.
138 * Returns: Id of new branch.
139 * Throws std::runtime_error: Invalid branch ID.
141 uint64_t create_branch(uint64_t pbid, const std::string& name);
143 * Delete a branch.
145 * Parameter bid: The branch id.
146 * Throws std::runtime_error: Invalid branch ID or branch has children.
148 void delete_branch(uint64_t bid);
150 * Get name of current branch as string.
152 std::string get_branch_string();
154 * Flush the project to disk.
156 void flush();
157 private:
158 void write(std::ostream& s);
161 class project_state
163 public:
164 project_state(voice_commentary& _commentary, memwatch_set& _mwatch, command::group& _command,
165 controller_state& _controls, settingvar::cache& _setcache);
166 ~project_state();
168 * Get currently active project.
170 * Returns: The currently active project or NULL if none.
172 project_info* get();
174 * Change currently active project. This reloads Lua VM, ROM and savestate.
176 * Parameter p: The new currently active project, or NULL to switch out of any project.
177 * Parameter current: If true, do not reload ROM, movie nor state.
179 bool set(project_info* p, bool current = false);
181 * Enumerate all known projects.
183 * Returns: Map from IDs of projects to project names.
185 std::map<std::string, std::string> enumerate();
187 * Load a given project.
189 * Parameter id: The ID of project to load.
190 * Returns: The project information.
192 project_info& load(const std::string& id);
194 * Get project movie path.
196 * Returns: The movie path.
198 std::string moviepath();
200 * Get project other path.
202 * Returns: The other path.
204 std::string otherpath();
206 * Get project savestate extension.
208 * Returns: The savestate extension.
210 std::string savestate_ext();
212 * Copy watches to project
214 void copy_watches(project_info& p);
216 * Copy macros to project.
218 void copy_macros(project_info& p, controller_state& s);
219 private:
220 project_info* active_project;
221 voice_commentary& commentary;
222 memwatch_set& mwatch;
223 command::group& command;
224 controller_state& controls;
225 settingvar::cache& setcache;
228 #endif