repackages xml-import into class and adds configuration dialog to it
parent
53c5c7b53a
commit
1c9d4a1f1f
16
src/main.mjs
16
src/main.mjs
|
|
@ -27,6 +27,8 @@ import {CultureDataModel} from "./module/data/culture.mjs";
|
||||||
import {CultureSheet} from "./module/sheets/CultureSheet.mjs";
|
import {CultureSheet} from "./module/sheets/CultureSheet.mjs";
|
||||||
import {SpeciesSheet} from "./module/sheets/SpeciesSheet.mjs";
|
import {SpeciesSheet} from "./module/sheets/SpeciesSheet.mjs";
|
||||||
import {ProfessionSheet} from "./module/sheets/ProfessionSheet.mjs";
|
import {ProfessionSheet} from "./module/sheets/ProfessionSheet.mjs";
|
||||||
|
import {XmlImport} from "./module/xml-import/xml-import.mjs";
|
||||||
|
import {XmlImportDialog} from "./module/dialog/xmlImportDialog.mjs";
|
||||||
|
|
||||||
async function preloadHandlebarsTemplates() {
|
async function preloadHandlebarsTemplates() {
|
||||||
return foundry.applications.handlebars.loadTemplates([
|
return foundry.applications.handlebars.loadTemplates([
|
||||||
|
|
@ -219,6 +221,20 @@ Hooks.once("ready", async function () {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
Hooks.on("getActorContextOptions", (application, menuItems) => {
|
||||||
|
menuItems.push({
|
||||||
|
name: "Import from XML",
|
||||||
|
icon: '<i class="fas fa-file"></i>',
|
||||||
|
callback: (li) => {
|
||||||
|
const actorId = li.getAttribute("data-entry-id")
|
||||||
|
const actor = game.actors.get(actorId)
|
||||||
|
//actor.import()
|
||||||
|
new XmlImportDialog(actor).render(true)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
async function createTalentMacro(data, slot) {
|
async function createTalentMacro(data, slot) {
|
||||||
console.log(data, slot)
|
console.log(data, slot)
|
||||||
if (data.type !== "Item") return;
|
if (data.type !== "Item") return;
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,88 @@
|
||||||
|
import {XmlImport} from "../xml-import/xml-import.mjs";
|
||||||
|
|
||||||
|
const {ApplicationV2, HandlebarsApplicationMixin} = foundry.applications.api
|
||||||
|
|
||||||
|
export class XmlImportDialog extends HandlebarsApplicationMixin(ApplicationV2) {
|
||||||
|
|
||||||
|
static DEFAULT_OPTIONS = {
|
||||||
|
classes: ['dsa41', 'dialog', 'xmlimport'],
|
||||||
|
tag: "form",
|
||||||
|
position: {
|
||||||
|
width: 320,
|
||||||
|
height: 478
|
||||||
|
},
|
||||||
|
window: {
|
||||||
|
resizable: false,
|
||||||
|
},
|
||||||
|
form: {
|
||||||
|
submitOnChange: false,
|
||||||
|
closeOnSubmit: true,
|
||||||
|
handler: XmlImportDialog.#onSubmitForm
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
static PARTS = {
|
||||||
|
form: {
|
||||||
|
template: 'systems/DSA_4-1/templates/dialog/xml-import.hbs',
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @type {Actor}
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
_actor = null
|
||||||
|
/**
|
||||||
|
* @type {XmlImport}
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
_xmlImport = null
|
||||||
|
|
||||||
|
constructor(actor) {
|
||||||
|
super();
|
||||||
|
this._actor = actor
|
||||||
|
this._xmlImport = new XmlImport()
|
||||||
|
}
|
||||||
|
|
||||||
|
static async #onSubmitForm(event, form, formData) {
|
||||||
|
event.preventDefault()
|
||||||
|
console.log("lets go", formData.object)
|
||||||
|
|
||||||
|
const options = {}
|
||||||
|
|
||||||
|
formData.object.importOption.forEach(p => {
|
||||||
|
options[p] = true
|
||||||
|
})
|
||||||
|
|
||||||
|
const file = form.querySelector('input[type="file"]').files[0]
|
||||||
|
|
||||||
|
try {
|
||||||
|
form.querySelector('button[type="submit"]').setAttribute("disabled", true)
|
||||||
|
await this._xmlImport.importCharacter(this._actor._id, file, options)
|
||||||
|
form.querySelector('button[type="submit"]').setAttribute("disabled", false)
|
||||||
|
return true
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e)
|
||||||
|
form.querySelector('button[type="submit"]').setAttribute("disabled", false)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_configureRenderOptions(options) {
|
||||||
|
super._configureRenderOptions(options)
|
||||||
|
options.window.title = `${this._actor.name} importieren`
|
||||||
|
return options
|
||||||
|
}
|
||||||
|
|
||||||
|
async _prepareContext(options) {
|
||||||
|
const context = await super._prepareContext(options)
|
||||||
|
context.options = XmlImport.getOptions()
|
||||||
|
return context
|
||||||
|
}
|
||||||
|
|
||||||
|
_onRender(context, options) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
import {importCharacter} from "../xml-import/xml-import.mjs";
|
|
||||||
import {LiturgyData} from "../data/miracle/liturgydata.mjs";
|
import {LiturgyData} from "../data/miracle/liturgydata.mjs";
|
||||||
import {Zonenruestung, Zonenwunde, Wunde} from "../data/Trefferzone.js";
|
import {Zonenruestung, Zonenwunde, Wunde} from "../data/Trefferzone.js";
|
||||||
import {PlayerCharacterDataModel} from "../data/character.mjs";
|
import {PlayerCharacterDataModel} from "../data/character.mjs";
|
||||||
|
|
||||||
export class Character extends Actor {
|
export class Character extends Actor {
|
||||||
|
|
||||||
|
/**
|
||||||
import() {
|
import() {
|
||||||
let input = document.createElement('input')
|
let input = document.createElement('input')
|
||||||
input.type = 'file'
|
input.type = 'file'
|
||||||
|
|
@ -13,7 +13,7 @@ export class Character extends Actor {
|
||||||
importCharacter(this.id, e.target.files[0])
|
importCharacter(this.id, e.target.files[0])
|
||||||
}
|
}
|
||||||
input.click()
|
input.click()
|
||||||
}
|
}*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @override
|
* @override
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load Diff
|
|
@ -0,0 +1,71 @@
|
||||||
|
.application.dsa41.dialog.xmlimport {
|
||||||
|
|
||||||
|
section.window-content {
|
||||||
|
|
||||||
|
section {
|
||||||
|
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: 1fr;
|
||||||
|
grid-template-rows: 32px 1fr 32px;
|
||||||
|
gap: 8px 0;
|
||||||
|
grid-template-areas: "file" "options" "actions";
|
||||||
|
|
||||||
|
.file-input {
|
||||||
|
grid-area: file;
|
||||||
|
display: flex;
|
||||||
|
gap: 8px;
|
||||||
|
|
||||||
|
label {
|
||||||
|
flex: 0;
|
||||||
|
height: 32px;
|
||||||
|
line-height: 32px;
|
||||||
|
vertical-align: middle;
|
||||||
|
width: 80px;
|
||||||
|
}
|
||||||
|
|
||||||
|
input {
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fieldset {
|
||||||
|
grid-area: options;
|
||||||
|
border-left: 0;
|
||||||
|
border-bottom: 0;
|
||||||
|
border-right: 0;
|
||||||
|
|
||||||
|
legend {
|
||||||
|
padding: 0 16px;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
div {
|
||||||
|
|
||||||
|
label {
|
||||||
|
|
||||||
|
height: 21px;
|
||||||
|
|
||||||
|
input {
|
||||||
|
line-height: 21px;
|
||||||
|
height: 21px;
|
||||||
|
}
|
||||||
|
|
||||||
|
span {
|
||||||
|
line-height: 21px;
|
||||||
|
height: 21px;
|
||||||
|
vertical-align: 2px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
button {
|
||||||
|
grid-area: actions;
|
||||||
|
width: 100%;
|
||||||
|
height: 32px;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -23,4 +23,5 @@
|
||||||
@use "organisms/culture-sheet";
|
@use "organisms/culture-sheet";
|
||||||
@use "organisms/species-sheet";
|
@use "organisms/species-sheet";
|
||||||
@use "organisms/profession-sheet";
|
@use "organisms/profession-sheet";
|
||||||
|
@use "organisms/xml-import-dialog";
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,21 @@
|
||||||
|
<section>
|
||||||
|
|
||||||
|
<div class="file-input">
|
||||||
|
<label for="file"><span>Quelldatei</span></label><input id="file" type="file" name="file" accept=".xml">
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<fieldset>
|
||||||
|
<legend>Folgendes <strong>nicht</strong> importieren</legend>
|
||||||
|
|
||||||
|
|
||||||
|
{{#each options}}
|
||||||
|
<div><label><input type="checkbox" name="importOption" value="{{@key}}"><span>{{this}}</span></label>
|
||||||
|
</div>
|
||||||
|
{{/each}}
|
||||||
|
|
||||||
|
</fieldset>
|
||||||
|
|
||||||
|
<button type="submit"><i class="fas fa-upload"></i>Import starten</button>
|
||||||
|
|
||||||
|
</section>
|
||||||
Loading…
Reference in New Issue