|
18 | 18 | import com.minecrafttas.tasmod.playback.metadata.PlaybackMetadata;
|
19 | 19 | import com.minecrafttas.tasmod.playback.tasfile.flavor.SerialiserFlavorBase;
|
20 | 20 | import com.minecrafttas.tasmod.registries.TASmodAPIRegistry;
|
| 21 | +import com.minecrafttas.tasmod.virtual.VirtualCameraAngle; |
| 22 | +import com.minecrafttas.tasmod.virtual.VirtualKey; |
| 23 | +import com.minecrafttas.tasmod.virtual.VirtualKeyboard; |
| 24 | +import com.minecrafttas.tasmod.virtual.VirtualMouse; |
21 | 25 |
|
22 | 26 | public class AlphaFlavor extends SerialiserFlavorBase {
|
23 | 27 |
|
@@ -106,6 +110,122 @@ public boolean checkFlavorName(List<String> headerLines) {
|
106 | 110 | return false;
|
107 | 111 | }
|
108 | 112 |
|
| 113 | + @Override |
| 114 | + protected List<String> serialiseKeyboard(VirtualKeyboard keyboard) { |
| 115 | + /* |
| 116 | + * Old code from when I did not know String.join exists, |
| 117 | + * kept relatively unaltered because I want to. |
| 118 | + */ |
| 119 | + List<String> out = new ArrayList<>(); |
| 120 | + |
| 121 | + List<String> stringy = keyboard.getCurrentPresses(); |
| 122 | + String keyString = ""; |
| 123 | + if (!stringy.isEmpty()) { |
| 124 | + String seperator = ","; |
| 125 | + for (int i = 0; i < stringy.size(); i++) { |
| 126 | + if (i == stringy.size() - 1) { |
| 127 | + seperator = ""; |
| 128 | + } |
| 129 | + keyString = keyString.concat(stringy.get(i) + seperator); |
| 130 | + } |
| 131 | + } |
| 132 | + List<Character> charList = keyboard.getCharList(); |
| 133 | + String charString = ""; |
| 134 | + if (!charList.isEmpty()) { |
| 135 | + for (int i = 0; i < charList.size(); i++) { |
| 136 | + charString = charString.concat(Character.toString(charList.get(i))); |
| 137 | + } |
| 138 | + charString = charString.replace("\r", "\\n"); |
| 139 | + charString = charString.replace("\n", "\\n"); |
| 140 | + } |
| 141 | + |
| 142 | + out.add("Keyboard:" + keyString + ";" + charString); // Keyboard didn't support subticks, only the current key is processed |
| 143 | + |
| 144 | + return out; |
| 145 | + } |
| 146 | + |
| 147 | + @Override |
| 148 | + protected List<String> serialiseMouse(VirtualMouse mouse) { |
| 149 | + /* |
| 150 | + * Old code from when I did not know String.join exists, |
| 151 | + * kept relatively unaltered because I want to. |
| 152 | + */ |
| 153 | + List<String> out = new ArrayList<>(); |
| 154 | + List<String> stringy = mouse.getCurrentPresses(); |
| 155 | + String keyString = ""; |
| 156 | + if (!stringy.isEmpty()) { |
| 157 | + String seperator = ","; |
| 158 | + for (int i = 0; i < stringy.size(); i++) { |
| 159 | + if (i == stringy.size() - 1) { |
| 160 | + seperator = ""; |
| 161 | + } |
| 162 | + keyString = keyString.concat(stringy.get(i) + seperator); |
| 163 | + } |
| 164 | + } |
| 165 | + |
| 166 | + List<VirtualMouse> path = new ArrayList<>(mouse.getSubticks()); // I previously called subticks "paths" as it was mainly used for the mouse... |
| 167 | +// pruneListEndEmptySubtickable(path); |
| 168 | + |
| 169 | + /* |
| 170 | + * The mouse supported subticks, |
| 171 | + * but it was handled differently in alpha... |
| 172 | + * The subticks where added in square brackets, seperated by a "->" |
| 173 | + * Not the best solution in hindsight, |
| 174 | + * but that was apparently the first thing that came to my mind back then... |
| 175 | + */ |
| 176 | + String pathString = ""; |
| 177 | + if (!path.isEmpty()) { |
| 178 | + String seperator = "->"; |
| 179 | + for (int i = 0; i < path.size(); i++) { |
| 180 | + if (i == path.size() - 1) { |
| 181 | + seperator = ""; |
| 182 | + } |
| 183 | + |
| 184 | + VirtualMouse singlePath = path.get(i); |
| 185 | + |
| 186 | + pathString = pathString.concat("[" + serialisePath(singlePath) + "]" + seperator); |
| 187 | + } |
| 188 | + } |
| 189 | + out.add("Mouse:" + keyString + ";" + pathString); |
| 190 | + return out; |
| 191 | + } |
| 192 | + |
| 193 | + protected String serialisePath(VirtualMouse path) { |
| 194 | + String keyString = ""; |
| 195 | + List<String> strings = new ArrayList<String>(); |
| 196 | + |
| 197 | + path.getPressedKeys().forEach((virtualkeys) -> { |
| 198 | + strings.add(VirtualKey.getName(virtualkeys)); |
| 199 | + }); |
| 200 | + if (!strings.isEmpty()) { |
| 201 | + String seperator = ","; |
| 202 | + for (int i = 0; i < strings.size(); i++) { |
| 203 | + if (i == strings.size() - 1) { |
| 204 | + seperator = ""; |
| 205 | + } |
| 206 | + keyString = keyString.concat(strings.get(i) + seperator); |
| 207 | + } |
| 208 | + } |
| 209 | + if (keyString.isEmpty()) { |
| 210 | + return "MOUSEMOVED," + path.getScrollWheel() + "," + path.getCursorX() + "," + path.getCursorY(); |
| 211 | + } else { |
| 212 | + return keyString + "," + path.getScrollWheel() + "," + path.getCursorX() + "," + path.getCursorY(); |
| 213 | + } |
| 214 | + } |
| 215 | + |
| 216 | + @Override |
| 217 | + protected List<String> serialiseCameraAngle(VirtualCameraAngle subticks) { |
| 218 | + List<String> out = new ArrayList<>(); |
| 219 | + |
| 220 | + /* |
| 221 | + * The camera was called "subticks" in previous iterations of this code. |
| 222 | + * To honor this fact, it is also called subticks here, even though |
| 223 | + * actual subticks were not supported |
| 224 | + */ |
| 225 | + out.add("Camera:" + subticks.getPitch() + ";" + subticks.getYaw()); |
| 226 | + return out; |
| 227 | + } |
| 228 | + |
109 | 229 | @Override
|
110 | 230 | protected void deserialiseMetadata(List<String> headerLines) {
|
111 | 231 | String author = "Insert author here";
|
|
0 commit comments