Add dev tools

2.0
Matheus Clemente 2023-11-09 14:14:29 -03:00
parent 0c2add7454
commit 6fb2a40216
26 changed files with 12372 additions and 155 deletions

13
.editorconfig 100644
View File

@ -0,0 +1,13 @@
# SPDX-FileCopyrightText: 2022 Johannes Loher
#
# SPDX-License-Identifier: MIT
root = true
[*]
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 2
charset = utf-8
trim_trailing_whitespace = true

5
.eslintignore 100644
View File

@ -0,0 +1,5 @@
# SPDX-FileCopyrightText: 2022 Johannes Loher
#
# SPDX-License-Identifier: MIT
dist

181
.eslintrc.cjs 100644
View File

@ -0,0 +1,181 @@
// SPDX-FileCopyrightText: 2022 Johannes Loher
// SPDX-FileCopyrightText: 2022 David Archibald
//
// SPDX-License-Identifier: MIT
module.exports = {
parserOptions: {
ecmaVersion: 13,
extraFileExtensions: [".cjs", ".mjs"],
sourceType: "module",
},
env: {
browser: true,
es6: true,
jquery: true,
},
extends: ["eslint:recommended", "@typhonjs-fvtt/eslint-config-foundry.js/0.8.0"],
plugins: [],
rules: {
"array-bracket-spacing": ["warn", "never"],
"array-callback-return": "warn",
"arrow-spacing": "warn",
"comma-dangle": ["warn", "only-multiline"],
"comma-style": "warn",
"computed-property-spacing": "warn",
"constructor-super": "error",
"default-param-last": "warn",
"dot-location": ["warn", "property"],
"eol-last": ["error", "always"],
eqeqeq: ["warn", "smart"],
"func-call-spacing": "warn",
"func-names": ["warn", "never"],
"getter-return": "warn",
"lines-between-class-members": "warn",
"new-parens": ["warn", "always"],
"no-alert": "warn",
"no-array-constructor": "warn",
"no-class-assign": "warn",
"no-compare-neg-zero": "warn",
"no-cond-assign": "warn",
"no-const-assign": "error",
"no-constant-condition": "warn",
"no-constructor-return": "warn",
"no-delete-var": "warn",
"no-dupe-args": "warn",
"no-dupe-class-members": "warn",
"no-dupe-keys": "warn",
"no-duplicate-case": "warn",
"no-duplicate-imports": ["warn", { includeExports: true }],
"no-empty": ["warn", { allowEmptyCatch: true }],
"no-empty-character-class": "warn",
"no-empty-pattern": "warn",
"no-func-assign": "warn",
"no-global-assign": "warn",
"no-implicit-coercion": ["warn", { allow: ["!!"] }],
"no-implied-eval": "warn",
"no-import-assign": "warn",
"no-invalid-regexp": "warn",
"no-irregular-whitespace": "warn",
"no-iterator": "warn",
"no-lone-blocks": "warn",
"no-lonely-if": "warn",
"no-misleading-character-class": "warn",
"no-mixed-operators": "warn",
"no-multi-str": "warn",
"no-multiple-empty-lines": ["warn", { max: 1 }],
"no-new-func": "warn",
"no-new-object": "warn",
"no-new-symbol": "warn",
"no-new-wrappers": "warn",
"no-nonoctal-decimal-escape": "warn",
"no-obj-calls": "warn",
"no-octal": "warn",
"no-octal-escape": "warn",
"no-promise-executor-return": "warn",
"no-proto": "warn",
"no-regex-spaces": "warn",
"no-script-url": "warn",
"no-self-assign": "warn",
"no-self-compare": "warn",
"no-setter-return": "warn",
"no-sequences": "warn",
"no-template-curly-in-string": "warn",
"no-this-before-super": "error",
"no-unexpected-multiline": "warn",
"no-unmodified-loop-condition": "warn",
"no-unneeded-ternary": "warn",
"no-unreachable": "warn",
"no-unreachable-loop": "warn",
"no-unsafe-negation": ["warn", { enforceForOrderingRelations: true }],
"no-unsafe-optional-chaining": ["warn", { disallowArithmeticOperators: true }],
"no-unused-expressions": "warn",
"no-useless-backreference": "warn",
"no-useless-call": "warn",
"no-useless-catch": "warn",
"no-useless-computed-key": ["warn", { enforceForClassMembers: true }],
"no-useless-concat": "warn",
"no-useless-constructor": "warn",
"no-useless-rename": "warn",
"no-useless-return": "warn",
"no-var": "warn",
"no-void": "warn",
"no-whitespace-before-property": "warn",
"prefer-numeric-literals": "warn",
"prefer-object-spread": "warn",
"prefer-regex-literals": "warn",
"prefer-spread": "warn",
"rest-spread-spacing": ["warn", "never"],
"semi-spacing": "warn",
"semi-style": ["warn", "last"],
"space-unary-ops": ["warn", { words: true, nonwords: false }],
"switch-colon-spacing": "warn",
"symbol-description": "warn",
"template-curly-spacing": ["warn", "never"],
"unicode-bom": ["warn", "never"],
"use-isnan": ["warn", { enforceForSwitchCase: true, enforceForIndexOf: true }],
"valid-typeof": ["warn", { requireStringLiterals: true }],
"wrap-iife": ["warn", "inside"],
"arrow-parens": ["warn", "always"],
"comma-spacing": "warn",
"dot-notation": "warn",
"key-spacing": "warn",
"keyword-spacing": ["warn", { overrides: { catch: { before: true, after: false } } }],
"max-len": [
"warn",
{
code: 120,
ignoreComments: true,
ignoreTrailingComments: true,
ignoreUrls: true,
ignoreStrings: true,
ignoreTemplateLiterals: true,
ignoreRegExpLiterals: true,
},
],
"no-extra-boolean-cast": ["warn", { enforceForLogicalOperands: true }],
"no-extra-semi": "warn",
"no-multi-spaces": ["warn", { ignoreEOLComments: true }],
"no-throw-literal": "error",
"no-trailing-spaces": "warn",
"no-useless-escape": "warn",
"no-unused-vars": ["warn", { args: "none" }],
"nonblock-statement-body-position": ["warn", "beside"],
"one-var": ["warn", "never"],
"operator-linebreak": [
"warn",
"before",
{
overrides: { "=": "after", "+=": "after", "-=": "after" },
},
],
"prefer-template": "warn",
"quote-props": ["warn", "as-needed", { keywords: false }],
quotes: ["warn", "double", { avoidEscape: true, allowTemplateLiterals: false }],
semi: "warn",
"space-before-blocks": ["warn", "always"],
"space-before-function-paren": [
"warn",
{
anonymous: "always",
named: "never",
asyncArrow: "always",
},
],
"spaced-comment": "warn",
},
overrides: [
{
files: ["./*.js", "./*.cjs", "./*.mjs"],
env: {
node: true,
},
},
],
};

