1 #ifndef _project__hpp__included__
2 #define _project__hpp__included__
8 #include "core/rom-small.hpp"
9 #include "library/command.hpp"
10 #include "library/json.hpp"
12 class voice_commentary
;
14 class controller_state
;
16 class emulator_dispatch
;
19 namespace settingvar
{ class cache
; }
22 struct project_branch_info
30 //Information about project.
33 //Internal ID of the project.
35 //Name of the project.
40 std::string roms
[ROM_SLOT_COUNT
];
42 std::string last_save
;
43 //Directory for save/load dialogs.
44 std::string directory
;
45 //Prefix for save/load dialogs.
47 //List of Lua scripts to run at startup.
48 std::list
<std::string
> luascripts
;
50 std::map
<std::string
, std::string
> watches
;
52 std::map
<std::string
, JSON::node
> macros
;
54 std::map
<uint64_t, project_branch_info
> branches
;
55 uint64_t active_branch
;
57 //Filename this was loaded from.
61 std::map
<std::string
, std::string
> settings
;
62 std::string coreversion
;
64 std::string projectid
;
65 std::string romimg_sha256
[ROM_SLOT_COUNT
];
66 std::string romxml_sha256
[ROM_SLOT_COUNT
];
67 std::string namehint
[ROM_SLOT_COUNT
];
68 std::vector
<std::pair
<std::string
, std::string
>> authors
;
69 std::map
<std::string
, std::vector
<char>> movie_sram
;
70 std::vector
<char> anchor_savestate
;
71 int64_t movie_rtc_second
;
72 int64_t movie_rtc_subsecond
;
74 * Make empty project info.
76 project_info(emulator_dispatch
& _dispatch
);
78 * Obtain parent of branch.
80 * Parameter bid: The branch ID.
81 * Returns: The parent branch ID.
82 * Throws std::runtime_error: Invalid branch ID.
84 * Note: bid 0 is root. Calling this on root always gives 0.
86 uint64_t get_parent_branch(uint64_t bid
);
88 * Get current branch id.
90 * Returns: The branch id.
92 uint64_t get_current_branch() { return active_branch
; }
96 * Parameter bid: The branch id.
97 * Throws std::runtime_error: Invalid branch ID.
99 void set_current_branch(uint64_t bid
);
101 * Get name of branch.
103 * Parameter bid: The branch id.
104 * Throws std::runtime_error: Invalid branch ID.
105 * Note: The name of ROOT branch is always empty string.
107 const std::string
& get_branch_name(uint64_t bid
);
109 * Set name of branch.
111 * Parameter bid: The branch id.
112 * Parameter name: The new name
113 * Throws std::runtime_error: Invalid branch ID.
114 * Note: The name of ROOT branch can't be changed.
116 void set_branch_name(uint64_t bid
, const std::string
& name
);
118 * Set parent branch of branch.
120 * Parameter bid: The branch id.
121 * Parameter pbid: The new parent branch id.
122 * Throws std::runtime_error: Invalid branch ID, or cyclic dependency.
123 * Note: The parent of ROOT branch can't be set.
125 void set_parent_branch(uint64_t bid
, uint64_t pbid
);
127 * Enumerate child branches of specified branch.
129 * Parameter bid: The branch id.
130 * Returns: The set of chilid branch IDs.
131 * Throws std::runtime_error: Invalid branch ID.
133 std::set
<uint64_t> branch_children(uint64_t bid
);
135 * Create a new branch.
137 * Parameter pbid: Parent of the new branch.
138 * Parameter name: Name of new branch.
139 * Returns: Id of new branch.
140 * Throws std::runtime_error: Invalid branch ID.
142 uint64_t create_branch(uint64_t pbid
, const std::string
& name
);
146 * Parameter bid: The branch id.
147 * Throws std::runtime_error: Invalid branch ID or branch has children.
149 void delete_branch(uint64_t bid
);
151 * Get name of current branch as string.
153 std::string
get_branch_string();
155 * Flush the project to disk.
159 void write(std::ostream
& s
);
160 emulator_dispatch
& edispatch
;
166 project_state(voice_commentary
& _commentary
, memwatch_set
& _mwatch
, command::group
& _command
,
167 controller_state
& _controls
, settingvar::group
& _setgroup
, button_mapping
& _buttons
,
168 emulator_dispatch
& _edispatch
, input_queue
& _iqueue
, loaded_rom
& _rom
, status_updater
& _supdater
);
171 * Get currently active project.
173 * Returns: The currently active project or NULL if none.
177 * Change currently active project. This reloads Lua VM, ROM and savestate.
179 * Parameter p: The new currently active project, or NULL to switch out of any project.
180 * Parameter current: If true, do not reload ROM, movie nor state.
182 bool set(project_info
* p
, bool current
= false);
184 * Enumerate all known projects.
186 * Returns: Map from IDs of projects to project names.
188 std::map
<std::string
, std::string
> enumerate();
190 * Load a given project.
192 * Parameter id: The ID of project to load.
193 * Returns: The project information.
195 project_info
& load(const std::string
& id
);
197 * Get project movie path.
199 * Returns: The movie path.
201 std::string
moviepath();
203 * Get project other path.
205 * Returns: The other path.
207 std::string
otherpath();
209 * Get project savestate extension.
211 * Returns: The savestate extension.
213 std::string
savestate_ext();
215 * Copy watches to project
217 void copy_watches(project_info
& p
);
219 * Copy macros to project.
221 void copy_macros(project_info
& p
, controller_state
& s
);
223 void recursive_list_branch(uint64_t bid
, std::set
<unsigned>& dset
, unsigned depth
, bool last_of
);
225 void do_branch_mk(const std::string
& a
);
226 void do_branch_rm(const std::string
& a
);
227 void do_branch_set(const std::string
& a
);
228 void do_branch_rp(const std::string
& a
);
229 void do_branch_mv(const std::string
& a
);
230 project_info
* active_project
;
231 voice_commentary
& commentary
;
232 memwatch_set
& mwatch
;
233 command::group
& command
;
234 controller_state
& controls
;
235 settingvar::group
& setgroup
;
236 button_mapping
& buttons
;
237 emulator_dispatch
& edispatch
;
240 status_updater
& supdater
;
241 command::_fnptr
<> branch_ls
;
242 command::_fnptr
<const std::string
&> branch_mk
;
243 command::_fnptr
<const std::string
&> branch_rm
;
244 command::_fnptr
<const std::string
&> branch_set
;
245 command::_fnptr
<const std::string
&> branch_rp
;
246 command::_fnptr
<const std::string
&> branch_mv
;