Robert Carnecky hace 10 años
padre
commit
53e4ca050f
Se han modificado 3 ficheros con 33 adiciones y 19 borrados
  1. 1
    1
      generator/generate.html
  2. 27
    14
      generator/js/card.ts
  3. 5
    4
      generator/js/ui.ts

+ 1
- 1
generator/generate.html Ver fichero

@@ -61,7 +61,7 @@
61 61
                             <button type="button" class="btn btn-primary btn-block" id="button-sort">Sort</button>
62 62
                         </div>
63 63
                         <div class="col-sm-6">
64
-                            <button type="button" class="btn btn-primary btn-block" id="button-save" onclick="ui_save_file()">Save to file</button>
64
+                            <button type="button" class="btn btn-primary btn-block" id="button-save">Save to file</button>
65 65
                             <a href="" download="rpg_cards.json" id="file-save-link" style="display:none">Hidden download link</a>
66 66
                         </div>
67 67
                     </div>

+ 27
- 14
generator/js/card.ts Ver fichero

@@ -26,10 +26,10 @@ module RpgCards {
26 26
         constructor() {
27 27
             this.foreground_color = "white";
28 28
             this.background_color = "white";
29
-            this.empty_color = "white";
29
+            this.empty_color = "black";
30 30
             this.default_color = "black";
31 31
             this.default_icon = "ace";
32
-            this.default_title_size = "13pt";
32
+            this.default_title_size = "13";
33 33
             this.page_size = "A4";
34 34
             this.page_rows = 3;
35 35
             this.page_columns = 3;
@@ -130,7 +130,7 @@ module RpgCards {
130 130
             return this.title || "";
131 131
         }
132 132
         public getTitleSize(options: Options): string {
133
-            return this.title_size || options.default_title_size || "13pt";
133
+            return this.title_size || options.default_title_size || "13";
134 134
         }
135 135
         public getColorFront(options: Options): string {
136 136
             return this.color_front || this.color || options.default_color || "black";
@@ -191,7 +191,7 @@ module RpgCards {
191 191
 
192 192
         public duplicateCard(card: Card): Card {
193 193
             var newCard = card.duplicate();
194
-            this._actions.push({ fn: "add", card: new Card(), ref: card });
194
+            this._actions.push({ fn: "add", card: newCard, ref: card });
195 195
             return newCard;
196 196
         }
197 197
 
@@ -216,6 +216,7 @@ module RpgCards {
216 216
                     }
217 217
                 }
218 218
             }
219
+            this._actions = [];
219 220
         }
220 221
     }
221 222
 
@@ -281,7 +282,7 @@ module RpgCards {
281 282
             var result = "";
282 283
             result += ind + '<card-dndstats';
283 284
             for (var i = 0; i < stats.length; ++i) {
284
-                var value = parseInt(params[0], 10) || "";
285
+                var value = parseInt(params[i], 10) || "";
285 286
                 var stat = stats[i];
286 287
                 result += ' ' + stat + '="' + value + '"';
287 288
             }
@@ -374,7 +375,10 @@ module RpgCards {
374 375
         }
375 376
 
376 377
         private  _card_empty(options: Options, ind: string, ind0: string): string {
377
-            return '';
378
+            var result = "";
379
+            result += ind + '<card-contents>\n';
380
+            result += ind + '</card-contents>\n';
381
+            return result;
378 382
         }
379 383
 
380 384
         private  _card(options: Options, ind: string, ind0: string, content: string, color: string): string {
@@ -461,7 +465,7 @@ module RpgCards {
461 465
 
462 466
         /** Empty slots on the page */
463 467
         public capacity(): number {
464
-            return this.cards.length - this.rows * this.cols;
468
+            return this.rows * this.cols - this.cards.length;
465 469
         }
466 470
 
467 471
         /** Empty slots on the current line */
@@ -475,10 +479,10 @@ module RpgCards {
475 479
                 throw new Error("Cannot perform this operation while the page is not full");
476 480
             }
477 481
 
478
-            for (var r = 0; r < Math.floor(this.rows / 2); ++r) {
479
-                for (var c = 0; c < this.cols; ++c) {
482
+            for (var r = 0; r < this.rows; ++r) {
483
+                for (var c = 0; c < Math.floor(this.cols / 2); ++c) {
480 484
                     var indexL = this._posToIndex(r, c);
481
-                    var indexR = this._posToIndex(this.rows - r - 1, c);
485
+                    var indexR = this._posToIndex(r, this.cols - c - 1);
482 486
                     var cardL = this.cards[indexL];
483 487
                     var cardR = this.cards[indexR];
484 488
                     this.cards[indexL] = cardR;
@@ -616,6 +620,9 @@ module RpgCards {
616 620
                 pages.addCards(front, card.count);
617 621
             }
618 622
 
623
+            // Fill empty slots
624
+            pages.forEach((page) => page.fillPage(empty));
625
+
619 626
             return pages;
620 627
         }
621 628
 
@@ -631,13 +638,19 @@ module RpgCards {
631 638
                 var card = cards[i];
632 639
                 var front = generator.card_front(card, options, this.indent);
633 640
                 var back = generator.card_back(card, options, this.indent);
634
-                if (pages.lastPage().capacityRow() < 2) {
635
-                    pages.lastPage().fillRow(empty);
641
+
642
+                for (var j = 0; j < card.count; ++j) {
643
+                    if (pages.pages.length > 0 && pages.lastPage().capacityRow() < 2) {
644
+                        pages.lastPage().fillRow(empty);
645
+                    }
646
+                    pages.addCard(front);
647
+                    pages.addCard(back);
636 648
                 }
637
-                pages.addCards(front, card.count);
638
-                pages.addCards(back, card.count);
639 649
             }
640 650
 
651
+            // Fill empty slots
652
+            pages.forEach((page) => page.fillPage(empty));
653
+
641 654
             return pages;
642 655
         }
643 656
 

+ 5
- 4
generator/js/ui.ts Ver fichero

@@ -32,7 +32,7 @@ module RpgCardsUI {
32 32
         if (index > -1) {
33 33
             $("#selected-card").val("" + index);
34 34
         } else {
35
-            $("#selected-card").val("0");
35
+            $("#selected-card").val("" + (deck.cards.length - 1));
36 36
         }
37 37
         update_selected_card();
38 38
     }
@@ -402,14 +402,15 @@ module RpgCardsUI {
402 402
     }
403 403
 
404 404
     function duplicate_card() {
405
+        var newCard = null;
405 406
         if (deck.cards.length > 0) {
406 407
             var old_card = selected_card();
407
-            var new_card = deck.duplicateCard(old_card);
408
+            newCard = deck.duplicateCard(old_card);
408 409
         } else {
409
-            deck.addNewCard();
410
+            newCard = deck.addNewCard();
410 411
         }
411 412
         update_card_list();
412
-        select_card_by_index(deck.cards.length - 1);
413
+        select_card_by_card(newCard);
413 414
     }
414 415
 
415 416
     function delete_card() {

Loading…
Cancelar
Guardar