65
.github/workflows/checks.yml vendored 100644
View File

@ -0,0 +1,65 @@
# SPDX-FileCopyrightText: 2022 Johannes Loher
#
# SPDX-License-Identifier: MIT
name: Checks
on:
- push
- pull_request
env:
node_version: 16
jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Install node
uses: actions/setup-node@v2
with:
node-version: ${{ env.node_version }}
- name: Cache Node.js modules
uses: actions/cache@v2
with:
path: .npm
key: ${{ runner.OS }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.OS }}-node-
${{ runner.OS }}-
- name: Install dependencies
run: npm ci --cache .npm --prefer-offline
- name: Lint
run: npm run lint
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Install node
uses: actions/setup-node@v2
with:
node-version: ${{ env.node_version }}
- name: Cache Node.js modules
uses: actions/cache@v2
with:
path: .npm
key: ${{ runner.OS }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.OS }}-node-
${{ runner.OS }}-
- name: Install dependencies
run: npm ci --cache .npm --prefer-offline
- name: Build
run: npm run build

116
.github/workflows/release.yml vendored 100644
View File

@ -0,0 +1,116 @@
# SPDX-FileCopyrightText: 2022 Johannes Loher
#
# SPDX-License-Identifier: MIT
name: Release
on:
release:
types: [published]
env:
package_type: module
node_version: 16
jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Install node
uses: actions/setup-node@v2
with:
node-version: ${{ env.node_version }}
- name: Cache Node.js modules
uses: actions/cache@v2
with:
path: .npm
key: ${{ runner.OS }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.OS }}-node-
${{ runner.OS }}-
- name: Install dependencies
run: npm ci --cache .npm --prefer-offline
- name: Lint
run: npm run lint
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Install node
uses: actions/setup-node@v2
with:
node-version: ${{ env.node_version }}
- name: Cache Node.js modules
uses: actions/cache@v2
with:
path: .npm
key: ${{ runner.OS }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.OS }}-node-
${{ runner.OS }}-
- name: Install dependencies
run: npm ci --cache .npm --prefer-offline
- name: Extract tag version number
id: get_version
uses: battila7/get-version-action@v2
- name: Substitute Manifest and Download Links For Versioned Ones
id: sub_manifest_link_version
uses: microsoft/variable-substitution@v1
with:
files: 'src/${{ env.package_type }}.json'
env:
version: ${{ steps.get_version.outputs.version-without-v }}
url: https://github.com/${{ github.repository }}
manifest: https://github.com/${{ github.repository }}/releases/latest/download/${{ env.package_type }}.json
download: https://github.com/${{ github.repository }}/releases/download/${{ github.event.release.tag_name }}/${{ env.package_type }}.zip
- name: Build
run: npm run build
- name: Archive production artifacts
uses: actions/upload-artifact@v2
with:
name: dist
path: dist
publish:
needs:
- lint
- build
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Download production artifacts for publication
uses: actions/download-artifact@v2
with:
name: dist
path: dist
- name: Create zip file
working-directory: ./dist
run: zip -r ../${{ env.package_type }}.zip .
- name: Create release
id: create_version_release
uses: ncipollo/release-action@v1
with:
allowUpdates: true
name: ${{ github.event.release.name }}
token: ${{ secrets.GITHUB_TOKEN }}
artifacts: './dist/${{ env.package_type }}.json, ./${{ env.package_type }}.zip'
body: ${{ github.event.release.body }}

