Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const parseFile = html => {
- const file = html.find('#file')[0].files[0]
- const tableId = html.find('#table-id')[0].value
- var reader = new FileReader();
- reader.onload = (e) => {
- const contents = e.target.result
- importContents(contents, tableId)
- }
- reader.readAsText(file)
- }
- const importContents = (contents, tableId) => {
- const table = game.tables.get(tableId)
- const entries = contents.split('\n').map(line => {
- return {
- type: 0, text: line, range: [1,2], weight: 1
- }
- })
- table.createEmbeddedDocuments("TableResult", entries)
- table.normalize()
- }
- await new Promise(resolve => {
- new Dialog({
- title: 'Import CSV File to RollTable',
- content: '<form><div class="form-group"><label style="max-width:100px">File</label><div class="form-fields"><input id="file" type="file"/></div></div><div class="form-group"><label style="max-width:100px">RollTable ID</label><div class="form-fields"><input id="table-id" type="string"></div></div></form>',
- buttons: {
- roll: {
- icon: '<i class="fas fa-file-import"></i>',
- label: "Import",
- callback: html => resolve(parseFile(html))
- },
- },
- close: () => resolve(null)
- }).render(true);})
Advertisement
Add Comment
Please, Sign In to add comment