Fix compendium
This commit is contained in:
@ -1,5 +1,34 @@
|
||||
import CthulhuEternalUtils from "../utils.mjs"
|
||||
|
||||
export default class CthulhuEternalActor extends Actor {
|
||||
|
||||
static async create(data, options) {
|
||||
|
||||
// Case of compendium global import
|
||||
if (data instanceof Array) {
|
||||
return super.create(data, options);
|
||||
}
|
||||
// If the created actor has items (only applicable to duplicated actors) bypass the new actor creation logic
|
||||
if (data.items) {
|
||||
let actor = super.create(data, options);
|
||||
return actor;
|
||||
}
|
||||
|
||||
if (data.type === 'protagonist') {
|
||||
let era = game.settings.get("fvtt-cthulhu-eternal", "settings-era")
|
||||
const skills = await CthulhuEternalUtils.loadCompendium("fvtt-cthulhu-eternal.skills")
|
||||
data.items = data.items || []
|
||||
for (let skill of skills) {
|
||||
if (skill.system.settings === era ) {
|
||||
data.items.push(skill.toObject())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return super.create(data, options);
|
||||
}
|
||||
|
||||
|
||||
async _preCreate(data, options, user) {
|
||||
await super._preCreate(data, options, user)
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
|
||||
export class CthulhuEternalUtils {
|
||||
export default class CthulhuEternalUtils {
|
||||
|
||||
static registerSettings() {
|
||||
game.settings.register("fvtt-cthulhu-eternal", "settings-era", {
|
||||
@ -14,6 +14,16 @@ export class CthulhuEternalUtils {
|
||||
});
|
||||
}
|
||||
|
||||
static async loadCompendiumData(compendium) {
|
||||
const pack = game.packs.get(compendium)
|
||||
return await pack?.getDocuments() ?? []
|
||||
}
|
||||
|
||||
static async loadCompendium(compendium, filter = item => true) {
|
||||
let compendiumData = await CthulhuEternalUtils.loadCompendiumData(compendium)
|
||||
return compendiumData.filter(filter)
|
||||
}
|
||||
|
||||
static registerHandlebarsHelpers() {
|
||||
|
||||
Handlebars.registerHelper('isNull', function (val) {
|
||||
@ -168,15 +178,16 @@ export class CthulhuEternalUtils {
|
||||
}
|
||||
|
||||
static setupCSSRootVariables() {
|
||||
const era = game.settings.get("fvtt-cthulhu-eternal", "settings-era")
|
||||
|
||||
const era = game.settings.get("fvtt-cthulhu-eternal", "settings-era")
|
||||
|
||||
let eraCSS = SYSTEM.ERA_CSS[era];
|
||||
if (!eraCSS) eraCSS = SYSTEM.ERA_CSS["jazz"];
|
||||
|
||||
document.documentElement.style.setProperty('--font-primary', eraCSS.primaryFont);
|
||||
document.documentElement.style.setProperty('--font-secondary', eraCSS.secondaryFont);
|
||||
document.documentElement.style.setProperty('--font-title', eraCSS.titleFont);
|
||||
document.documentElement.style.setProperty('--font-title', eraCSS.titleFont);
|
||||
document.documentElement.style.setProperty('--img-icon-color-filter', eraCSS.imgFilter);
|
||||
document.documentElement.style.setProperty('--background-image-base', `linear-gradient(rgba(255, 255, 255, 0.8), rgba(255, 255, 255, 0.8)), url("../assets/ui/${era}_background_main.webp")`);
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user