Update sheets and fix basic bugs

This commit is contained in:
2024-12-04 15:16:33 +01:00
parent 1cc3a0bc21
commit eaba806fec
33 changed files with 453 additions and 696 deletions

View File

@ -32,8 +32,7 @@ export default class CthulhuEternalActorSheet extends HandlebarsApplicationMixin
editImage: CthulhuEternalActorSheet.#onEditImage,
toggleSheet: CthulhuEternalActorSheet.#onToggleSheet,
edit: CthulhuEternalActorSheet.#onItemEdit,
delete: CthulhuEternalActorSheet.#onItemDelete,
createSpell: CthulhuEternalActorSheet.#onCreateSpell,
delete: CthulhuEternalActorSheet.#onItemDelete
},
}
@ -109,7 +108,9 @@ export default class CthulhuEternalActorSheet extends HandlebarsApplicationMixin
* @param {DragEvent} event The originating DragEvent
* @protected
*/
async _onDrop(event) {}
async _onDrop(event) {
}
/**
* Define whether a user is able to begin a dragstart workflow for a given drag selector
@ -128,7 +129,7 @@ export default class CthulhuEternalActorSheet extends HandlebarsApplicationMixin
* @protected
*/
_canDragDrop(selector) {
return this.isEditable && this.document.isOwner
return true //this.isEditable && this.document.isOwner
}
/**
@ -203,6 +204,7 @@ export default class CthulhuEternalActorSheet extends HandlebarsApplicationMixin
_onDragOver(event) {}
async _onDropItem(item) {
console.log("Dropped item", item)
let itemData = item.toObject()
await this.document.createEmbeddedDocuments("Item", [itemData], { renderSheet: false })
}
@ -272,20 +274,8 @@ export default class CthulhuEternalActorSheet extends HandlebarsApplicationMixin
*/
static async #onItemDelete(event, target) {
const itemUuid = target.getAttribute("data-item-uuid")
const talent = await fromUuid(itemUuid)
await talent.deleteDialog()
}
/**
* Handles the creation of a new attack item.
*
* @param {Event} event The event that triggered the creation of the attack.
* @param {Object} target The target object where the attack will be created.
* @private
* @static
*/
static #onCreateSpell(event, target) {
const item = this.document.createEmbeddedDocuments("Item", [{ name: "Nouveau sortilège", type: "spell" }])
const item = await fromUuid(itemUuid)
await item.deleteDialog()
}
// #endregion

View File

