Initial system import

This commit is contained in:
2025-05-01 09:29:56 +02:00
commit 7672f861ff
94 changed files with 12616 additions and 0 deletions

View File

@@ -0,0 +1,11 @@
export { default as HellbornWeaponSheet } from "./sheets/weapon-sheet.mjs"
export { default as HellbornVehicleSheet } from "./sheets/vehicle-sheet.mjs"
export { default as HellbornCharacterSheet } from "./sheets/character-sheet.mjs"
export { default as HellbornEquipmentSheet } from "./sheets/equipment-sheet.mjs"
export { default as HellbornCreatureSheet } from "./sheets/creature-sheet.mjs"
export { default as HellbornRitualSheet } from "./sheets/ritual-sheet.mjs"
export { default as HellbornItemSheet } from "./sheets/base-item-sheet.mjs"
export { default as HellbornCreatureSheet } from "./sheets/creature-sheet.mjs"
export { default as HellbornSpeciesTraitSheet } from "./sheets/species-trait-sheet.mjs"
export { default as HellbornPerkSheet } from "./sheets/perk-sheet.mjs"
export { default as HellbornMaleficiasSheet } from "./sheets/maleficias-sheet.mjs"

View File

@@ -0,0 +1,218 @@
const { HandlebarsApplicationMixin } = foundry.applications.api
export default class HellbornActorSheet extends HandlebarsApplicationMixin(foundry.applications.sheets.ActorSheetV2) {
/**
* Different sheet modes.r
* @enum {number}
*/
static SHEET_MODES = { EDIT: 0, PLAY: 1 }
constructor(options = {}) {
super(options)
this.#dragDrop = this.#createDragDropHandlers()
}
#dragDrop
/** @override */
static DEFAULT_OPTIONS = {
classes: ["fvtt-hellborn", "actor"],
position: {
width: 1400,
height: "auto",
},
form: {
submitOnChange: true,
},
window: {
resizable: true,
},
dragDrop: [{ dragSelector: '[data-drag="true"], .rollable', dropSelector: null }],
actions: {
editImage: HellbornActorSheet.#onEditImage,
toggleSheet: HellbornActorSheet.#onToggleSheet,
edit: HellbornActorSheet.#onItemEdit,
delete: HellbornActorSheet.#onItemDelete
},
}
/**
* The current sheet mode.
* @type {number}
*/
_sheetMode = this.constructor.SHEET_MODES.PLAY
/**
* Is the sheet currently in 'Play' mode?
* @type {boolean}
*/
get isPlayMode() {
return this._sheetMode === this.constructor.SHEET_MODES.PLAY
}
/**
* Is the sheet currently in 'Edit' mode?
* @type {boolean}
*/
get isEditMode() {
return this._sheetMode === this.constructor.SHEET_MODES.EDIT
}
/** @override */
async _prepareContext() {
const context = {
fields: this.document.schema.fields,
systemFields: this.document.system.schema.fields,
actor: this.document,
system: this.document.system,
source: this.document.toObject(),
isEncumbered: this.document.system.isEncumbered(),
enrichedDescription: await TextEditor.enrichHTML(this.document.system.description, { async: true }),
isEditMode: this.isEditMode,
isPlayMode: this.isPlayMode,
isEditable: this.isEditable,
}
return context
}
/** @override */
_onRender(context, options) {
this.#dragDrop.forEach((d) => d.bind(this.element))
// Add listeners to rollable elements
const rollables = this.element.querySelectorAll(".rollable")
rollables.forEach((d) => d.addEventListener("click", this._onRoll.bind(this)))
}
// #region Drag-and-Drop Workflow
/**
* Create drag-and-drop workflow handlers for this Application
* @returns {DragDrop[]} An array of DragDrop handlers
* @private
*/
#createDragDropHandlers() {
return this.options.dragDrop.map((d) => {
d.permissions = {
dragstart: this._canDragStart.bind(this),
drop: this._canDragDrop.bind(this),
}
d.callbacks = {
dragover: this._onDragOver.bind(this),
drop: this._onDrop.bind(this),
}
return new DragDrop(d)
})
}
/**
* Callback actions which occur when a dragged element is dropped on a target.
* @param {DragEvent} event The originating DragEvent
* @protected
*/
async _onDrop(event) {
}
/**
* Define whether a user is able to begin a dragstart workflow for a given drag selector
* @param {string} selector The candidate HTML selector for dragging
* @returns {boolean} Can the current user drag this selector?
* @protected
*/
_canDragStart(selector) {
return this.isEditable
}
/**
* Define whether a user is able to conclude a drag-and-drop workflow for a given drop selector
* @param {string} selector The candidate HTML selector for the drop target
* @returns {boolean} Can the current user drop on this selector?
* @protected
*/
_canDragDrop(selector) {
return true //this.isEditable && this.document.isOwner
}
/**
* Callback actions which occur when a dragged element is over a drop target.
* @param {DragEvent} event The originating DragEvent
* @protected
*/
_onDragOver(event) {}
async _onDropItem(item) {
console.log("Dropped item", item)
let itemData = item.toObject()
await this.document.createEmbeddedDocuments("Item", [itemData], { renderSheet: false })
}
// #endregion
// #region Actions
/**
* Handle toggling between Edit and Play mode.
* @param {Event} event The initiating click event.
* @param {HTMLElement} target The current target of the event listener.
*/
static #onToggleSheet(event, target) {
const modes = this.constructor.SHEET_MODES
this._sheetMode = this.isEditMode ? modes.PLAY : modes.EDIT
this.render()
}
/**
* Handle changing a Document's image.
*
* @this HellbornActorSheet
* @param {PointerEvent} event The originating click event
* @param {HTMLElement} target The capturing HTML element which defined a [data-action]
* @returns {Promise}
* @private
*/
static async #onEditImage(event, target) {
const attr = target.dataset.edit
const current = foundry.utils.getProperty(this.document, attr)
const { img } = this.document.constructor.getDefaultArtwork?.(this.document.toObject()) ?? {}
const fp = new FilePicker({
current,
type: "image",
redirectToRoot: img ? [img] : [],
callback: (path) => {
this.document.update({ [attr]: path })
},
top: this.position.top + 40,
left: this.position.left + 10,
})
return fp.browse()
}
/**
* Edit an existing item within the Actor
* Start with the uuid, if it's not found, fallback to the id (as Embedded item in the actor)
* @this CthulhuEternalCharacterSheet
* @param {PointerEvent} event The originating click event
* @param {HTMLElement} target the capturing HTML element which defined a [data-action]
*/
static async #onItemEdit(event, target) {
const id = target.getAttribute("data-item-id")
const uuid = target.getAttribute("data-item-uuid")
let item
item = await fromUuid(uuid)
if (!item) item = this.document.items.get(id)
if (!item) return
item.sheet.render(true)
}
/**
* Delete an existing talent within the Actor
* Use the uuid to display the talent sheet
* @param {PointerEvent} event The originating click event
* @param {HTMLElement} target the capturing HTML element which defined a [data-action]
*/
static async #onItemDelete(event, target) {
const itemUuid = target.getAttribute("data-item-uuid")
const item = await fromUuid(itemUuid)
await item.deleteDialog()
}
// #endregion
}

View File

