Browse Source

Adding card tag

crobi 10 years ago
parent
commit
8613cee9ae
4 changed files with 164 additions and 34 deletions
  1. 18
    10
      generator/data/card_data_example.js
  2. 72
    3
      generator/generate.html
  3. 13
    1
      generator/js/cards.js
  4. 61
    20
      generator/js/ui.js

+ 18
- 10
generator/data/card_data_example.js View File

18
             "fill | 3",
18
             "fill | 3",
19
             "section | At higher levels",
19
             "section | At higher levels",
20
             "text | +1d6 damage for each slot above 1st"
20
             "text | +1d6 damage for each slot above 1st"
21
-        ]
21
+        ],
22
+        "tags": ["spell", "mage"]
22
     },
23
     },
23
     {
24
     {
24
         "count": 1,
25
         "count": 1,
33
             "text | You can take a <b>bonus action on each of your turns</b> in combat. This action can be used only to take the <b>Dash, Disengage, or Hide</b> action.",
34
             "text | You can take a <b>bonus action on each of your turns</b> in combat. This action can be used only to take the <b>Dash, Disengage, or Hide</b> action.",
34
             "fill | 2",
35
             "fill | 2",
35
             "section | Fast hands (Thief 3rd)",
36
             "section | Fast hands (Thief 3rd)",
36
-            "text | You can also use the bonus action to make a Dexterity (<b>Sleight of Hand</b>) check, use your thieves' tools to <b>disarm a trap</b> or <b>open a lock</b>, or take the <b>Use an Object</b> action.",
37
-        ]
37
+            "text | You can also use the bonus action to make a Dexterity (<b>Sleight of Hand</b>) check, use your thieves' tools to <b>disarm a trap</b> or <b>open a lock</b>, or take the <b>Use an Object</b> action."
38
+        ],
39
+        "tags": ["feature", "rogue"]
38
     },
40
     },
39
     {
41
     {
40
         "count": 1,
42
         "count": 1,
52
             "description | Heavy | Unless you have the required strength, your speed is reduced by 10 feet.",
54
             "description | Heavy | Unless you have the required strength, your speed is reduced by 10 feet.",
53
             "description | Stealth | You have disadvantage on Dexterity (Stealth) checks.",
55
             "description | Stealth | You have disadvantage on Dexterity (Stealth) checks.",
54
             "fill | 3"
56
             "fill | 3"
55
-        ]
57
+        ],
58
+        "tags": ["item", "armor"]
56
     },
59
     },
57
     {
60
     {
58
         "count": 1,
61
         "count": 1,
71
             "description | Light | When you attack while dual wielding light weapons, you may use a bonus action to attack with your off hand.",
74
             "description | Light | When you attack while dual wielding light weapons, you may use a bonus action to attack with your off hand.",
72
             "description | Thrown | You can throw the weapon to make a ranged attack with the given range.",
75
             "description | Thrown | You can throw the weapon to make a ranged attack with the given range.",
73
             "fill | 3"
76
             "fill | 3"
74
-        ]
77
+        ],
78
+        "tags": ["item", "weapon"]
75
     },
79
     },
76
     {
80
     {
77
         "count": 1,
81
         "count": 1,
90
             "description | Finesse | Use your choice of Strength or Dexterity modifier for attack and damage.",
94
             "description | Finesse | Use your choice of Strength or Dexterity modifier for attack and damage.",
91
             "description | Light | When you attack while dual wielding light weapons, you may use a bonus action to attack with your off hand.",
95
             "description | Light | When you attack while dual wielding light weapons, you may use a bonus action to attack with your off hand.",
92
             "fill | 3"
96
             "fill | 3"
93
-        ]
97
+        ],
98
+        "tags": ["item", "weapon", "magic"]
94
     },
99
     },
95
     {
100
     {
96
         "count": 1,
101
         "count": 1,
111
             "bullet | magic missile, 3rd level (3 charges)",
116
             "bullet | magic missile, 3rd level (3 charges)",
112
             "fill | 3",
117
             "fill | 3",
113
             "boxes | 7 | 2.5"
118
             "boxes | 7 | 2.5"
114
-        ]
119
+        ],
120
+        "tags": ["item", "wondrous-item", "magic"]
115
     },
121
     },
116
     {
122
     {
117
         "count": 2,
123
         "count": 2,
128
             "text | When you drink this potion, you regain 2d4+2 hitpoints.",
134
             "text | When you drink this potion, you regain 2d4+2 hitpoints.",
129
             "text | Drinking or administering a potion takes 1 action.",
135
             "text | Drinking or administering a potion takes 1 action.",
130
             "fill | 3"
136
             "fill | 3"
131
-        ]
137
+        ],
138
+        "tags": ["item", "consumable"]
132
     },