@ -19,22 +19,25 @@ export default class CthulhuEternalProtagonistSheet extends CthulhuEternalActorS
/** @override */
static PARTS = {
main: {
template: "systems/fvtt-cthulhu-eternal/templates/character-main.hbs",
template: "systems/fvtt-cthulhu-eternal/templates/protagonist-main.hbs",
},
tabs: {
template: "systems/fvtt-cthulhu-eternal/templates/generic/tab-navigation.hbs",
template: "templates/generic/tab-navigation.hbs",
},
items: {
template: "systems/fvtt-cthulhu-eternal/templates/character-items.hbs",
skills: {
template: "systems/fvtt-cthulhu-eternal/templates/protagonist-skills.hbs",
},
equipment: {
template: "systems/fvtt-cthulhu-eternal/templates/protagonist-equipment.hbs",
},
biography: {
template: "systems/fvtt-cthulhu-eternal/templates/character-biography.hbs",
template: "systems/fvtt-cthulhu-eternal/templates/protagonist-biography.hbs",
},
}
/** @override */
tabGroups = {
sheet: "items",
sheet: "skills",
}
/**
@ -43,8 +46,9 @@ export default class CthulhuEternalProtagonistSheet extends CthulhuEternalActorS
*/
#getTabs() {
const tabs = {
items: { id: "items", group: "sheet", icon: "fa-solid fa-shapes", label: "CTHULHUETERNAL.Character.Label.details" },
biography: { id: "biography", group: "sheet", icon: "fa-solid fa-book", label: "CTHULHUETERNAL.Character.Label.biography" },
skills: { id: "skills", group: "sheet", icon: "fa-solid fa-shapes", label: "CTHULHUETERNAL.Label.skills" },
equipment: { id: "equipment", group: "sheet", icon: "fa-solid fa-shapes", label: "CTHULHUETERNAL.Label.equipment" },
biography: { id: "biography", group: "sheet", icon: "fa-solid fa-book", label: "CTHULHUETERNAL.Label.biography" },
}
for (const v of Object.values(tabs)) {
v.active = this.tabGroups[v.group] === v.id
@ -58,13 +62,25 @@ export default class CthulhuEternalProtagonistSheet extends CthulhuEternalActorS
const context = await super._prepareContext()
context.tabs = this.#getTabs()
context.tooltipsCaracteristiques = {
context.tooltipsCharacteristic = {
str: game.i18n.localize("CTHULHUETERNAL.Characteristic.Str"),
dex: game.i18n.localize("CTHULHUETERNAL.Characteristic.Dex"),
con: game.i18n.localize("CTHULHUETERNAL.Characteristic.Con"),
int: game.i18n.localize("CTHULHUETERNAL.Characteristic.Int"),
pow: game.i18n.localize("CTHULHUETERNAL.Characteristic.Pow"),
cha: game.i18n.localize("CTHULHUETERNAL.Characteristic.Cha")
}
context.tooltipsRessources = {
}
context.rollType = {
str: "characteristic",
dex: "characteristic",
con: "characteristic",
int: "characteristic",
pow: "characteristic",
cha: "characteristic"
}
return context
}
@ -77,14 +93,16 @@ export default class CthulhuEternalProtagonistSheet extends CthulhuEternalActorS
const doc = this.document
switch (partId) {
case "main":
context.enrichedBiens = await TextEditor.enrichHTML(doc.system.biens, { async: true })
break
case "items":
context.tab = context.tabs.items
case "skills":
context.tab = context.tabs.skills
context.skills = doc.itemTypes.skill
break
case "equipment":
context.tab = context.tabs.equipment
context.weapons = doc.itemTypes.weapon
context.armors = doc.itemTypes.armor
context.spells = doc.itemTypes.spell
context.hasSpells = context.spells.length > 0
context.gears = doc.itemTypes.gear
break
case "biography":
context.tab = context.tabs.biography
@ -95,34 +113,6 @@ export default class CthulhuEternalProtagonistSheet extends CthulhuEternalActorS
return context
}
// #region Drag-and-Drop Workflow
/**
* Callback actions which occur when a dragged element is dropped on a target.
* @param {DragEvent} event The originating DragEvent
* @protected
*/
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)
if (!["path", "weapon", "armor", "spell"].includes(item.type)) return
if (item.type === "path") return this.#onDropPathItem(item)
if (item.type === "weapon") return super._onDropItem(item)
if (item.type === "armor") return this._onDropItem(item)
if (item.type === "spell") return this._onDropItem(item)
}
}
async #onDropPathItem(item) {
await this.document.addPath(item)
}
/**
* Creates a new attack item directly from the sheet and embeds it into the document.
* @param {Event} event The initiating click event.
@ -169,5 +159,18 @@ export default class CthulhuEternalProtagonistSheet extends CthulhuEternalActorS
}
await this.document.system.roll(rollType, rollTarget)
}
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)
}
}
// #endregion
}

View File

@ -39,6 +39,7 @@ export const SYSTEM = {
id: SYSTEM_ID,
CHARACTERISTICS: PROTAGONIST.CHARACTERISTICS,
WEAPON_TYPE: WEAPON.WEAPON_TYPE,
WEAPON_SUBTYPE: WEAPON.WEAPON_SUBTYPE,
BOND_TYPE: BOND.BOND_TYPE,
AVAILABLE_SETTINGS,
ASCII

View File

@ -1,6 +1,17 @@
export const WEAPON_TYPE = {
"melee": "CTHULHUETERNAL.Weapon.WeaponType.melee",
"ranged": "CTHULHUETERNAL.Weapon.WeaponType.ranged"
"rangedprimitive": "CTHULHUETERNAL.Weapon.WeaponType.rangedprimitive",
"rangedthrown": "CTHULHUETERNAL.Weapon.WeaponType.rangedthrown",
"rangedfirearm": "CTHULHUETERNAL.Weapon.WeaponType.rangedfirearm",
"unarmed": "CTHULHUETERNAL.Weapon.WeaponType.unarmed"
}
export const WEAPON_SUBTYPE = {
"basicfirearm": "CTHULHUETERNAL.Weapon.WeaponSubtype.basicfirearm",
"pistol": "CTHULHUETERNAL.Weapon.WeaponSubtype.pistol",
"shotgun": "CTHULHUETERNAL.Weapon.WeaponSubtype.shotgun",
"submachinegun": "CTHULHUETERNAL.Weapon.WeaponSubtype.submachinegun",
"riflecarabine": "CTHULHUETERNAL.Weapon.WeaponSubtype.riflecarabine",
}
export const WEAPON_RANGE_UNIT = {

View File

@ -1,6 +1,6 @@
import { SYSTEM } from "../config/system.mjs"
export default class CthulhuEternalEquipment extends foundry.abstract.TypeDataModel {
export default class CthulhuEternalGHear extends foundry.abstract.TypeDataModel {
static defineSchema() {
const fields = foundry.data.fields
const schema = {}
@ -14,6 +14,6 @@ export default class CthulhuEternalEquipment extends foundry.abstract.TypeDataMo
}
/** @override */
static LOCALIZATION_PREFIXES = ["CTHULHUETERNAL.Equipment"]
static LOCALIZATION_PREFIXES = ["CTHULHUETERNAL.Gear"]
}