@@ -0,0 +1,193 @@
const { HandlebarsApplicationMixin } = foundry.applications.api
export default class HellbornItemSheet extends HandlebarsApplicationMixin(foundry.applications.sheets.ItemSheetV2) {
/**
* Different sheet modes.
* @enum {number}
*/
static SHEET_MODES = { EDIT: 0, PLAY: 1 }
constructor(options = {}) {
super(options)
this.#dragDrop = this.#createDragDropHandlers()
}
#dragDrop
/** @override */
static DEFAULT_OPTIONS = {
classes: ["fvtt-hellborn", "item"],
position: {
width: 600,
height: "auto",
},
form: {
submitOnChange: true,
},
window: {
resizable: true,
},
dragDrop: [{ dragSelector: "[data-drag]", dropSelector: null }],
actions: {
toggleSheet: HellbornItemSheet.#onToggleSheet,
editImage: HellbornItemSheet.#onEditImage,
},
}
/**
* The current sheet mode.
* @type {number}
*/
_sheetMode = this.constructor.SHEET_MODES.PLAY
/**
* Is the sheet currently in 'Play' mode?
* @type {boolean}
*/
get isPlayMode() {
return this._sheetMode === this.constructor.SHEET_MODES.PLAY
}
/**
* Is the sheet currently in 'Edit' mode?
* @type {boolean}
*/
get isEditMode() {
return this._sheetMode === this.constructor.SHEET_MODES.EDIT
}
/** @override */
async _prepareContext() {
const context = {
fields: this.document.schema.fields,
systemFields: this.document.system.schema.fields,
item: this.document,
system: this.document.system,
source: this.document.toObject(),
enrichedDescription: await TextEditor.enrichHTML(this.document.system.description, { async: true }),
isEditMode: this.isEditMode,
isPlayMode: this.isPlayMode,
isEditable: this.isEditable,
}
return context
}
/** @override */
_onRender(context, options) {
this.#dragDrop.forEach((d) => d.bind(this.element))
}
// #region Drag-and-Drop Workflow
/**
* Create drag-and-drop workflow handlers for this Application
* @returns {DragDrop[]} An array of DragDrop handlers
* @private
*/
#createDragDropHandlers() {
return this.options.dragDrop.map((d) => {
d.permissions = {
dragstart: this._canDragStart.bind(this),
drop: this._canDragDrop.bind(this),
}
d.callbacks = {
dragstart: this._onDragStart.bind(this),
dragover: this._onDragOver.bind(this),
drop: this._onDrop.bind(this),
}
return new DragDrop(d)
})
}
/**
* Define whether a user is able to begin a dragstart workflow for a given drag selector
* @param {string} selector The candidate HTML selector for dragging
* @returns {boolean} Can the current user drag this selector?
* @protected
*/
_canDragStart(selector) {
return this.isEditable
}
/**
* Define whether a user is able to conclude a drag-and-drop workflow for a given drop selector
* @param {string} selector The candidate HTML selector for the drop target
* @returns {boolean} Can the current user drop on this selector?
* @protected
*/
_canDragDrop(selector) {
return this.isEditable && this.document.isOwner
}
/**
* Callback actions which occur at the beginning of a drag start workflow.
* @param {DragEvent} event The originating DragEvent
* @protected
*/
_onDragStart(event) {
const el = event.currentTarget
if ("link" in event.target.dataset) return
// Extract the data you need
let dragData = null
if (!dragData) return
// Set data transfer
event.dataTransfer.setData("text/plain", JSON.stringify(dragData))
}
/**
* Callback actions which occur when a dragged element is over a drop target.
* @param {DragEvent} event The originating DragEvent
* @protected
*/
_onDragOver(event) {}
/**
* Callback actions which occur when a dragged element is dropped on a target.
* @param {DragEvent} event The originating DragEvent
* @protected
*/
async _onDrop(event) {}
// #endregion
// #region Actions
/**
* Handle toggling between Edit and Play mode.
* @param {Event} event The initiating click event.
* @param {HTMLElement} target The current target of the event listener.
*/
static #onToggleSheet(event, target) {
const modes = this.constructor.SHEET_MODES
this._sheetMode = this.isEditMode ? modes.PLAY : modes.EDIT
this.render()
}
/**
* Handle changing a Document's image.
*
* @this CthulhuEternalCharacterSheet
* @param {PointerEvent} event The originating click event
* @param {HTMLElement} target The capturing HTML element which defined a [data-action]
* @returns {Promise}
* @private
*/
static async #onEditImage(event, target) {
const attr = target.dataset.edit
const current = foundry.utils.getProperty(this.document, attr)
const { img } = this.document.constructor.getDefaultArtwork?.(this.document.toObject()) ?? {}
const fp = new FilePicker({
current,
type: "image",
redirectToRoot: img ? [img] : [],
callback: (path) => {
this.document.update({ [attr]: path })
},
top: this.position.top + 40,
left: this.position.left + 10,
})
return fp.browse()
}
// #endregion
}

View File

@@ -0,0 +1,189 @@
import HellbornActorSheet from "./base-actor-sheet.mjs"
export default class HellbornCharacterSheet extends HellbornActorSheet {
/** @override */
static DEFAULT_OPTIONS = {
classes: ["character"],
position: {
width: 860,
height: 620,
},
window: {
contentClasses: ["character-content"],
},
actions: {
createEquipment: HellbornCharacterSheet.#onCreateEquipment,
createArmor: HellbornCharacterSheet.#onCreateArmor,
createWeapon: HellbornCharacterSheet.#onCreateWeapon,
createTalent: HellbornCharacterSheet.#onCreateTalent,
createImplant: HellbornCharacterSheet.#onCreateImplant,
createPsionic: HellbornCharacterSheet.#onCreatePsionic,
createLanguage: HellbornCharacterSheet.#onCreateLanguage
},
}
/** @override */
static PARTS = {
main: {
template: "systems/fvtt-hellborn/templates/character-main.hbs",
},
tabs: {
template: "templates/generic/tab-navigation.hbs",
},
talents: {
template: "systems/fvtt-hellborn/templates/character-talents.hbs",
},
equipment: {
template: "systems/fvtt-hellborn/templates/character-equipment.hbs",
},
biography: {
template: "systems/fvtt-hellborn/templates/character-biography.hbs",
},
}
/** @override */
tabGroups = {
sheet: "talents",
}
/**
* Prepare an array of form header tabs.
* @returns {Record<string, Partial<ApplicationTab>>}
*/
#getTabs() {
const tabs = {
talents: { id: "talents", group: "sheet", icon: "fa-solid fa-compass", label: "HELLBORN.Label.talents" },
equipment: { id: "equipment", group: "sheet", icon: "fa-solid fa-shapes", label: "HELLBORN.Label.equipment" },
biography: { id: "biography", group: "sheet", icon: "fa-solid fa-book", label: "HELLBORN.Label.biography" },
}
for (const v of Object.values(tabs)) {
v.active = this.tabGroups[v.group] === v.id
v.cssClass = v.active ? "active" : ""
}
return tabs
}
/** @override */
async _prepareContext() {
const context = await super._prepareContext()
context.tabs = this.#getTabs()
context.enrichedDescription = await TextEditor.enrichHTML(this.document.system.description, { async: true })
context.enrichedNotes = await TextEditor.enrichHTML(this.document.system.notes, { async: true })
return context
}
/** @override */
async _preparePartContext(partId, context) {
const doc = this.document
switch (partId) {
case "main":
break
case "talents":
context.tab = context.tabs.talents
context.talents = doc.itemTypes.talent
context.talents.sort((a, b) => a.name.localeCompare(b.name))
context.implants = doc.itemTypes.implant
context.implants.sort((a, b) => a.name.localeCompare(b.name))
context.psionics = doc.itemTypes.psionic
context.psionics.sort((a, b) => a.name.localeCompare(b.name))
context.languages = doc.itemTypes.language
context.languages.sort((a, b) => a.name.localeCompare(b.name))
break
case "equipment":
context.tab = context.tabs.equipment
context.weapons = doc.itemTypes.weapon
context.weapons.sort((a, b) => a.name.localeCompare(b.name))
context.armors = doc.itemTypes.armor
context.armors.sort((a, b) => a.name.localeCompare(b.name))
context.equipments = doc.itemTypes.equipment
context.equipments.sort((a, b) => a.name.localeCompare(b.name))
break
case "biography":
context.tab = context.tabs.biography
context.enrichedDescription = await TextEditor.enrichHTML(doc.system.description, { async: true })
context.enrichedNotes = await TextEditor.enrichHTML(doc.system.notes, { async: true })
break
}
return context
}
static #onCreateEquipment(event, target) {
this.document.createEmbeddedDocuments("Item", [{ name: game.i18n.localize("HELLBORN.Label.newEquipment"), type: "equipment" }])
}
static #onCreateWeapon(event, target) {
this.document.createEmbeddedDocuments("Item", [{ name: game.i18n.localize("HELLBORN.Label.newWeapon"), type: "weapon" }])
}
static #onCreateArmor(event, target) {
this.document.createEmbeddedDocuments("Item", [{ name: game.i18n.localize("HELLBORN.Label.newArmor"), type: "armor" }])
}
static #onCreateTalent(event, target) {
this.document.createEmbeddedDocuments("Item", [{ name: game.i18n.localize("HELLBORN.Label.newTalent"), type: "talent" }])
}
static #onCreateImplant(event, target) {
this.document.createEmbeddedDocuments("Item", [{ name: game.i18n.localize("HELLBORN.Label.newImplant"), type: "implant" }])
}
static #onCreatePsionic(event, target) {
this.document.createEmbeddedDocuments("Item", [{ name: game.i18n.localize("HELLBORN.Label.newPsionic"), type: "psionic" }])
}
static #onCreateLanguage(event, target) {
this.document.createEmbeddedDocuments("Item", [{ name: game.i18n.localize("HELLBORN.Label.newLanguage"), type: "language" }])
}
/**
* Handles the roll action triggered by user interaction.
*
* @param {PointerEvent} event The event object representing the user interaction.
* @param {HTMLElement} target The target element that triggered the roll.
*
* @returns {Promise<void>} A promise that resolves when the roll action is complete.
*
* @throws {Error} Throws an error if the roll type is not recognized.
*
* @description This method checks the current mode (edit or not) and determines the type of roll
* (save, resource, or damage) based on the target element's data attributes. It retrieves the
* corresponding value from the document's system and performs the roll.
*/
async _onRoll(event, target) {
const rollType = $(event.currentTarget).data("roll-type")
let item
let li
switch (rollType) {
case "skill":
let skillId = $(event.currentTarget).data("skill-id");
item = this.actor.system.skills[skillId];
break
case "weapon":
case "damage":
li = $(event.currentTarget).parents(".item");
item = this.actor.items.get(li.data("item-id"));
break
default:
throw new Error(`Unknown roll type ${rollType}`)
}
await this.document.system.roll(rollType, item)
}
async _onDrop(event) {
if (!this.isEditable || !this.isEditMode) return
const data = TextEditor.getDragEventData(event)
// Handle different data types
switch (data.type) {
case "Item":
const item = await fromUuid(data.uuid)
return super._onDropItem(item)
}
}
}

View File

