1
- import { PATH , log } from '../js/helpers.js' ;
1
+ import { PATH } from '../js/helpers.js' ;
2
2
3
3
export default class Scenery extends FormApplication {
4
4
static get defaultOptions ( ) {
@@ -71,10 +71,13 @@ export default class Scenery extends FormApplication {
71
71
* Add a new empty row to the form
72
72
* @param {Object } formData
73
73
*/
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 ) ;
78
81
}
79
82
80
83
/**
@@ -92,6 +95,7 @@ export default class Scenery extends FormApplication {
92
95
* Scan for variations in current directory of default img
93
96
*/
94
97
async scan ( ) {
98
+ window . t = this ;
95
99
const path = this . element . find ( '[name="variations.0.file"]' ) [ 0 ] . value ;
96
100
const fp = await FilePicker . browse ( 'data' , path ) ;
97
101
const defName = path . split ( '/' ) . pop ( ) . split ( '.' ) . slice ( 0 , - 1 ) . join ( '.' ) ;
@@ -105,9 +109,11 @@ export default class Scenery extends FormApplication {
105
109
}
106
110
return acc ;
107
111
} , [ ] ) ;
108
-
112
+ // eslint-disable-next-line no-restricted-syntax
113
+ let index = this . element . find ( 'tbody>tr' ) . length ;
109
114
variations . forEach ( ( v ) => {
110
- this . addVariation ( v . name , v . file ) ;
115
+ this . addVariation ( v . name , v . file , index ) ;
116
+ index ++ ;
111
117
} ) ;
112
118
}
113
119
@@ -127,8 +133,8 @@ export default class Scenery extends FormApplication {
127
133
const variations = Object . values ( formData . variations )
128
134
. slice ( 1 )
129
135
. 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 ;
132
138
if ( ! gm || ! pl ) {
133
139
ui . notifications . error ( 'GM & Player view must have a file' ) ;
134
140
return ;
@@ -146,7 +152,10 @@ export default class Scenery extends FormApplication {
146
152
*/
147
153
static setImage ( img , draw = true ) {
148
154
canvas . scene . data . img = img ;
149
- if ( draw ) canvas . draw ( ) ;
155
+ if ( draw ) {
156
+ canvas . draw ( ) ;
157
+ setTimeout ( ( ) => canvas . draw ( ) , 60 ) ;
158
+ }
150
159
}
151
160
152
161
/**
0 commit comments