139
     },
133
     {
140
     {
134
         "count": 1,
141
         "count": 1,
150
             "fill | 2",
157
             "fill | 2",
151
             "section | Actions",
158
             "section | Actions",
152
             "description | Scimitar | Melee Weapon Attack: +4 to hit, reach 5 ft., one target. Hit: 5 (1d6 + 2) slashing damage"
159
             "description | Scimitar | Melee Weapon Attack: +4 to hit, reach 5 ft., one target. Hit: 5 (1d6 + 2) slashing damage"
153
-        ]
160
+        ],
161
+        "tags": ["creature", "humanoid"]
154
     }
162
     }
155
-];
163
+]

+ 72
- 3
generator/generate.html View File

67
                     </div>
67
                     </div>
68
                     <div class="form-group">
68
                     <div class="form-group">
69
                         <div class="col-sm-6">
69
                         <div class="col-sm-6">
70
-                            <button type="button" class="btn btn-primary btn-block" id="button-sort-name">Sort by name</button>
70
+                            <button type="button" class="btn btn-primary btn-block" id="button-sort">Sort</button>
71
                         </div>
71
                         </div>
72
                         <div class="col-sm-6">
72
                         <div class="col-sm-6">
73
                             <button type="button" class="btn btn-primary btn-block" id="button-save" onclick="ui_save_file()">Save to file</button>
73
                             <button type="button" class="btn btn-primary btn-block" id="button-save" onclick="ui_save_file()">Save to file</button>
76
                     </div>
76
                     </div>
77
                     <div class="form-group">
77
                     <div class="form-group">
78
                         <div class="col-sm-6">
78
                         <div class="col-sm-6">
79
-                            <button type="button" class="btn btn-primary btn-block" id="button-sort-icon">Sort by icon</button>
79
+                            <button type="button" class="btn btn-primary btn-block" id="button-filter">Map/Filter</button>
80
                         </div>
80
                         </div>
81
                         <div class="col-sm-6">
81
                         <div class="col-sm-6">
82
                             <button type="button" class="btn btn-success btn-block" id="button-generate">Generate</button>
82
                             <button type="button" class="btn btn-success btn-block" id="button-generate">Generate</button>
266
                             <input type="number" id="card-count" class="form-control" placeholder="Count" data-property="count" value="1">
266
                             <input type="number" id="card-count" class="form-control" placeholder="Count" data-property="count" value="1">
267
                         </div>
267
                         </div>
268
                     </div>
268
                     </div>
269
+                    <div class="form-group">
270
+                        <label for="card-tags" class="col-sm-2 control-label">Tags</label>
271
+                        <div class="col-sm-10">
272
+                            <input type="text" id="card-tags" class="form-control" placeholder="Tags">
273
+                        </div>
274
+                    </div>
269
                     <div class="form-group">
275
                     <div class="form-group">
270
                         <label for="card-icon" class="col-sm-2 control-label">Icon</label>
276
                         <label for="card-icon" class="col-sm-2 control-label">Icon</label>
271
                         <div class="col-sm-10">
277
                         <div class="col-sm-10">
341
             </div>
347
             </div>
342
         </div>
348
         </div>
343
     </div>
349
     </div>
344
-    <!-- Modal -->
350
+    <!-- Modal (Info)-->
345
     <div class="modal" id="help-modal" tabindex="-1" role="dialog">
351
     <div class="modal" id="help-modal" tabindex="-1" role="dialog">
346
         <div class="modal-dialog">
352
         <div class="modal-dialog">
347
             <div class="modal-content">
353
             <div class="modal-content">
378
             </div>
384
             </div>
379
         </div>
385
         </div>
380
     </div>
386
     </div>