32
.gitignore vendored 100644
View File

@ -0,0 +1,32 @@
# SPDX-FileCopyrightText: 2022 Johannes Loher
#
# SPDX-License-Identifier: MIT
# IDE
.idea/
.vs/
# Node Modules
node_modules/
npm-debug.log
# yarn2
.yarn/*
!.yarn/patches
!.yarn/releases
!.yarn/plugins
!.yarn/sdks
!.yarn/versions
.pnp.*
# Local configuration
foundryconfig.json
# Distribution files
dist
# ESLint
.eslintcache
# Junit results
junit.xml

5
.gulp.json 100644
View File

@ -0,0 +1,5 @@
{
"flags": {
"gulpfile": "gulpfile.mjs"
}
}

View File

@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"
npx lint-staged

1
.nvmrc 100644
View File

@ -0,0 +1 @@
lts/*

8
.prettierignore 100644
View File

@ -0,0 +1,8 @@
# SPDX-FileCopyrightText: 2022 Johannes Loher
#
# SPDX-License-Identifier: MIT
dist
package-lock.json
.pnp.cjs
.pnp.js

9
.prettierrc.cjs 100644
View File

@ -0,0 +1,9 @@
// SPDX-FileCopyrightText: 2022 Johannes Loher
//
// SPDX-License-Identifier: MIT
module.exports = {
printWidth: 120,
tabWidth: 4,
useTabs: true,
};

65
CONTRIBUTING.md 100644
View File

@ -0,0 +1,65 @@
## Development
### Prerequisites
In order to build this module, recent versions of `node` and `npm` are
required. Most likely, using `yarn` also works, but only `npm` is officially
supported. We recommend using the latest lts version of `node`. If you use `nvm`
to manage your `node` versions, you can simply run
```
nvm install
```
in the project's root directory.
You also need to install the project's dependencies. To do so, run
```
npm install
```
### Building
You can build the project by running
```
npm run build
```
Alternatively, you can run
```
npm run build:watch
```
to watch for changes and automatically build as necessary.
### Linking the built project to Foundry VTT
In order to provide a fluent development experience, it is recommended to link
the built module to your local Foundry VTT installation's data folder. In
order to do so, first add a file called `foundryconfig.json` to the project root
with the following content:
```
{
"dataPath": ["/absolute/path/to/your/FoundryVTT"]
}
```
(if you are using Windows, make sure to use `\` as a path separator instead of
`/`)
Then run
```
npm run link-project
```
On Windows, creating symlinks requires administrator privileges, so
unfortunately you need to run the above command in an administrator terminal for
it to work.
You can also link to multiple data folders by specifying multiple paths in the
`dataPath` array.

View File

@ -4,16 +4,6 @@ Tired of scrolling compendia? Easily browse and filter for spells, feats, items,
Compendium Browser is faster and better-behaved; **it no longer loads all the compendia into memory on start-up** (which sometimes hung servers because of memory or CPU requirements). Instead, it filters and loads on-demand, as well as giving you a Module Setting to control how many rows are loaded at a time.
## Summary
- **Authors**: Discord: Spetzel#0103; Felix (felix.mueller.86@web.de); ZoltantheDM (Zoltan#8700); eduardopato41
- **Version**: 0.9.0
- **Foundry VTT Compatibility**: 9-10
- **System Compatibility (If applicable)**: dnd5e
- **Translation Support**: en, de (thanks https://github.com/CarnVanBeck), es (thanks https://github.com/JJBocanegra), fr, ja, pt-BR
[Patch Notes](https://github.com/ZoltanTheDM/compendium-browser/blob/master/Patchnotes.md)
## Installation
1. Go to the Add-on Modules tab in Foundry Setup
@ -32,6 +22,8 @@ All filters featured in the app are included in this manner and can be found in
## License
<a rel="license" href="http://creativecommons.org/licenses/by/4.0/"><img alt="Creative Commons Licence" style="border-width:0" src="https://i.creativecommons.org/l/by/4.0/88x31.png" /></a><br /><span xmlns:dct="http://purl.org/dc/terms/" property="dct:title">Compendium Browser - a module for Foundry VTT -</span> by <a xmlns:cc="http://creativecommons.org/ns#" href="https://github.com/syl3r86?tab=repositories" property="cc:attributionName" rel="cc:attributionURL">Felix Müller</a> is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by/4.0/">Creative Commons Attribution 4.0 International License</a>.
This project is a fork of Compendium Browser by [Felix Müller](https://github.com/syl3r86).
This work is licensed under Foundry Virtual Tabletop [EULA - Limited License Agreement for module development v 0.1.6](http://foundryvtt.com/pages/license.html).
## Community Contribution
See the [CONTRIBUTING](/CONTRIBUTING.md) file for information about how you can help this project.

176
gulpfile.mjs 100644
View File

@ -0,0 +1,176 @@
// SPDX-FileCopyrightText: 2022 Johannes Loher
// SPDX-FileCopyrightText: 2022 David Archibald
//
// SPDX-License-Identifier: MIT
import fs from "fs-extra";
import gulp from "gulp";
import less from "gulp-less";
import sourcemaps from "gulp-sourcemaps";
import path from "node:path";
import buffer from "vinyl-buffer";
import source from "vinyl-source-stream";
import yargs from "yargs";
import { hideBin } from "yargs/helpers";
import rollupStream from "@rollup/stream";
import rollupConfig from "./rollup.config.mjs";
/** ******************/
/* CONFIGURATION */
/** ******************/
const packageId = "compendium-browser";
const sourceDirectory = "./src";
const distDirectory = "./dist";
const stylesDirectory = `${sourceDirectory}/styles`;
const stylesExtension = "less";
const sourceFileExtension = "js";
const staticFiles = ["assets", "fonts", "lang", "packs", "templates", "module.json"];
/** ******************/
/* BUILD */
/** ******************/
let cache;
/**
* Build the distributable JavaScript code
*/
function buildCode() {
return rollupStream({ ...rollupConfig(), cache })
.on("bundle", (bundle) => {
cache = bundle;
})
.pipe(source(`${packageId}.js`))
.pipe(buffer())
.pipe(sourcemaps.init({ loadMaps: true }))
.pipe(sourcemaps.write("."))
.pipe(gulp.dest(`${distDirectory}/module`));
}
/**
* Build style sheets
*/
function buildStyles() {
return gulp
.src(`${stylesDirectory}/${packageId}.${stylesExtension}`)
.pipe(less())
.pipe(gulp.dest(`${distDirectory}/styles`));
}
/**
* Copy static files
*/
async function copyFiles() {
for (const file of staticFiles) {
if (fs.existsSync(`${sourceDirectory}/${file}`)) {
await fs.copy(`${sourceDirectory}/${file}`, `${distDirectory}/${file}`);
}
}
}
/**
* Watch for changes for each build step
*/
export function watch() {
gulp.watch(`${sourceDirectory}/**/*.${sourceFileExtension}`, { ignoreInitial: false }, buildCode);
gulp.watch(`${stylesDirectory}/**/*.${stylesExtension}`, { ignoreInitial: false }, buildStyles);
gulp.watch(
staticFiles.map((file) => `${sourceDirectory}/${file}`),
{ ignoreInitial: false },
copyFiles,
);
}
export const build = gulp.series(clean, gulp.parallel(buildCode, buildStyles, copyFiles));
/** ******************/
/* CLEAN */
/** ******************/
/**
* Remove built files from `dist` folder while ignoring source files
*/
export async function clean() {
const files = [...staticFiles, "module"];
if (fs.existsSync(`${stylesDirectory}/${packageId}.${stylesExtension}`)) {
files.push("styles");
}
console.log(" ", "Files to clean:");
console.log(" ", files.join("\n "));
for (const filePath of files) {
await fs.remove(`${distDirectory}/${filePath}`);
}
}
/** ******************/
/* LINK */
/** ******************/
/**
* Get the data paths of Foundry VTT based on what is configured in `foundryconfig.json`
*/
function getDataPaths() {
const config = fs.readJSONSync("foundryconfig.json");
const dataPath = config?.dataPath;
if (dataPath) {
const dataPaths = Array.isArray(dataPath) ? dataPath : [dataPath];
return dataPaths.map((dataPath) => {
if (typeof dataPath !== "string") {
throw new Error(
`Property dataPath in foundryconfig.json is expected to be a string or an array of strings, but found ${dataPath}`,
);
}
if (!fs.existsSync(path.resolve(dataPath))) {
throw new Error(`The dataPath ${dataPath} does not exist on the file system`);
}
return path.resolve(dataPath);
});
} else {
throw new Error("No dataPath defined in foundryconfig.json");
}
}
/**
* Link build to User Data folder
*/
export async function link() {
let destinationDirectory;
if (fs.existsSync(path.resolve(sourceDirectory, "module.json"))) {
destinationDirectory = "modules";
} else {
throw new Error("Could not find module.json");
}
const linkDirectories = getDataPaths().map((dataPath) =>
path.resolve(dataPath, "Data", destinationDirectory, packageId),
);
const argv = yargs(hideBin(process.argv)).option("clean", {
alias: "c",
type: "boolean",
default: false,
}).argv;
const clean = argv.c;
for (const linkDirectory of linkDirectories) {
if (clean) {
console.log(`Removing build in ${linkDirectory}.`);
await fs.remove(linkDirectory);
} else if (!fs.existsSync(linkDirectory)) {
console.log(`Linking dist to ${linkDirectory}.`);
await fs.ensureDir(path.resolve(linkDirectory, ".."));
await fs.symlink(path.resolve(distDirectory), linkDirectory);
} else {
console.log(`Skipped linking to ${linkDirectory}, as it already exists.`);
}
}
}