@@ -0,0 +1,158 @@
import HellbornActorSheet from "./base-actor-sheet.mjs"
export default class HellbornCreatureSheet extends HellbornActorSheet {
/** @override */
static DEFAULT_OPTIONS = {
classes: ["creature"],
position: {
width: 860,
height: 620,
},
window: {
contentClasses: ["creature-content"],
},
actions: {
createTrait: HellbornCreatureSheet.#onCreateTrait,
createAbility: HellbornCreatureSheet.#onCreateAbility
},
}
/** @override */
static PARTS = {
main: {
template: "systems/fvtt-hellborn/templates/creature-main.hbs",
},
tabs: {
template: "templates/generic/tab-navigation.hbs",
},
traits: {
template: "systems/fvtt-hellborn/templates/creature-sheet-trait.hbs",
},
biography: {
template: "systems/fvtt-hellborn/templates/creature-biography.hbs",
},
}
/** @override */
tabGroups = {
sheet: "traits",
}
/**
* Prepare an array of form header tabs.
* @returns {Record<string, Partial<ApplicationTab>>}
*/
#getTabs() {
const tabs = {
traits: { id: "traits", group: "sheet", icon: "fa-solid fa-shapes", label: "HELLBORN.Label.traits" },
biography: { id: "biography", group: "sheet", icon: "fa-solid fa-book", label: "HELLBORN.Label.biography" },
}
for (const v of Object.values(tabs)) {
v.active = this.tabGroups[v.group] === v.id
v.cssClass = v.active ? "active" : ""
}
return tabs
}
/** @override */
async _prepareContext() {
const context = await super._prepareContext()
context.tabs = this.#getTabs()
context.enrichedDescription = await TextEditor.enrichHTML(this.document.system.description, { async: true })
context.enrichedNotes = await TextEditor.enrichHTML(this.document.system.notes, { async: true })
return context
}
/** @override */
async _preparePartContext(partId, context) {
const doc = this.document
switch (partId) {
case "main":
break
case "traits":
context.tab = context.tabs.traits
context.abilities = doc.itemTypes["creature-ability"]
context.abilities.sort((a, b) => a.name.localeCompare(b.name))
context.traits = doc.itemTypes["creature-trait"]
context.traits.sort((a, b) => a.name.localeCompare(b.name))
break
case "biography":
context.tab = context.tabs.biography
context.enrichedDescription = await TextEditor.enrichHTML(doc.system.description, { async: true })
context.enrichedNotes = await TextEditor.enrichHTML(doc.system.notes, { async: true })
break
}
return context
}
/**
* Creates a new attack item directly from the sheet and embeds it into the document.
* @param {Event} event The initiating click event.
* @param {HTMLElement} target The current target of the event listener.
*/
static #onCreateTrait(event, target) {
this.document.createEmbeddedDocuments("Item", [{ name: game.i18n.localize("HELLBORN.Label.newTrait"), type: "creature-trait" }])
}
static #onCreateAbility(event, target) {
this.document.createEmbeddedDocuments("Item", [{ name: game.i18n.localize("HELLBORN.Label.newAbility"), type: "creature-ability" }])
}
/**
* Handles the roll action triggered by user interaction.
*
* @param {PointerEvent} event The event object representing the user interaction.
* @param {HTMLElement} target The target element that triggered the roll.
*
* @returns {Promise<void>} A promise that resolves when the roll action is complete.
*
* @throws {Error} Throws an error if the roll type is not recognized.
*
* @description This method checks the current mode (edit or not) and determines the type of roll
* (save, resource, or damage) based on the target element's data attributes. It retrieves the
* corresponding value from the document's system and performs the roll.
*/
async _onRoll(event, target) {
const rollType = $(event.currentTarget).data("roll-type")
let item
let formula
let roll
switch (rollType) {
case "skill":
let skillId = $(event.currentTarget).data("skill-id");
item = this.actor.system.skills[skillId];
await this.document.system.roll(rollType, item)
break
case "creature-damage":
formula = this.actor.system.damage
// Rolll the damage
roll = new Roll(formula)
await roll.evaluate()
roll.toMessage( { flavor: `${this.actor.name} : Damage roll` })
break
case "creature-number":
formula = this.actor.system.numberAppearing
// Rolll the damage
roll = new Roll(formula)
await roll.evaluate()
roll.toMessage({flavor: `${this.actor.name} : Number Appearing roll`})
break
default:
throw new Error(`Unknown roll type ${rollType}`)
}
}
async _onDrop(event) {
if (!this.isEditable || !this.isEditMode) return
const data = TextEditor.getDragEventData(event)
// Handle different data types
switch (data.type) {
case "Item":
const item = await fromUuid(data.uuid)
return super._onDropItem(item)
}
}
}

View File

@@ -0,0 +1,28 @@
import HellbornItemSheet from "./base-item-sheet.mjs"
export default class HellbornEquipmentSheet extends HellbornItemSheet {
/** @override */
static DEFAULT_OPTIONS = {
classes: ["equipment"],
position: {
width: 600,
},
window: {
contentClasses: ["equipment-content"],
},
}
/** @override */
static PARTS = {
main: {
template: "systems/fvtt-hellborn/templates/equipment.hbs",
},
}
/** @override */
async _prepareContext() {
const context = await super._prepareContext()
context.enrichedDescription = await TextEditor.enrichHTML(this.document.system.description, { async: true })
return context
}
}

View File

@@ -0,0 +1,28 @@
import HellbornItemSheet from "./base-item-sheet.mjs"
export default class HellbornMaleficiasSheet extends HellbornItemSheet {
/** @override */
static DEFAULT_OPTIONS = {
classes: ["maleficias"],
position: {
width: 600,
},
window: {
contentClasses: ["maleficias-content"],
},
}
/** @override */
static PARTS = {
main: {
template: "systems/fvtt-hellborn/templates/maleficias.hbs",
},
}
/** @override */
async _prepareContext() {
const context = await super._prepareContext()
context.enrichedDescription = await TextEditor.enrichHTML(this.document.system.description, { async: true })
return context
}
}

View File

@@ -0,0 +1,28 @@
import HellbornItemSheet from "./base-item-sheet.mjs"
export default class HellbornPerkSheet extends HellbornItemSheet {
/** @override */
static DEFAULT_OPTIONS = {
classes: ["perk"],
position: {
width: 600,
},
window: {
contentClasses: ["perk-content"],
},
}
/** @override */
static PARTS = {
main: {
template: "systems/fvtt-hellborn/templates/perk.hbs",
},
}
/** @override */
async _prepareContext() {
const context = await super._prepareContext()
context.enrichedDescription = await TextEditor.enrichHTML(this.document.system.description, { async: true })
return context
}
}

View File

@@ -0,0 +1,27 @@
import HellbornItemSheet from "./base-item-sheet.mjs"
export default class HellbornRitualSheet extends HellbornItemSheet {
/** @override */
static DEFAULT_OPTIONS = {
classes: ["ritual"],
position: {
width: 600,
},
window: {
contentClasses: ["ritual-content"],
},
}
/** @override */
static PARTS = {
main: {
template: "systems/fvtt-hellborn/templates/ritual.hbs",
},
}
/** @override */
async _prepareContext() {
const context = await super._prepareContext()
return context
}
}

View File

@@ -0,0 +1,28 @@
import HellbornItemSheet from "./base-item-sheet.mjs"
export default class HellbornSpeciesTraitSheet extends HellbornItemSheet {
/** @override */
static DEFAULT_OPTIONS = {
classes: ["species-trait"],
position: {
width: 600,
},
window: {
contentClasses: ["species-trait-content"],
},
}
/** @override */
static PARTS = {
main: {
template: "systems/fvtt-hellborn/templates/species-trait.hbs",
},
}
/** @override */
async _prepareContext() {
const context = await super._prepareContext()
context.enrichedDescription = await TextEditor.enrichHTML(this.document.system.description, { async: true })
return context
}
}

View File

@@ -0,0 +1,134 @@
import HellbornActorSheet from "./base-actor-sheet.mjs"
export default class HellbornVehicleSheet extends HellbornActorSheet {
/** @override */
static DEFAULT_OPTIONS = {
classes: ["vehicle"],
position: {
width: 680,
height: 540,
},
window: {
contentClasses: ["vehicle-content"],
},
actions: {
createEquipment: HellbornVehicleSheet.#onCreateEquipment,
createWeapon: HellbornVehicleSheet.#onCreateWeapon,
},
}
/** @override */
static PARTS = {
main: {
template: "systems/fvtt-hellborn/templates/vehicle-main.hbs",
},
tabs: {
template: "templates/generic/tab-navigation.hbs",
},
equipment: {
template: "systems/fvtt-hellborn/templates/vehicle-equipment.hbs",
},
description: {
template: "systems/fvtt-hellborn/templates/vehicle-description.hbs",
},
}
/** @override */
tabGroups = {
sheet: "equipment",
}
/**
* Prepare an array of form header tabs.
* @returns {Record<string, Partial<ApplicationTab>>}
*/
#getTabs() {
const tabs = {
equipment: { id: "equipment", group: "sheet", icon: "fa-solid fa-shapes", label: "HELLBORN.Label.equipment" },
description: { id: "description", group: "sheet", icon: "fa-solid fa-book", label: "HELLBORN.Label.description" },
}
for (const v of Object.values(tabs)) {
v.active = this.tabGroups[v.group] === v.id
v.cssClass = v.active ? "active" : ""
}
return tabs
}
/** @override */
async _prepareContext() {
const context = await super._prepareContext()
context.tabs = this.#getTabs()
context.enrichedDescription = await TextEditor.enrichHTML(this.document.system.description, { async: true })
context.enrichedNotes = await TextEditor.enrichHTML(this.document.system.notes, { async: true })
return context
}
_generateTooltip(type, target) {
}
/** @override */
async _preparePartContext(partId, context) {
const doc = this.document
switch (partId) {
case "main":
break
case "equipment":
context.tab = context.tabs.equipment
context.weapons = doc.itemTypes.weapon
context.weapons.sort((a, b) => a.name.localeCompare(b.name))
context.equipments = doc.itemTypes.equipment
context.equipments.sort((a, b) => a.name.localeCompare(b.name))
break
case "description":
context.tab = context.tabs.description
context.enrichedDescription = await TextEditor.enrichHTML(doc.system.description, { async: true })
context.enrichedNotes = await TextEditor.enrichHTML(doc.system.notes, { async: true })
break
}
return context
}
/**
* Creates a new attack item directly from the sheet and embeds it into the document.
* @param {Event} event The initiating click event.
* @param {HTMLElement} target The current target of the event listener.
*/
static #onCreateEquipment(event, target) {
this.document.createEmbeddedDocuments("Item", [{ name: game.i18n.localize("HELLBORN.Label.newEquipment"), type: "equipment" }])
}
static #onCreateWeapon(event, target) {
this.document.createEmbeddedDocuments("Item", [{ name: game.i18n.localize("HELLBORN.Label.newWeapon"), type: "weapon" }])
}
async _onRoll(event, target) {
const rollType = $(event.currentTarget).data("roll-type")
let item
let li
switch (rollType) {
case "damage":
li = $(event.currentTarget).parents(".item");
item = this.actor.items.get(li.data("item-id"));
break
default:
throw new Error(`Unknown roll type ${rollType}`)
}
await this.document.system.roll(rollType, item)
}
async _onDrop(event) {
if (!this.isEditable || !this.isEditMode) return
const data = TextEditor.getDragEventData(event)
// Handle different data types
switch (data.type) {
case "Item":
const item = await fromUuid(data.uuid)
return super._onDropItem(item)
}
}
}

