3import java.util.ArrayList;
6import java.util.concurrent.ConcurrentHashMap;
7import java.util.concurrent.CopyOnWriteArrayList;
11 protected Map<String, Object>
variables =
new ConcurrentHashMap<>();
12 protected Map<String, List<Object>>
lists =
new ConcurrentHashMap<>();
56 return lists.computeIfAbsent(
name, k ->
new CopyOnWriteArrayList<>());
59 public void addToList(String listName, Object item) {
64 List<Object> list =
getList(listName);
65 if (index >= 1 && index <= list.size()) {
66 list.remove(index - 1);
71 List<Object> list =
getList(listName);
72 if (index >= 1 && index <= list.size()) {
73 return list.get(index - 1);
80 return (
int) (Math.random() * (max - min + 1)) + min;
83 public String
join(Object a, Object b) {
87 public String
letterOf(
int index, String text) {
88 if (index >= 1 && index <= text.length()) {
89 return String.valueOf(text.charAt(index - 1));
100 if (o instanceof Number)
return ((Number) o).doubleValue();
102 return Double.parseDouble(o.toString());
103 }
catch (Exception e) {
109 return o ==
null ?
"" : o.toString();
114 Thread t =
new Thread(() -> {
143 Thread.sleep((
long) (sec * 1000));
144 }
catch (Exception e) {
145 Thread.currentThread().interrupt();
150 private List<javax.sound.sampled.Clip>
activeClips =
new java.util.concurrent.CopyOnWriteArrayList<>();
155 java.io.File file =
new java.io.File(soundPath);
156 if (!file.exists())
return;
157 javax.sound.sampled.AudioInputStream ais = javax.sound.sampled.AudioSystem.getAudioInputStream(file);
158 javax.sound.sampled.Clip clip = javax.sound.sampled.AudioSystem.getClip();
161 javax.sound.sampled.FloatControl gainControl = (javax.sound.sampled.FloatControl) clip.getControl(javax.sound.sampled.FloatControl.Type.MASTER_GAIN);
162 float dB = (float) (Math.log(
volume / 100.0) / Math.log(10.0) * 20.0);
163 if (dB < -80.0f) dB = -80.0f;
164 gainControl.setValue(dB);
167 clip.addLineListener(event -> {
168 if (event.getType() == javax.sound.sampled.LineEvent.Type.STOP) {
174 }
catch (Exception e) {}
179 for (javax.sound.sampled.Clip clip :
activeClips) {
187 this.volume = percent;
Object getVariable(String name)
void changeVariableBy(String name, double amount)
ScratchObject(String name)
List< Thread > activeScripts
void addToList(String listName, Object item)
double castToDouble(Object o)
String getVariableAsString(String name)
void deleteFromList(String listName, int index)
Map< String, Object > variables
void setVolume(double percent)
void playSound(String soundPath)
int pickRandom(int min, int max)
double getVariableAsNumber(String name)
Object itemOfList(String listName, int index)
String castToString(Object o)
Map< String, List< Object > > lists
List< Object > getList(String name)
void broadcast(String message)
void startScript(Runnable script)
List< javax.sound.sampled.Clip > activeClips
String letterOf(int index, String text)
int lengthOf(String text)
void whenKeyPressed(int keyCode, Runnable action)
void setVariable(String name, Object value)
void whenIReceive(String message, Runnable action)
String join(Object a, Object b)
void broadcast(String message)
static Stage getInstance()
void whenIReceive(String message, Runnable action)
void whenKeyPressed(int keyCode, Runnable action)