11471
package-lock.json generated 100644

File diff suppressed because it is too large Load Diff

32
package.json 100644
View File

@ -0,0 +1,32 @@
{
"scripts": {
"build": "gulp build",
"build:watch": "gulp watch",
"link-project": "gulp link",
"clean": "gulp clean",
"clean:link": "gulp link --clean",
"lint": "eslint --ext .js,.cjs,.mjs .",
"lint:fix": "eslint --ext .js,.cjs,.mjs --fix .",
"postinstall": "husky install"
},
"devDependencies": {
"@rollup/plugin-node-resolve": "^15.2.3",
"@rollup/stream": "^3.0.1",
"@typhonjs-fvtt/eslint-config-foundry.js": "^0.8.0",
"eslint": "^8.53.0",
"fs-extra": "^11.1.1",
"gulp": "^4.0.2",
"gulp-less": "^5.0.0",
"gulp-sourcemaps": "^3.0.0",
"husky": "^8.0.3",
"less": "^3.13.1",
"lint-staged": "^15.0.2",
"rollup": "^2.79.1",
"vinyl-buffer": "^1.0.1",
"vinyl-source-stream": "^2.0.0",
"yargs": "^17.7.2"
},
"lint-staged": {
"*.(js|cjs|mjs)": "eslint --fix"
}
}