View File

@@ -0,0 +1,21 @@
import HellbornItemSheet from "./base-item-sheet.mjs"
export default class HellbornWeaponSheet extends HellbornItemSheet {
/** @override */
static DEFAULT_OPTIONS = {
classes: ["weapon"],
position: {
width: 620,
},
window: {
contentClasses: ["weapon-content"],
},
}
/** @override */
static PARTS = {
main: {
template: "systems/fvtt-hellborn/templates/weapon.hbs",
},
}
}

154
module/config/system.mjs Normal file
View File

@@ -0,0 +1,154 @@
export const SYSTEM_ID = "fvtt-hellborn"
export const ASCII = `
░▒▓████████▓▒░▒▓████████▓▒░▒▓█▓▒░ ░▒▓███████▓▒░ ░▒▓██████▓▒░░▒▓██████████████▓▒░ ░▒▓██████▓▒░░▒▓███████▓▒░
░▒▓█▓▒░ ░▒▓█▓▒░ ░▒▓█▓▒░ ░▒▓██▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░
░▒▓█▓▒░ ░▒▓█▓▒░ ░▒▓█▓▒░ ░▒▓██▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░
░▒▓██████▓▒░ ░▒▓█▓▒░ ░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░░▒▓█▓▒░▒▓████████▓▒░▒▓█▓▒░░▒▓█▓▒░
░▒▓█▓▒░ ░▒▓█▓▒░ ░▒▓█▓▒░ ░▒▓██▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░
░▒▓█▓▒░ ░▒▓█▓▒░ ░▒▓█▓▒░ ░▒▓██▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░
░▒▓█▓▒░ ░▒▓█▓▒░ ░▒▓████████▓▒░ ░▒▓█▓▒░░▒▓█▓▒░░▒▓██████▓▒░░▒▓█▓▒░░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░▒▓███████▓▒░
`
export const SKILLS = {
"combat": { id: "combat", label: "HELLBORN.Skill.Combat" },
"knowledge": { id: "knowledge", label: "HELLBORN.Skill.Knowledge" },
"social": { id: "social", label: "HELLBORN.Skill.Social" },
"physical": { id: "physical", label: "HELLBORN.Skill.Physical" },
"stealth": { id: "stealth", label: "HELLBORN.Skill.Stealth" },
"vehicles": { id: "vehicles", label: "HELLBORN.Skill.Vehicles" },
"technology": { id: "technology", label: "HELLBORN.Skill.Technology" }
}
export const TECH_AGES = {
"notech": { id: "notech", level: 0, label: "HELLBORN.TechAge.NoTech" },
"earlyprimitive": { id: "earlyprimitive", label: "HELLBORN.TechAge.EarlyPrimitive", level: 1 },
"lateprimitive": { id: "lateprimitive", label: "HELLBORN.TechAge.LatePrimitive", level: 2 },
"earlymechanical": { id: "earlymechanical", label: "HELLBORN.TechAge.EarlyMechanical", level: 3 },
"latemechanical": { id: "latemechanical", label: "HELLBORN.TechAge.LateMechanical", level: 4 },
"earlyatomic": { id: "earlyatomic", label: "HELLBORN.TechAge.EarlyAtomic", level: 5 },
"lateatomic": { id: "lateatomic", label: "HELLBORN.TechAge.LateAtomic", level: 6 },
"earlyspace": { id: "earlyspace", label: "HELLBORN.TechAge.EarlySpace", level: 7 },
"latespace": { id: "latespace", label: "HELLBORN.TechAge.LateSpace", level: 8 },
"earlyinterstellar": { id: "earlyinterstellar", label: "HELLBORN.TechAge.EarlyInterstellar", level: 9 },
"lateinterstellar": { id: "lateinterstellar", label: "HELLBORN.TechAge.LateInterstellar", level: 10 },
"earlygalactic": { id: "earlygalactic", label: "HELLBORN.TechAge.EarlyGalactic", level: 11 },
"lategalactic": { id: "lategalactic", label: "HELLBORN.TechAge.LateGalactic", level: 12 },
"cosmic": { id: "cosmic", label: "HELLBORN.TechAge.Cosmic", level: 13 }
}
export const WEAPON_TYPES = {
"melee": { id: "melee", label: "HELLBORN.Weapon.Types.Melee" },
"projectile": { id: "projectile", label: "HELLBORN.Weapon.Types.Projectile" },
"energy": { id: "energy", label: "HELLBORN.Weapon.Types.Energy" },
"heavy": { id: "heavy", label: "HELLBORN.Weapon.Types.Heavy" },
"grenade": { id: "grenade", label: "HELLBORN.Weapon.Types.Grenade" },
"vehicle": { id: "vehicle", label: "HELLBORN.Weapon.Types.Vehicle" }
}
export const WEAPON_RANGE = {
"handgun": { id: "handgun", label: "HELLBORN.Weapon.Range.Handgun", range: {close: 0, near:0, far:-2} },
"assault": { id: "assault", label: "HELLBORN.Weapon.Range.Assault", range: {close: -2, near:0, far:-1, distant: -2} },
"rifle": { id: "rifle", label: "HELLBORN.Weapon.Range.Rifle", range: {close: -3, near:0, far:0, distant: -1} },
"melee": { id: "melee", label: "HELLBORN.Weapon.Range.Melee", range: {close: 0} },
"heavyweapon": { id: "heavyweapon", label: "HELLBORN.Weapon.Range.HeavyWeapon", range: {near:-1, far:0, distant: 0} },
"thrownweapon": { id: "thrownweapon", label: "HELLBORN.Weapon.Range.ThrownWeapon", range: {close: 0, near:-1} }
}
export const ATTACK_MODIFIERS = {
"two-attacks": -1,
"aiming": 1,
"dim": -1,
"darkness": -2,
"prone": -1,
"cover": -2,
"recoil-first": -1,
"recoil-third": -2,
"aware": -1
}
export const TRIAGE_RESULTS = {
"none": { id: "none", dice:0, label: "HELLBORN.TriageResults.None" },
"death": { id: "death", dice:3, label: "HELLBORN.TriageResults.Death" },
"critical": { id: "critical", dice:4, label: "HELLBORN.TriageResults.Critical" },
"severe": { id: "severe", dice:7, label: "HELLBORN.TriageResults.Severe" },
"moderate": { id: "moderate", dice:10, label: "HELLBORN.TriageResults.Moderate" },
"fleshwound": { id: "fleshwound", dice:12, label: "HELLBORN.TriageResults.FleshWound" }
}
export const CREATURE_TERRAIN_TYPES = {
"cave": { id: "cave", label: "HELLBORN.Creature.Terrain.Cave", niche:0, size: 0 },
"coast": { id: "coast", label: "HELLBORN.Creature.Terrain.Coast", niche:1, size: 0 },
"desert": { id: "desert", label: "HELLBORN.Creature.Terrain.Desert", niche:-1, size: -1 },
"forest": { id: "forest", label: "HELLBORN.Creature.Terrain.Forest", niche:1, size: 1 },
"jungle": { id: "jungle", label: "HELLBORN.Creature.Terrain.Jungle", niche:1, size: 1 },
"mixed": { id: "mixed", label: "HELLBORN.Creature.Terrain.Mixed", niche:0, size: 0 },
"mountain": { id: "mountain", label: "HELLBORN.Creature.Terrain.Mountain", niche:-1, size: -1 },
"ocean": { id: "ocean", label: "HELLBORN.Creature.Terrain.Ocean", niche:-1, size: 1 },
"river": { id: "river", label: "HELLBORN.Creature.Terrain.River", niche:1, size: 0 },
"ruins": { id: "ruins", label: "HELLBORN.Creature.Terrain.Ruins", niche:0, size: 1 },
"savannah": { id: "savannah", label: "HELLBORN.Creature.Terrain.Savannah", niche:0, size: 1 },
"shallows": { id: "shallows", label: "HELLBORN.Creature.Terrain.Shallows", niche:1, size: 0 },
"swamp": { id: "swamp", label: "HELLBORN.Creature.Terrain.Swamp", niche:1, size: 1 }
}
export const CREATURE_NICHES = {
"prey": { id: "prey", label: "HELLBORN.Creature.Niche.Prey" },
"opportunist": { id: "opportunist", label: "HELLBORN.Creature.Niche.Opportunist" },
"herbivore": { id: "herbivore", label: "HELLBORN.Creature.Niche.Herbivore" },
"predator": { id: "predator", label: "HELLBORN.Creature.Niche.Predator" }
}
export const CREATURE_SIZES = {
"tiny": { id: "tiny", label: "HELLBORN.Creature.Size.Tiny" },
"small": { id: "small", label: "HELLBORN.Creature.Size.Small" },
"medium": { id: "medium", label: "HELLBORN.Creature.Size.Medium" },
"large": { id: "large", label: "HELLBORN.Creature.Size.Large" },
"giant": { id: "giant", label: "HELLBORN.Creature.Size.Giant" },
"titanic": { id: "titanic", label: "HELLBORN.Creature.Size.Titanic" }
}
export const MODIFIER_CHOICES = {
"easy": { id: "easy", label: "HELLBORN.Label.Easy", value :"1" },
"moderate": { id: "moderate", label: "HELLBORN.Label.Moderate", value: "0" },
"difficult": { id: "difficult", label: "HELLBORN.Label.Difficult", value: "-1" },
"formidable": { id: "formidable", label: "HELLBORN.Label.Formidable", value: "-2" },
"impossible": { id: "impossible", label: "HELLBORN.Label.Impossible", value: "-4" }
}
export const STARSHIP_HULL = {
"pod": { id: "pod", label: "HELLBORN.Starship.Hull.Pod" },
"micro": { id: "micro", label: "HELLBORN.Starship.Hull.Micro" },
"small": { id: "small", label: "HELLBORN.Starship.Hull.Small" },
"scout": { id: "scout", label: "HELLBORN.Starship.Hull.Scout" },
"picket": { id: "picket", label: "HELLBORN.Starship.Hull.Picket" },
"destroyer": { id: "destroyer", label: "HELLBORN.Starship.Hull.Destroyer" },
"cruiser": { id: "cruiser", label: "HELLBORN.Starship.Hull.Cruiser" },
"battleship": { id: "battleship", label: "HELLBORN.Starship.Hull.Battleship" },
"carrier": { id: "carrier", label: "HELLBORN.Starship.Hull.Carrier" }
}
/**
* Include all constant definitions within the SYSTEM global export
* @type {Object}
*/
export const SYSTEM = {
id: SYSTEM_ID,
MODIFIER_CHOICES,
ATTACK_MODIFIERS,
TECH_AGES,
WEAPON_TYPES,
WEAPON_RANGE,
TRIAGE_RESULTS,
CREATURE_TERRAIN_TYPES,
CREATURE_SIZES,
CREATURE_NICHES,
STARSHIP_HULL,
SKILLS,
ASCII
}

