|
17 | 17 |
|
18 | 18 | // Headers
|
19 | 19 | #include <map>
|
| 20 | +#include <numeric> |
20 | 21 |
|
21 | 22 | #include "dynrpg_easyrpg.h"
|
22 | 23 | #include "string_view.h"
|
@@ -99,42 +100,86 @@ bool DynRpg::EasyRpgPlugin::EasyRaw(dyn_arg_list args, Game_Interpreter* interpr
|
99 | 100 | Constants constList;
|
100 | 101 |
|
101 | 102 | const std::string func = "easyrpg_raw";
|
102 |
| - bool okay = false; |
| 103 | + |
103 | 104 | int codeArgIndex = 0;
|
104 | 105 | int stringArgIndex = 1;
|
| 106 | + int indentArgIndex = -1; |
| 107 | + |
105 | 108 | bool endOfLine = false;
|
| 109 | + bool okay = false; |
106 | 110 |
|
107 | 111 | lcf::rpg::EventCommand cmd;
|
| 112 | + lcf::rpg::EventCommand _cmd; |
108 | 113 | std::vector<int32_t> outputArgs;
|
109 | 114 | std::vector<lcf::rpg::EventCommand> cmdList;
|
110 | 115 |
|
111 | 116 | for (size_t i = 0; i < args.size(); ++i) {
|
112 |
| - if (i == args.size() - 1) { |
113 |
| - if (args[i].back() == ';') args[i] = args[i].substr(0, args[i].length() - 1); |
114 |
| - endOfLine = true; |
| 117 | + |
| 118 | + bool valid = !args[i].empty(); |
| 119 | + |
| 120 | + if (valid && args[i].front() == '[') args[i] = args[i].substr(1); |
| 121 | + if (valid && args[i].back() == ']') { |
| 122 | + args[i] = args[i].substr(0, args[i].length() - 1); |
| 123 | + indentArgIndex = i + 1; |
115 | 124 | }
|
116 | 125 |
|
117 |
| - // TODO: Implement multi-line command interpretation split by ';'. |
| 126 | + valid = !args[i].empty(); |
118 | 127 |
|
119 |
| - if (i == codeArgIndex) { |
120 |
| - if (args[i].front() == '@') args[i] = constList.get("EventCode", args[i].substr(1)); |
121 |
| - std::tie(cmd.code) = DynRpg::ParseArgs<int>(func, args, &okay); |
122 |
| - } |
123 |
| - else if (i == stringArgIndex) { |
124 |
| - auto [stringArg] = DynRpg::ParseArgs<std::string>(func, args.subspan(i), &okay); |
125 |
| - cmd.string = lcf::DBString(stringArg); |
126 |
| - } |
127 |
| - else { |
128 |
| - if (args[i].front() == '@') args[i] = constList.get("DestinyScript", args[i].substr(1)); |
129 |
| - auto [intArg] = DynRpg::ParseArgs<int>(func, args.subspan(i), &okay); |
130 |
| - outputArgs.push_back(intArg); |
| 128 | + if (i == args.size() - 1) endOfLine = true; |
| 129 | + |
| 130 | + |
| 131 | + else if (args[i] == ";") { |
| 132 | + endOfLine = !args[i + 1].empty(); |
| 133 | + valid = 0; |
131 | 134 | }
|
132 | 135 |
|
| 136 | + if (valid) { |
| 137 | + if (i == codeArgIndex) |
| 138 | + { |
| 139 | + size_t start_pos = args[i].find_first_not_of(" \t\r\n"); |
| 140 | + if (start_pos != std::string::npos) |
| 141 | + args[i] = args[i].substr(start_pos); |
| 142 | + |
| 143 | + // Output::Debug("code ----> {}", args[i]); |
| 144 | + |
| 145 | + if (args[i].front() == '$') |
| 146 | + args[i] = constList.get("EventCode", args[i].substr(1)); |
| 147 | + std::tie(cmd.code) = DynRpg::ParseArgs<int>(func, args.subspan(i), &okay); |
| 148 | + } |
| 149 | + else if (i == stringArgIndex) |
| 150 | + { |
| 151 | + // Output::Debug("str ----> {}", args[i]); |
| 152 | + auto [stringArg] = DynRpg::ParseArgs<std::string>(func, args.subspan(i), &okay); |
| 153 | + cmd.string = lcf::DBString(stringArg); |
| 154 | + } |
| 155 | + else |
| 156 | + { |
| 157 | + if (args[i].front() == '$') |
| 158 | + args[i] = constList.get("DestinyScript", args[i].substr(1)); |
| 159 | + auto [intArg] = DynRpg::ParseArgs<int>(func, args.subspan(i), &okay); |
| 160 | + |
| 161 | + if (indentArgIndex == i) { |
| 162 | + // Output::Debug("idt ----> {}", args[i]); |
| 163 | + indentArgIndex = -1; |
| 164 | + cmd.indent = intArg; |
| 165 | + } |
| 166 | + else |
| 167 | + // Output::Debug("pls ----> {}", args[i]), |
| 168 | + outputArgs.push_back(intArg); |
| 169 | + } |
| 170 | + } |
133 | 171 | if (endOfLine) {
|
134 |
| - codeArgIndex = i + 1; |
135 |
| - stringArgIndex = i + 2; |
| 172 | + // Output::Debug("com ----> {}\n\n", cmd.code); |
136 | 173 | cmd.parameters = lcf::DBArray<int32_t>(outputArgs.begin(), outputArgs.end());
|
137 | 174 | cmdList.push_back(cmd);
|
| 175 | + outputArgs.clear(); |
| 176 | + |
| 177 | + cmd = _cmd; |
| 178 | + |
| 179 | + codeArgIndex = i + 1; |
| 180 | + stringArgIndex = i + 2; |
| 181 | + |
| 182 | + endOfLine = false; |
138 | 183 | }
|
139 | 184 |
|
140 | 185 | if (!okay) return true;
|
|
0 commit comments