16
rollup.config.mjs 100644
View File

@ -0,0 +1,16 @@
// SPDX-FileCopyrightText: 2022 Johannes Loher
// SPDX-FileCopyrightText: 2022 David Archibald
//
// SPDX-License-Identifier: MIT
import { nodeResolve } from "@rollup/plugin-node-resolve";
export default () => ({
input: "src/module/compendium-browser.js",
output: {
dir: "dist/module",
format: "es",
sourcemap: true,
},
plugins: [nodeResolve()],
});

View File

@ -2,16 +2,23 @@
"id": "compendium-browser",
"title": "Compendium Browser",
"description": "Easily browse and filter spells, feats, items, and npcs loaded from compendiums!",
"version": "2.0.0",
"authors": [
{
"name": "Matheus Clemente",
"discord": "mclemente#5524"
}
],
"systems": ["dnd5e"],
"scripts": ["./compendium-browser.js"],
"styles": ["./compendium-browser.css"],
"url": "This is auto replaced",
"readme": "https://github.com/mclemente/compendium-browser/blob/master/README.md",
"bugs": "https://github.com/mclemente/compendium-browser/issues",
"changelog": "https://github.com/mclemente/compendium-browser/blob/master/Patchnotes.md",
"version": "This is auto replaced",
"compatibility": {
"minimum": "11",
"verified": "11"
},
"esmodules": ["module/compendium-browser.js"],
"styles": ["styles/compendium-browser.css"],
"languages": [
{
"lang": "en",
@ -44,15 +51,14 @@
"path": "lang/de.json"
}
],
"url": "https://github.com/mclemente/compendium-browser",
"manifest": "https://github.com/mclemente/compendium-browser/releases/latest/download/module.json",
"download": "https://github.com/mclemente/compendium-browser/releases/download/latest/compendium-browser.zip",
"compatibility": {
"minimum": "11",
"verified": "11"
"relationships": {
"systems": [{
"id": "dnd5e",
"type": "system"
}],
"requires": [],
"conflicts": []
},
"allowBugReporter": true,
"bugs": "https://github.com/mclemente/compendium-browser/issues",
"readme": "https://github.com/mclemente/compendium-browser/blob/master/README.md",
"changelog": "https://github.com/mclemente/compendium-browser/blob/master/Patchnotes.md"
"manifest": "This is auto replaced",
"download": "This is auto replaced"
}