View File

@@ -0,0 +1,4 @@
export { default as HellbornActor } from "./actor.mjs"
export { default as HellbornItem } from "./item.mjs"
export { default as HellbornRoll } from "./roll.mjs"
export { default as HellbornChatMessage } from "./chat-message.mjs"

View File

@@ -0,0 +1,53 @@
import HellbornUtils from "../utils.mjs"
export default class HellbornActor 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 === 'character') {
}
return super.create(data, options);
}
_onUpdate(changed, options, userId) {
// DEBUG : console.log("CthulhuEternalActor.update", changed, options, userId)
if (changed?.system?.wp?.exhausted) {
ChatMessage.create({
user: userId,
speaker: { alias: this.name },
rollMode: "selfroll",
content: game.i18n.localize("HELLBORN.ChatMessage.exhausted"),
type: CONST.CHAT_MESSAGE_STYLES.OTHER
})
}
return super._onUpdate(changed, options, userId)
}
async _preCreate(data, options, user) {
await super._preCreate(data, options, user)
// Configure prototype token settings
const prototypeToken = {}
if (this.type === "character") {
Object.assign(prototypeToken, {
sight: { enabled: true },
actorLink: true,
disposition: CONST.TOKEN_DISPOSITIONS.FRIENDLY,
})
this.updateSource({ prototypeToken })
}
}
}

View File

@@ -0,0 +1,21 @@
import HellbornRoll from "./roll.mjs"
export default class HellbornChatMessage extends ChatMessage {
async _renderRollContent(messageData) {
const data = messageData.message
if (this.rolls[0] instanceof HellbornRoll) {
const isPrivate = !this.isContentVisible
// _renderRollHTML va appeler render sur tous les rolls
const rollHTML = await this._renderRollHTML(isPrivate)
if (isPrivate) {
data.flavor = game.i18n.format("CHAT.PrivateRollContent", { user: this.user.name })
messageData.isWhisper = false
messageData.alias = this.user.name
}
data.content = `<section class="dice-rolls">${rollHTML}</section>`
return
}
return super._renderRollContent(messageData)
}
}

17
module/documents/item.mjs Normal file
View File

@@ -0,0 +1,17 @@
export const defaultItemImg = {
weapon: "systems/fvtt-hellborn/assets/icons/icon_weapon.svg",
equipment: "systems/fvtt-hellborn/assets/icons/icon_equipment.svg",
ritual: "systems/fvtt-hellborn/assets/icons/icon_psionic.svg",
maleficias: "systems/fvtt-hellborn/assets/icons/icon_talent.svg",
perk: "systems/fvtt-hellborn/assets/icons/icon_language.svg",
"species-trait": "systems/fvtt-hellborn/assets/icons/icon_creature_trait.svg"
}
export default class HellbornItem extends Item {
constructor(data, context) {
if (!data.img) {
data.img = defaultItemImg[data.type];
}
super(data, context);
}
}

350
module/documents/roll.mjs Normal file
View File

