|
19 | 19 | #include <map> |
20 | 20 |
|
21 | 21 | #include "dynrpg_easyrpg.h" |
| 22 | +#include "string_view.h" |
22 | 23 | #include "main_data.h" |
23 | 24 | #include "game_variables.h" |
24 | 25 | #include "utils.h" |
@@ -93,30 +94,43 @@ bool DynRpg::EasyRpgPlugin::EasyRaw(dyn_arg_list args, Game_Interpreter* interpr |
93 | 94 | return true; |
94 | 95 | } |
95 | 96 |
|
96 | | - auto func = "raw"; |
| 97 | + auto func = "easyrpg_raw"; |
97 | 98 | bool okay = false; |
98 | 99 |
|
99 | | - lcf::rpg::EventCommand outputCommand; |
100 | | - std::vector<int32_t> outputParams = {}; |
| 100 | + lcf::rpg::EventCommand cmd; |
| 101 | + std::vector<int32_t> output_args; |
101 | 102 |
|
102 | | - for (std::size_t i = 0; i < args.size(); ++i) { |
103 | | - std::string currValue = DynRpg::ParseVarArg(func, args, i, okay); |
104 | | - Output::Warning("{}", currValue); |
| 103 | + if (args.empty()) { |
| 104 | + Output::Warning("easyrpg_raw: Command too short"); |
| 105 | + return true; |
| 106 | + } |
| 107 | + |
| 108 | + std::tie(cmd.code) = DynRpg::ParseArgs<int>(func, args, &okay); |
| 109 | + |
| 110 | + if (!okay) { |
| 111 | + return true; |
| 112 | + } |
105 | 113 |
|
106 | | - if (!okay) return true; |
| 114 | + if (args.size() >= 2) { |
| 115 | + auto [string_arg] = DynRpg::ParseArgs<std::string>(func, args.subspan(1), &okay); |
| 116 | + cmd.string = lcf::DBString(string_arg); |
107 | 117 |
|
108 | | - if (i == 0) outputCommand.code = stoi(currValue); |
109 | | - if (i == 1) outputCommand.string = lcf::DBString(currValue); |
110 | | - else outputParams.push_back(stoi(currValue)); |
| 118 | + if (!okay) { |
| 119 | + return true; |
| 120 | + } |
| 121 | + |
| 122 | + for (size_t i = 2; i < args.size(); ++i) { |
| 123 | + auto [int_arg] = DynRpg::ParseArgs<int>(func, args.subspan(i), &okay); |
| 124 | + |
| 125 | + if (!okay) { |
| 126 | + return true; |
| 127 | + } |
| 128 | + } |
111 | 129 | } |
112 | 130 |
|
113 | | - outputCommand.parameters = lcf::DBArray<int32_t>(outputParams.begin(), outputParams.end()); |
| 131 | + cmd.parameters = lcf::DBArray<int32_t>(output_args.begin(), output_args.end()); |
114 | 132 |
|
115 | | - //FIXME: this will crash when you two interpreters run a raw command in parallel. |
116 | | - // The lack to access the current interpreter frame is a lack in the dynrpg API design. |
117 | | - // Have to fix this. The current frame should be easy to access |
118 | | - std::vector<lcf::rpg::EventCommand> cmdList = { outputCommand }; |
119 | | - interpreter->Push(cmdList, 0, false); |
| 133 | + interpreter->Push({ cmd }, 0, false); |
120 | 134 |
|
121 | 135 | return true; |
122 | 136 | } |
|
0 commit comments