Robert Carnecky 10 年前
父节点
当前提交
53e4ca050f
共有 3 个文件被更改,包括 33 次插入19 次删除
  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 查看文件

61
                             <button type="button" class="btn btn-primary btn-block" id="button-sort">Sort</button>
61
                             <button type="button" class="btn btn-primary btn-block" id="button-sort">Sort</button>
62
                         </div>
62
                         </div>
63
                         <div class="col-sm-6">
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
                             <a href="" download="rpg_cards.json" id="file-save-link" style="display:none">Hidden download link</a>
65
                             <a href="" download="rpg_cards.json" id="file-save-link" style="display:none">Hidden download link</a>
66
                         </div>
66
                         </div>
67
                     </div>
67
                     </div>

+ 27
- 14
generator/js/card.ts 查看文件

26
         constructor() {
26
         constructor() {
27
             this.foreground_color = "white";
27
             this.foreground_color = "white";
28
             this.background_color = "white";
28
             this.background_color = "white";
29
-            this.empty_color = "white";
29
+            this.empty_color = "black";
30
             this.default_color = "black";
30
             this.default_color = "black";
31
             this.default_icon = "ace";
31
             this.default_icon = "ace";
32
-            this.default_title_size = "13pt";
32
+            this.default_title_size = "13";
33
             this.page_size = "A4";
33
             this.page_size = "A4";
34
             this.page_rows = 3;
34
             this.page_rows = 3;
35
             this.page_columns = 3;
35
             this.page_columns = 3;
130
             return this.title || "";
130
             return this.title || "";
131
         }
131
         }
132
         public getTitleSize(options: Options): string {
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
         public getColorFront(options: Options): string {
135
         public getColorFront(options: Options): string {
136
             return this.color_front || this.color || options.default_color || "black";
136
             return this.color_front || this.color || options.default_color || "black";
191
 
191
 
192
         public duplicateCard(card: Card): Card {
192
         public duplicateCard(card: Card): Card {
193
             var newCard = card.duplicate();
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
             return newCard;
195
             return newCard;
196
         }
196
         }
197
 
197
 
216
                     }
216
                     }
217
                 }
217
                 }
218
             }
218
             }
219
+            this._actions = [];
219
         }
220
         }
220
     }
221
     }
221
 
222
 
281
             var result = "";
282
             var result = "";
282
             result += ind + '<card-dndstats';
283
             result += ind + '<card-dndstats';
283
             for (var i = 0; i < stats.length; ++i) {
284
             for (var i = 0; i < stats.length; ++i) {
284
-                var value = parseInt(params[0], 10) || "";
285
+                var value = parseInt(params[i], 10) || "";
285
                 var stat = stats[i];
286
                 var stat = stats[i];
286
                 result += ' ' + stat + '="' + value + '"';
287
                 result += ' ' + stat + '="' + value + '"';
287
             }
288
             }
374
         }
375
         }
375
 
376
 
376
         private  _card_empty(options: Options, ind: string, ind0: string): string {
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
         private  _card(options: Options, ind: string, ind0: string, content: string, color: string): string {
384
         private  _card(options: Options, ind: string, ind0: string, content: string, color: string): string {
461
 
465
 
462
         /** Empty slots on the page */
466
         /** Empty slots on the page */
463
         public capacity(): number {
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
         /** Empty slots on the current line */
471
         /** Empty slots on the current line */
475
                 throw new Error("Cannot perform this operation while the page is not full");
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
                     var indexL = this._posToIndex(r, c);
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
                     var cardL = this.cards[indexL];
486
                     var cardL = this.cards[indexL];
483
                     var cardR = this.cards[indexR];
487
                     var cardR = this.cards[indexR];
484
                     this.cards[indexL] = cardR;
488
                     this.cards[indexL] = cardR;
616
                 pages.addCards(front, card.count);
620
                 pages.addCards(front, card.count);
617
             }
621
             }
618
 
622
 
623
+            // Fill empty slots
624
+            pages.forEach((page) => page.fillPage(empty));
625
+
619
             return pages;
626
             return pages;
620
         }
627
         }
621
 
628
 
631
                 var card = cards[i];
638
                 var card = cards[i];
632
                 var front = generator.card_front(card, options, this.indent);
639
                 var front = generator.card_front(card, options, this.indent);
633
                 var back = generator.card_back(card, options, this.indent);
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
             return pages;
654
             return pages;
642
         }
655
         }
643
 
656
 

+ 5
- 4
generator/js/ui.ts 查看文件

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

正在加载...
取消
保存