made disco loop forever and controlable via irc
This commit is contained in:
parent
e97ae350ad
commit
9b8791a468
|
@ -14,6 +14,8 @@ public class TheGame implements StatemachineListener, GuiEventListener, IRCEvent
|
||||||
private IMPDController mpdController;
|
private IMPDController mpdController;
|
||||||
private IRelaisboard relaisboard;
|
private IRelaisboard relaisboard;
|
||||||
private int gamerRating = 3;
|
private int gamerRating = 3;
|
||||||
|
private Thread discoThread;
|
||||||
|
private boolean shouldStopDisco;
|
||||||
|
|
||||||
public TheGame(IGuiControl guiControl) {
|
public TheGame(IGuiControl guiControl) {
|
||||||
this.guiControl = guiControl;
|
this.guiControl = guiControl;
|
||||||
|
@ -55,6 +57,7 @@ public class TheGame implements StatemachineListener, GuiEventListener, IRCEvent
|
||||||
|
|
||||||
switch (newState) {
|
switch (newState) {
|
||||||
case NEUTRAL:
|
case NEUTRAL:
|
||||||
|
discoStop();
|
||||||
bunti.setPar56(255,255,255);
|
bunti.setPar56(255,255,255);
|
||||||
bunti.setLampel(false,false,false);
|
bunti.setLampel(false,false,false);
|
||||||
machine.stopTimer();
|
machine.stopTimer();
|
||||||
|
@ -64,6 +67,7 @@ public class TheGame implements StatemachineListener, GuiEventListener, IRCEvent
|
||||||
gamerRating = 3;
|
gamerRating = 3;
|
||||||
machine.stopTimer();
|
machine.stopTimer();
|
||||||
resetDomotics();
|
resetDomotics();
|
||||||
|
discoStop();
|
||||||
|
|
||||||
guiControl.setExtra("");
|
guiControl.setExtra("");
|
||||||
guiControl.setWall("");
|
guiControl.setWall("");
|
||||||
|
@ -266,6 +270,10 @@ public class TheGame implements StatemachineListener, GuiEventListener, IRCEvent
|
||||||
guiControl.setExtra(message.substring("extra".length()).trim());
|
guiControl.setExtra(message.substring("extra".length()).trim());
|
||||||
} else if(message.startsWith("relais")) {
|
} else if(message.startsWith("relais")) {
|
||||||
handleRelaisCommand(message);
|
handleRelaisCommand(message);
|
||||||
|
} else if(message.startsWith("disco start")) {
|
||||||
|
disco();
|
||||||
|
} else if(message.startsWith("disco stop")) {
|
||||||
|
discoStop();
|
||||||
} else {
|
} else {
|
||||||
ircClient.say("y u no use valid command?");
|
ircClient.say("y u no use valid command?");
|
||||||
}
|
}
|
||||||
|
@ -383,6 +391,8 @@ public class TheGame implements StatemachineListener, GuiEventListener, IRCEvent
|
||||||
} else if(message.contains("relais")) {
|
} else if(message.contains("relais")) {
|
||||||
ircClient.say("control the relais board");
|
ircClient.say("control the relais board");
|
||||||
ircClient.say("valid commands: lamp on, lamp off, lamp blink, lamp stop, oven on, oven off, rokets");
|
ircClient.say("valid commands: lamp on, lamp off, lamp blink, lamp stop, oven on, oven off, rokets");
|
||||||
|
} else if(message.contains("disco")) {
|
||||||
|
ircClient.say("party! use: disco {on,off}");
|
||||||
} else {
|
} else {
|
||||||
ircClient.say("dafuq?");
|
ircClient.say("dafuq?");
|
||||||
}
|
}
|
||||||
|
@ -411,42 +421,58 @@ public class TheGame implements StatemachineListener, GuiEventListener, IRCEvent
|
||||||
mpdController.clearPlaylist();
|
mpdController.clearPlaylist();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void discoStop() {
|
||||||
|
if(discoThread != null) {
|
||||||
|
shouldStopDisco = true;
|
||||||
|
discoThread.interrupt();
|
||||||
|
try {
|
||||||
|
discoThread.join(500);
|
||||||
|
} catch (InterruptedException e) { }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void disco() {
|
private void disco() {
|
||||||
|
discoStop();
|
||||||
|
|
||||||
Runnable r = new Runnable() {
|
Runnable r = new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
for(int i = 0; i < 10; i++) {
|
while(true) {
|
||||||
|
if(shouldStopDisco) return;
|
||||||
bunti.setPar56(0, 255, 0, 0);
|
bunti.setPar56(0, 255, 0, 0);
|
||||||
bunti.setPar56(1, 0, 255, 0);
|
bunti.setPar56(1, 0, 255, 0);
|
||||||
bunti.setPar56(2, 0, 255, 0);
|
bunti.setPar56(2, 0, 255, 0);
|
||||||
bunti.setPar56(3, 255, 0, 0);
|
bunti.setPar56(3, 255, 0, 0);
|
||||||
|
if(shouldStopDisco) return;
|
||||||
Thread.sleep(500);
|
Thread.sleep(500);
|
||||||
bunti.setPar56(0, 0, 0, 255);
|
bunti.setPar56(0, 0, 0, 255);
|
||||||
bunti.setPar56(1, 255, 255, 0);
|
bunti.setPar56(1, 255, 255, 0);
|
||||||
bunti.setPar56(2, 255, 255, 0);
|
bunti.setPar56(2, 255, 255, 0);
|
||||||
bunti.setPar56(3, 0, 0, 255);
|
bunti.setPar56(3, 0, 0, 255);
|
||||||
|
if(shouldStopDisco) return;
|
||||||
Thread.sleep(500);
|
Thread.sleep(500);
|
||||||
bunti.setPar56(0, 255, 128, 0);
|
bunti.setPar56(0, 255, 128, 0);
|
||||||
bunti.setPar56(1, 0, 255, 255);
|
bunti.setPar56(1, 0, 255, 255);
|
||||||
bunti.setPar56(2, 0, 255, 255);
|
bunti.setPar56(2, 0, 255, 255);
|
||||||
bunti.setPar56(3, 255, 128, 0);
|
bunti.setPar56(3, 255, 128, 0);
|
||||||
|
if(shouldStopDisco) return;
|
||||||
Thread.sleep(500);
|
Thread.sleep(500);
|
||||||
bunti.setPar56(0, 0, 255, 255);
|
bunti.setPar56(0, 0, 255, 255);
|
||||||
bunti.setPar56(1, 0, 255, 0);
|
bunti.setPar56(1, 0, 255, 0);
|
||||||
bunti.setPar56(2, 0, 255, 0);
|
bunti.setPar56(2, 0, 255, 0);
|
||||||
bunti.setPar56(3, 0, 255, 255);
|
bunti.setPar56(3, 0, 255, 255);
|
||||||
|
if(shouldStopDisco) return;
|
||||||
Thread.sleep(500);
|
Thread.sleep(500);
|
||||||
}
|
}
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) { }
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
new Thread(r).start();
|
discoThread = new Thread(r);
|
||||||
|
shouldStopDisco = false;
|
||||||
|
discoThread.start();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue