Browse Source

bert bigint fix. initial reveal dialog

Maxim Sokhatsky 11 years ago
parent
commit
a3cb3745dc

+ 28 - 1
apps/web/priv/static/app/js/bert.js

@@ -19,6 +19,8 @@ ATOM = itoa(100);
 BINARY = itoa(109);
 SINT = itoa(97);
 INT = itoa(98);
+SBIG = itoa(110);
+LBIG = itoa(111);
 FLOAT = itoa(99);
 STR = itoa(107);
 LIST = itoa(108);
@@ -53,12 +55,29 @@ function ltoi(S, Length) {
     }
     if (isNegative) { Num = Num * (0 - 1); }
     return Num; };
+function btol(Int) {
+    var isNegative, Rem, s = "";
+    isNegative = Int < 0;
+    if (isNegative) { Int *= -1; s += itoa(1); } else { s += itoa(0); }
+    while (Int !== 0) { Rem = Int % 256; s += itoa(Rem); Int = Math.floor(Int / 256); }
+    return s; };
+function ltob(S, Count) {
+    var isNegative, i, n, Num = 0;
+    isNegative = (S.charCodeAt(0) === 1);
+    S = S.substring(1);
+    for (i = Count - 1; i >= 0; i--) {
+        n = S.charCodeAt(i);
+        if (Num === 0) { Num = n; } else { Num = Num * 256 + n; } }
+    if (isNegative) { return Num * -1; }
+    return Num; };
 
 function encode(o) { return BERT + en_inner(o); };
 function en_inner(Obj) { if(Obj === undefined) return NIL; var func = 'en_' + typeof(Obj); return eval(func)(Obj); };
 function en_string(Obj) { return STR + itol(Obj.length, 2) + Obj; };
 function en_boolean(Obj) { if (Obj) return en_inner(atom("true")); else return en_inner(atom("false")); };
-function en_number(Obj) { var s, isi = (Obj % 1 === 0); if (!isi) { return en_float(Obj); }
+function en_number(Obj) {
+    var s, isi = (Obj % 1 === 0);
+    if (!isi) { return en_float(Obj); }
     if (isi && Obj >= 0 && Obj < 256) { return SINT + itol(Obj, 1); }
     return INT + itol(Obj, 4); };
 function en_float(Obj) { var s = Obj.toExponential(); while (s.length < 31) { s += ZERO; } return FLOAT + s; };
@@ -100,6 +119,8 @@ function de_inner(S) {
         case BINARY: return de_bin(S);
         case SINT: return de_integer(S, 1);
         case INT: return de_integer(S, 4);
+        case SBIG: return de_big(S, 1);
+        case LBIG: return de_big(S, 4);
         case FLOAT: return de_float(S);
         case STR: return de_string(S);
         case LIST: return de_list(S);
@@ -145,6 +166,12 @@ function de_tuple(S, Count) {
     for (i = 0; i < Size; i++) { El = de_inner(S); Arr.push(El.value); S = El.rest; }
     return { value: tuple(Arr), rest: S }; };
 function de_nil(S) { return { value: [], rest: S }; };
+function de_big(S, Count) {
+    var Size, Value;
+    Size = ltoi(S, Count);
+    S = S.substring(Count);
+    Value = ltob(S, Size);
+    return { value : Value, rest: S.substring(Size + 1) }; };
 
 function utf8toByteArray(str) {
     var byteArray = [];

+ 21 - 1
apps/web/priv/static/app/js/bootloader.js

@@ -204,5 +204,25 @@ function initPauseOverlay() {
     var page = document.getElementById("Kakaranet-12-maxim");
     var kakush = document.getElementById("Kakush");
     page.insertBefore(svg(html),kakush);
+}
+
+function showRevealHand(o) {
+
+    var player    = o.value[0][3][0].value[0][1].value,
+        discard   = o.value[0][3][1].value[0][1].value,
+        deck = [];
+
+    deck[0] = o.value[0][3][2].value[0][1][0],
+    deck[1] = o.value[0][3][2].value[0][1][1];
 
-}
+    console.log(player);
+    console.log(discard);
+    console.log(deck);
+
+    if (!document.getElementById("RevealDeck"))
+        $.load("svg/Deck.svg", function(h) { $overlay.append(svg(h)); });
+
+    $overlay.show();
+    $overlay.find("text").text(player + " revealed ");
+
+}

+ 6 - 3
apps/web/priv/static/app/js/okey/okey.js

@@ -9,6 +9,8 @@ function PostLoad()
     window.deck = scope.deck;
     scope.user = document.user;
 
+    $overlay = $("#overlay");
+
     var centralCard,
         apiProvider = new scope.ApiProvider({url: scope.apiUrl, gameId: scope.gameId });
 
@@ -78,6 +80,7 @@ function PostLoad()
     apiProvider.on("okey_game_info", function(x) {
         var e = {detail: x.detail.json, raw: x.detail.bert};
         scope.user = document.user;
+        $overlay.hide();
         if (!scope.started) {
             for (var playerInfo, players = e.detail.players, i = 0; i < players.length; i++) 
                 if (playerInfo = players[i].PlayerInfo, playerInfo[0] == scope.user)
@@ -208,10 +211,11 @@ function PostLoad()
 
     apiProvider.on("okey_revealed", function(x) {
         var e = {detail: x.detail.json, raw: x.detail.bert};
-        ended = !0, alert(e.detail.player), deck.fill([]);
+        showRevealHand(dec(e.raw));
+        ended = !0;//, deck.fill([]);
         for (var hand in playersLeftHandsMap) playersLeftHandsMap[hand].clear();
         for (var playerName in playersMap) playersMap[playerName].unselect();
-//        $gosterme.remove();
+        // $gosterme.remove();
     });
 
     apiProvider.on("player_left", function(x) {
@@ -233,7 +237,6 @@ function PostLoad()
 
     var whoPausedGame = false;
 
-    $overlay = $("#overlay");
     $overlay.attr({cursor: "pointer"});
     $overlay.on("click", function sendPause() { apiProvider.pause(true); });
 

+ 1 - 1
apps/web/priv/static/app/js/okey/okey_protocol.js

@@ -101,7 +101,7 @@ function OkeyApiProviderScope(scope) {
             return msg;
         },
         emitEvent: function(raw,msg) {
-//            console.log(JSON.stringify(msg));
+            //console.log(String(dec(raw)));
             for (var event, i = eventMap.length; i--; ) event = eventMap[i], msg[event] && this.$socket.trigger(event, {
                 detail: {json:msg[event],bert:raw}
             });

BIN
apps/web/priv/static/doc/Kakaranet-Scene.sketch/Data


+ 1 - 1
apps/web/priv/static/doc/Kakaranet-Scene.sketch/metadata

@@ -16,7 +16,7 @@
 		<string>ZapfDingbatsITC</string>
 	</array>
 	<key>length</key>
-	<integer>2878322</integer>
+	<integer>2878316</integer>
 	<key>version</key>
 	<integer>37</integer>
 </dict>