View File

@ -35,6 +35,7 @@ export default class CthulhuEternalProtagonist extends foundry.abstract.TypeData
schema.hp = new fields.SchemaField({
value: new fields.NumberField({ ...requiredInteger, initial: 0, min: 0 }),
max: new fields.NumberField({ ...requiredInteger, initial: 0, min: 0 }),
stunned: new fields.BooleanField({ required: true, initial: false })
})
schema.san = new fields.SchemaField({

View File

@ -27,39 +27,21 @@ export default class LethalFantasySkill extends foundry.abstract.TypeDataModel {
computeBase() {
let actor = this.parent?.actor;
if (Number(this.base)) {
return Number(this.base) + this.bonus;
}
if (!actor) {
return `${this.base } + ${ String(this.bonus)}`;
return `${this.base} + ${ String(this.bonus)}`;
}
// Split the base value per stat : WIS,DEX,STR,INT,CHA (example)
const base = this.base;
let baseSplit = base.split(",");
let baseSplitLength = baseSplit.length;
if ( baseSplitLength > 0) {
// Select the max stat value from the parent actor
let maxStat = 0;
for (let i = 0; i < baseSplitLength; i++) {
const stat = baseSplit[i];
const statValue = actor.system.characteristics[stat.toLowerCase()]?.value || 0;
if (statValue > maxStat) {
maxStat = statValue;
}
}
return maxStat;
} else {
// Split with + calculate the total
baseSplit = base.split("+");
baseSplitLength = baseSplit.length;
if ( baseSplitLength > 0) {
let total = 0;
for (let i = 0; i < baseSplitLength; i++) {
const stat = baseSplit[i];
const statValue = actor.system.characteristics[stat.toLowerCase()]?.value || 0;
total += statValue;
}
return total
}
let base = this.base.toLowerCase();
let char = actor.system.characteristics[base];
if (!char) {
ui.notifications.error(`The characteristic ${base} is wrong for actor ${actor.name}`);
return `${this.base } + ${ String(this.bonus)}`;
}
return `${this.base } + ${ String(this.bonus)}`;
let charValue = char.value;
return charValue + this.bonus
}
}

View File

@ -15,6 +15,8 @@ export default class LethalFantasySkill extends foundry.abstract.TypeDataModel {
schema.rangeUnit = new fields.StringField({ required: true, initial: "yard", choices: SYSTEM.WEAPON_RANGE_UNIT })
schema.lethality = new fields.NumberField({ required: true, initial: 0, min: 0 })
schema.killRadius = new fields.NumberField({ required: true, initial: 0, min: 0 })
schema.armorPiercing = new fields.NumberField({ required: true, initial: 0, min: 0 })
schema.weaponSubtype = new fields.StringField({ required: true, initial: "basicfirearm", choices: SYSTEM.WEAPON_SUBTYPE })
schema.resourceLevel = new fields.NumberField({ required: true, initial: 0, min: 0 })