repackages xml-import into class and adds configuration dialog to it

pull/61/head
macniel 2025-10-21 11:02:19 +02:00
parent 53c5c7b53a
commit 1c9d4a1f1f
7 changed files with 740 additions and 523 deletions

View File

@ -27,6 +27,8 @@ import {CultureDataModel} from "./module/data/culture.mjs";
import {CultureSheet} from "./module/sheets/CultureSheet.mjs";
import {SpeciesSheet} from "./module/sheets/SpeciesSheet.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() {
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) {
console.log(data, slot)
if (data.type !== "Item") return;

View File

@ -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) {
}
}

View File

@ -1,10 +1,10 @@
import {importCharacter} from "../xml-import/xml-import.mjs";
import {LiturgyData} from "../data/miracle/liturgydata.mjs";
import {Zonenruestung, Zonenwunde, Wunde} from "../data/Trefferzone.js";
import {PlayerCharacterDataModel} from "../data/character.mjs";
export class Character extends Actor {
/**
import() {
let input = document.createElement('input')
input.type = 'file'
@ -13,7 +13,7 @@ export class Character extends Actor {
importCharacter(this.id, e.target.files[0])
}
input.click()
}
}*/
/**
* @override

File diff suppressed because it is too large Load Diff

View File

@ -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;
}
}
}
}

View File

@ -23,4 +23,5 @@
@use "organisms/culture-sheet";
@use "organisms/species-sheet";
@use "organisms/profession-sheet";
@use "organisms/xml-import-dialog";

View File

@ -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>