rigs specialabilities for import.
parent
9f91606516
commit
7fe5ba1595
63
gulpfile.mjs
63
gulpfile.mjs
|
|
@ -5,7 +5,7 @@ import {getRandomValues} from 'node:crypto';
|
|||
import * as dartSass from 'sass';
|
||||
import gulpSass from 'gulp-sass';
|
||||
import {deleteAsync} from 'del';
|
||||
import {readdirSync, readFileSync, writeFileSync, rmdirSync, existsSync, mkdirSync} from "fs";
|
||||
import {readdirSync, readFileSync, writeFileSync, rmdirSync, existsSync, mkdirSync, statSync} from "fs";
|
||||
import {join} from 'node:path';
|
||||
|
||||
import {compilePack} from '@foundryvtt/foundryvtt-cli';
|
||||
|
|
@ -30,36 +30,46 @@ function randomID(length = 16) {
|
|||
return id;
|
||||
}
|
||||
|
||||
const convert = function (from, to, ofType) {
|
||||
const convert = function (from, to, ofType, overwrite = true) {
|
||||
|
||||
const SOURCE = from;
|
||||
const DEST = to;
|
||||
const TYPE = ofType;
|
||||
|
||||
try {
|
||||
rmdirSync(DEST, {force: true, recursive: true})
|
||||
} catch (e) {
|
||||
}
|
||||
mkdirSync(DEST)
|
||||
|
||||
readdirSync(SOURCE).forEach(file => {
|
||||
console.log(file)
|
||||
let originalSource = JSON.parse(readFileSync(join(SOURCE, file), {encoding: "utf8"}));
|
||||
let id = randomID();
|
||||
|
||||
let targetSource = {
|
||||
_id: id,
|
||||
_key: "!items!" + id,
|
||||
type: TYPE,
|
||||
img: originalSource.image,
|
||||
name: originalSource.name.trim(),
|
||||
system: {...originalSource},
|
||||
if (overwrite) {
|
||||
try {
|
||||
rmdirSync(DEST, {force: true, recursive: true})
|
||||
} catch (e) {
|
||||
}
|
||||
delete targetSource.system.image;
|
||||
let target = JSON.stringify(targetSource, null, 2);
|
||||
let newFileName = "./" + join(DEST, id + ".json");
|
||||
writeFileSync(newFileName, target, {encoding: "utf8"});
|
||||
});
|
||||
mkdirSync(DEST)
|
||||
}
|
||||
|
||||
const filewalker = (source) => {
|
||||
console.log("entering directory", source);
|
||||
readdirSync(source).forEach(file => {
|
||||
if (statSync(join(source, file)).isDirectory()) {
|
||||
filewalker(join(source, file));
|
||||
} else {
|
||||
let originalSource = JSON.parse(readFileSync(join(source, file), {encoding: "utf8"}));
|
||||
let id = randomID();
|
||||
|
||||
let targetSource = {
|
||||
_id: id,
|
||||
_key: "!items!" + id,
|
||||
type: TYPE,
|
||||
img: originalSource.image,
|
||||
name: originalSource.name.trim(),
|
||||
system: {...originalSource},
|
||||
}
|
||||
delete targetSource.system.image;
|
||||
let target = JSON.stringify(targetSource, null, 2);
|
||||
let newFileName = "./" + join(DEST, id + ".json");
|
||||
writeFileSync(newFileName, target, {encoding: "utf8"});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
filewalker(SOURCE)
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -99,7 +109,8 @@ async function prepareDB() {
|
|||
convert("./src/packs/_source/talente", "./src/packs/__source/talente", "Skill");
|
||||
convert("./src/packs/_source/zauber", "./src/packs/__source/zauber", "Spell");
|
||||
convert("./src/packs/_source/vorteile", "./src/packs/__source/vorteile", "Advantage");
|
||||
convert("./src/packs/_source/nachteile", "./src/packs/__source/vorteile", "Advantage");
|
||||
convert("./src/packs/_source/nachteile", "./src/packs/__source/vorteile", "Advantage", false);
|
||||
convert("./src/packs/_source/sonderfertigkeiten", "./src/packs/__source/sonderfertigkeiten", "SpecialAbility");
|
||||
convert("./src/packs/_source/waffen", "./src/packs/__source/waffen", "Equipment");
|
||||
convert("./src/packs/_source/munition", "./src/packs/__source/munition", "Equipment");
|
||||
convert("./src/packs/_source/ruestzeug", "./src/packs/__source/ruestzeug", "Equipment");
|
||||
|
|
|
|||
|
|
@ -1,12 +1,28 @@
|
|||
import BaseItem from "./base-item.mjs";
|
||||
|
||||
const {BooleanField, NumberField, SchemaField, ArrayField, StringField, HTMLField} = foundry.data.fields;
|
||||
const {
|
||||
BooleanField,
|
||||
NumberField,
|
||||
SchemaField,
|
||||
ArrayField,
|
||||
StringField,
|
||||
HTMLField,
|
||||
ObjectField
|
||||
} = foundry.data.fields;
|
||||
|
||||
export class SpecialAbilityDataModel extends BaseItem {
|
||||
|
||||
static defineSchema() {
|
||||
return {
|
||||
name: new StringField()
|
||||
name: new StringField(),
|
||||
seite: new NumberField(),
|
||||
aktionsText: new HTMLField(),
|
||||
text: new HTMLField(),
|
||||
requirements: new ObjectField(), // TODO something more meaningful with this data
|
||||
waffenLimit: new ArrayField(
|
||||
new StringField(),
|
||||
),
|
||||
mehrereAktionen: new BooleanField(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,9 +18,9 @@ export class SpecialAbilitySheet extends HandlebarsApplicationMixin(DocumentShee
|
|||
static TABS = {
|
||||
sheet: {
|
||||
tabs: [
|
||||
{id: 'json', group: 'sheet', label: 'JSON'},
|
||||
{id: 'specialability', group: 'sheet', label: 'Sonderfertigkeit'},
|
||||
],
|
||||
initial: 'json'
|
||||
initial: 'specialability'
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -29,8 +29,8 @@ export class SpecialAbilitySheet extends HandlebarsApplicationMixin(DocumentShee
|
|||
form: {
|
||||
template: `systems/DSA_4-1/templates/item/specialability/main-sheet.hbs`
|
||||
},
|
||||
json: {
|
||||
template: `systems/DSA_4-1/templates/item/specialability/tab-json.hbs`
|
||||
specialability: {
|
||||
template: `systems/DSA_4-1/templates/item/specialability/tab-specialability.hbs`
|
||||
},
|
||||
}
|
||||
|
||||
|
|
@ -55,7 +55,9 @@ export class SpecialAbilitySheet extends HandlebarsApplicationMixin(DocumentShee
|
|||
|
||||
context.system = specialabilityData.system;
|
||||
context.flags = specialabilityData.flags;
|
||||
context.json = JSON.stringify(specialabilityData);
|
||||
context.text = specialabilityData.system.text;
|
||||
context.aktionsText = specialabilityData.system.aktionsText;
|
||||
|
||||
return context;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ import {Blessing} from "../documents/blessing.mjs";
|
|||
import {Profession} from "../documents/profession.mjs";
|
||||
import {Culture} from "../documents/culture.mjs";
|
||||
import {Species} from "../documents/species.mjs";
|
||||
import {SpecialAbility} from "../documents/specialAbility.mjs";
|
||||
|
||||
export class XmlImport {
|
||||
#months = [
|
||||
|
|
@ -273,7 +274,7 @@ export class XmlImport {
|
|||
}
|
||||
}
|
||||
}
|
||||
json.sonderfertigkeiten = specialAbilities
|
||||
this.#mapSpecialAbilities(actor, specialAbilities)
|
||||
json.liturgien = liturgies
|
||||
|
||||
let combatValues = []
|
||||
|
|
@ -510,6 +511,33 @@ export class XmlImport {
|
|||
})
|
||||
}
|
||||
|
||||
async #mapSpecialAbilities(actor, specialAbilities) {
|
||||
if (actor.itemTypes["SpecialAbility"].length > 0) {
|
||||
actor.itemTypes["SpecialAbility"].forEach(s => {
|
||||
actor.items.get(s._id).delete()
|
||||
})
|
||||
}
|
||||
specialAbilities.forEach((specialAbility) => {
|
||||
const compendiumOfSF = game.packs.get('DSA_4-1.sonderfertigkeiten');
|
||||
const sfId = compendiumOfSF?.index.find(sf => sf.name === specialAbility.name)
|
||||
|
||||
if (sfId) {
|
||||
compendiumOfSF.getDocument(sfId._id).then(sf => actor.createEmbeddedDocuments('Item', [sf]))
|
||||
} else {
|
||||
actor.createEmbeddedDocuments('Item', [
|
||||
new SpecialAbility({
|
||||
name: specialAbility.name,
|
||||
type: "SpecialAbility",
|
||||
system: {
|
||||
description: specialAbility.auswahl?.wahl?.join("\n"),
|
||||
}
|
||||
})
|
||||
])
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
async #mapSpezies(actor, spezies) {
|
||||
if (actor.itemTypes["Species"].length > 0) {
|
||||
actor.itemTypes["Species"].forEach(s => {
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@
|
|||
},
|
||||
{
|
||||
"name": "spells",
|
||||
"label": "Basiszauber",
|
||||
"label": "Zauber",
|
||||
"system": "DSA_4-1",
|
||||
"type": "Item",
|
||||
"path": "packs/zauber",
|
||||
|
|
@ -43,15 +43,17 @@
|
|||
},
|
||||
{
|
||||
"name": "liturgien",
|
||||
"label": "Basisliturgien",
|
||||
"label": "Liturgien",
|
||||
"system": "DSA_4-1",
|
||||
"type": "Item"
|
||||
"type": "Item",
|
||||
"path": "packs/liturgien"
|
||||
},
|
||||
{
|
||||
"name": "sonderfertigkeiten",
|
||||
"label": "Basissonderfertigkeiten",
|
||||
"label": "Sonderfertigkeiten",
|
||||
"system": "DSA_4-1",
|
||||
"type": "Item"
|
||||
"type": "Item",
|
||||
"path": "packs/sonderfertigkeiten"
|
||||
},
|
||||
{
|
||||
"name": "Advantage",
|
||||
|
|
|
|||
Loading…
Reference in New Issue