387
+    <!-- Modal (Sort)-->
388
+    <div class="modal" id="sort-modal" tabindex="-1" role="dialog">
389
+        <div class="modal-dialog">
390
+            <div class="modal-content">
391
+                <div class="modal-header">
392
+                    <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
393
+                    <h4 class="modal-title" id="myModalLabel">Sort cards</h4>
394
+                </div>
395
+                <div class="modal-body">
396
+                    <p>
397
+                        Enter the comparison function below.
398
+                        The comparison function is a block of javascript code.
399
+                        Return -1 if card_a should appear before card_b.
400
+                    </p>
401
+                    <textarea class="form-control" rows="10" id="sort-function" wrap="off">
402
+if (card_a.title < card_b.title) {
403
+    return -1;
404
+}
405
+else if (card_a.title > card_b.title) {
406
+    return 1;
407
+}
408
+else {
409
+    return 0;
410
+}
411
+                    </textarea>
412
+                </div>
413
+                <div class="modal-footer">
414
+                    <button type="button" class="btn btn-default" id="sort-execute">Sort</button>
415
+                </div>
416
+            </div>
417
+        </div>
418
+    </div>
419
+    <!-- Modal (Filter)-->
420
+    <div class="modal" id="filter-modal" tabindex="-1" role="dialog">
421
+        <div class="modal-dialog">
422
+            <div class="modal-content">
423
+                <div class="modal-header">
424
+                    <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
425
+                    <h4 class="modal-title" id="myModalLabel">Filter/map cards</h4>
426
+                </div>
427
+                <div class="modal-body">
428
+                    <p>
429
+                        Enter code below that will be executed for each card in the deck.
430
+                        Return false to remove the current card from the deck.
431
+                    </p>
432
+                    <textarea class="form-control" rows="10" id="filter-function" wrap="off">
433
+// Color all spell cards yellow
434
+if (card_has_tag(card, "spell")) {
435
+    card.color = "yellow";
436
+}
437
+
438
+// Remove all creature cards
439
+if (card_has_tag(card, "creature")) {
440
+    return false;
441
+}
442
+                    </textarea>
443
+                </div>
444
+                <div class="modal-footer">
445
+                    <button type="button" class="btn btn-default" id="filter-execute">Filter</button>
446
+                </div>
447
+            </div>
448
+        </div>
449
+    </div>
381
 </body>
450
 </body>
382
 </html>
451
 </html>

+ 13
- 1
generator/js/cards.js View File

22
     return {
22
     return {
23
         count: 1,
23
         count: 1,
24
         title: "New card",
24
         title: "New card",
25
-        contents: []
25
+        contents: [],
26
+        tags: []
26
     }
27
     }
27
 }
28
 }
28
 
29
 
30
+function card_init(card) {
31
+    card.title = card.title || "";
32
+    card.contents = card.contents || [];
33
+    card.tags = card.tags || [];
34
+}
35
+
36
+function card_has_tag(card, tag) {
37
+    var index = card.tags.indexOf(tag.toLowerCase());
38
+    return index > -1;
39
+}
40
+
29
 // ============================================================================
41
 // ============================================================================
30
 // Card definition related functions
42
 // Card definition related functions
31
 // ============================================================================
43
 // ============================================================================

+ 61
- 20
generator/js/ui.js View File

59
 
59
 
60
 function ui_load_sample() {
60
 function ui_load_sample() {
61
     card_data = card_data_example;
61
     card_data = card_data_example;
62
+    ui_init_cards(card_data);
62
     ui_update_card_list();
63
     ui_update_card_list();
63
 }
64
 }
64
 
65
 
87
     $("#file-load-form")[0].reset();
88
     $("#file-load-form")[0].reset();
88
 }
89
 }
89
 
90
 
91
+function ui_init_cards(data) {
92
+    data.forEach(function (card) {
93
+        card_init(card);
94
+    });
95
+}
96
+
90
 function ui_add_cards(data) {
97
 function ui_add_cards(data) {
98
+    ui_init_cards(data);
91
     card_data = card_data.concat(data);
99
     card_data = card_data.concat(data);
92
     ui_update_card_list();
100
     ui_update_card_list();
93
 }
101
 }
169
         $("#card-icon").val(card.icon);
177
         $("#card-icon").val(card.icon);
170
         $("#card-icon-back").val(card.icon_back);
178
         $("#card-icon-back").val(card.icon_back);
171
         $("#card-contents").val(card.contents.join("\n"));
179
         $("#card-contents").val(card.contents.join("\n"));
180
+        $("#card-tags").val(card.tags.join(", "));
172
         $("#card-color").val(card.color).change();
181
         $("#card-color").val(card.color).change();
173
     } else {
182
     } else {
174
         $("#card-title").val("");
183
         $("#card-title").val("");
177
         $("#card-icon").val("");
186
         $("#card-icon").val("");
178
         $("#card-icon-back").val("");
187
         $("#card-icon-back").val("");
179
         $("#card-contents").val("");
188
         $("#card-contents").val("");
189
+        $("#card-tags").val("");
180
         $("#card-color").val("").change();
190
         $("#card-color").val("").change();
181
     }
191
     }
182
 
192
 
333
     }
343
     }
334
 }
344
 }
335
 
345
 
