11#include " replay_system.hpp"
22#include " hooks.hpp"
3+ #include < filesystem>
4+ #include < fstream>
35
46void ReplaySystem::record_action (bool hold, bool player1, bool flip) {
57 if (is_recording ()) {
@@ -179,4 +181,73 @@ void ReplaySystem::_update_status_label() {
179181 } else if (recorder.m_recording ) {
180182 recorder.stop ();
181183 }
184+ }
185+
186+ std::filesystem::path get_save_file_path () {
187+ const auto path = CCFileUtils::sharedFileUtils ()->getWritablePath ();
188+ return std::filesystem::path (path) / " replaybot.txt" ;
189+ }
190+
191+ void ReplaySystem::save () {
192+ const auto path = get_save_file_path ();
193+ std::ofstream file (path);
194+ // incredible
195+ file << " fps=" << default_fps << ' \n ' ;
196+ file << " type=" << static_cast <int >(default_type) << ' \n ' ;
197+ file << " real_time=" << real_time_mode << ' \n ' ;
198+ file << " showcase_mode=" << showcase_mode << ' \n ' ;
199+ file << " recorder_width=" << recorder.m_width << ' \n ' ;
200+ file << " recorder_height=" << recorder.m_height << ' \n ' ;
201+ file << " recorder_fps=" << recorder.m_fps << ' \n ' ;
202+ file << " recorder_until_end=" << recorder.m_until_end << ' \n ' ;
203+ file << " recorder_codec=" << recorder.m_codec << ' \n ' ;
204+ file << " recorder_bitrate=" << recorder.m_bitrate << ' \n ' ;
205+ file << " recorder_extra_args=" << recorder.m_extra_args << ' \n ' ;
206+ file << " recorder_extra_audio_args=" << recorder.m_extra_audio_args << ' \n ' ;
207+ file << " recorder_after_end_duration=" << recorder.m_after_end_duration << ' \n ' ;
208+ }
209+
210+ void ReplaySystem::load () {
211+ const auto path = get_save_file_path ();
212+ if (!std::filesystem::exists (path)) return ;
213+ std::ifstream file (path);
214+ std::string line;
215+ // incredible
216+ try {
217+ while (std::getline (file, line)) {
218+ if (line.empty ()) continue ;
219+ const auto [key, value] = split_once (line, ' =' );
220+ using namespace std ::literals::string_view_literals;
221+ // incredible
222+ if (key == " fps" sv)
223+ default_fps = std::stof (std::string (value));
224+ else if (key == " type" sv)
225+ default_type = ReplayType (std::stoi (std::string (value)));
226+ else if (key == " real_time" sv)
227+ real_time_mode = value == " 1" sv;
228+ else if (key == " showcase_mode" sv)
229+ showcase_mode = value == " 1" sv;
230+ else if (key == " recorder_width" sv)
231+ recorder.m_width = std::stoul (std::string (value));
232+ else if (key == " recorder_height" sv)
233+ recorder.m_height = std::stoul (std::string (value));
234+ else if (key == " recorder_fps" sv)
235+ recorder.m_fps = std::stoul (std::string (value));
236+ else if (key == " recorder_until_end" sv)
237+ recorder.m_until_end = value == " 1" sv;
238+ else if (key == " recorder_codec" sv)
239+ recorder.m_codec = value;
240+ else if (key == " recorder_bitrate" sv)
241+ recorder.m_bitrate = value;
242+ else if (key == " recorder_extra_args" sv)
243+ recorder.m_extra_args = value;
244+ else if (key == " recorder_extra_audio_args" sv)
245+ recorder.m_extra_audio_args = value;
246+ else if (key == " recorder_after_end_duration" sv)
247+ recorder.m_after_end_duration = std::stof (std::string (value));
248+ }
249+ } catch (...) {
250+ // no care
251+ }
252+
182253}
0 commit comments