]> Pileus Git - ~andy/spades/commitdiff
Add cards display from IRC messages
authorAndy Spencer <andy753421@gmail.com>
Mon, 22 Apr 2013 02:56:50 +0000 (02:56 +0000)
committerAndy Spencer <andy753421@gmail.com>
Mon, 22 Apr 2013 03:26:34 +0000 (03:26 +0000)
src/org/pileus/spades/Cards.java
src/org/pileus/spades/Main.java
src/org/pileus/spades/Message.java
src/org/pileus/spades/Spades.java

index e4c566e1afc4c5c60859de63c71821ee345f6894..1cf4c3e0542bce9c3e20f26c7489e854d0c659d1 100644 (file)
@@ -144,14 +144,8 @@ public class Cards extends GLSurfaceView implements GLSurfaceView.Renderer
 
                this.ylim  = 0.4f;
 
-               this.hand  = new String[] {
-                       "As", "7s", "6s",  "6h", "2h", "Ac",
-                       "Kc", "3c", "10d", "9d", "8d", "7d", "2d"
-               };
-
-               this.pile  = new String[] {
-                       "As", "7s", "6s"
-               };
+               this.hand  = "As Ks Qs Js 10s 9s 8s 7s 6s 5s 4s 3s 2s".split(" ");
+               this.pile  = "Ah Ac Ad".split(" ");
 
                this.index = new HashMap<String,Integer>(52);
                for (int i = 0; i < 52; i++)
index 56691e403306cd11426593676d7deae4468996f8..f85e06fccb3947c56345028187313ee81c84ddd1 100644 (file)
@@ -257,14 +257,14 @@ public class Main extends Activity
                                        .setContent(R.id.debug));
 
                        // Setup Spades game and cards view
-                       this.game  = new Spades();
+                       this.game  = new Spades("rhawk");
                        this.cards = new Cards(this);
 
                        this.game.cards = this.cards;
                        this.cards.game = this.game;
 
                        this.spades.addView(cards);
-                       
+
                        // Attach to background service
                        this.register();
 
index d13ea1ceaee1fe2dbe7a3ded2170227804e06982..f241c8d5add8fe95f2f4596a72694ce0b9469b07 100644 (file)
@@ -58,6 +58,14 @@ public class Message
        public String  to   = "";
        public String  txt  = "";
 
+       /* Static methods */
+       public static String clean(String msg)
+       {
+               String num = "0?[0-9]|1[0-5]";
+               return msg.replaceAll("[\\002\\011\\017\\025]", "")
+                         .replaceAll("[\\003\\013]("+num+")(,"+num+")?", "");
+       }
+
        /* Private methods */
        private String notnull(String string)
        {
index a9fd1504d2dd8641848915cc42225b151a4de91d..f7924bc8f17b8bcb4b3870b7d8cd32ad5af92a04 100644 (file)
@@ -2,19 +2,49 @@ package org.pileus.spades;
 
 public class Spades
 {
-       /* Private data */
-       public Task  task;
-       public Cards cards;
+       /* Properties */
+       public  Task    task;
+       public  Cards   cards;
+       public  String  admin;
+
+       /* Static methods */
+       private static String[] getCards(String msg, String regex)
+       {
+               String cards = Message.clean(msg)
+                       .replaceAll(regex, "$1")
+                       .replaceAll(",", " ")
+                       .replaceAll("♠", "s")
+                       .replaceAll("♥", "h")
+                       .replaceAll("♦", "d")
+                       .replaceAll("♣", "c");
+               Os.debug("Cards: getCards - [" + cards + "]:" + Os.base64(cards));
+               return cards.split("\\s+");
+       }
 
        /* Widget callback functions */
-       public Spades()
+       public Spades(String admin)
        {
+               this.admin = admin;
        }
 
        /* IRC Callbacks */
        public void onMessage(Message msg)
        {
-               Os.debug("Spades: onMessage");
+               Os.debug("Spades: onMessage - " + msg.msg);
+               if (msg.type != Message.Type.PRIVMSG)
+                       return;
+               if (!msg.from.equals(this.admin))
+                       return;
+
+               String txt = msg.txt;
+               if (txt.startsWith("You have: ")) {
+                       this.cards.hand = Spades.getCards(txt, "You have: (.*)");
+                       this.cards.requestRender();
+               }
+               if (txt.matches("turn!")) {
+                       this.cards.pile = Spades.getCards(txt, ".*turn! (.*)");
+                       this.cards.requestRender();
+               }
        }
 
        /* UI Callbacks */