@@ -0,0 +1,350 @@
import { SYSTEM } from "../config/system.mjs"
export default class HellbornRoll extends Roll {
/**
* The HTML template path used to render dice checks of this type
* @type {string}
*/
static CHAT_TEMPLATE = "systems/fvtt-hellborn/templates/chat-message.hbs"
get type() {
return this.options.type
}
get isDamage() {
return this.type === ROLL_TYPE.DAMAGE
}
get target() {
return this.options.target
}
get value() {
return this.options.value
}
get actorId() {
return this.options.actorId
}
get actorName() {
return this.options.actorName
}
get actorImage() {
return this.options.actorImage
}
get help() {
return this.options.help
}
get resultType() {
return this.options.resultType
}
get isFailure() {
return this.resultType === "failure"
}
get hasTarget() {
return this.options.hasTarget
}
get realDamage() {
return this.options.realDamage
}
get weapon() {
return this.options.weapon
}
static updateFullFormula(options) {
let fullFormula
if ( options.numericModifier >= 0) {
fullFormula = `${options.formula} + ${options.rollItem.value} + ${options.numericModifier}D`
} else {
fullFormula = `${options.formula} + ${options.rollItem.value} - ${Math.abs(options.numericModifier)}D`
}
$('#roll-dialog-full-formula').text(fullFormula)
options.fullFormula = fullFormula
}
/**
* Prompt the user with a dialog to configure and execute a roll.
*
* @param {Object} options Configuration options for the roll.
* @param {string} options.rollType The type of roll being performed.
* @param {string} options.rollTarget The target of the roll.
* @param {string} options.actorId The ID of the actor performing the roll.
* @param {string} options.actorName The name of the actor performing the roll.
* @param {string} options.actorImage The image of the actor performing the roll.
* @param {boolean} options.hasTarget Whether the roll has a target.
* @param {Object} options.data Additional data for the roll.
*
* @returns {Promise<Object|null>} The roll result or null if the dialog was cancelled.
*/
static async prompt(options = {}) {
let formula = "2d6"
switch (options.rollType) {
case "skill":
break
case "damage":
let formula = options.rollItem.system.damage
let damageRoll = new Roll(formula)
await damageRoll.evaluate()
await damageRoll.toMessage({
flavor: `${options.rollItem.name} - Damage Roll`
});
return
case "weapon":
let actor = game.actors.get(options.actorId)
options.weapon = foundry.utils.duplicate(options.rollItem)
options.rollItem = actor.system.skills.combat
break
default:
break
}
const rollModes = Object.fromEntries(Object.entries(CONFIG.Dice.rollModes).map(([key, value]) => [key, game.i18n.localize(value)]))
const fieldRollMode = new foundry.data.fields.StringField({
choices: rollModes,
blank: false,
default: "public",
})
const choiceModifier = SYSTEM.MODIFIER_CHOICES
let choiceRangeModifier = {}
let rangeModifier = 0
if ( options.weapon) {
// Build the range modifiers
let range = SYSTEM.WEAPON_RANGE[options.weapon.system.rangeType]
for (let [key, value] of Object.entries(range.range)) {
choiceRangeModifier[key] = { label: `${key} (${value}D)`, value: value }
if (!rangeModifier && value) {
rangeModifier = value
}
}
}
let modifier = "0"
options.numericModifier = rangeModifier
let fullFormula = `${formula} + ${options.rollItem.value}`
if (options.isEncumbered) {
options.numericModifier += -1
fullFormula += ` - ${options.numericModifier}D`
} else {
options.numericModifier += 0
fullFormula += ` + ${options.numericModifier}D`
}
options.fullFormula = fullFormula
options.formula = formula
let dialogContext = {
actorId: options.actorId,
actorName: options.actorName,
rollType: options.rollType,
rollItem: foundry.utils.duplicate(options.rollItem), // Object only, no class
fullFormula,
weapon: options?.weapon,
isEncumbered: options.isEncumbered,
talents: options.talents,
rollModes,
fieldRollMode,
choiceModifier,
choiceRangeModifier,
rangeModifier,
formula,
hasTarget: options.hasTarget,
modifier,
}
const content = await renderTemplate("systems/fvtt-hellborn/templates/roll-dialog.hbs", dialogContext)
const title = HellbornRoll.createTitle(options.rollType, options.rollTarget)
const label = game.i18n.localize("HELLBORN.Roll.roll")
const rollContext = await foundry.applications.api.DialogV2.wait({
window: { title: title },
classes: ["fvtt-hellborn"],
content,
buttons: [
{
label: label,
callback: (event, button, dialog) => {
const output = Array.from(button.form.elements).reduce((obj, input) => {
if (input.name) obj[input.name] = input.value
return obj
}, {})
return output
},
},
],
actions: {
},
rejectClose: false, // Click on Close button will not launch an error
render: (event, dialog) => {
$(".roll-skill-modifier").change(event => {
options.numericModifier += Number(event.target.value)
HellbornRoll.updateFullFormula(options)
})
$(".roll-skill-range-modifier").change(event => {
options.numericModifier += Number(event.target.value)
HellbornRoll.updateFullFormula(options)
})
$(".select-combat-option").change(event => {
console.log(event)
let field = $(event.target).data("field")
let modifier = SYSTEM.ATTACK_MODIFIERS[field]
if ( event.target.checked) {
options.numericModifier += modifier
} else {
options.numericModifier -= modifier
}
HellbornRoll.updateFullFormula(options)
})
}
})
// If the user cancels the dialog, exit
if (rollContext === null) return
let rollData = foundry.utils.mergeObject(foundry.utils.duplicate(options), rollContext)
rollData.rollMode = rollContext.visibility
// Update target score
rollData.targetScore = 8
if (Hooks.call("fvtt-hellborn.preRoll", options, rollData) === false) return
let diceFormula = `${2+Math.abs(options.numericModifier)}D6`
if ( options.numericModifier > 0 ) {
diceFormula += `kh2 + ${options.rollItem.value}`
} else {
diceFormula += `kl2 + ${options.rollItem.value}`
}
const roll = new this(diceFormula, options.data, rollData)
await roll.evaluate()
roll.displayRollResult(roll, options, rollData)
if (Hooks.call("fvtt-hellborn.Roll", options, rollData, roll) === false) return
return roll
}
displayRollResult(formula, options, rollData) {
// Compute the result quality
let resultType = "failure"
if (this.total >= 8) {
resultType = "success"
// Detect if decimal == unit in the dire total result
}
this.options.resultType = resultType
this.options.isSuccess = resultType === "success"
this.options.isFailure = resultType === "failure"
this.options.isEncumbered = rollData.isEncumbered
this.options.rollData = foundry.utils.duplicate(rollData)
}
/**
* Creates a title based on the given type.
*
* @param {string} type The type of the roll.
* @param {string} target The target of the roll.
* @returns {string} The generated title.
*/
static createTitle(type, target) {
switch (type) {
case "skill":
return `${game.i18n.localize("HELLBORN.Label.titleSkill")}`
case "weapon":
return `${game.i18n.localize("HELLBORN.Label.titleWeapon")}`
default:
return game.i18n.localize("HELLBORN.Label.titleStandard")
}
}
/** @override */
async render(chatOptions = {}) {
let chatData = await this._getChatCardData(chatOptions.isPrivate)
return await renderTemplate(this.constructor.CHAT_TEMPLATE, chatData)
}
/**
* Generates the data required for rendering a roll chat card.
*
* @param {boolean} isPrivate Indicates if the chat card is private.
* @returns {Promise<Object>} A promise that resolves to an object containing the chat card data.
* @property {Array<string>} css - CSS classes for the chat card.
* @property {Object} data - The data associated with the roll.
* @property {number} diceTotal - The total value of the dice rolled.
* @property {boolean} isGM - Indicates if the user is a Game Master.
* @property {string} formula - The formula used for the roll.
* @property {number} total - The total result of the roll.
* @property {boolean} isFailure - Indicates if the roll is a failure.
* @property {string} actorId - The ID of the actor performing the roll.
* @property {string} actingCharName - The name of the character performing the roll.
* @property {string} actingCharImg - The image of the character performing the roll.
* @property {string} resultType - The type of result (e.g., success, failure).
* @property {boolean} hasTarget - Indicates if the roll has a target.
* @property {string} targetName - The name of the target.
* @property {number} targetArmor - The armor value of the target.
* @property {number} realDamage - The real damage dealt.
* @property {boolean} isPrivate - Indicates if the chat card is private.
* @property {string} cssClass - The combined CSS classes as a single string.
* @property {string} tooltip - The tooltip text for the chat card.
*/
async _getChatCardData(isPrivate) {
let cardData = foundry.utils.duplicate(this.options)
cardData.css = [SYSTEM.id, "dice-roll"]
cardData.data = this.data
cardData.diceTotal = this.dice.reduce((t, d) => t + d.total, 0)
cardData.isGM = game.user.isGM
cardData.formula = this.formula
cardData.fullFormula = this.options.fullFormula
cardData.numericModifier = this.options.numericModifier
cardData.total = this.total
cardData.actorId = this.actorId
cardData.actingCharName = this.actorName
cardData.actingCharImg = this.actorImage
cardData.resultType = this.resultType
cardData.hasTarget = this.hasTarget
cardData.targetName = this.targetName
cardData.targetArmor = this.targetArmor
cardData.realDamage = this.realDamage
cardData.isPrivate = isPrivate
cardData.weapon = this.weapon
cardData.isEncumbered = this.isEncumbered
cardData.cssClass = cardData.css.join(" ")
cardData.tooltip = isPrivate ? "" : await this.getTooltip()
return cardData
}
/**
* Converts the roll result to a chat message.
*
* @param {Object} [messageData={}] Additional data to include in the message.
* @param {Object} options Options for message creation.
* @param {string} options.rollMode The mode of the roll (e.g., public, private).
* @param {boolean} [options.create=true] Whether to create the message.
* @returns {Promise} - A promise that resolves when the message is created.
*/
async toMessage(messageData = {}, { rollMode, create = true } = {}) {
super.toMessage(
{
isFailure: this.resultType === "failure",
actingCharName: this.actorName,
actingCharImg: this.actorImage,
hasTarget: this.hasTarget,
realDamage: this.realDamage,
...messageData,
},
{ rollMode: rollMode },
)
}
}

View File

@@ -0,0 +1,9 @@
export { default as HellbornCreature } from "./creature.mjs"
export { default as HellbornVehicle } from "./vehicle.mjs"
export { default as HellbornCharacter } from "./character.mjs"
export { default as HellbornEquipment } from "./equipment.mjs"
export { default as HellbornRitual } from "./ritual.mjs"
export { default as HellbornPerk } from "./perk.mjs"
export { default as HellbornMaleficias } from "./maleficias.mjs"
export { default as HellbornSpeciesTrait } from "./species-trait.mjs"
export { default as HellbornWeapon } from "./weapon.mjs"

136
module/models/character.mjs Normal file
View File