346
+function ui_change_card_tags() {
347
+    var value = $(this).val();
348
+
349
+    var card = ui_selected_card();
350
+    if (card) {
351
+        if (value.trim().length == 0) {
352
+            card.tags = [];
353
+        } else {
354
+            card.tags = value.split(",").map(function (val) {
355
+                return val.trim().toLowerCase();
356
+            });
357
+        }
358
+        ui_render_selected_card();
359
+    }
360
+}
361
+
336
 function ui_change_default_title_size() {
362
 function ui_change_default_title_size() {
337
     card_options.default_title_size = $(this).val();
363
     card_options.default_title_size = $(this).val();
338
     ui_render_selected_card();
364
     ui_render_selected_card();
343
     ui_render_selected_card();
369
     ui_render_selected_card();
344
 }
370
 }
345
 
371
 
346
-function ui_sort_by_name() {
347
-    card_data = mergeSort(card_data, function (a, b) {
348
-        if (a.title > b.title) {
349
-            return 1;
350
-        }
351
-        if (a.title < b.title) {
352
-            return -1;
353
-        }
354
-        return 0;
372
+function ui_sort() {
373
+    $("#sort-modal").modal('show');
374
+}
375
+
376
+function ui_sort_execute() {
377
+    $("#sort-modal").modal('hide');
378
+
379
+    var fn_code = $("#sort-function").val();
380
+    var fn = new Function("card_a", "card_b", fn_code);
381
+
382
+    card_data = card_data.sort(function (card_a, card_b) {
383
+        var result = fn(card_a, card_b);
384
+        return result;
355
     });
385
     });
386
+
356
     ui_update_card_list();
387
     ui_update_card_list();
357
 }
388
 }
358
 
389
 
359
-function ui_sort_by_icon() {
360
-    card_data = mergeSort(card_data, function (a, b) {
361
-        if (a.icon > b.icon) {
362
-            return 1;
363
-        }
364
-        if (a.icon < b.icon) {
365
-            return -1;
366
-        }
367
-        return 0;
390
+function ui_filter() {
391
+    $("#filter-modal").modal('show');
392
+}
393
+
394
+function ui_filter_execute() {
395
+    $("#filter-modal").modal('hide');
396
+
397
+    var fn_code = $("#filter-function").val();
398
+    var fn = new Function("card", fn_code);
399
+
400
+    card_data = card_data.filter(function (card) {
401
+        var result = fn(card);
402
+        if (result === undefined) return true;
403
+        else return false;
368
     });
404
     });
405
+
369
     ui_update_card_list();
406
     ui_update_card_list();
370
 }
407
 }
371
 
408
 
400
     $("#button-clear").click(ui_clear_all);
437
     $("#button-clear").click(ui_clear_all);
401
     $("#button-load-sample").click(ui_load_sample);
438
     $("#button-load-sample").click(ui_load_sample);
402
     //$("#button-save").click(ui_save_file);
439
     //$("#button-save").click(ui_save_file);
403
-    $("#button-sort-name").click(ui_sort_by_name);
404
-    $("#button-sort-icon").click(ui_sort_by_icon);
440
+    $("#button-sort").click(ui_sort);
441
+    $("#button-filter").click(ui_filter);
405
     $("#button-add-card").click(ui_add_new_card);
442
     $("#button-add-card").click(ui_add_new_card);
406
     $("#button-duplicate-card").click(ui_duplicate_card);
443
     $("#button-duplicate-card").click(ui_duplicate_card);
407
     $("#button-delete-card").click(ui_delete_card);
444
     $("#button-delete-card").click(ui_delete_card);
419
     $("#card-icon-back").change(ui_change_card_property);
456
     $("#card-icon-back").change(ui_change_card_property);
420
     $("#card-color").change(ui_change_card_color);
457
     $("#card-color").change(ui_change_card_color);
421
     $("#card-contents").change(ui_change_card_contents);
458
     $("#card-contents").change(ui_change_card_contents);
459
+    $("#card-tags").change(ui_change_card_tags);
422
 
460
 
423
     $("#page-size").change(ui_change_option);
461
     $("#page-size").change(ui_change_option);
424
     $("#page-rows").change(ui_change_option);
462
     $("#page-rows").change(ui_change_option);
433
     $("#small-icons").change(ui_change_default_icon_size);
471
     $("#small-icons").change(ui_change_default_icon_size);
434
 
472
 
435
     $(".icon-select-button").click(ui_select_icon);
473
     $(".icon-select-button").click(ui_select_icon);
474
+
475
+    $("#sort-execute").click(ui_sort_execute);
476
+    $("#filter-execute").click(ui_filter_execute);
436
     
477
     
437
     ui_update_card_list();
478
     ui_update_card_list();
438
 });
479
 });

Loading…
Cancel
Save