Skip to content

Commit 4c16c46

Browse files
committed
fixes issue with indexing of bulk variation adder
1 parent 8adea86 commit 4c16c46

File tree

3 files changed

+22
-17
lines changed

3 files changed

+22
-17
lines changed

.eslintrc.js

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ module.exports = {
3131
ObjectPattern: { multiline: true, minProperties: 4 },
3232
}],
3333
'newline-per-chained-call': 'off',
34+
'no-plusplus': 'off',
3435
},
3536
globals: {
3637
AudioHelper: 'readonly',

classes/Scenery.js

+19-10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { PATH, log } from '../js/helpers.js';
1+
import { PATH } from '../js/helpers.js';
22

33
export default class Scenery extends FormApplication {
44
static get defaultOptions() {
@@ -71,10 +71,13 @@ export default class Scenery extends FormApplication {
7171
* Add a new empty row to the form
7272
* @param {Object} formData
7373
*/
74-
async addVariation(name = '', file = '') {
75-
const id = this.element.find('tbody>tr').length;
76-
const row = await renderTemplate(`${PATH}/templates/variation.hbs`, { id, name, file });
77-
this.element.find('.scenery-table').append(row);
74+
async addVariation(name = '', file = '', id = null) {
75+
const html = this.element;
76+
if (id === null) id = html.find('tbody>tr').length;
77+
const row = $(await renderTemplate(`${PATH}/templates/variation.hbs`, { id, name, file }));
78+
row.find('.delete').click(() => Scenery.deleteVariation(html));
79+
row.find('.preview').click(() => Scenery.previewVariation(html));
80+
await html.find('.scenery-table').append(row);
7881
}
7982

8083
/**
@@ -92,6 +95,7 @@ export default class Scenery extends FormApplication {
9295
* Scan for variations in current directory of default img
9396
*/
9497
async scan() {
98+
window.t = this;
9599
const path = this.element.find('[name="variations.0.file"]')[0].value;
96100
const fp = await FilePicker.browse('data', path);
97101
const defName = path.split('/').pop().split('.').slice(0, -1).join('.');
@@ -105,9 +109,11 @@ export default class Scenery extends FormApplication {
105109
}
106110
return acc;
107111
}, []);
108-
112+
// eslint-disable-next-line no-restricted-syntax
113+
let index = this.element.find('tbody>tr').length;
109114
variations.forEach((v) => {
110-
this.addVariation(v.name, v.file);
115+
this.addVariation(v.name, v.file, index);
116+
index++;
111117
});
112118
}
113119

@@ -127,8 +133,8 @@ export default class Scenery extends FormApplication {
127133
const variations = Object.values(formData.variations)
128134
.slice(1)
129135
.filter((v) => v.file);
130-
const gm = formData.variations[formData.gm]?.file;
131-
const pl = formData.variations[formData.pl]?.file;
136+
const gm = formData.variations[$('input[name="gm"]:checked').val()]?.file;
137+
const pl = formData.variations[$('input[name="gm"]:checked').val()]?.file;
132138
if (!gm || !pl) {
133139
ui.notifications.error('GM & Player view must have a file');
134140
return;
@@ -146,7 +152,10 @@ export default class Scenery extends FormApplication {
146152
*/
147153
static setImage(img, draw = true) {
148154
canvas.scene.data.img = img;
149-
if (draw) canvas.draw();
155+
if (draw) {
156+
canvas.draw();
157+
setTimeout(() => canvas.draw(), 60);
158+
}
150159
}
151160

152161
/**

css/scenery.css

+2-7
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
#scenery-config {
22
height: auto !important;
3-
max-height: 500px;
3+
max-height: 700px;
44
}
5-
6-
75
table.scenery-table {
86
border: 1px solid #444;
97
margin: 0 0 6px 0;
@@ -19,17 +17,14 @@ td.scenery-gm,
1917
td.scenery-player {
2018
text-align: center;
2119
}
22-
2320
.scenery-delete,
2421
.scenery-preview {
2522
padding-right: 6px;
2623
}
27-
2824
.scenery-delete button,
2925
.scenery-preview button {
3026
padding: 1px 2px 1px 5px;
3127
flex: 0 0 32px;
32-
margin: 0 5px 0 0;
3328
line-height: 24px;
3429
text-align: center;
3530
background: rgba(0, 0, 0, 0.1);
@@ -38,4 +33,4 @@ td.scenery-player {
3833
}
3934
.scenery-delete button[disabled] {
4035
opacity: 0.5;
41-
}
36+
}

0 commit comments

Comments
 (0)