@@ -0,0 +1,136 @@
import { SYSTEM } from "../config/system.mjs"
import HellbornRoll from "../documents/roll.mjs"
export default class HellbornActor extends foundry.abstract.TypeDataModel {
static defineSchema() {
const fields = foundry.data.fields
const requiredInteger = { required: true, nullable: false, integer: true }
const schema = {}
schema.description = new fields.HTMLField({ required: true, textSearch: true })
schema.notes = new fields.HTMLField({ required: true, textSearch: true })
schema.name = new fields.StringField({ required: true, nullable: false, initial: "" })
schema.concept = new fields.StringField({ required: true, nullable: false, initial: "" })
schema.species = new fields.StringField({ required: true, nullable: false, initial: "" })
schema.archetype = new fields.StringField({ required: true, nullable: false, initial: "" })
// Carac
const skillField = (label) => {
const schema = {
value: new fields.NumberField({ ...requiredInteger, initial: 0, min: 0, max: 5 }),
label: new fields.StringField({ required: true, nullable: false, initial: label })
}
return new fields.SchemaField(schema, { label })
}
schema.skills = new fields.SchemaField(
Object.values(SYSTEM.SKILLS).reduce((obj, characteristic) => {
obj[characteristic.id] = skillField(characteristic.label)
return obj
}, {}),
)
schema.heroPoints = new fields.NumberField({ ...requiredInteger, initial: 0, min: 0 })
schema.health = new fields.SchemaField({
staminaValue: new fields.NumberField({ ...requiredInteger, initial: 1, min: 0 }),
staminaMax: new fields.NumberField({ ...requiredInteger, initial: 1, min: 0 }),
wounds: new fields.NumberField({ ...requiredInteger, initial:0, min: 0 }),
triageResults: new fields.StringField({ required: true, nullable: false, initial: "none", choices: SYSTEM.TRIAGE_RESULTS })
})
schema.enc = new fields.SchemaField({
value: new fields.NumberField({ ...requiredInteger, initial: 0, min: 0 }),
max: new fields.NumberField({ ...requiredInteger, initial: 0, min: 0 })
})
schema.armor = new fields.SchemaField({
value: new fields.NumberField({ ...requiredInteger, initial: 0, min: 0 })
})
schema.credits = new fields.NumberField({ ...requiredInteger, initial: 0, min: 0 })
schema.rank = new fields.SchemaField({
experienced: new fields.NumberField({ ...requiredInteger, initial: 0, min: 0, max: 5 }),
expert: new fields.NumberField({ ...requiredInteger, initial: 0, min: 0, max: 5 }),
veteran: new fields.NumberField({ ...requiredInteger, initial: 0, min: 0, max: 5 }),
elite: new fields.NumberField({ ...requiredInteger, initial: 0, min: 0, max: 5 }),
legend: new fields.NumberField({ ...requiredInteger, initial: 0, min: 0, max: 5 })
})
schema.biodata = new fields.SchemaField({
age: new fields.NumberField({ ...requiredInteger, initial: 15, min: 6 }),
height: new fields.NumberField({ ...requiredInteger, initial: 170, min: 50 }),
weight: new fields.NumberField({ ...requiredInteger, initial: 70, min: 1 }),
gender: new fields.StringField({ required: true, nullable: false, initial: "" }),
home: new fields.StringField({ required: true, nullable: false, initial: "" }),
birthplace: new fields.StringField({ required: true, nullable: false, initial: "" }),
eyes: new fields.StringField({ required: true, nullable: false, initial: "" }),
hair: new fields.StringField({ required: true, nullable: false, initial: "" })
})
return schema
}
/** @override */
static LOCALIZATION_PREFIXES = ["HELLBORN.Character"]
prepareDerivedData() {
super.prepareDerivedData();
let encMax = 10 + (2*this.skills.physical.value)
if (encMax !== this.enc.max) {
this.enc.max = encMax
}
let enc = 0
let armor = 0
for (let i of this.parent.items) {
if (i.system?.enc) {
enc += i.system.enc
}
if ( i.system?.protection) {
armor += i.system.protection
}
}
if (enc !== this.enc.value) {
this.enc.value = enc
}
if (armor !== this.armor.value) {
this.armor.value = armor
}
let staminaMax = 14 + (3*this.skills.physical.value)
if (staminaMax !== this.health.staminaMax) {
this.health.staminaMax = staminaMax
}
}
isEncumbered() {
return this.enc.value > this.enc.max
}
/** */
/**
* Rolls a dice for a character.
* @param {("save"|"resource|damage")} rollType The type of the roll.
* @param {number} rollItem The target value for the roll. Which caracteristic or resource. If the roll is a damage roll, this is the id of the item.
* @returns {Promise<null>} - A promise that resolves to null if the roll is cancelled.
*/
async roll(rollType, rollItem) {
let opponentTarget
const hasTarget = opponentTarget !== undefined
let roll = await HellbornRoll.prompt({
rollType,
rollItem,
actorId: this.parent.id,
actorName: this.parent.name,
actorImage: this.parent.img,
talents: this.parent.items.filter(i => i.type === "talent" && i.system.isAdvantage),
isEncumbered: this.isEncumbered(),
hasTarget,
target: opponentTarget
})
if (!roll) return null
await roll.toMessage({}, { rollMode: roll.options.rollMode })
}
}

View File

@@ -0,0 +1,72 @@
import { SYSTEM } from "../config/system.mjs"
import HellbornRoll from "../documents/roll.mjs"
export default class HellbornCreature extends foundry.abstract.TypeDataModel {
static defineSchema() {
const fields = foundry.data.fields
const requiredInteger = { required: true, nullable: false, integer: true }
const schema = {}
// Carac
const skillField = (label) => {
const schema = {
value: new fields.NumberField({ ...requiredInteger, initial: 0, min: 0, max: 5 }),
label: new fields.StringField({ required: true, nullable: false, initial: label }),
enabled: new fields.BooleanField({ required: true, initial: true }),
}
return new fields.SchemaField(schema, { label })
}
schema.skills = new fields.SchemaField(
Object.values(SYSTEM.SKILLS).reduce((obj, characteristic) => {
obj[characteristic.id] = skillField(characteristic.label)
return obj
}, {}),
)
schema.terrain = new fields.StringField({ required: true, nullable: false, initial: "cave", choices: SYSTEM.CREATURE_TERRAIN_TYPES })
schema.niche = new fields.StringField({ required: true, nullable: false, initial: "prey", choices: SYSTEM.CREATURE_NICHES })
schema.size = new fields.StringField({ required: true, nullable: false, initial: "small", choices: SYSTEM.CREATURE_SIZES })
schema.numberAppearing = new fields.StringField({ required: true, initial: "1d6" })
schema.health = new fields.SchemaField({
staminaValue: new fields.NumberField({ ...requiredInteger, initial: 1, min: 0 }),
staminaMax: new fields.NumberField({ ...requiredInteger, initial: 1, min: 1 }),
})
schema.damage = new fields.StringField({ required: true, initial: "1d6" })
schema.description = new fields.HTMLField({ required: true, textSearch: true })
schema.notes = new fields.HTMLField({ required: true, textSearch: true })
return schema
}
/** @override */
static LOCALIZATION_PREFIXES = ["HELLBORN.Creature"]
isEncumbered() {
return false
}
async roll(rollType, rollItem) {
let opponentTarget
const hasTarget = opponentTarget !== undefined
let roll = await HellbornRoll.prompt({
rollType,
rollItem,
actorId: this.parent.id,
actorName: this.parent.name,
actorImage: this.parent.img,
traits: this.parent.items.filter(i => i.type === "creature-trait" && i.system.isAdvantage),
abilities: this.parent.items.filter(i => i.type === "creature-ability" && i.system.isAdvantage),
isEncumbered: this.isEncumbered(),
hasTarget,
target: opponentTarget
})
if (!roll) return null
await roll.toMessage({}, { rollMode: roll.options.rollMode })
}
}

View File

@@ -0,0 +1,22 @@
import { SYSTEM } from "../config/system.mjs"
export default class HellbornEquipment extends foundry.abstract.TypeDataModel {
static defineSchema() {
const fields = foundry.data.fields
const schema = {}
const requiredInteger = { required: true, nullable: false, integer: true }
schema.description = new fields.HTMLField({ required: true, textSearch: true })
schema.techAge = new fields.StringField({ required: true, choices: SYSTEM.TECH_AGES, initial : "lateatomic" })
schema.enc = new fields.NumberField({ ...requiredInteger, required: true, initial: 0, min: 0 })
schema.cost = new fields.NumberField({ required: true, initial: 0, min: 0 })
return schema
}
/** @override */
static LOCALIZATION_PREFIXES = ["HELLBORN.Equipment"]
}

View File

@@ -0,0 +1,22 @@
import { SYSTEM } from "../config/system.mjs"
export default class HellbornMaleficias extends foundry.abstract.TypeDataModel {
static defineSchema() {
const fields = foundry.data.fields
const schema = {}
const requiredInteger = { required: true, nullable: false, integer: true }
schema.description = new fields.HTMLField({ required: true, textSearch: true })
schema.techAge = new fields.StringField({ required: true, choices: SYSTEM.TECH_AGES, initial : "lateatomic" })
schema.enc = new fields.NumberField({ ...requiredInteger, required: true, initial: 0, min: 0 })
schema.cost = new fields.NumberField({ required: true, initial: 0, min: 0 })
return schema
}
/** @override */
static LOCALIZATION_PREFIXES = ["HELLBORN.Implant"]
}

17
module/models/perk.mjs Normal file
View File

@@ -0,0 +1,17 @@
import { SYSTEM } from "../config/system.mjs"
export default class HellbornPerk extends foundry.abstract.TypeDataModel {
static defineSchema() {
const fields = foundry.data.fields
const schema = {}
const requiredInteger = { required: true, nullable: false, integer: true }
schema.description = new fields.HTMLField({ required: true, textSearch: true })
return schema
}
/** @override */
static LOCALIZATION_PREFIXES = ["HELLBORN.Psionic"]
}

20
module/models/ritual.mjs Normal file
View File

@@ -0,0 +1,20 @@
import { SYSTEM } from "../config/system.mjs"
export default class HellbornRitual extends foundry.abstract.TypeDataModel {
static defineSchema() {
const fields = foundry.data.fields
const requiredInteger = { required: true, nullable: false, integer: true }
const schema = {}
schema.description = new fields.HTMLField({
required: false,
blank: true,
initial: "",
textSearch: true,
})
return schema
}
/** @override */
static LOCALIZATION_PREFIXES = ["HELLBORN.Language"]
}

View File

@@ -0,0 +1,16 @@
import { SYSTEM } from "../config/system.mjs";
export default class HellbornSpeciesTrait extends foundry.abstract.TypeDataModel {
static defineSchema() {
const fields = foundry.data.fields;
const schema = {};
schema.isAdvantage = new fields.BooleanField({ required: true, initial: false });
schema.description = new fields.HTMLField({ required: true, textSearch: true })
return schema;
}
/** @override */
static LOCALIZATION_PREFIXES = ["HELLBORN.CreatureTrait"];
}

55
module/models/vehicle.mjs Normal file
View File

