forked from MinecraftTAS/TASmod
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOptionsFileCommandExtension.java
120 lines (100 loc) · 3.32 KB
/
OptionsFileCommandExtension.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
package com.minecrafttas.tasmod.playback.filecommands.builtin;
import java.io.IOException;
import java.nio.file.Path;
import com.dselent.bigarraylist.BigArrayList;
import com.minecrafttas.tasmod.TASmod;
import com.minecrafttas.tasmod.playback.PlaybackControllerClient.TickContainer;
import com.minecrafttas.tasmod.playback.filecommands.PlaybackFileCommand;
import com.minecrafttas.tasmod.playback.filecommands.PlaybackFileCommand.PlaybackFileCommandContainer;
import com.minecrafttas.tasmod.playback.filecommands.PlaybackFileCommand.PlaybackFileCommandExtension;
import com.minecrafttas.tasmod.playback.filecommands.PlaybackFileCommand.PlaybackFileCommandLine;
import com.minecrafttas.tasmod.util.LoggerMarkers;
public class OptionsFileCommandExtension extends PlaybackFileCommandExtension {
private boolean shouldRenderHud = true;
BigArrayList<PlaybackFileCommandContainer> hud;
public OptionsFileCommandExtension() {
this("hud");
}
public OptionsFileCommandExtension(String tempDirName) {
super(tempDirName);
hud = new BigArrayList<>(tempDir.toString());
enabled = true;
}
public OptionsFileCommandExtension(Path tempDir) {
super(tempDir);
this.hud = new BigArrayList<>(tempDir.toString());
enabled = true;
}
@Override
public String getExtensionName() {
return "tasmod_options@v1";
}
@Override
public String[] getFileCommandNames() {
return new String[] { "hud" };
}
@Override
public PlaybackFileCommandContainer onSerialiseInlineComment(long tick, TickContainer tickContainer) {
PlaybackFileCommandContainer fileCommandContainer = new PlaybackFileCommandContainer();
if (hud.size() != 0 && hud.get(tick).get("hud") != null) {
fileCommandContainer = hud.get(tick);
}
return fileCommandContainer;
}
@Override
public void onDeserialiseInlineComment(long tick, TickContainer container, PlaybackFileCommandContainer fileCommandContainer) {
if (fileCommandContainer.containsKey("hud")) {
hud.add(fileCommandContainer.split("hud"));
}
}
@Override
public void onPlayback(long tick, TickContainer tickContainer) {
if (hud.size() <= tick) {
return;
}
PlaybackFileCommandContainer containerInTick = hud.get(tick);
if (containerInTick == null) {
return;
}
PlaybackFileCommandLine line = containerInTick.get("hud");
if (line == null) {
return;
}
for (PlaybackFileCommand command : line) {
String[] args = command.getArgs();
if (args.length == 1) {
/*
* Ok this may seem dumb, but Boolean.parseBoolean returns false,
* even if something other then true or false was passed...
* If someone finds something less idiotic please tell me...
*/
switch (args[0]) {
case "true":
shouldRenderHud = true;
break;
case "false":
shouldRenderHud = false;
break;
default:
TASmod.LOGGER.warn(LoggerMarkers.Playback, "FileCommand hud has the wrong argument in tick {}: {} (Must be true or false)", tick, args[0]);
break;
}
} else {
TASmod.LOGGER.warn(LoggerMarkers.Playback, "FileCommand hud has the wrong number of arguments in tick {}: {}", tick, args.length);
}
}
}
@Override
public void onClear() {
try {
hud.clearMemory();
} catch (IOException e) {
e.printStackTrace();
}
hud = new BigArrayList<>();
shouldRenderHud = true;
}
public boolean shouldRenderHud() {
return shouldRenderHud;
}
}