forked from celoko/batclient_triggers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbph.bcs
96 lines (79 loc) · 2.18 KB
/
bph.bcs
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
SCRIPT_NAME = "bph";
SCRIPT_DESC = "Script to help deliver bard play";
// Usage:
// Make keybinding to $bph
// Run $bph without agruments to do line
// $bph goto x to change current line
// For role change, make command cr enter;ne;wear $*;sw;e
int counter = 0;
List lines = new ArrayList();
// Read story to lines array
void loadStory() {
// Change the path!
file = "/path/to/story.txt";
String result = "";
BufferedReader in;
try{
in = new BufferedReader(new FileReader( file ));
int token = 0;
while(token >= 0){
token = in.read();
if(token >= 0){
// Split on linebreak and write to array
if ((char)token == '\n') {
lines.add(result);
result = "";
} else {
result += (char)token;
}
}
}
in.close();
}catch(Exception e){
clientGUI.printText("general", ""+e);
return;
}
}
doLine() {
String line = lines.get(counter);
// If line starts with cr (= costume change)
// run it and next line also
// otherwise do just one line
if ( line.split(" ")[0].equals("cr") ) {
//clientGUI.printText("general", line + "\n" );
clientGUI.doCommand( line );
counter++;
if (counter <= lines.size() ) {
doLine();
}
} else {
//clientGUI.printText("general", line + "\n" );
clientGUI.doCommand( line );
counter++;
}
}
void run(){
//clientGUI.printText("general", "Bard_play_helper: Arg: "+ argument +".\n" );
if (argument == null || "".equals(argument) || !argument.contains(" ") ) {
if (counter < lines.size()) {
doLine();
} else {
clientGUI.printText("general", "Bard_play_helper: Play is over\n" );
}
} else {
String command = argument.split(" ")[0];
int newLine = Integer.parseInt(argument.split(" ")[1]);
if ( "goto".equals(command) ) {
if ( (newLine != null) && (newLine <= lines.size()) ) {
counter = newLine;
clientGUI.printText("general", "Bph: Counter set to: " + counter +".\n" );
clientGUI.printText("general", "Bph: Current line: " + lines.get(counter) +".\n" );
} else {
clientGUI.printText("general", "Bph: Wrong line.\n" );
}
}
}
}
void bootup() {
loadStory();
}