-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsite.html
914 lines (781 loc) · 31.9 KB
/
site.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
<!DOCTYPE html>
<html lang="en">
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script>
<script>
var ctrlIsPressed = false;
$(document).keydown(function (event) {
if (event.which == "17")
ctrlIsPressed = true;
});
$(document).keyup(function (event) {
ctrlIsPressed = false;
})
var xmlHttp = new XMLHttpRequest();
function queryDB(query) {
xmlHttp.open("GET", `http://localhost:3000/${query}`, false);
xmlHttp.send(null);
return xmlHttp.responseText.replace(/%20/g, ' ');
}
</script>
<meta name="viewport" content="width=device-width, initial-scale=1" charset="utf-8">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<style>
body {
font-family: "Lato", sans-serif;
background-image: url("https://i.imgur.com/t3FGMcO.jpg");
background-repeat: no-repeat;
background-size: cover;
background-attachment: fixed;
position: fixed;
}
.sidenav {
height: 100%;
width: 200px;
position: fixed;
z-index: 2;
top: 70px;
left: 0px;
overflow-x: hidden;
padding-top: 15px;
/* space between top side nave */
background-image: url("https://i.imgur.com/t3FGMcO.jpg");
background-repeat: no-repeat;
background-size: cover;
background-attachment: fixed;
}
.logo {
height: 100%;
width: 200px;
position: fixed;
z-index: 1;
top: 0;
left: 0;
background-color: black;
background-image: url("https://i.imgur.com/T5vOLr7.jpg");
background-position: 0% 0%;
background-repeat: no-repeat;
background-size: 200px, 200px;
background-attachment: fixed;
overflow-x: hidden;
padding-top: 50px;
/* space between top side nave */
}
/* Style the sidenav links and the dropdown button */
.sidenav a,
.dropdown-btn,
.add-creature-btn,
.creature-btn,
.add-item-btn{
padding: 6px 8px 6px 16px;
text-decoration: none;
font-size: 20px;
color: #818181;
display: block;
border: none;
background: none;
width: 100%;
text-align: left;
cursor: pointer;
outline: none;
background-image: url("https://i.imgur.com/t3FGMcO.jpg");
background-repeat: no-repeat;
background-size: cover;
background-attachment: fixed;
}
.btn-delete {
padding-right: 50px;
right: 100px;
margin-right: 50px;
}
/* On mouse-over */
.sidenav a:hover,
.dropdown-btn:hover,
.creature-btn:hover,
.add-creature-btn:hover,
.add-item-btn:hover {
color: #f1f1f1;
/* color of whole box when hovering over it */
}
/* Main content */
.main {
margin-left: 200px;
/* Same as the width of the sidenav */
font-size: 20px;
/* Increased text to enable scrolling */
padding: 0px 0px;
/* left gives height and right value further shifts more pad */
color: green;
}
/* Add an active class to the active dropdown button */
.active {
/*background-color: green; background when selected */
color: white;
/* text when selected */
}
/* Dropdown container (hidden by default). Optional: add a lighter background color and some left padding to change the design of the dropdown content */
.dropdown-container {
display: none;
background-color: #262626;
/* drop down color */
padding-left: 14px;
/* shift leters to right */
background-image: url("https://i.imgur.com/t3FGMcO.jpg");
background-repeat: no-repeat;
background-size: cover;
background-attachment: fixed;
}
/* Optional: Style the caret down icon */
.fa-caret-down {
float: right;
padding-right: 8px;
}
/* Some media queries for responsiveness */
@media screen and (max-height: 450px) {
.sidenav {
padding-top: 15px;
}
.sidenav a {
font-size: 18px;
}
}
.card {
display: table-cell;
position: absolute;
min-width: 350px;
z-index: 9;
background-color: #f1f1f1;
text-align: left;
border: 1px solid #d3d3d3;
background-image: url("https://i.imgur.com/UoLHwVf.png");
color: #4d1919;
font-family: "Times New Roman", Times, serif;
}
.grip {
padding: 5px;
cursor: move;
z-index: 0;
background-color: #2196F3;
background-image: url("https://i.imgur.com/UoLHwVf.png");
border: 2px solid #111111;
text-align: left;
}
.x {
float: right;
z-index: 10;
}
.singlestat {
float: left;
text-align: center;
line-height: 20px;
padding: 0;
margin: 0;
}
.description {
overflow: auto;
width: 90%;
background-color: rgba(0, 0, 0, 0.01)
}
.dmgBox {
width: 50px;
}
button {
background-color: rgba(0, 0, 0, 0.01)
}
input[type="number"] {
width: 50px;
cursor: auto;
background-color: rgba(0, 0, 0, 0.01)
}
input[type="text"] {
cursor: auto;
background-color: rgba(0, 0, 0, 0.01)
}
select {
width: 60px;
background-color: rgba(0, 0, 0, 0.01)
}
</style>
</head>
<body>
<div class="logo"> </div>
<div class="sidenav" id="sidenav">
<button id="Location-btn" class="dropdown-btn">Location
<i class="fa fa-caret-down"></i>
</button>
<div class="dropdown-container" id="Locations">
</div>
</div>
<div id="desktop" class="main">
<h2>DND</h2>
<p>Manage your cards:</p>
<script>
var locationTabs = [];
var locationTabHTML = [];
add_dropdown();
function add_dropdown() {
var tabmarkup;
var all_location_info = JSON.parse(queryDB('SELECT * FROM Location;'));
var all_creature_info = JSON.parse(queryDB('SELECT * FROM Creature;'));
var all_both_info = JSON.parse(queryDB('SELECT * FROM CreatureAppearance;'));
var all_item_info = JSON.parse(queryDB('SELECT * FROM Item;'));
var Location_size = all_location_info.length;
var Creatures_size = all_creature_info.length;
var Item_size = all_item_info.length;
var i;
var j;
var k;
for (i = 0; i < Location_size; i++) {
var new_location = document.createElement('dropdown-btn');
var loc_info = all_location_info[i]
var loc_name = loc_info.location_name;
var idLocation = loc_info.idLocation;
new_location.id = idLocation;
tabmarkup = `
<button id=${idLocation} class="dropdown-btn" onclick="addLocationCard(${idLocation})">${loc_name}
<i class="fa fa-caret-down"></i>
</button>
<div id=${idLocation}blk class="dropdown-container">
<button class="dropdown-btn">Creatures
<i class="fa fa-caret-down"></i>
</button>
<div class="dropdown-container ">
`;
for (j = 0; j < Creatures_size; j++) {
var crea_info = all_creature_info[j];
var crea_name = crea_info.creature_name;
var crea_id = crea_info.idCreature;
for (k = 0; k < Creatures_size; k++) {
var both_info = all_both_info[k];
var Location_idLocation = both_info.Location_idLocation;
var Creature_idCreature = both_info.Creature_idCreature;
if (crea_id == Creature_idCreature && Location_idLocation == idLocation) {
tabmarkup = tabmarkup +
`<button id="${crea_id}c" class="creature-btn" onclick="addCreatureCard(${crea_id})">${crea_name}</button>`;
k = 100;
}
}
}
tabmarkup = tabmarkup +
`<button class="add-creature-btn" onclick="addCreature(this)">Add Creature</button>
</div>
<button class="dropdown-btn">Items
<i class="fa fa-caret-down"></i>
</button>
<div class="dropdown-container" >`;
for (j = 0; j < Item_size; j++) {
var item_info = all_item_info[j];
var item_name = item_info.item_name;
var item_location = item_info.Location_idLocation;
var item_id = item_info.idItem;
if (item_location == idLocation) {
tabmarkup = tabmarkup +
`<button id="${item_id}d" class="add-item-btn" onclick="addItemCard(${item_id})">${item_name}</button>`;
j = 100;
}
}
tabmarkup = tabmarkup +
`<button class="add-creature-btn" onclick="addItem(this, ${idLocation})">Add Item</button>`;
tabmarkup = tabmarkup +
`</div>
<button id=sub_${idLocation} class="dropdown-btn">Sublocations
<i class="fa fa-caret-down"></i>
</button>
<div id=${idLocation}_sublocations class="dropdown-container"></div>`;
tabmarkup = tabmarkup + `
<button class="add-creature-btn" onclick="addLocation(sub_${idLocation}, ${idLocation})">Add Location</button>;
</div>`;
new_location.innerHTML = tabmarkup;
var Locations = document.getElementById("Locations");
locationTabs.push(new_location);
locationTabHTML.push(tabmarkup);
//if(loc_info.superLocation_idLocation == null)
{
Locations.appendChild(new_location);
}
}
var endaddloc = document.createElement('div');
endaddloc.innerHTML = `<button class="add-creature-btn" onclick="addLocation(this, null)">Add Location</button>`;
Locations.appendChild(endaddloc);
}
</script>
<!-- for adding -->
<script>
function addCreature(el) {
newCreatureCard(el);
}
function addItem(el, loc) {
newItemCard(el, loc);
}
function addLocation(el, loc) {
newLocationCard(el, loc);
}
</script>
<script>
$("input").change(function (e) { autoUpdateDB(e) });
$("textarea").change(function (e) { autoUpdateDB(e) });
$("select").change(function (e) { autoUpdateDB(e) });
function reloadListeners() {
$("input").change(function (e) { autoUpdateDB(e) });
$("textarea").change(function (e) { autoUpdateDB(e) });
$("select").change(function (e) { autoUpdateDB(e) });
}
function autoUpdateDB(e) {
var changedCardId = $(e.target).closest(".entrycontainer")[0].id;
try {
var val1 = document.getElementById(changedCardId + '-btn').textContent;
var val2 = document.getElementById(changedCardId + "header").getElementsByTagName("input")[0].value;
if (val1 != val2) {
document.getElementById(changedCardId + '-btn').textContent = document.getElementById(changedCardId + "header").getElementsByTagName("input")[0].value;
}
} catch (err) {
console.log(err.message + " but it's probably fine");
}
var ccidComponents = changedCardId.split('_');
var type = ccidComponents[0];
var id = ccidComponents[1];
var newValue = e.target.value;
var table = '';
if (type == "creature") {
table = "Creature";
}
else if (type == "attack") {
table = "Attack";
}
else if (type == "damage") {
table = "Damage";
}
else if (type == "item") {
table = "Item";
}
else if (type == "location"){
table = "Location";
}
column = e.target.id;
queryDB(`UPDATE ${table} SET ${table}.${column} = ` + "\"" + `${newValue}` + "\"" + ` WHERE id${table} = ${id};`);
}
function addItemCard(itemID) {
var itemQuery = queryDB('SELECT * FROM Item WHERE idItem=' + itemID + ';');
var item = JSON.parse(itemQuery)[0];
var newcard = document.createElement('div');
newcard.id = "item_" + itemID;
newcard.className = "card entrycontainer";
cardmarkup = `
<div id="${newcard.id}header" class="grip"><input id=item_name style="font-size:25px" type="text" size="10" value="${item.item_name}"> <div align=right class="x"><button type="button" onclick="closeCard('${newcard.id}')">X</button></div> </div>
<button onclick=DeleteItem(${itemID},'${newcard.id}')>Delete</button>
<p><textarea class=description id=item_description type=text>${item.item_description}</textarea></p>
<div>
</div>
`;
newcard.innerHTML = cardmarkup;
var desktop = document.getElementById("desktop");
desktop.appendChild(newcard);
reloadListeners();
dragElement(newcard);
}
function addLocationCard(locationID){
addLocationCard(locationID, false);
}
function addLocationCard(locationID, openCard) {
if (ctrlIsPressed || openCard) {
var locationQuery = queryDB('SELECT * FROM Location WHERE idLocation=' + locationID + ';');
var location = JSON.parse(locationQuery)[0];
var newcard = document.createElement('div');
newcard.id = "location_" + locationID;
newcard.className = "card entrycontainer";
cardmarkup = `
<div id="${newcard.id}header" class="grip"><input id=location_name style="font-size:25px" type="text" size="10" value="${location.location_name}"> <div align=right class="x"><button type="button" onclick="closeCard('${newcard.id}')">X</button></div> </div>
<button onclick=DeleteCard(${locationID})>Delete</button>
<p><textarea class=description id=location_description type=text>${location.location_description}</textarea></p>
<div>
</div>
`;
newcard.innerHTML = cardmarkup;
var desktop = document.getElementById("desktop");
desktop.appendChild(newcard);
reloadListeners();
dragElement(newcard);
}
var subTab = document.getElementById(`${locationID}_sublocations`);
var sublocationsQuery = queryDB(`SELECT idLocation FROM Location WHERE superLocation_idLocation=${locationID}`);
var sublocations = JSON.parse(sublocationsQuery);
for(i in sublocations)
{
for(j in locationTabs)
{
if(sublocations[i].idLocation == locationTabs[j].id)
{
subTab.appendChild(locationTabs[j]);
//var e = document.getElementById(`${locationTabs[j].id}blk`)
}
}
}
}
function newItemCard(element, locationID)
{
var newID = JSON.parse(queryDB(`SELECT max(idItem) from Item`))[0][`max(idItem)`] + 1;
queryDB(`INSERT INTO Item (idItem, item_name, Location_idLocation) VALUES (${newID}, 'New Item', ${locationID})`);
addItemCard(newID);
if (element != null) {
$(element).parent().prepend(`<button id="item_${newID}-btn" class="creature-btn" onClick="addItemCard(${newID})">New Item</button>`)//todo
}
}
function newLocationCard(element, locationID)
{
var newID = JSON.parse(queryDB(`SELECT max(idLocation) from Location`))[0][`max(idLocation)`] + 1;
queryDB(`INSERT INTO Location (idLocation, location_name, superLocation_idLocation) VALUES (${newID}, 'New Location', ${locationID})`);
addLocationCard(newID, true);
if (element != null) {
$(element).append(`<button id="location_${newID}-btn" class="creature-btn" onClick="addLocationCard(${newID})">New Location</button>`)//todo
}
}
function newCard(element = null, type = "creature") {
var location_id;
if (element != null) {
location_id = element.parentElement.parentElement.parentElement.id;
}
type = type.toLowerCase();
var newID = JSON.parse(queryDB(`SELECT max(id${type}) from Creature`))[0][`max(id${type})`] + 1;
queryDB(`INSERT INTO Creature (id${type}, ${type}_name) VALUES (${newID}, 'New ${type}')`); //inserts entity into database
if (element != null) {
$(element).parent().prepend(`<button id="${type}_${newID}-btn" class="${type}-btn" onClick="addCreatureCard(${newID})">New ${type}</button>`)//todo
}
if (type.toLowerCase() == "creature") {
console.log("location_id: " + location_id);
queryDB("INSERT INTO `DND`.`CreatureAppearance` (`Location_idLocation`, `Creature_idCreature`, `appearance_specific_information`) VALUES (" + location_id + "," + newID + ",NULL);");
addCreatureCard(newID);
} else {
console.error("Unknown card type - failed to create card. Card type: " + type);
}
}
function newCreatureCard(element = null, type = "creature") {
console.warn("newCreatureCard is deprecated - please use newCard instead");
newCard(element, type);
}
function addCreatureCard(cardid) {
var creature = JSON.parse(queryDB('SELECT * FROM Creature WHERE idCreature=' + cardid + ';'))[0];
var newcard = document.createElement('div');
newcard.id = "creature_" + cardid;
newcard.className = "card entrycontainer";
cardmarkup = `
<div id="${newcard.id}header" class="grip"><input id=creature_name style="font-size:25px" type="text" size="10" value="${creature.creature_name}"> <div align=right class="x"><button type="button" onclick="closeCard('${newcard.id}')">X</button></div> </div>
<button onclick=DeleteCard(${cardid},'${newcard.id}')>Delete</button>
<p>AC: <input id=ac type="number" size="1" value=${creature.ac}></p>
<p>HP: <input id=hp type="number" value=${creature.hp}></p>
<p>Speed: <input id=speed type="number" value=${creature.speed}>
<span align=right>XP: <input id=xp type="number" value=${creature.xp}><span></p>
<div class="singlestat">Str<p><input id=str type="number" value=${creature.str}></p></div>
<div class="singlestat">Dex<p><input id=dex type="number" value=${creature.dex}></p></div>
<div class="singlestat">Con<p><input id=con type="number" value=${creature.con}></p></div>
<div class="singlestat">Int<p><input id=int type="number" value=${creature.int}></p></div>
<div class="singlestat">Wis<p><input id=wis type="number" value=${creature.wis}></p></div>
<div class="singlestat">Cha<p><input id=cha type="number" value=${creature.cha}></p></div>
<p><textarea class=description id=creature_description type=text>${creature.creature_description}</textarea></p>
<div>
<table id=${cardid}_attacks style="font-size:10px">
<tr>
<th>Attack</th>
<th>Modifier</th>
<th>Damage</th>
<th>Description</th>
</tr>
</table>
</div>
`;
newcard.innerHTML = cardmarkup;
var desktop = document.getElementById("desktop");
desktop.appendChild(newcard);
var attackQuery = queryDB(`SELECT * FROM CreatureAttack LEFT JOIN Attack ON Attack_idAttack=idAttack WHERE Creature_idCreature=${cardid};`);
var attacks = null;
console.log(attackQuery);
if (attackQuery != null && isJSON(attackQuery) && attackQuery != "undefined" && attackQuery != "")
attacks = JSON.parse(attackQuery);
var attackTable = document.getElementById(`${cardid}_attacks`);
for (i in attacks) {
var newRow = attackTable.insertRow();
var attack = attacks[i];
newRow.className = 'entrycontainer';
newRow.id = 'attack_' + attack.idAttack;
var name = newRow.insertCell(0);
var modifier = newRow.insertCell(1);
var damage = newRow.insertCell(2);
var description = newRow.insertCell(3);
var rowX = newRow.insertCell(4);
name.innerHTML = `<input id=attack_name type=text style="width:40%" value=${attack.attack_name}>`;
modifier.innerHTML = `<input id=attack_modifier type=number value=${attack.attack_modifier}>`;
description.innerHTML = `<textarea id=attack_description style='background-color: rgba(0, 0, 0, 0.01)' type=text>${attack.attack_description}</textarea>`;
rowX.innerHTML = `<div align=right class="x"><button type="button" onclick="deleteAttack(${attack.idAttack}, ${cardid}, ${newRow.id})">X</button></div>`;
var damageTable = document.createElement("table");
damageTable.id = "table_" + cardid + "_" + attack.idAttack;
var damageQuery = queryDB(`SELECT * FROM Damage WHERE Attack_idAttack=${attack.idAttack};`);
var damages = null;
if (damageQuery != null && isJSON(damageQuery) && damageQuery != "undefined" && damageQuery != "") {
damages = JSON.parse(damageQuery);
dmgList = ""
for (j in damages) {
var d = damages[j];
var damageRow = damageTable.insertRow();
damageRow.className = "entrycontainer";
damageRow.id = `damage_${d.idDamage}`;
var rollCell = damageRow.insertCell(0);
var typeCell = damageRow.insertCell(1);
var delCell = damageRow.insertCell(2);
rollCell.innerHTML = `<input id=damage_roll type=text class=dmgBox value=${d.damage_roll}>`;
typeCell.innerHTML = `<select id=damage_type selected=${d.damage_type} class="btn btn-select resizeselect" value=${d.damage_type}>
<option value=${d.damage_type} selected disabled hidden>${d.damage_type}</option>
<option>acid</option>
<option>bludgeoning</option>
<option>cold</option>
<option>fire</option>
<option>force</option>
<option>lightning</option>
<option>necrotic</option>
<option>piercing</option>
<option>poison</option>
<option>psychic</option>
<option>radiant</option>
<option>slashing</option>
<option>thunder</option>
</select>`;
delCell.innerHTML = `<div align=right class="x"><button type="button" onclick="removeDamage(${d.idDamage})">X</button></div>`;
}
}
damageTable.createTFoot().innerHTML = `<button onclick="addDamage(${attack.idAttack}, ${cardid})">+</button>`;
damage.appendChild(damageTable);
}
attackTable.createTFoot().innerHTML = `<div> <button onclick=addAttackEntry(${cardid})>Add</button>
</div>
`;
dragElement(newcard);
reloadListeners();
}
function DeleteCard(id, cardid) {
closeCard(cardid);
queryDB(`DELETE FROM creatureattack WHERE Creature_idCreature = ${id};`);
queryDB(`DELETE FROM creatureappearance WHERE Creature_idCreature = ${id};`);
queryDB(`DELETE FROM item WHERE Creature_idCreature = ${id};`);
queryDB(`DELETE FROM Creature WHERE template_idCreature = ${id};`);
queryDB(`DELETE FROM Creature WHERE idCreature = ${id};`);
try {
var del = document.getElementById(id + "c");
del.parentNode.removeChild(del);
}
catch{
var del = document.getElementById("creature_" + id + "-btn");
del.parentNode.removeChild(del);
}
}
function DeleteItem(id,cardid){
closeCard(cardid);
queryDB(`DELETE FROM itemattack WHERE Item_idItem = ${id};`);
queryDB(`DELETE FROM item WHERE idItem = ${id};`);
try {
var del = document.getElementById(id + "d");
del.parentNode.removeChild(del);
}
catch{
var del = document.getElementById("item_" + id + "-btn");
del.parentNode.removeChild(del);
}
}
function isJSON(s) {
if (/^[\],:{}\s]*$/.test(s.replace(/\\["\\\/bfnrtu]/g, '@').
replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']').
replace(/(?:^|:|,)(?:\s*\[)+/g, '')))
return true;
return false;
}
function closeCard(id) {
var desktop = document.getElementById("desktop");
try {
desktop.removeChild(document.getElementById(id));
} catch {
//VERY HACKY
console.warn("removeChild didn't work, trying backup");
var element = document.getElementById(id);
console.log(element.parentElement);
console.log(desktop);
element.parentElement.removeChild(element);
closeCard(id);
}
}
function addAttackEntry(creatureID) {
var attackTable = document.getElementById(`${creatureID}_attacks`);
var newID = JSON.parse(queryDB('SELECT max(idAttack) from Attack'))[0]["max(idAttack)"] + 1;
queryDB(`INSERT INTO Attack (idAttack, attack_name) VALUES (${newID}, "new");`);
queryDB(`INSERT INTO CreatureAttack (Attack_idAttack, Creature_idCreature)
VALUES (${newID}, ${creatureID});`);
var newRow = attackTable.insertRow();
newRow.className = 'entrycontainer';
newRow.id = 'attack_' + newID;
var name = newRow.insertCell(0);
var modifier = newRow.insertCell(1);
var damage = newRow.insertCell(2);
var description = newRow.insertCell(3);
var rowX = newRow.insertCell(4);
var damageTable = document.createElement("table");
damageTable.id = "table_" + creatureID + "_" + newID;
var damageQuery = queryDB(`SELECT * FROM Damage WHERE Attack_idAttack=${newID};`);
var damages = null;
if (damageQuery != null && isJSON(damageQuery) && damageQuery != "undefined" && damageQuery != "") {
damages = JSON.parse(damageQuery);
dmgList = ""
for (j in damages) {
var d = damages[j];
var damageRow = damageTable.insertRow();
damageRow.className = "entrycontainer";
damageRow.id = `damage_${d.idDamage}`;
var rollCell = damageRow.insertCell(0);
var typeCell = damageRow.insertCell(1);
var delCell = damageRow.insertCell(2);
rollCell.innerHTML = `<input id=damage_roll type=text class=dmgBox value=${d.damage_roll}>`;
typeCell.innerHTML = `<select id=damage_type selected=${d.damage_type} class="btn btn-select resizeselect" value=${d.damage_type}>
<option value=${d.damage_type} selected disabled hidden>${d.damage_type}</option>
<option>acid</option>
<option>bludgeoning</option>
<option>cold</option>
<option>fire</option>
<option>force</option>
<option>lightning</option>
<option>necrotic</option>
<option>piercing</option>
<option>poison</option>
<option>psychic</option>
<option>radiant</option>
<option>slashing</option>
<option>thunder</option>
</select>`;
delCell.innerHTML = `<div align=right class="x"><button type="button" onclick="removeDamage(${d.idDamage})">X</button></div>`;
}
}
damageTable.createTFoot().innerHTML = `<button onclick="addDamage(${newID}, ${creatureID})">+</button>`;
damage.appendChild(damageTable);
name.innerHTML = `<input id=attack_name type=text style="width:40%">`;
modifier.innerHTML = `<input id=attack_modifier type=number>`;
description.innerHTML = `<textarea id=attack_description style='background-color: rgba(0, 0, 0, 0.01)' type=text></textarea>`;
rowX.innerHTML = `<div align=right class="x"><button type="button" onclick="deleteAttack(${newID}, ${creatureID}, ${newRow.id})">X</button></div>`;
reloadListeners();
}
function deleteAttack(attackID, creatureID, rowID) {
var row = document.getElementById('attack_' + attackID);
row.parentElement.removeChild(row);
queryDB(`DELETE FROM CreatureAttack WHERE Attack_idAttack=${attackID} AND Creature_idCreature=${creatureID};`);
}
function addDamage(attackID, creatureID) {
var newID = JSON.parse(queryDB('SELECT max(idDamage) from Damage'))[0]["max(idDamage)"] + 1;
queryDB(`INSERT INTO Damage (idDamage, Attack_idAttack, damage_roll, damage_type) VALUES (${newID}, ${attackID}, "", "piercing")`);
var dt = document.getElementById("table_" + creatureID + "_" + attackID);
var newRow = dt.insertRow();
newRow.className = 'entrycontainer';
newRow.id = `damage_${newID}`
var newRoll = newRow.insertCell(0);
var newType = newRow.insertCell(1);
var delCell = newRow.insertCell(2);
newRoll.innerHTML = `<input id=damage_roll type=text class=dmgBox value="">`;
newType.innerHTML = `<select id=damage_type selected='piercing' class="btn btn-select resizeselect" value='piercing'>
<option value='piercing' selected disabled hidden>piercing</option>
<option>acid</option>
<option>bludgeoning</option>
<option>cold</option>
<option>fire</option>
<option>force</option>
<option>lightning</option>
<option>necrotic</option>
<option>piercing</option>
<option>poison</option>
<option>psychic</option>
<option>radiant</option>
<option>slashing</option>
<option>thunder</option>
</select>`;
delCell.innerHTML = `<div align=right class="x"><button type="button" onclick="removeDamage(${newID})">X</button></div>`;
reloadListeners();
}
function removeDamage(damageID) {
var row = document.getElementById('damage_' + damageID);
row.parentElement.removeChild(row);
queryDB(`DELETE FROM Damage WHERE idDamage=${damageID};`);
}
/* Loop through all dropdown buttons to toggle between hiding and showing its dropdown content - This allows the user to have multiple dropdowns without any conflict */
var dropdown = document.getElementsByClassName("dropdown-btn");
var i;
for (i = 0; i < dropdown.length; i++) {
dropdown[i].addEventListener("click", function () {
this.classList.toggle("active");
var dropdownContent = this.nextElementSibling;
if (dropdownContent.style.display === "block") {
dropdownContent.style.display = "none";
} else {
dropdownContent.style.display = "block";
}
});
}
//Make the DIV element draggagle:
var deck = document.getElementsByClassName("card");
for (i in deck) {
dragElement(deck[i]);
}
function dragElement(elmnt) {
var pos1 = 0, pos2 = 0, pos3 = 0, pos4 = 0;
if (document.getElementById(elmnt.id + "header")) {
/* if present, the header is where you move the DIV from:*/
document.getElementById(elmnt.id + "header").onmousedown = dragMouseDown;
} else {
/* otherwise, move the DIV from anywhere inside the DIV:*/
elmnt.onmousedown = dragMouseDown;
}
function dragMouseDown(e) {
e = e || window.event;
// get the mouse cursor position at startup:
pos3 = e.clientX;
pos4 = e.clientY;
document.onmouseup = closeDragElement;
// call a function whenever the cursor moves:
document.onmousemove = elementDrag;
}
function elementDrag(e) {
e = e || window.event;
e.preventDefault();
// calculate the new cursor position:
pos1 = pos3 - e.clientX;
pos2 = pos4 - e.clientY;
pos3 = e.clientX;
pos4 = e.clientY;
// set the element's new position:
elmnt.style.top = (elmnt.offsetTop - pos2) + "px";
elmnt.style.left = (elmnt.offsetLeft - pos1) + "px";
}
function closeDragElement() {
/* stop moving when mouse button is released:*/
document.onmouseup = null;
document.onmousemove = null;
}
}
(function ($, window) {
var arrowWidth = 30;
$.fn.resizeselect = function (settings) {
return this.each(function () {
$(this).change(function () {
var $this = $(this);
// create test element
var text = $this.find("option:selected").text();
var $test = $("<span>").html(text).css({
"font-size": $this.css("font-size"), // ensures same size text
"visibility": "hidden" // prevents FOUC
});
// add to parent, get width, and get out
$test.appendTo($this.parent());
var width = $test.width();
$test.remove();
// set select width
$this.width(width + arrowWidth);
// run on start
}).change();
});
};
// run by default
$("select.resizeselect").resizeselect();
})(jQuery, window);
</script>
</body>
</html>