View File

@ -1,4 +1,7 @@
const STOP_SEARCH = "StopSearchException";
import { preloadTemplates } from "./preloadTemplates.js";
import { registerSettings } from "./settings.js";
const STOP_SEARCH = "StopSearchException";
const NOT_MIGRATED = "NotMigratedException";
class CompendiumBrowser extends Application {
@ -7,7 +10,7 @@ class CompendiumBrowser extends Application {
title: "CMPBrowser.compendiumBrowser",
tabs: [{ navSelector: ".tabs", contentSelector: ".content", initial: "spell" }],
classes: ["compendium-browser"],
template: "modules/compendium-browser/template/template.html",
template: "modules/compendium-browser/templates/template.html",
width: 800,
height: 730,
resizable: true,
@ -446,8 +449,8 @@ class CompendiumBrowser extends Application {
const decoratedItem = this.decorateItem(item5e);
if (
decoratedItem &&
this.passesFilter(decoratedItem, this.spellFilters.activeFilters)
decoratedItem
&& this.passesFilter(decoratedItem, this.spellFilters.activeFilters)
) {
itemsList[item5e.id] = {
compendium: pack.collection,
@ -482,9 +485,9 @@ class CompendiumBrowser extends Application {
const decoratedItem = this.decorateItem(item5e);
if (
decoratedItem &&
["feat", "class", "subclass", "background"].includes(decoratedItem.type) &&
this.passesFilter(decoratedItem, this.featFilters.activeFilters)
decoratedItem
&& ["feat", "class", "subclass", "background"].includes(decoratedItem.type)
&& this.passesFilter(decoratedItem, this.featFilters.activeFilters)
) {
itemsList[item5e.id] = {
compendium: pack.collection,
@ -515,11 +518,11 @@ class CompendiumBrowser extends Application {
const decoratedItem = this.decorateItem(item5e);
if (
decoratedItem &&
!["spell", "feat", "class", "subclass", "background"].includes(
decoratedItem
&& !["spell", "feat", "class", "subclass", "background"].includes(
decoratedItem.type
) &&
this.passesFilter(decoratedItem, this.itemFilters.activeFilters)
)
&& this.passesFilter(decoratedItem, this.itemFilters.activeFilters)
) {
itemsList[item5e.id] = {
compendium: pack.collection,
@ -602,8 +605,8 @@ class CompendiumBrowser extends Application {
if (npc5e.name != "#[CF_tempEntity]") {
const decoratedNpc = this.decorateNpc(npc5e, indexFields);
if (
decoratedNpc &&
this.passesFilter(decoratedNpc, this.npcFilters.activeFilters)
decoratedNpc
&& this.passesFilter(decoratedNpc, this.npcFilters.activeFilters)
) {
actorsList[npc5e._id] = {
compendium: pack.collection,
@ -761,7 +764,7 @@ class CompendiumBrowser extends Application {
async renderLoading(messageElement, itemType, numLoaded, maxLoaded = false, doneLoading = false) {
if (!messageElement) return;
let loadingHTML = await renderTemplate("modules/compendium-browser/template/loading.html", {
let loadingHTML = await renderTemplate("modules/compendium-browser/templates/loading.html", {
numLoaded: numLoaded,
itemType: itemType,
maxLoaded: maxLoaded,
@ -777,7 +780,7 @@ class CompendiumBrowser extends Application {
} else {
listItems = await this.loadAndFilterItems(browserTab, updateLoading);
}
const html = await renderTemplate(`modules/compendium-browser/template/${browserTab}-browser-list.html`, {
const html = await renderTemplate(`modules/compendium-browser/templates/${browserTab}-browser-list.html`, {
listItems: listItems,
});
@ -1022,7 +1025,7 @@ class CompendiumBrowser extends Application {
decoratedNpc.orderCR = cr;
if (cr > 0 && cr < 1) cr = "1/" + 1 / cr;
if (cr > 0 && cr < 1) cr = `1/${1 / cr}`;
decoratedNpc.displayCR = cr;
decoratedNpc.displaySize = "unset";
@ -1116,10 +1119,10 @@ class CompendiumBrowser extends Application {
} else {
if (prop === undefined) return false;
if (
filter.value !== undefined &&
prop !== undefined &&
prop != filter.value &&
!(filter.value === true && prop)
filter.value !== undefined
&& prop !== undefined
&& prop != filter.value
&& !(filter.value === true && prop)
) {
return false;
}
@ -1196,13 +1199,13 @@ class CompendiumBrowser extends Application {
if (compendium.documentName === "Item") {
defaultSettings.loadedSpellCompendium[compendium.collection] = {
load: true,
name: `${compendium["metadata"]["label"]} (${compendium.collection})`,
name: `${compendium.metadata.label} (${compendium.collection})`,
};
}
if (compendium.documentName === "Actor") {
defaultSettings.loadedNpcCompendium[compendium.collection] = {
load: true,
name: `${compendium["metadata"]["label"]} (${compendium.collection})`,
name: `${compendium.metadata.label} (${compendium.collection})`,
};
}
}
@ -1246,10 +1249,10 @@ class CompendiumBrowser extends Application {
defaultSettings.loadedNpcCompendium[compKey].load = settings.loadedNpcCompendium[compKey].load;
}
}
defaultSettings.allowSpellBrowser = settings.allowSpellBrowser ? true : false;
defaultSettings.allowFeatBrowser = settings.allowFeatBrowser ? true : false;
defaultSettings.allowItemBrowser = settings.allowItemBrowser ? true : false;
defaultSettings.allowNpcBrowser = settings.allowNpcBrowser ? true : false;
defaultSettings.allowSpellBrowser = !!settings.allowSpellBrowser;
defaultSettings.allowFeatBrowser = !!settings.allowFeatBrowser;
defaultSettings.allowItemBrowser = !!settings.allowItemBrowser;
defaultSettings.allowNpcBrowser = !!settings.allowNpcBrowser;
if (game.user.isGM) {
game.settings.set("compendium-browser", "settings", defaultSettings);
@ -1719,7 +1722,7 @@ class CompendiumBrowser extends Application {
c.prop("checked", true);
}
} else {
ui.notifications.warn(`Unknown filter type?`);
ui.notifications.warn("Unknown filter type?");
}
}
};
@ -1795,7 +1798,7 @@ class CompendiumBrowser extends Application {
ui.notifications.warn("Could not find the filter!!");
console.warn(filterTarget);
return;
}
static async addTidySheetButton(cb, html, actor) {
@ -1916,20 +1919,9 @@ class CompendiumBrowser extends Application {
}
}
Hooks.on("init", async () => {
await loadTemplates([
"modules/compendium-browser/template/spell-browser.html",
"modules/compendium-browser/template/spell-browser-list.html",
"modules/compendium-browser/template/npc-browser.html",
"modules/compendium-browser/template/npc-browser-list.html",
"modules/compendium-browser/template/feat-browser.html",
"modules/compendium-browser/template/feat-browser-list.html",
"modules/compendium-browser/template/item-browser.html",
"modules/compendium-browser/template/item-browser-list.html",
"modules/compendium-browser/template/filter-container.html",
"modules/compendium-browser/template/settings.html",
"modules/compendium-browser/template/loading.html",
]);
Hooks.once("init", async () => {
registerSettings();
await preloadTemplates();
});
Hooks.on("ready", () => {
@ -1955,11 +1947,11 @@ function stripDotCharacters(str) {
}
function set(obj, path, value) {
var schema = obj; // a moving reference to internal objects within obj
var pList = path.split(".");
var len = pList.length;
for (var i = 0; i < len - 1; i++) {
var elem = pList[i];
let schema = obj; // a moving reference to internal objects within obj
let pList = path.split(".");
let len = pList.length;
for (let i = 0; i < len - 1; i++) {
let elem = pList[i];
if (!schema[elem]) schema[elem] = {};
schema = schema[elem];
}
@ -1970,13 +1962,13 @@ function set(obj, path, value) {
function getPropByString(obj, propString) {
if (!propString) return obj;
var prop,
props = propString.split(".");
let prop;
let props = propString.split(".");
for (var i = 0, iLen = props.length - 1; i < iLen; i++) {
prop = props[i];
var candidate = obj[prop];
let candidate = obj[prop];
if (candidate !== undefined) {
obj = candidate;
} else {

View File

@ -0,0 +1,21 @@
// SPDX-FileCopyrightText: 2022 Johannes Loher
//
// SPDX-License-Identifier: MIT
export async function preloadTemplates() {
const templatePaths = [
"modules/compendium-browser/templates/spell-browser.html",
"modules/compendium-browser/templates/spell-browser-list.html",
"modules/compendium-browser/templates/npc-browser.html",
"modules/compendium-browser/templates/npc-browser-list.html",
"modules/compendium-browser/templates/feat-browser.html",
"modules/compendium-browser/templates/feat-browser-list.html",
"modules/compendium-browser/templates/item-browser.html",
"modules/compendium-browser/templates/item-browser-list.html",
"modules/compendium-browser/templates/filter-container.html",
"modules/compendium-browser/templates/settings.html",
"modules/compendium-browser/templates/loading.html",
];
return loadTemplates(templatePaths);
}

View File

@ -0,0 +1,7 @@
// SPDX-FileCopyrightText: 2022 Johannes Loher
//
// SPDX-License-Identifier: MIT
export function registerSettings() {
// Register any custom module settings here
}

View File

@ -24,11 +24,11 @@
<button id="reset-feat-filter">{{localize "CMPBrowser.Filters.ResetFilters"}}</button>
<!-- <button id="copy-search-feat">Export to <i class="fa-brands fa-square-js"></i></button> -->
</div>
{{> "modules/compendium-browser/template/filter-container.html" filters=featFilters}}
{{> "modules/compendium-browser/templates/filter-container.html" filters=featFilters}}
</div>
<div class="list-area flexcol">
<ul id="CBFeats">
{{> "modules/compendium-browser/template/feat-browser-list.html" feats=items}}
{{> "modules/compendium-browser/templates/feat-browser-list.html" feats=items}}
</ul>
<span class="loading" id="CBFeatsMessage" style="flex: 0"></span>
</div>

View File

@ -24,11 +24,11 @@
<button id="reset-item-filter">{{localize "CMPBrowser.Filters.ResetFilters"}}</button>
<!-- <button id="copy-search-item">Export to <i class="fa-brands fa-square-js"></i></button> -->
</div>
{{> "modules/compendium-browser/template/filter-container.html" filters=itemFilters}}
{{> "modules/compendium-browser/templates/filter-container.html" filters=itemFilters}}
</div>
<div class="list-area flexcol">
<ul id="CBItems">
{{> "modules/compendium-browser/template/item-browser-list.html" items=items}}
{{> "modules/compendium-browser/templates/item-browser-list.html" items=items}}
</ul>
<span class="loading" id="CBItemsMessage" style="flex: 0"></span>
</div>

View File

@ -25,11 +25,11 @@
<button id="reset-npc-filter">{{localize "CMPBrowser.Filters.ResetFilters"}}</button>
<!-- <button id="copy-search-item">Export to <i class="fa-brands fa-square-js"></i></button> -->
</div>
{{> "modules/compendium-browser/template/filter-container.html" filters=npcFilters}}
{{> "modules/compendium-browser/templates/filter-container.html" filters=npcFilters}}
</div>
<div class="list-area flexcol">
<ul id="CBNPCs">
{{> "modules/compendium-browser/template/npc-browser-list.html" npcs=npcs}}
{{> "modules/compendium-browser/templates/npc-browser-list.html" npcs=npcs}}
</ul>
<span class="loading" id="CBNpcsMessage" style="flex: 0"></span>
</div>

View File

@ -24,11 +24,11 @@
<button id="reset-spell-filter">{{localize "CMPBrowser.Filters.ResetFilters"}}</button>
<!-- <button id="copy-search-spell">Export to <i class="fa-brands fa-square-js"></i></button> -->
</div>
{{> "modules/compendium-browser/template/filter-container.html" filters=spellFilters}}
{{> "modules/compendium-browser/templates/filter-container.html" filters=spellFilters}}
</div>
<div class="list-area flexcol">
<ul id="CBSpells">
{{> "modules/compendium-browser/template/spell-browser-list.html" spells=items}}
{{> "modules/compendium-browser/templates/spell-browser-list.html" spells=items}}
</ul>
<span class="loading" id="CBSpellsMessage" style="flex: 0"></span>
</div>

View File

@ -16,23 +16,23 @@
<div class="content">
<div class="tab" data-tab="spell">
{{#if showSpellBrowser}}{{>
"modules/compendium-browser/template/spell-browser.html"}}{{/if}}
"modules/compendium-browser/templates/spell-browser.html"}}{{/if}}
</div>
<div class="tab" data-tab="feat">
{{#if showFeatBrowser}}{{>
"modules/compendium-browser/template/feat-browser.html"}}{{/if}}
"modules/compendium-browser/templates/feat-browser.html"}}{{/if}}
</div>
<div class="tab" data-tab="item">
{{#if showItemBrowser}}{{>
"modules/compendium-browser/template/item-browser.html"}}{{/if}}
"modules/compendium-browser/templates/item-browser.html"}}{{/if}}
</div>
<div class="tab" data-tab="npc">
{{#if showNpcBrowser}} {{>
"modules/compendium-browser/template/npc-browser.html"}}{{/if}}
"modules/compendium-browser/templates/npc-browser.html"}}{{/if}}
</div>
<div class="tab" data-tab="setting">
{{#if isGM}} {{>
"modules/compendium-browser/template/settings.html"}}{{/if}}
"modules/compendium-browser/templates/settings.html"}}{{/if}}
</div>
</div>
</div>