From b3f11df06a022c54426395fa6e8332c14f2adba8 Mon Sep 17 00:00:00 2001 From: Julen Bordonaba Date: Wed, 7 Aug 2024 14:06:43 +0200 Subject: [PATCH 01/26] wip - custom import --- src/animabf.mjs | 17 +++++++++++++++++ src/module/actor/ABFActor.ts | 29 +++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/src/animabf.mjs b/src/animabf.mjs index f8876e1f..777f945e 100644 --- a/src/animabf.mjs +++ b/src/animabf.mjs @@ -72,6 +72,23 @@ Hooks.once('ready', () => { applyMigrations(); }); +Hooks.on('getActorDirectoryEntryContext', (html, options) => { + // Add a new context menu option + options.push({ + name: "Custom Option", + icon: '', // You can change this to any FontAwesome icon + callback: target => { + let actorId = target.data('document-id'); + let actor = game.actors.get(actorId); + if (actor) { + // Your custom action here + console.log(`Custom option clicked for actor: ${actor.name}`); + ui.notifications.info(`Custom option clicked for actor: ${actor.name}`); + } + } + }); +}); + // Add any additional hooks if necessary // This function allow us to use xRoot in templates to extract the root object in Handlebars template diff --git a/src/module/actor/ABFActor.ts b/src/module/actor/ABFActor.ts index 93b2efcb..6cf08ba2 100644 --- a/src/module/actor/ABFActor.ts +++ b/src/module/actor/ABFActor.ts @@ -921,4 +921,33 @@ export class ABFActor extends Actor { private getItem(itemId: string) { return this.getEmbeddedDocument('Item', itemId); } + +// // Custom export function +// exportToJSON() { +// console.log("Custom Export") + +// const data = this.system; +// // Add your custom export logic here +// const customData = JSON.stringify(data); +// saveDataToFile(customData, 'application/json', `${this.name}.json`); +// } + +// // Custom static import function +// static async importFromJSON(json) { +// console.log("Custom Import") +// const data = JSON.parse(json); +// // Add your custom import logic here +// await Actor.create(data); +// } + } +// // Utility function to save data to file +// function saveDataToFile(data, type, filename) { +// const blob = new Blob([data], { type }); +// const url = URL.createObjectURL(blob); +// const a = document.createElement('a'); +// a.href = url; +// a.download = filename; +// a.click(); +// URL.revokeObjectURL(url); +// } \ No newline at end of file From 3006e1959504af0bec2346cf559d3a0159b2da1b Mon Sep 17 00:00:00 2001 From: Julen Bordonaba Date: Mon, 12 Aug 2024 15:48:31 +0200 Subject: [PATCH 02/26] UPDATED - Actor directory Removed unnecessary comment and log --- src/module/SidebarDirectories/ABFActorDirectory.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/module/SidebarDirectories/ABFActorDirectory.js b/src/module/SidebarDirectories/ABFActorDirectory.js index 7bc05fba..e20618be 100644 --- a/src/module/SidebarDirectories/ABFActorDirectory.js +++ b/src/module/SidebarDirectories/ABFActorDirectory.js @@ -1,7 +1,5 @@ export default class ABFActorDirectory extends ActorDirectory { constructor(...args) { super(...args); - console.log('ABFActorDirectory constructor'); - // Custom initialization code } } \ No newline at end of file From 6f83038fae149e5fc4369b3dadde4ff6dc5c9129 Mon Sep 17 00:00:00 2001 From: Julen Bordonaba Date: Sat, 31 Aug 2024 14:03:34 +0200 Subject: [PATCH 03/26] WIP - Import from excel --- src/animabf.mjs | 17 -- .../SidebarDirectories/ABFActorDirectory.js | 160 ++++++++++++++++++ .../dialog/import-data-from-excel.html | 8 + 3 files changed, 168 insertions(+), 17 deletions(-) create mode 100644 src/templates/dialog/import-data-from-excel.html diff --git a/src/animabf.mjs b/src/animabf.mjs index f933f826..073ce172 100644 --- a/src/animabf.mjs +++ b/src/animabf.mjs @@ -74,23 +74,6 @@ Hooks.once('ready', () => { applyMigrations(); }); -Hooks.on('getActorDirectoryEntryContext', (html, options) => { - // Add a new context menu option - options.push({ - name: "Custom Option", - icon: '', // You can change this to any FontAwesome icon - callback: target => { - let actorId = target.data('document-id'); - let actor = game.actors.get(actorId); - if (actor) { - // Your custom action here - console.log(`Custom option clicked for actor: ${actor.name}`); - ui.notifications.info(`Custom option clicked for actor: ${actor.name}`); - } - } - }); -}); - // Add any additional hooks if necessary // This function allow us to use xRoot in templates to extract the root object in Handlebars template diff --git a/src/module/SidebarDirectories/ABFActorDirectory.js b/src/module/SidebarDirectories/ABFActorDirectory.js index e20618be..6a00e238 100644 --- a/src/module/SidebarDirectories/ABFActorDirectory.js +++ b/src/module/SidebarDirectories/ABFActorDirectory.js @@ -1,5 +1,165 @@ +//import { read, utils } from './../external_modules/xlsx-0.20.3/package/xlsx.mjs'; +//import * as XLSX from 'xlsx'; + export default class ABFActorDirectory extends ActorDirectory { constructor(...args) { super(...args); } + + _getEntryContextOptions(){ + let result = super._getEntryContextOptions(); + let excelImportEntry = this.getExcelImportContextOption(); + result.push(excelImportEntry); + console.log("ABFActorDirectory _getEntryContextOptions"); + console.log(result); + return result; + } + + getExcelImportContextOption() { + return { + name: 'Excel Import', + icon: '', + condition: header => { + const li = header.closest(".directory-item"); + const document = this.collection.get(li.data("documentId")); + return document.isOwner; + }, + callback: header => { + const li = header.closest(".directory-item"); + const document = this.collection.get(li.data("documentId")); + return this.importFromExcelDialog(); + } + }; + } + + /** + * Render an import dialog for updating the data related to this Document through an exported JSON file + * @returns {Promise} + * @memberof ClientDocumentMixin# + */ + async importFromExcelDialog() { + new Dialog({ + title: `Import Data: ${this.name}`, + content: await renderTemplate("systems/animabf/templates/dialog/import-data-from-excel.html", { + hint1: game.i18n.format("DOCUMENT.ImportDataHint1", {document: this.documentName}), + hint2: game.i18n.format("DOCUMENT.ImportDataHint2", {name: this.name}) + }), + buttons: { + import: { + icon: '', + label: "Import", + callback: html => { + const form = html.find("form")[0]; + if ( !form.data.files.length ) return ui.notifications.error("You did not upload a data file!"); + + console.log(form.data.files[0]); + + const reader = new FileReader(); + reader.onload = function (e) { + //var XLSX = require("xlsx"); + const data = new Uint8Array(e.target.result); + const workbook = read(data, { type: 'array' }); + console.log(workbook); + const sheetName = workbook.SheetNames[0]; + console.log(sheetName); + const worksheet = workbook.Sheets[sheetName]; + console.log(worksheet); + const json = utils.sheet_to_json(worksheet); + console.log(json); + }; + reader.readAsArrayBuffer(form.data.files[0]); + + //this.readSpreadsheet(); + //readTextFromFile(form.data.files[0]).then(excel => this.importFromExcel(excel)); + } + }, + no: { + icon: '', + label: "Cancel" + } + }, + default: "import" + }, { + width: 400 + }).render(true); + } + + + +// // Function to read an Excel spreadsheet using SheetJS +// readSpreadsheet(file) { +// const reader = new FileReader(); + +// reader.onload = function (e) { +// const data = new Uint8Array(e.target.result); +// const workbook = XLSX.read(data, { type: "array" }); + +// // Assuming you want to work with the first sheet +// const sheetName = workbook.SheetNames[0]; +// const worksheet = workbook.Sheets[sheetName]; + +// // Convert the sheet to JSON +// const jsonData = XLSX.utils.sheet_to_json(worksheet); + +// // Log the data to the console for now +// console.log(jsonData); + +// // Optionally: Handle the imported data, e.g., creating actors/items in Foundry +// this.handleImportedData(jsonData); +// }; + +// reader.readAsArrayBuffer(file); +// } + +// // Example function to handle imported data +// handleImportedData(data) { +// // Example: Loop through the data and create actors/items +// data.forEach(item => { +// console.log(`Importing: ${item.Name}`); // Adjust as per your sheet's structure + +// // Example of creating a new item in Foundry +// const newItemData = { +// name: item.Name, // Replace with actual column names from your Excel sheet +// type: "weapon", // or whatever type you are importing +// data: { +// damage: item.Damage, +// range: item.Range, +// // Add more fields as needed +// } +// }; + +// // Create the item in the Foundry system +// Item.create(newItemData, { temporary: false }); +// }); +// } + + + + /** + * Update this Document using a provided JSON string. + * @this {ClientDocument} + * @param {string} json Raw JSON data to import + * @returns {Promise} The updated Document instance + */ + async importFromExcel(json) { + if ( !CONFIG[this.documentName]?.collection ) throw new Error("Only primary Documents may be imported from JSON"); + + // Construct a document class to (strictly) clean and validate the source data + const doc = new this.constructor(JSON.parse(json), {strict: true}); + + // Treat JSON import using the same workflows that are used when importing from a compendium pack + const data = this.collection.fromCompendium(doc, {addFlags: false}); + + // Preserve certain fields from the destination document + const preserve = Object.fromEntries(this.constructor.metadata.preserveOnImport.map(k => { + return [k, foundry.utils.getProperty(this, k)]; + })); + preserve.folder = this.folder?.id; + foundry.utils.mergeObject(data, preserve); + + // Commit the import as an update to this document + await this.update(data, {diff: false, recursive: false, noHook: true}); + ui.notifications.info(game.i18n.format("DOCUMENT.Imported", {document: this.documentName, name: this.name})); + return this; + } } \ No newline at end of file diff --git a/src/templates/dialog/import-data-from-excel.html b/src/templates/dialog/import-data-from-excel.html new file mode 100644 index 00000000..958d2596 --- /dev/null +++ b/src/templates/dialog/import-data-from-excel.html @@ -0,0 +1,8 @@ +
+

{{hint1}}

+

{{hint2}}

+
+ + +
+
\ No newline at end of file From ab526cf58e1b32b19d36f6ea42ab2a419f3da892 Mon Sep 17 00:00:00 2001 From: Julen Bordonaba Date: Sat, 31 Aug 2024 21:05:07 +0200 Subject: [PATCH 04/26] ADD - Read excel data --- package-lock.json | 15 +- package.json | 5 +- .../SidebarDirectories/ABFActorDirectory.js | 131 +++++------------- src/module/actor/ABFActor.ts | 31 +---- src/module/actor/utils/parseExcelToActor.js | 26 ++++ 5 files changed, 79 insertions(+), 129 deletions(-) create mode 100644 src/module/actor/utils/parseExcelToActor.js diff --git a/package-lock.json b/package-lock.json index 706ea43a..0ee1e8e2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,7 +8,8 @@ "name": "anima-beyond-foundry", "version": "1.18.1", "dependencies": { - "jquery": "^3.6.0" + "jquery": "^3.6.0", + "xlsx": "https://cdn.sheetjs.com/xlsx-0.20.3/xlsx-0.20.3.tgz" }, "devDependencies": { "@digitak/tsc-esm": "^3.1.4", @@ -14194,6 +14195,18 @@ } } }, + "node_modules/xlsx": { + "version": "0.20.3", + "resolved": "https://cdn.sheetjs.com/xlsx-0.20.3/xlsx-0.20.3.tgz", + "integrity": "sha512-oLDq3jw7AcLqKWH2AhCpVTZl8mf6X2YReP+Neh0SJUzV/BdZYjth94tG5toiMB1PPrYtxOCfaoUCkvtuH+3AJA==", + "license": "Apache-2.0", + "bin": { + "xlsx": "bin/xlsx.njs" + }, + "engines": { + "node": ">=0.8" + } + }, "node_modules/xml-name-validator": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/xml-name-validator/-/xml-name-validator-3.0.0.tgz", diff --git a/package.json b/package.json index 5a79de10..ff3c4bbc 100644 --- a/package.json +++ b/package.json @@ -24,9 +24,9 @@ "license": "", "devDependencies": { "@digitak/tsc-esm": "^3.1.4", + "@foundryvtt/foundryvtt-cli": "^1.0.3", "@sveltejs/vite-plugin-svelte": "^2.5.3", "@tinymce/tinymce-svelte": "^2.0.1", - "@foundryvtt/foundryvtt-cli": "^1.0.3", "@types/faker": "^5.5.6", "@types/handlebars": "^4.1.0", "@types/jest": "^26.0.23", @@ -62,7 +62,8 @@ "yargs": "^16.2.0" }, "dependencies": { - "jquery": "^3.6.0" + "jquery": "^3.6.0", + "xlsx": "https://cdn.sheetjs.com/xlsx-0.20.3/xlsx-0.20.3.tgz" }, "lint-staged": { "src/**/*.ts": "eslint --fix --cache", diff --git a/src/module/SidebarDirectories/ABFActorDirectory.js b/src/module/SidebarDirectories/ABFActorDirectory.js index 6a00e238..62d39d05 100644 --- a/src/module/SidebarDirectories/ABFActorDirectory.js +++ b/src/module/SidebarDirectories/ABFActorDirectory.js @@ -1,5 +1,7 @@ //import { read, utils } from './../external_modules/xlsx-0.20.3/package/xlsx.mjs'; -//import * as XLSX from 'xlsx'; +import { read, utils } from 'xlsx'; +import { INITIAL_ACTOR_DATA } from '../actor/constants'; +import { parseExcelToActor } from '../actor/utils/parseExcelToActor.js'; export default class ABFActorDirectory extends ActorDirectory { constructor(...args) { @@ -17,7 +19,7 @@ export default class ABFActorDirectory extends ActorDirectory { getExcelImportContextOption() { return { - name: 'Excel Import', + name: 'Import from Excel', icon: '', condition: header => { const li = header.closest(".directory-item"); @@ -27,7 +29,7 @@ export default class ABFActorDirectory extends ActorDirectory { callback: header => { const li = header.closest(".directory-item"); const document = this.collection.get(li.data("documentId")); - return this.importFromExcelDialog(); + return this.importFromExcelDialog(document); } }; } @@ -37,7 +39,8 @@ export default class ABFActorDirectory extends ActorDirectory { * @returns {Promise} * @memberof ClientDocumentMixin# */ - async importFromExcelDialog() { + async importFromExcelDialog(document) { + console.log(document); new Dialog({ title: `Import Data: ${this.name}`, content: await renderTemplate("systems/animabf/templates/dialog/import-data-from-excel.html", { @@ -54,23 +57,8 @@ export default class ABFActorDirectory extends ActorDirectory { console.log(form.data.files[0]); - const reader = new FileReader(); - reader.onload = function (e) { - //var XLSX = require("xlsx"); - const data = new Uint8Array(e.target.result); - const workbook = read(data, { type: 'array' }); - console.log(workbook); - const sheetName = workbook.SheetNames[0]; - console.log(sheetName); - const worksheet = workbook.Sheets[sheetName]; - console.log(worksheet); - const json = utils.sheet_to_json(worksheet); - console.log(json); - }; - reader.readAsArrayBuffer(form.data.files[0]); - - //this.readSpreadsheet(); - //readTextFromFile(form.data.files[0]).then(excel => this.importFromExcel(excel)); + this.readExcelData(form).then(excelRows => parseExcelToActor(excelRows, document)); + ; } }, no: { @@ -84,82 +72,31 @@ export default class ABFActorDirectory extends ActorDirectory { }).render(true); } + readExcelData(form) { + const reader = new FileReader(); + return new Promise((resolve, reject) => { + reader.onload = function (e) { + const data = new Uint8Array(e.target.result); + const workbook = read(data, { type: 'array' }); + const worksheet = workbook.Sheets["FoundryData"]; + if (typeof worksheet !== "undefined") { + const rows = utils.sheet_to_json(worksheet).reduce((acc, obj) => { + acc[obj.ID] = obj.Value; + return acc; + }, {}); + resolve(rows); + } + else{ + reject(); + } + }; + reader.onerror = ev => { + reader.abort(); + reject(); + }; + reader.readAsArrayBuffer(form.data.files[0]); + }); + } -// // Function to read an Excel spreadsheet using SheetJS -// readSpreadsheet(file) { -// const reader = new FileReader(); - -// reader.onload = function (e) { -// const data = new Uint8Array(e.target.result); -// const workbook = XLSX.read(data, { type: "array" }); - -// // Assuming you want to work with the first sheet -// const sheetName = workbook.SheetNames[0]; -// const worksheet = workbook.Sheets[sheetName]; - -// // Convert the sheet to JSON -// const jsonData = XLSX.utils.sheet_to_json(worksheet); - -// // Log the data to the console for now -// console.log(jsonData); - -// // Optionally: Handle the imported data, e.g., creating actors/items in Foundry -// this.handleImportedData(jsonData); -// }; - -// reader.readAsArrayBuffer(file); -// } - -// // Example function to handle imported data -// handleImportedData(data) { -// // Example: Loop through the data and create actors/items -// data.forEach(item => { -// console.log(`Importing: ${item.Name}`); // Adjust as per your sheet's structure - -// // Example of creating a new item in Foundry -// const newItemData = { -// name: item.Name, // Replace with actual column names from your Excel sheet -// type: "weapon", // or whatever type you are importing -// data: { -// damage: item.Damage, -// range: item.Range, -// // Add more fields as needed -// } -// }; - -// // Create the item in the Foundry system -// Item.create(newItemData, { temporary: false }); -// }); -// } - - - - /** - * Update this Document using a provided JSON string. - * @this {ClientDocument} - * @param {string} json Raw JSON data to import - * @returns {Promise} The updated Document instance - */ - async importFromExcel(json) { - if ( !CONFIG[this.documentName]?.collection ) throw new Error("Only primary Documents may be imported from JSON"); - - // Construct a document class to (strictly) clean and validate the source data - const doc = new this.constructor(JSON.parse(json), {strict: true}); - - // Treat JSON import using the same workflows that are used when importing from a compendium pack - const data = this.collection.fromCompendium(doc, {addFlags: false}); - - // Preserve certain fields from the destination document - const preserve = Object.fromEntries(this.constructor.metadata.preserveOnImport.map(k => { - return [k, foundry.utils.getProperty(this, k)]; - })); - preserve.folder = this.folder?.id; - foundry.utils.mergeObject(data, preserve); - - // Commit the import as an update to this document - await this.update(data, {diff: false, recursive: false, noHook: true}); - ui.notifications.info(game.i18n.format("DOCUMENT.Imported", {document: this.documentName, name: this.name})); - return this; - } } \ No newline at end of file diff --git a/src/module/actor/ABFActor.ts b/src/module/actor/ABFActor.ts index 6cf08ba2..aa8b3d80 100644 --- a/src/module/actor/ABFActor.ts +++ b/src/module/actor/ABFActor.ts @@ -51,6 +51,7 @@ export class ABFActor extends Actor { await prepareActor(this); } + /** * Updates the value of the 'fatigue' secondary characteristic of an ABFActor object. * @@ -921,33 +922,5 @@ export class ABFActor extends Actor { private getItem(itemId: string) { return this.getEmbeddedDocument('Item', itemId); } - -// // Custom export function -// exportToJSON() { -// console.log("Custom Export") - -// const data = this.system; -// // Add your custom export logic here -// const customData = JSON.stringify(data); -// saveDataToFile(customData, 'application/json', `${this.name}.json`); -// } - -// // Custom static import function -// static async importFromJSON(json) { -// console.log("Custom Import") -// const data = JSON.parse(json); -// // Add your custom import logic here -// await Actor.create(data); -// } -} -// // Utility function to save data to file -// function saveDataToFile(data, type, filename) { -// const blob = new Blob([data], { type }); -// const url = URL.createObjectURL(blob); -// const a = document.createElement('a'); -// a.href = url; -// a.download = filename; -// a.click(); -// URL.revokeObjectURL(url); -// } \ No newline at end of file +} \ No newline at end of file diff --git a/src/module/actor/utils/parseExcelToActor.js b/src/module/actor/utils/parseExcelToActor.js new file mode 100644 index 00000000..105c26e5 --- /dev/null +++ b/src/module/actor/utils/parseExcelToActor.js @@ -0,0 +1,26 @@ +import { ABFActor } from "../ABFActor"; + + /** + * Parses excel data to actor data + * + * @param {any} excelData - provided exel data + * @param {ABFActor} actor - provided Actor to update + */ + export const parseExcelToActor = (excelData, actor) => { + console.log(actor); + actor.update({ + name: excelData.name, + system: { + characteristics: { + secondaries: { + lifePoints: { + value: excelData.health_current, + max: excelData.health_max + } + } + } + } + }); + } + + From 8afbbb7c7a80ac9a051714156edca7ca86417e8c Mon Sep 17 00:00:00 2001 From: Julen Bordonaba Date: Tue, 3 Sep 2024 17:39:09 +0200 Subject: [PATCH 05/26] WIP - Import from excel MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A la espera de concretar con Guote una versión definitiva del excel. --- .../SidebarDirectories/ABFActorDirectory.js | 12 +- src/module/actor/utils/parseExcelToActor.js | 600 +++++++++++++++++- 2 files changed, 598 insertions(+), 14 deletions(-) diff --git a/src/module/SidebarDirectories/ABFActorDirectory.js b/src/module/SidebarDirectories/ABFActorDirectory.js index 62d39d05..73386aa1 100644 --- a/src/module/SidebarDirectories/ABFActorDirectory.js +++ b/src/module/SidebarDirectories/ABFActorDirectory.js @@ -12,8 +12,6 @@ export default class ABFActorDirectory extends ActorDirectory { let result = super._getEntryContextOptions(); let excelImportEntry = this.getExcelImportContextOption(); result.push(excelImportEntry); - console.log("ABFActorDirectory _getEntryContextOptions"); - console.log(result); return result; } @@ -42,10 +40,10 @@ export default class ABFActorDirectory extends ActorDirectory { async importFromExcelDialog(document) { console.log(document); new Dialog({ - title: `Import Data: ${this.name}`, + title: `Import Data: ${document.name}`, content: await renderTemplate("systems/animabf/templates/dialog/import-data-from-excel.html", { - hint1: game.i18n.format("DOCUMENT.ImportDataHint1", {document: this.documentName}), - hint2: game.i18n.format("DOCUMENT.ImportDataHint2", {name: this.name}) + hint1: "Puede importar los datos de este " + document.documentName + " desde un archivo Excel", + hint2: game.i18n.format("DOCUMENT.ImportDataHint2", {name: document.name}) }), buttons: { import: { @@ -78,10 +76,10 @@ export default class ABFActorDirectory extends ActorDirectory { reader.onload = function (e) { const data = new Uint8Array(e.target.result); const workbook = read(data, { type: 'array' }); - const worksheet = workbook.Sheets["FoundryData"]; + const worksheet = workbook.Sheets["NamedRangesList"]; if (typeof worksheet !== "undefined") { const rows = utils.sheet_to_json(worksheet).reduce((acc, obj) => { - acc[obj.ID] = obj.Value; + acc[obj.Name] = obj.Value; return acc; }, {}); resolve(rows); diff --git a/src/module/actor/utils/parseExcelToActor.js b/src/module/actor/utils/parseExcelToActor.js index 105c26e5..6f7475d6 100644 --- a/src/module/actor/utils/parseExcelToActor.js +++ b/src/module/actor/utils/parseExcelToActor.js @@ -1,4 +1,7 @@ -import { ABFActor } from "../ABFActor"; +import { ABFActor } from '../ABFActor'; +import { ABFItems } from '../../items/ABFItems'; +import { calculateRegenerationTypeFromConstitution } from './prepareActor/calculations/actor/general/calculations/calculateRegenerationTypeFromConstitution'; +import { calculateAttributeModifier } from './prepareActor/calculations/util/calculateAttributeModifier'; /** * Parses excel data to actor data @@ -6,21 +9,604 @@ import { ABFActor } from "../ABFActor"; * @param {any} excelData - provided exel data * @param {ABFActor} actor - provided Actor to update */ - export const parseExcelToActor = (excelData, actor) => { + export const parseExcelToActor = async (excelData, actor) => { console.log(actor); - actor.update({ - name: excelData.name, + + const movementModifier = excelData.TipodeMovimiento - excelData.AGI; + const regenerationModifier = excelData.Regeneración_final - calculateRegenerationTypeFromConstitution(excelData.CON); + const extraDamage = (excelData.DañoIncrementado ? 10 : 0) + (excelData.Extensióndelauraalarma ? 10 : 0); + const conResistance = excelData.Presencia_final + calculateAttributeModifier(excelData.CON); + const podResistance = excelData.Presencia_final + calculateAttributeModifier(excelData.POD); + const volResistance = excelData.Presencia_final + calculateAttributeModifier(excelData.VOL); + + //Esto es para cuando esté la automatización de las resistencias + const bonoRF = excelData.RF_final-conResistance; + const bonoRE = excelData.RE_final-conResistance; + const bonoRV = excelData.RV_final-conResistance; + const bonoRM = excelData.RM_final-podResistance; + const bonoRP = excelData.RP_final-volResistance; + + + console.log(excelData); + + await actor.update({ + name: excelData.Nombre, + prototypeToken: { + name: excelData.Nombre + }, system: { characteristics: { + primaries: { + agility: { + value: excelData.AGI + }, + constitution: { + value: excelData.CON + }, + dexterity: { + value: excelData.DES + }, + strength: { + value: excelData.FUE + }, + intelligence: { + value: excelData.INT + }, + power: { + value: excelData.POD + }, + perception: { + value: excelData.PER + }, + willPower: { + value: excelData.VOL + } + }, secondaries: { + fatigue: { + value: excelData.Cansancio, + max: excelData.Cansancio + }, + initiative: { + base: { + value: excelData.Turno_Nat_final + } + }, lifePoints: { - value: excelData.health_current, - max: excelData.health_max - } + value: excelData.Vida_final, + max: excelData.Vida_final + }, + movementType: { + mod: { + value: movementModifier + } + }, + regenerationType: { + mod: { + value: regenerationModifier + } + }, + resistances: { + physical: { + base: { + value: excelData.RF_final + } + }, + disease: { + base: { + value: excelData.RE_final + } + }, + poison: { + base: { + value: excelData.RV_final + } + }, + magic: { + base: { + value: excelData.RM_final + } + }, + psychic: { + base: { + value: excelData.RP_final + } + } + } + } + }, + combat: { + attack: { + base: { + value: excelData.HA_final + } + }, + block: { + base: { + value: excelData.HD_final + } + }, + dodge: { + base: { + value: excelData.HE_final + } + }, + wearArmor: { + value: excelData.LlevarArmadura_final + } + }, + general: { + presence: { + base: { + value: excelData.Presencia_final + } + }, + modifiers: { + extraDamage: { + value: extraDamage + } + }, + settings: { + inhuman: { + value: excelData.Inhumanidad + }, + zen: { + value: excelData.Zen + } + } + }, + mystic: { + act: { + main: { + base: { + value: excelData.ACT_final + } + } + }, + magicProjection: { + imbalance: { + defensive: { + base: { + value: excelData.ProyecciónMágicaDefensiva_final + } + }, + offensive: { + base: { + value: excelData.ProyecciónMágicaOfensiva_final + } + } + } + }, + summoning: { + summon: { + base: { + value: excelData.Convocar_final + } + }, + control: { + base: { + value: excelData.Controlar_final + } + }, + bind: { + base: { + value: excelData.Atar_final + } + }, + banish: { + base: { + value: excelData.Desconvocar_final + } + } + }, + zeon: { + value: excelData.Zeón_final, + max: excelData.Zeón_final + }, + zeonRegeneration: { + base: { + value: excelData.RegZeon_final + } + } + }, + psychic: { + psychicPotential: { + base: { + value: excelData.PotencialPsi_final + } + }, + psychicProjection: { + base: { + value: excelData.Proyecciónpsíquica_final + }, + imbalance: { + offensive: { + base: { + value: excelData.Proyecciónpsíquica_final + } + }, + defensive: { + base: { + value: excelData.Proyecciónpsíquica_final + } + } + } + }, + psychicPoints: { + value: excelData.CVLibres_actual, + max: excelData.CVLibres_final + }, + innatePsychicPower: { + amount: { + value: excelData.Innatos_Psi + } + } + }, + secondaries: { + athletics: { + acrobatics: { + base: { + value: excelData.Acrobacias_final + } + }, + athleticism: { + base: { + value: excelData.Atletismo_final + } + }, + ride: { + base: { + value: excelData.Montar_final + } + }, + swim: { + base: { + value: excelData.Nadar_final + } + }, + climb: { + base: { + value: excelData.Trepar_final + } + }, + jump: { + base: { + value: excelData.Saltar_final + } + }, + piloting: { + base: { + value: excelData.Pilotar_final + } + } + }, + vigor: { + composure: { + base: { + value: excelData.Frialdad_final + } + }, + featsOfStrength: { + base: { + value: excelData["P.Fuerza_final"] + } + }, + withstandPain: { + base: { + value: excelData["Res.Dolor_final"] + } + } + }, + perception: { + notice: { + base: { + value: excelData.Advertir_final + } + }, + search: { + base: { + value: excelData.Buscar_final + } + }, + track: { + base: { + value: excelData.Rastrear_final + } + } + }, + intellectual: { + animals: { + base: { + value: excelData.Animales_final + } + }, + science: { + base: { + value: excelData.Ciencia_final + } + }, + law: { + base: { + value: excelData.Ley_final + } + }, + herbalLore: { + base: { + value: excelData.Herbolaria_final + } + }, + history: { + base: { + value: excelData.Historia_final + } + }, + tactics: { + base: { + value: excelData.Tactica_final + } + }, + medicine: { + base: { + value: excelData.Medicina_final + } + }, + memorize: { + base: { + value: excelData.Memorizar_final + } + }, + navigation: { + base: { + value: excelData.Navegación_final + } + }, + occult: { + base: { + value: excelData.Ocultismo_final + } + }, + appraisal: { + base: { + value: excelData.Tasación_final + } + }, + magicAppraisal: { + base: { + value: excelData["V.Mágica_final"] + } + } + }, + social: { + style: { + base: { + value: excelData.Estilo_final + } + }, + intimidate: { + base: { + value: excelData.Intimidar_final + } + }, + leadership: { + base: { + value: excelData.Liderazgo_final + } + }, + persuasion: { + base: { + value: excelData.Persuasión_final + } + }, + trading: { + base: { + value: excelData.Comercio_final + } + }, + streetwise: { + base: { + value: excelData.Callejeo_final + } + }, + etiquette: { + base: { + value: excelData.Etiqueta_final + } + } + }, + subterfuge: { + lockPicking: { + base: { + value: excelData.Cerrajería_final + } + }, + disguise: { + base: { + value: excelData.Disfraz_final + } + }, + hide: { + base: { + value: excelData.Ocultarse_final + } + }, + theft: { + base: { + value: excelData.Robo_final + } + }, + stealth: { + base: { + value: excelData.Sigilo_final + } + }, + trapLore: { + base: { + value: excelData.Trampería_final + } + }, + poisons: { + base: { + value: excelData.Venenos_final + } + } + }, + creative: { + art: { + base: { + value: excelData.Arte_final + } + }, + dance: { + base: { + value: excelData.Baile_final + } + }, + forging: { + base: { + value: excelData.Forja_final + } + }, + runes: { + base: { + value: excelData.Runas_final + } + }, + alchemy: { + base: { + value: excelData.Alquimia_final + } + }, + animism: { + base: { + value: excelData.Animismo_final + } + }, + music: { + base: { + value: excelData.Música_final + } + }, + sleightOfHand: { + base: { + value: excelData["T.Manos_final"] + } + }, + ritualCalligraphy: { + base: { + value: excelData.Caligrafíaritual_final + } + }, + jewelry: { + base: { + value: excelData.Orfebrería_final + } + }, + tailoring: { + base: { + value: excelData.Confección_final + } + }, + puppetMaking: { + base: { + value: excelData["Conf.marionetas_final"] + } + } } + }, + domine: { + martialKnowledge: { + used: { + value: excelData.CM_usado + }, + max: { + value: excelData.CM_final + } + }, + kiAccumulation: { + strength: { + base: { + value: excelData.KiAccumulationFUE_final + } + }, + agility: { + base: { + value: excelData.KiAccumulationAGI_final + } + }, + dexterity: { + base: { + value: excelData.KiAccumulationDES_final + } + }, + constitution: { + base: { + value: excelData.KiAccumulationCON_final + } + }, + willPower: { + base: { + value: excelData.KiAccumulationVOL_final + } + }, + power: { + base: { + value: excelData.KiAccumulationPOD_final + } + }, + generic: { + value: excelData.Ki_final, + max: excelData.Ki_final + } + }, + kiSkills: [], + nemesisSkills: [] } } }); + + const habilidades = separarHabilidadesKi(excelData.HabilidadesKiNemesis); + console.log(habilidades[0]); + console.log(habilidades[1]); + const habilidadesKi = habilidades[0].split(',').map(value => value.trim()).filter(element => element !== ''); + const habilidadesNem = habilidades[1].split(',').map(value => value.trim()).filter(element => element !== ''); + console.log(habilidadesKi); + console.log(habilidadesNem); + for (var i = 0; i < habilidadesKi.length; i++) { + let abilityName = habilidadesKi[i]; + if(abilityName.indexOf("Detección del Ki") !== -1) + { + abilityName = splitAndRemoveLast(habilidadesKi[i]); + } + await actor.createInnerItem({ + name: abilityName, + type: ABFItems.KI_SKILL + }); + }; + for (var i = 0; i < habilidadesNem.length; i++) { + await actor.createInnerItem({ + name: habilidadesNem[i], + type: ABFItems.NEMESIS_SKILL + }); + }; } + function separarHabilidadesKi(habilidades) { + const índice = habilidades.indexOf("Uso del Némesis"); + + if (índice === -1) { + return [habilidades, ""]; + } + + const habilidadesKi = habilidades.slice(0, índice).trim(); + const habilidadesNem = habilidades.slice(índice).trim(); + + return [habilidadesKi, habilidadesNem]; +} + +function splitAndRemoveLast(cadena) { + const partes = cadena.split(' '); + partes.pop(); + return partes.join(' ').trim(); +} + From eaf02793ad3a43841f8302de00e15bf154b18c3f Mon Sep 17 00:00:00 2001 From: Julen_BZ Date: Wed, 16 Oct 2024 10:39:18 +0200 Subject: [PATCH 06/26] FIX - Merge error --- src/svelte/ui/item.svelte | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/svelte/ui/item.svelte b/src/svelte/ui/item.svelte index 6044451d..3395e1bd 100644 --- a/src/svelte/ui/item.svelte +++ b/src/svelte/ui/item.svelte @@ -1,6 +1,6 @@