Register and use commands
[kaka/cakelight.git] / src / kaka / cakelight / mode / TwoColorNoiseMode.java
index 6d2dabe..4046cbd 100644 (file)
@@ -1,6 +1,8 @@
 package kaka.cakelight.mode;
 
-import kaka.cakelight.*;
+import kaka.cakelight.Color;
+import kaka.cakelight.Console;
+import kaka.cakelight.LedFrame;
 import kaka.cakelight.util.SimplexNoise3D;
 
 public class TwoColorNoiseMode extends AmbientMode {
@@ -9,41 +11,21 @@ public class TwoColorNoiseMode extends AmbientMode {
 
     public static Console.Command getCommand() {
         return new Console.Command() {
+            @Override
             public String[] getNames() {
                 return new String[] {"n", "noise"};
             }
 
-            public void activate(CakeLight cakelight, Configuration config, String[] args) {
-                if (args.length == 3) { // cmd + col1 + col2
-                    cakelight.setMode(new TwoColorNoiseMode(
-                            parseColor(args[1]),
-                            parseColor(args[2])
+            @Override
+            public void activate(Console console, String[] args) {
+                if (args.length == 2) { // col1 + col2
+                    console.getCakelight().setMode(new TwoColorNoiseMode(
+                            parseColor(args[0]),
+                            parseColor(args[1])
                     ));
+                    output("setting two-color noise mode");
                 }
             }
-
-            private Color parseColor(String s) {
-                switch (s.toLowerCase()) {
-                    case "r": return Color.rgb(255, 0, 0);
-                    case "g": return Color.rgb(0, 255, 0);
-                    case "b": return Color.rgb(0, 0, 255);
-                    default: // assume hexadecimal
-                        if (s.length() == 3) {
-                            return Color.rgb(
-                                    Integer.parseInt(s.substring(0, 1), 16) * 16 + Integer.parseInt(s.substring(0, 1), 16),
-                                    Integer.parseInt(s.substring(1, 2), 16) * 16 + Integer.parseInt(s.substring(1, 2), 16),
-                                    Integer.parseInt(s.substring(2, 3), 16) * 16 + Integer.parseInt(s.substring(2, 3), 16)
-                            );
-                        } else if (s.length() == 6) {
-                            return Color.rgb(
-                                    Integer.parseInt(s.substring(0, 2), 16),
-                                    Integer.parseInt(s.substring(2, 4), 16),
-                                    Integer.parseInt(s.substring(4, 6), 16)
-                            );
-                        }
-                }
-                return Color.BLACK;
-            }
         };
     }