-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCusLib.java
More file actions
132 lines (120 loc) · 4.13 KB
/
CusLib.java
File metadata and controls
132 lines (120 loc) · 4.13 KB
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
121
122
123
124
125
126
127
128
129
130
131
132
import java.util.ArrayList;
public class CusLib {
public static final String RESET = "\u001B[0m";
public static final String RED = "\u001B[31m";
public static final String GREEN = "\u001B[32m";
public static final String YELLOW = "\u001B[33m";
public static final String BLUE = "\u001B[34m";
public static final String PURPLE = "\u001B[35m";
public static final String CYAN = "\u001B[36m";
public static final String WHITE = "\u001B[37m";
private static ArrayList<String> queuedText = new ArrayList<>();
public static int percentage(int part, int total){
return (int)(((double)part/(double)total) * 100);
}
public static int randomNum(int min, int max){
return (int)Math.floor(Math.random()*(max-min+1)+min);
}
//param f is the interpolation fraction, typically between 0 and 1, if you purposely want the min to be bigger than the max (or vice versa) then set the override to true
public static double linearInterp(double f, double min, double max, boolean override){ // From http://www.java2s.com/example/java/java.lang/computes-a-linear-interpolation-between-two-values.html
if(!override){
double tempMin = 0.0;
double tempMax = 0.0;
if(min > max){
// System.out.println("Fixing Min Max's");
tempMin = max;
tempMax = min;
max = tempMax;
min = tempMin;
}
}
DebugOutputLn(String.format("Fraction: %s, Min: %s, Max: %s",f,min,max));
DebugOutputLn(max + f * (max-min));
return max + f * (max-min);
}
public static double randomNum(double min, double max){
double ran = Math.random()*(max-min+1)+min;
if(ran < min){
ran = min;
}
if(ran > max){
ran = max;
}
return ran;
}
public static <T> String colorText(T text, String color){
String finalColor = getColor(color);
return String.format("%s%s%s",finalColor,text,RESET);
}
public static String getColor(String color){
String finalColor = "";
switch(color.toLowerCase()){
case "red":
finalColor = RED;
break;
case "green":
finalColor = GREEN;
break;
case "yellow":
finalColor = YELLOW;
break;
case "white":
finalColor = WHITE;
break;
case "blue":
finalColor = BLUE;
break;
case "cyan":
finalColor = CYAN;
break;
case "purple":
finalColor = PURPLE;
break;
}
return finalColor;
}
public static <T> void DebugOutputLn(T text){
if(Main.debugMode){
System.out.println(text);
}
}
public static <T> void DebugOutput(T text){
if(Main.debugMode){
System.out.print(text);
}
}
public static <T> void advanceTextLn(T text){
System.out.println(text);
String input = Game.input.nextLine();
if(input != null){
return;
}
}
public static <T> void advanceText(T text){
System.out.print(text);
String input = Game.input.nextLine();
if(input != null){
return;
}
}
public static <T> void queueText(T text){
String finalText = "" + text;
queuedText.add(finalText);
DebugOutputLn("Added new Text ID " + (queuedText.size()-1) + " to queue.");
}
public static void callQueue(boolean advance, boolean newLine){
CusLib.DebugOutputLn("Calling Queue");
for(int i=0;i<queuedText.size();i++){
if(newLine){
queuedText.set(i, queuedText.get(i) + "\n");
}
if(advance){
advanceText(queuedText.get(i));
} else {
System.out.print(queuedText.get(i));
}
}
queuedText.clear();
DebugOutput("Called all queued Text and emptied the queue: " + queuedText.size());
}
}