-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathdrawCardsToTable.js
114 lines (105 loc) · 3.4 KB
/
drawCardsToTable.js
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
/*
Features
- Draw n cards placing them in the scene
- This macro can reset the table preventing from the error
- This macro can line up the cards
*/
getRequirements();
function getRequirements() {
//How Many Cards to Draw
//Width/Height
//Which Table to Draw From
let cardsList = "";
Array.from(game.tables).map((el) => {
cardsList += `<option value="${el.data.name}">${el.data.name}</option>`;
});
let template = `
<p>Table to Draw From: <select id="tableName">${cardsList}</select></p>
<p>
Cards to Draw (Lines x Columns): <input id="dogFightLines" type="number" min="1" style="width: 50px;" value=1> x <input id="dogFightColumns" type="number" min="1" style="width: 50px;" value=9>
</p>
<p>
Height: <input id="height" type="number" min="1" style="width: 50px" value=150>
Width: <input id="width" type="number" min="1" style="width: 50px" value=107>
</p>
<br />
<p>
<input type="checkbox" id="reset" checked/>
Reset Table?
</p>
<p>
<input type="checkbox" id="stackupcards"/>
Just stack up all cards
</p>
<br />
<p>
<h3>Horizontal spacing between cards</h3>
<input id="spacingx" type="range" min="0" max="100" value="20" step="5">
</p>
<p>
<h3>Vertical spacing between cards (dogfight only)</h3>
<input id="spacingy" type="range" min="0" max="100" value="100" step="5">
</p>
`;
new Dialog({
title: "Draw Cards To Table",
content: template,
buttons: {
ok: {
label: "Draw",
callback: async (html) => {
makeTiles(html);
},
},
cancel: {
label: "Cancel",
},
},
}).render(true);
}
async function makeTiles(html) {
let spacingx = html.find("#spacingx")[0].value/100;
let spacingy = html.find("#spacingy")[0].value/100;
let dogFightLines = html.find("#dogFightLines")[0].value;
let dogFightColumns = html.find("#dogFightColumns")[0].value;
let resetTable = html.find("#reset")[0].value;
const stackupcards = html.find("#stackupcards")[0].checked;
let tableName = html.find("#tableName")[0].value;
let cardsToDraw = dogFightLines*dogFightColumns;
let _height = html.find("#height")[0].value;
let _width = html.find("#width")[0].value;
if (resetTable=='on') {
await game.tables.find((el) => el.data.name == tableName).reset();
}
let cardDraws = (
await game.tables
.find((el) => el.data.name == tableName)
.drawMany(cardsToDraw)
).results;
let centerX = game.scenes.active.data.width / 3;
let centerY = game.scenes.active.data.height / 2;
let deltaX = 0;
let deltaY = 0;
let counter = 0;
//console.log(spacingx + '/' + spacingy + ' stackupcards:' + (stackupcards!='on'));
for (let y = 0; y < dogFightLines; y++) {
deltaY = ( _height*y + _height*spacingy*y );
for (let x = 0; x < dogFightColumns; x++) {
deltaX = ( _width*x + _width*spacingx*x );
if (stackupcards) {
deltaX = 0;
deltaY = 0;
}
await Tile.create({
img: cardDraws[counter].img,
width: _width,
height: _height,
x: centerX + deltaX,
y: centerY + deltaY
});
//console.log('x:' + x + ' y:' + y + ' counter:' + counter + ' deltaX:' + deltaX + ' deltaY:' + deltaY);
counter = counter + 1;
//console.log('centerX: ' + centerX + ' / deltaX: ' + deltaX + ' / centerX+deltaX:' + (centerX+deltaX) );
}
}
}