@@ -0,0 +1,55 @@
import { SYSTEM } from "../config/system.mjs"
import HellbornRoll from "../documents/roll.mjs"
export default class HellbornVehicle extends foundry.abstract.TypeDataModel {
static defineSchema() {
const fields = foundry.data.fields
const requiredInteger = { required: true, nullable: false, integer: true }
const schema = {}
schema.agility = new fields.NumberField({ ...requiredInteger, initial: 0, min: 0 })
schema.armor = new fields.StringField({ required: true, initial: "" })
schema.cargo = new fields.NumberField({ ...requiredInteger, initial: 0, min: 0 })
schema.crew = new fields.NumberField({ ...requiredInteger, initial: 1, min: 1 })
schema.force = new fields.NumberField({ ...requiredInteger, initial: 1, min: 1 })
schema.range = new fields.StringField({ required: true, initial: "1d6" })
schema.speed = new fields.StringField({ required: true, initial: "1d6" })
schema.techAge = new fields.StringField({ required: true, initial: "1d6" })
schema.tonnage = new fields.NumberField({ required: true, initial: 1, min: 0 })
schema.damages = new fields.StringField({ required: true, initial: "" })
schema.cost = new fields.NumberField({ required: true, initial: 0, min: 0 })
schema.description = new fields.HTMLField({ required: true, textSearch: true })
schema.notes = new fields.HTMLField({ required: true, textSearch: true })
return schema
}
/** @override */
static LOCALIZATION_PREFIXES = ["HELLBORN.Vehicle"]
isEncumbered() {
return false
}
async roll(rollType, rollItem) {
let opponentTarget
const hasTarget = opponentTarget !== undefined
let roll = await HellbornRoll.prompt({
rollType,
rollItem,
actorId: this.parent.id,
actorName: this.parent.name,
actorImage: this.parent.img,
isEncumbered: this.isEncumbered(),
hasTarget,
target: opponentTarget
})
if (!roll) return null
await roll.toMessage({}, { rollMode: roll.options.rollMode })
}
}

37
module/models/weapon.mjs Normal file
View File

@@ -0,0 +1,37 @@
import { SYSTEM } from "../config/system.mjs"
export default class HellbornWeapon extends foundry.abstract.TypeDataModel {
static defineSchema() {
const fields = foundry.data.fields
const schema = {}
const requiredInteger = { required: true, nullable: false, integer: true }
schema.description = new fields.HTMLField({ required: true, textSearch: true })
schema.techAge = new fields.StringField({ required: true, choices: SYSTEM.TECH_AGES, initial : "lateatomic" })
schema.weaponType = new fields.StringField({ required: true, initial: "melee", choices: SYSTEM.WEAPON_TYPES })
schema.rangeType = new fields.StringField({ required: true, initial: "melee", choices: SYSTEM.WEAPON_RANGE })
schema.damage = new fields.StringField({required: true, initial: "1d6"})
schema.magazine = new fields.NumberField({ required: true, initial: 1, min: 0 })
schema.range = new fields.SchemaField({
close: new fields.NumberField({ ...requiredInteger, initial: 0 }),
near: new fields.NumberField({ ...requiredInteger, initial: 0 }),
far: new fields.NumberField({ ...requiredInteger, initial: 0 }),
dist: new fields.NumberField({ ...requiredInteger, initial: 0 }),
})
schema.enc = new fields.NumberField({ required: true, initial: 0, min: 0 })
schema.aspect = new fields.StringField({ required: true, initial: ""})
schema.cost = new fields.NumberField({ required: true, initial: 0, min: 0 })
schema.ammoCost = new fields.NumberField({ required: true, initial: 0, min: 0 })
return schema
}
/** @override */
static LOCALIZATION_PREFIXES = ["FTLNOMAD.Weapon"]
}

13
module/socket.mjs Normal file
View File

@@ -0,0 +1,13 @@
/**
* Handles socket events based on the provided action.
*
* @param {Object} [params={}] The parameters for the socket event.
* @param {string|null} [params.action=null] The action to be performed.
* @param {Object} [params.data={}] The data associated with the action.
* @returns {*} The result of the action handler, if applicable.
*/
export function handleSocketEvent({ action = null, data = {} } = {}) {
console.debug("handleSocketEvent", action, data)
}

198
module/utils.mjs Normal file
View File

@@ -0,0 +1,198 @@
import { SYSTEM } from "./config/system.mjs"
export default class HellbornUtils {
static registerSettings() {
game.settings.register("fvtt-hellborn", "settings-era", {
name: game.i18n.localize("FTLNOMAD.Settings.era"),
hint: game.i18n.localize("HELLBORN.Settings.eraHint"),
default: "jazz",
scope: "world",
type: String,
choices: SYSTEM.AVAILABLE_SETTINGS,
config: true,
onChange: _ => window.location.reload()
});
}
static async loadCompendiumData(compendium) {
const pack = game.packs.get(compendium)
return await pack?.getDocuments() ?? []
}
static async loadCompendium(compendium, filter = item => true) {
let compendiumData = await HellbornUtils.loadCompendiumData(compendium)
return compendiumData.filter(filter)
}
static registerHandlebarsHelpers() {
Handlebars.registerHelper('isNull', function (val) {
return val == null;
});
Handlebars.registerHelper('exists', function (val) {
return val != null && val !== undefined;
});
Handlebars.registerHelper('isEmpty', function (list) {
if (list) return list.length === 0;
else return false;
});
Handlebars.registerHelper('notEmpty', function (list) {
return list.length > 0;
});
Handlebars.registerHelper('isNegativeOrNull', function (val) {
return val <= 0;
});
Handlebars.registerHelper('isNegative', function (val) {
return val < 0;
});
Handlebars.registerHelper('isPositive', function (val) {
return val > 0;
});
Handlebars.registerHelper('equals', function (val1, val2) {
return val1 === val2;
});
Handlebars.registerHelper('neq', function (val1, val2) {
return val1 !== val2;
});
Handlebars.registerHelper('gt', function (val1, val2) {
return val1 > val2;
})
Handlebars.registerHelper('lt', function (val1, val2) {
return val1 < val2;
})
Handlebars.registerHelper('gte', function (val1, val2) {
return val1 >= val2;
})
Handlebars.registerHelper('lte', function (val1, val2) {
return val1 <= val2;
})
Handlebars.registerHelper('and', function (val1, val2) {
return val1 && val2;
})
Handlebars.registerHelper('or', function (val1, val2) {
return val1 || val2;
})
Handlebars.registerHelper('or3', function (val1, val2, val3) {
return val1 || val2 || val3;
})
Handlebars.registerHelper('for', function (from, to, incr, block) {
let accum = '';
for (let i = from; i < to; i += incr)
accum += block.fn(i);
return accum;
})
Handlebars.registerHelper('not', function (cond) {
return !cond;
})
Handlebars.registerHelper('count', function (list) {
return list.length;
})
Handlebars.registerHelper('countKeys', function (obj) {
return Object.keys(obj).length;
})
Handlebars.registerHelper('isEnabled', function (configKey) {
return game.settings.get("bol", configKey);
})
Handlebars.registerHelper('split', function (str, separator, keep) {
return str.split(separator)[keep];
})
// If you need to add Handlebars helpers, here are a few useful examples:
Handlebars.registerHelper('concat', function () {
let outStr = '';
for (let arg in arguments) {
if (typeof arguments[arg] != 'object') {
outStr += arguments[arg];
}
}
return outStr;
})
Handlebars.registerHelper('add', function (a, b) {
return parseInt(a) + parseInt(b);
});
Handlebars.registerHelper('mul', function (a, b) {
return parseInt(a) * parseInt(b);
})
Handlebars.registerHelper('sub', function (a, b) {
return parseInt(a) - parseInt(b);
})
Handlebars.registerHelper('abbrev2', function (a) {
return a.substring(0, 2);
})
Handlebars.registerHelper('abbrev3', function (a) {
return a.substring(0, 3);
})
Handlebars.registerHelper('valueAtIndex', function (arr, idx) {
return arr[idx];
})
Handlebars.registerHelper('includesKey', function (items, type, key) {
return items.filter(i => i.type === type).map(i => i.system.key).includes(key);
})
Handlebars.registerHelper('includes', function (array, val) {
return array.includes(val);
})
Handlebars.registerHelper('eval', function (expr) {
return eval(expr);
})
Handlebars.registerHelper('isOwnerOrGM', function (actor) {
console.log("Testing actor", actor.isOwner, game.userId)
return actor.isOwner || game.isGM;
})
Handlebars.registerHelper('upperFirst', function (text) {
if (typeof text !== 'string') return text
return text.charAt(0).toUpperCase() + text.slice(1)
})
Handlebars.registerHelper('upperFirstOnly', function (text) {
if (typeof text !== 'string') return text
return text.charAt(0).toUpperCase()
})
Handlebars.registerHelper('isCreature', function (key) {
return key === "creature" || key === "daemon";
})
// Handle v12 removal of this helper
Handlebars.registerHelper('select', function (selected, options) {
const escapedValue = RegExp.escape(Handlebars.escapeExpression(selected));
const rgx = new RegExp(' value=[\"\']' + escapedValue + '[\"\']');
const html = options.fn(this);
return html.replace(rgx, "$& selected");
});
}
static setupCSSRootVariables() {
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-size-standard', eraCSS.baseFontSize);
document.documentElement.style.setProperty('--font-size-title', eraCSS.titleFontSize);
document.documentElement.style.setProperty('--font-size-result', eraCSS.titleFontSize);
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('--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")`);
}
}