mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-03-10 11:13:05 +01:00
Reworked beastform to hold it's data entirely in the beastformEffect
This commit is contained in:
parent
3186468f28
commit
51bd7c18af
7 changed files with 76 additions and 60 deletions
|
|
@ -1189,6 +1189,7 @@
|
||||||
"LevelUp": "You can level up",
|
"LevelUp": "You can level up",
|
||||||
"Features": "Features",
|
"Features": "Features",
|
||||||
"CompanionFeatures": "Companion Features",
|
"CompanionFeatures": "Companion Features",
|
||||||
|
"beastformFeatures": "Beastform Features",
|
||||||
"Tabs": {
|
"Tabs": {
|
||||||
"Features": "Features",
|
"Features": "Features",
|
||||||
"Inventory": "Inventory",
|
"Inventory": "Inventory",
|
||||||
|
|
|
||||||
|
|
@ -307,7 +307,7 @@ export default class CharacterSheet extends DaggerheartSheet(ActorSheetV2) {
|
||||||
const itemId = listElement.dataset.itemId;
|
const itemId = listElement.dataset.itemId;
|
||||||
if (listElement.dataset.type === 'effect') {
|
if (listElement.dataset.type === 'effect') {
|
||||||
return this.document.effects.get(itemId);
|
return this.document.effects.get(itemId);
|
||||||
} else if (listElement.dataset.type === 'features') {
|
} else if (['armor', 'weapon', 'feature', 'consumable', 'miscellaneous'].includes(listElement.dataset.type)) {
|
||||||
return this.document.items.get(itemId);
|
return this.document.items.get(itemId);
|
||||||
} else {
|
} else {
|
||||||
return this.document.system[listElement.dataset.type].system.actions.find(x => x.id === itemId);
|
return this.document.system[listElement.dataset.type].system.actions.find(x => x.id === itemId);
|
||||||
|
|
@ -618,7 +618,9 @@ export default class CharacterSheet extends DaggerheartSheet(ActorSheetV2) {
|
||||||
if (!item) return;
|
if (!item) return;
|
||||||
|
|
||||||
// Should dandle its actions. Or maybe they'll be separate buttons as per an Issue on the board
|
// Should dandle its actions. Or maybe they'll be separate buttons as per an Issue on the board
|
||||||
if (item.type === 'feature' || item instanceof ActiveEffect) {
|
if (item.type === 'feature') {
|
||||||
|
item.use(event);
|
||||||
|
} else if (item instanceof ActiveEffect) {
|
||||||
item.toChat(this);
|
item.toChat(this);
|
||||||
} else {
|
} else {
|
||||||
const wasUsed = await item.use(event);
|
const wasUsed = await item.use(event);
|
||||||
|
|
|
||||||
|
|
@ -19,12 +19,16 @@ export default class BeastformSheet extends DHBaseItemSheet {
|
||||||
features: {
|
features: {
|
||||||
template: 'systems/daggerheart/templates/sheets/global/tabs/tab-features.hbs',
|
template: 'systems/daggerheart/templates/sheets/global/tabs/tab-features.hbs',
|
||||||
scrollable: ['.features']
|
scrollable: ['.features']
|
||||||
|
},
|
||||||
|
effects: {
|
||||||
|
template: 'systems/daggerheart/templates/sheets/global/tabs/tab-effects.hbs',
|
||||||
|
scrollable: ['.effects']
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
static TABS = {
|
static TABS = {
|
||||||
primary: {
|
primary: {
|
||||||
tabs: [{ id: 'settings' }, { id: 'features' }],
|
tabs: [{ id: 'settings' }, { id: 'features' }, { id: 'effects' }],
|
||||||
initial: 'settings',
|
initial: 'settings',
|
||||||
labelPrefix: 'DAGGERHEART.Sheets.TABS'
|
labelPrefix: 'DAGGERHEART.Sheets.TABS'
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -786,14 +786,12 @@ export class DhBeastformAction extends DHBaseAction {
|
||||||
}
|
}
|
||||||
|
|
||||||
async handleActiveTransformations() {
|
async handleActiveTransformations() {
|
||||||
const activeBeastforms = this.actor.items.filter(x => x.type === 'beastform');
|
const beastformEffects = this.actor.effects.filter(x => x.type === 'beastform');
|
||||||
if (activeBeastforms.length > 0) {
|
if (beastformEffects.length > 0) {
|
||||||
for (let form of activeBeastforms) {
|
for (let effect of beastformEffects) {
|
||||||
await form.delete();
|
await effect.delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.actor.effects.filter(x => x.type === 'beastform').forEach(x => x.delete());
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,45 @@
|
||||||
|
import { updateActorTokens } from '../../helpers/utils.mjs';
|
||||||
|
|
||||||
export default class BeastformEffect extends foundry.abstract.TypeDataModel {
|
export default class BeastformEffect extends foundry.abstract.TypeDataModel {
|
||||||
static defineSchema() {
|
static defineSchema() {
|
||||||
const fields = foundry.data.fields;
|
const fields = foundry.data.fields;
|
||||||
return {
|
return {
|
||||||
isBeastform: new fields.BooleanField({ initial: false })
|
isBeastform: new fields.BooleanField({ initial: false }),
|
||||||
|
characterTokenData: new fields.SchemaField({
|
||||||
|
tokenImg: new fields.FilePathField({
|
||||||
|
categories: ['IMAGE'],
|
||||||
|
base64: false,
|
||||||
|
nullable: true
|
||||||
|
}),
|
||||||
|
tokenSize: new fields.SchemaField({
|
||||||
|
height: new fields.NumberField({ integer: true, nullable: true }),
|
||||||
|
width: new fields.NumberField({ integer: true, nullable: true })
|
||||||
|
})
|
||||||
|
}),
|
||||||
|
advantageOn: new fields.ArrayField(new fields.StringField()),
|
||||||
|
featureIds: new fields.ArrayField(new fields.StringField()),
|
||||||
|
effectIds: new fields.ArrayField(new fields.StringField())
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
async _preDelete() {
|
async _preDelete() {
|
||||||
if (this.parent.parent.type === 'character') {
|
if (this.parent.parent.type === 'character') {
|
||||||
for (let item of this.parent.parent.items) {
|
const update = {
|
||||||
if (item.type === 'beastform') {
|
height: this.characterTokenData.tokenSize.height,
|
||||||
await item.delete();
|
width: this.characterTokenData.tokenSize.width,
|
||||||
|
texture: {
|
||||||
|
src: this.characterTokenData.tokenImg
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
await updateActorTokens(this.parent.parent, update);
|
||||||
|
|
||||||
|
for (var feature of this.parent.parent.items.filter(x => this.featureIds.includes(x.id))) {
|
||||||
|
await feature.delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
for (var effect of this.parent.parent.effects.filter(x => this.effectIds.includes(x.id))) {
|
||||||
|
await effect.delete();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -33,18 +33,6 @@ export default class DHBeastform extends BaseDataItem {
|
||||||
height: new fields.NumberField({ integer: true, min: 1, initial: null, nullable: true }),
|
height: new fields.NumberField({ integer: true, min: 1, initial: null, nullable: true }),
|
||||||
width: new fields.NumberField({ integer: true, min: 1, initial: null, nullable: true })
|
width: new fields.NumberField({ integer: true, min: 1, initial: null, nullable: true })
|
||||||
}),
|
}),
|
||||||
characterTokenData: new fields.SchemaField({
|
|
||||||
tokenImg: new fields.FilePathField({
|
|
||||||
categories: ['IMAGE'],
|
|
||||||
base64: false,
|
|
||||||
nullable: true,
|
|
||||||
initial: null
|
|
||||||
}),
|
|
||||||
tokenSize: new fields.SchemaField({
|
|
||||||
height: new fields.NumberField({ integer: true, initial: null, nullable: true }),
|
|
||||||
width: new fields.NumberField({ integer: true, initial: null, nullable: true })
|
|
||||||
})
|
|
||||||
}),
|
|
||||||
examples: new fields.StringField(),
|
examples: new fields.StringField(),
|
||||||
advantageOn: new fields.ArrayField(new fields.StringField()),
|
advantageOn: new fields.ArrayField(new fields.StringField()),
|
||||||
features: new ForeignDocumentUUIDArrayField({ type: 'Item' })
|
features: new ForeignDocumentUUIDArrayField({ type: 'Item' })
|
||||||
|
|
@ -65,49 +53,44 @@ export default class DHBeastform extends BaseDataItem {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.updateSource({
|
const features = await this.parent.parent.createEmbeddedDocuments(
|
||||||
characterTokenData: {
|
'Item',
|
||||||
tokenImg: this.parent.parent.prototypeToken.texture.src,
|
this.features.map(x => x.toObject())
|
||||||
tokenSize: {
|
);
|
||||||
height: this.parent.parent.prototypeToken.height,
|
const effects = await this.parent.parent.createEmbeddedDocuments(
|
||||||
width: this.parent.parent.prototypeToken.width
|
'ActiveEffect',
|
||||||
}
|
this.parent.effects.map(x => x.toObject())
|
||||||
}
|
);
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
_onCreate(data, options, userId) {
|
await this.parent.parent.createEmbeddedDocuments('ActiveEffect', [
|
||||||
super._onCreate(data, options, userId);
|
|
||||||
|
|
||||||
const update = {
|
|
||||||
height: this.tokenSize.height,
|
|
||||||
width: this.tokenSize.width,
|
|
||||||
texture: {
|
|
||||||
src: this.tokenImg
|
|
||||||
}
|
|
||||||
};
|
|
||||||
updateActorTokens(this.parent.parent, update);
|
|
||||||
|
|
||||||
this.parent.parent.createEmbeddedDocuments('ActiveEffect', [
|
|
||||||
{
|
{
|
||||||
type: 'beastform',
|
type: 'beastform',
|
||||||
name: game.i18n.localize('DAGGERHEART.Sheets.Beastform.beastformEffect'),
|
name: game.i18n.localize('DAGGERHEART.Sheets.Beastform.beastformEffect'),
|
||||||
img: 'icons/creatures/abilities/paw-print-pair-purple.webp',
|
img: 'icons/creatures/abilities/paw-print-pair-purple.webp',
|
||||||
system: {
|
system: {
|
||||||
isBeastform: true
|
isBeastform: true,
|
||||||
|
characterTokenData: {
|
||||||
|
tokenImg: this.parent.parent.prototypeToken.texture.src,
|
||||||
|
tokenSize: {
|
||||||
|
height: this.parent.parent.prototypeToken.height,
|
||||||
|
width: this.parent.parent.prototypeToken.width
|
||||||
|
}
|
||||||
|
},
|
||||||
|
advantageOn: this.advantageOn,
|
||||||
|
featureIds: features.map(x => x.id),
|
||||||
|
effectIds: effects.map(x => x.id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]);
|
]);
|
||||||
}
|
|
||||||
|
|
||||||
async _preDelete() {
|
await updateActorTokens(this.parent.parent, {
|
||||||
const update = {
|
height: this.tokenSize.height,
|
||||||
height: this.characterTokenData.tokenSize.height,
|
width: this.tokenSize.width,
|
||||||
width: this.characterTokenData.tokenSize.width,
|
|
||||||
texture: {
|
texture: {
|
||||||
src: this.characterTokenData.tokenImg
|
src: this.tokenImg
|
||||||
}
|
}
|
||||||
};
|
});
|
||||||
await updateActorTokens(this.parent.parent, update);
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -97,16 +97,16 @@ export default class DHItem extends foundry.documents.Item {
|
||||||
|
|
||||||
async use(event) {
|
async use(event) {
|
||||||
const actions = this.system.actions;
|
const actions = this.system.actions;
|
||||||
let response;
|
|
||||||
if (actions?.length) {
|
if (actions?.length) {
|
||||||
let action = actions[0];
|
let action = actions[0];
|
||||||
if (actions.length > 1 && !event?.shiftKey) {
|
if (actions.length > 1 && !event?.shiftKey) {
|
||||||
// Actions Choice Dialog
|
// Actions Choice Dialog
|
||||||
action = await this.selectActionDialog();
|
action = await this.selectActionDialog();
|
||||||
}
|
}
|
||||||
if (action) response = action.use(event);
|
if (action) return action.use(event);
|
||||||
}
|
}
|
||||||
return response;
|
|
||||||
|
return this.toChat();
|
||||||
}
|
}
|
||||||
|
|
||||||
async toChat(origin) {
|
async toChat(origin) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue