Skip to content

Commit

Permalink
Merge branch 'main' into fix/seals-hbs
Browse files Browse the repository at this point in the history
  • Loading branch information
Julen-BZ committed Nov 10, 2024
2 parents 5ced1fe + 2bb39bf commit 5fecfe5
Show file tree
Hide file tree
Showing 17 changed files with 1,421 additions and 12 deletions.
15 changes: 14 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"name": "anima-beyond-foundry",
"version": "1.19.2",
"version": "1.19.3",
"description": "Unofficial Anima Beyond Fantasy system for Foundry VTT",
"type": "module",
"scripts": {
Expand All @@ -10,8 +10,8 @@
"build:prod": "npm run compendia:pack && npx vite build",
"svelte-check": "npx svelte-check --no-tsconfig --threshold error",
"clean": "rimraf dist/",
"release": "node scripts/release/release.js",
"release:dry": "node scripts/release/release.js --dry",
"release": "node scripts/release/release.cjs",
"release:dry": "node scripts/release/release.cjs --dry",
"test": "NODE_OPTIONS=--experimental-vm-modules npx jest src",
"hook:pre-commit": "lint-staged",
"cypress:open": "cd integration && cypress open",
Expand Down Expand Up @@ -64,7 +64,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",
Expand Down
5 changes: 5 additions & 0 deletions scripts/copyDirectoryToFoundrySystem.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ let destPath;
try {
console.log(chalk.yellow('Trying to use fvtt to get dataPath...'));
dataPath = execSync('fvtt configure get dataPath', { encoding: 'utf8' }).trim();
if (!dataPath || dataPath === 'undefined') {
msg = 'Error: fvtt not configured!';
console.log(chalk.yellow(msg));
throw new Error(msg);
}
destPath = `${dataPath}/Data/systems`;
} catch (e) {
console.log(chalk.yellow('Falling back to foundryconfig.json'));
Expand Down
8 changes: 4 additions & 4 deletions scripts/release/release.js → scripts/release/release.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ const prettier = require('prettier');

const { argv } = require('yargs');

const { log } = require('./utils/log');
const { getFile } = require('./utils/getFile');
const { throwError } = require('./utils/throwError');
const { zip } = require('./utils/zip');
const { log } = require('./utils/log.cjs');
const { getFile } = require('./utils/getFile.cjs');
const { throwError } = require('./utils/throwError.cjs');
const { zip } = require('./utils/zip.cjs');

const { dry } = argv;

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 2 additions & 0 deletions src/animabf.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { registerHelpers } from './utils/handlebars-helpers/registerHelpers';
import ABFItemSheet from './module/items/ABFItemSheet';
import { ABFConfig } from './module/ABFConfig';
import ABFItem from './module/items/ABFItem';
import ABFActorDirectory from './module/SidebarDirectories/ABFActorDirectory';
import { registerCombatWebsocketRoutes } from './module/combat/websocket/registerCombatWebsocketRoutes';
import { attachCustomMacroBar } from './utils/attachCustomMacroBar';
import { applyMigrations } from './module/migration/migrate';
Expand Down Expand Up @@ -36,6 +37,7 @@ Hooks.once('init', async () => {
};

CONFIG.Item.documentClass = ABFItem;
CONFIG.ui.actors = ABFActorDirectory;

// Register custom sheets (if any)
Actors.unregisterSheet('core', ActorSheet);
Expand Down
4 changes: 4 additions & 0 deletions src/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,10 @@
"anima.ui.inventoryItemsSection.name.title": "Object",
"anima.ui.inventoryItemsSection.title": "Inventory",
"anima.ui.inventoryItemsSection.weight.title": "Weight (kg)",
"anima.ui.importDataFromExcelHint1": "You can import data from this {documentType} from an Excel file.",
"anima.ui.importDataFromExcelHint2": "This operation will update the data for {name} and cannot be undone.",
"anima.ui.importDataFromExcelTitle": "Import Data: {name}",
"anima.ui.importDataFromExcelWarning": "Incompatible excel version, please try with one of the following ",
"anima.ui.languageSection.base": "Base",
"anima.ui.languageSection.title": "Languages",
"anima.ui.levelSection.title": "Level",
Expand Down
4 changes: 4 additions & 0 deletions src/lang/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,10 @@
"anima.ui.inventoryItemsSection.name.title": "Objeto",
"anima.ui.inventoryItemsSection.title": "Inventario",
"anima.ui.inventoryItemsSection.weight.title": "Peso (kg)",
"anima.ui.importDataFromExcelHint1": "Puede importar los datos de este {documentType} desde un archivo de Excel.",
"anima.ui.importDataFromExcelHint2": "Esta operación actualizará los datos de {name} y no podrá deshacerse.",
"anima.ui.importDataFromExcelTitle": "Importar Datos: {name}",
"anima.ui.importDataFromExcelWarning": "Versión del Excel no compatible, por favor, intente usar una de las siguientes: ",
"anima.ui.languageSection.base": "Base",
"anima.ui.languageSection.title": "Idiomas",
"anima.ui.levelSection.title": "Categorías",
Expand Down
4 changes: 4 additions & 0 deletions src/lang/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,10 @@
"anima.ui.inventoryItemsSection.name.title": "Objet",
"anima.ui.inventoryItemsSection.title": "Inventaire",
"anima.ui.inventoryItemsSection.weight.title": "Poids (kg)",
"anima.ui.importDataFromExcelHint1": "Vous pouvez importer des données de ce {documentType} à partir d'un fichier Excel.",
"anima.ui.importDataFromExcelHint2": "Cette opération met à jour les données de {name} et ne peut être annulée.",
"anima.ui.importDataFromExcelTitle": "Importer des données: {name}",
"anima.ui.importDataFromExcelWarning": "Version incompatible d'Excel, veuillez essayer avec l'une des versions suivantes: ",
"anima.ui.languageSection.base": "Base",
"anima.ui.languageSection.title": "Langues",
"anima.ui.levelSection.title": "Niveau",
Expand Down
102 changes: 102 additions & 0 deletions src/module/SidebarDirectories/ABFActorDirectory.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import { read, utils } from 'xlsx';
import { parseExcelToActor } from '../actor/utils/parseExcelToActor.js';

export default class ABFActorDirectory extends ActorDirectory {
_getEntryContextOptions() {
let result = super._getEntryContextOptions();
let excelImportEntry = this.getExcelImportContextOption();
result.push(excelImportEntry);
return result;
}

getExcelImportContextOption() {
return {
name: 'Import from Excel',
icon: '<i class="fas fa-file-import"></i>',
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(document);
}
};
}

/**
* Render an import dialog for updating the data related to this Document from an excel file
* @param {import('@module/actor/ABFActor').ABFActor} document
* @returns {Promise<void>}
*/
async importFromExcelDialog(document) {
new Dialog(
{
title: game.i18n.format('anima.ui.importDataFromExcelTitle', {
name: document.name
}),
content: await renderTemplate(
'systems/animabf/templates/dialog/import-data-from-excel.html',
{
hint1: game.i18n.format('anima.ui.importDataFromExcelHint1', {
documentType: document.documentName
}),
hint2: game.i18n.format('anima.ui.importDataFromExcelHint2', {
name: document.name
})
}
),
buttons: {
import: {
icon: '<i class="fas fa-file-import"></i>',
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!');

this.readExcelData(form).then(excelRows =>
parseExcelToActor(excelRows, document)
);
}
},
no: {
icon: '<i class="fas fa-times"></i>',
label: 'Cancel'
}
},
default: 'import'
},
{
width: 400
}
).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['NamedRangesList'];
if (typeof worksheet !== 'undefined') {
const rows = utils.sheet_to_json(worksheet).reduce((acc, obj) => {
acc[obj.Name] = obj.Value;
return acc;
}, {});
resolve(rows);
} else {
reject();
}
};
reader.onerror = ev => {
reader.abort();
reject();
};
reader.readAsArrayBuffer(form.data.files[0]);
});
}
}
1 change: 1 addition & 0 deletions src/module/actor/ABFActor.js
Original file line number Diff line number Diff line change
Expand Up @@ -910,3 +910,4 @@ export class ABFActor extends Actor {
return this.getEmbeddedDocument('Item', itemId);
}
}

Loading

0 comments on commit 5fecfe5

Please sign in to comment.