MCPcopy Create free account
hub / github.com/EasyRPG/Player / CommandManiacControlGlobalSave

Method CommandManiacControlGlobalSave

src/game_interpreter.cpp:4859–4985  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4857}
4858
4859bool Game_Interpreter::CommandManiacControlGlobalSave(lcf::rpg::EventCommand const& com) {
4860 if (!Player::IsPatchManiac()) {
4861 return true;
4862 }
4863
4864 int operation = com.parameters[0];
4865
4866 auto load_global_save = [&]() {
4867 Main_Data::global_save_opened = true;
4868
4869 // Load
4870 auto lgs = FileFinder::Save().OpenFile("Save.lgs");
4871 if (!lgs) {
4872 return;
4873 }
4874
4875 lcf::LcfReader reader(lgs);
4876 std::string header;
4877 reader.ReadString(header, reader.ReadInt());
4878 if (header.length() != 13 || header != "LcfGlobalSave") {
4879 Output::Debug("This is not a valid global save.");
4880 return;
4881 }
4882
4883 lcf::LcfReader::Chunk chunk;
4884
4885 while (!reader.Eof()) {
4886 chunk.ID = reader.ReadInt();
4887 chunk.length = reader.ReadInt();
4888 switch (chunk.ID) {
4889 case 1: {
4890 Game_Switches::Switches_t switches;
4891 reader.Read(switches, chunk.length);
4892 Main_Data::game_switches_global->SetData(std::move(switches));
4893 break;
4894 }
4895 case 2: {
4896 Game_Variables::Variables_t variables;
4897 reader.Read(variables, chunk.length);
4898 Main_Data::game_variables_global->SetData(std::move(variables));
4899 break;
4900 }
4901 default:
4902 reader.Skip(chunk, "CommandManiacControlGlobalSave");
4903 }
4904 }
4905 };
4906
4907 if (operation == 0) {
4908 // Open
4909 load_global_save();
4910 } else if (operation == 1) {
4911 // Close
4912 Main_Data::global_save_opened = false;
4913 } else if (operation == 2 || operation == 3) {
4914 // 2: Save (write to file)
4915 // 3: Save and Close
4916 if (!Main_Data::global_save_opened) {

Callers

nothing calls this directly

Calls 10

OpenFileMethod · 0.80
OpenOutputStreamMethod · 0.80
WriteMethod · 0.80
ReadMethod · 0.45
SetDataMethod · 0.45
FindFileMethod · 0.45
emptyMethod · 0.45
GetSizeMethod · 0.45
SetMethod · 0.45
GetMethod · 0.45

Tested by

no test coverage detected