mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-12 03:31:07 +01:00
[Feature] Compedium Browser (#707)
* Create files * Item Browser v0.5 * dialog with (temporary) * Css * initial style in compedium browser * config * fixes * Replace compendium calls * Level Up * style compedium item list * removing css files --------- Co-authored-by: Dapoolp <elcatnet@gmail.com> Co-authored-by: WBHarry <williambjrklund@gmail.com>
This commit is contained in:
parent
a19c77ae4a
commit
a25007b994
34 changed files with 1650 additions and 123 deletions
|
|
@ -51,7 +51,7 @@ export default class DHDamageAction extends DHBaseAction {
|
|||
dialog: {},
|
||||
data: this.getRollData(),
|
||||
targetSelection: systemData.targets.length > 0
|
||||
}
|
||||
};
|
||||
if (this.hasSave) config.onSave = this.save.damageMod;
|
||||
if (data.system) {
|
||||
config.source.message = data._id;
|
||||
|
|
|
|||
|
|
@ -1,20 +1,21 @@
|
|||
const fields = foundry.data.fields;
|
||||
|
||||
const targetsField = () => new fields.ArrayField(
|
||||
new fields.SchemaField({
|
||||
id: new fields.StringField({}),
|
||||
actorId: new fields.StringField({}),
|
||||
name: new fields.StringField({}),
|
||||
img: new fields.StringField({}),
|
||||
difficulty: new fields.NumberField({ integer: true, nullable: true }),
|
||||
evasion: new fields.NumberField({ integer: true }),
|
||||
hit: new fields.BooleanField({ initial: false }),
|
||||
saved: new fields.SchemaField({
|
||||
result: new fields.NumberField(),
|
||||
success: new fields.BooleanField({ nullable: true, initial: null })
|
||||
const targetsField = () =>
|
||||
new fields.ArrayField(
|
||||
new fields.SchemaField({
|
||||
id: new fields.StringField({}),
|
||||
actorId: new fields.StringField({}),
|
||||
name: new fields.StringField({}),
|
||||
img: new fields.StringField({}),
|
||||
difficulty: new fields.NumberField({ integer: true, nullable: true }),
|
||||
evasion: new fields.NumberField({ integer: true }),
|
||||
hit: new fields.BooleanField({ initial: false }),
|
||||
saved: new fields.SchemaField({
|
||||
result: new fields.NumberField(),
|
||||
success: new fields.BooleanField({ nullable: true, initial: null })
|
||||
})
|
||||
})
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
export default class DHActorRoll extends foundry.abstract.TypeDataModel {
|
||||
targetHook = null;
|
||||
|
|
@ -40,27 +41,25 @@ export default class DHActorRoll extends foundry.abstract.TypeDataModel {
|
|||
action: new fields.StringField()
|
||||
}),
|
||||
damage: new fields.ObjectField(),
|
||||
costs: new fields.ArrayField(
|
||||
new fields.ObjectField()
|
||||
),
|
||||
costs: new fields.ArrayField(new fields.ObjectField()),
|
||||
successConsumed: new fields.BooleanField({ initial: false })
|
||||
};
|
||||
}
|
||||
|
||||
get actionActor() {
|
||||
if(!this.source.actor) return null;
|
||||
if (!this.source.actor) return null;
|
||||
return fromUuidSync(this.source.actor);
|
||||
}
|
||||
|
||||
get actionItem() {
|
||||
const actionActor = this.actionActor;
|
||||
if(!actionActor || !this.source.item) return null;
|
||||
if (!actionActor || !this.source.item) return null;
|
||||
return actionActor.items.get(this.source.item);
|
||||
}
|
||||
|
||||
get action() {
|
||||
const actionItem = this.actionItem;
|
||||
if(!actionItem || !this.source.action) return null;
|
||||
if (!actionItem || !this.source.action) return null;
|
||||
return actionItem.system.actionsList?.find(a => a.id === this.source.action);
|
||||
}
|
||||
|
||||
|
|
@ -76,90 +75,85 @@ export default class DHActorRoll extends foundry.abstract.TypeDataModel {
|
|||
this.targetSelection = mode;
|
||||
this.updateTargets();
|
||||
this.registerTargetHook();
|
||||
this.parent.update(
|
||||
{
|
||||
system: {
|
||||
targetSelection: this.targetSelection,
|
||||
oldTargets: this.oldTargets
|
||||
}
|
||||
this.parent.update({
|
||||
system: {
|
||||
targetSelection: this.targetSelection,
|
||||
oldTargets: this.oldTargets
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
get hitTargets() {
|
||||
return this.currentTargets.filter(t => (t.hit || !this.hasRoll || !this.targetSelection));
|
||||
return this.currentTargets.filter(t => t.hit || !this.hasRoll || !this.targetSelection);
|
||||
}
|
||||
|
||||
async updateTargets() {
|
||||
this.currentTargets = this.getTargetList();
|
||||
if(!this.targetSelection) {
|
||||
if (!this.targetSelection) {
|
||||
this.currentTargets.forEach(ct => {
|
||||
if(this.targets.find(t => t.actorId === ct.actorId)) return;
|
||||
if (this.targets.find(t => t.actorId === ct.actorId)) return;
|
||||
const indexTarget = this.oldTargets.findIndex(ot => ot.actorId === ct.actorId);
|
||||
if(indexTarget === -1)
|
||||
this.oldTargets.push(ct);
|
||||
if (indexTarget === -1) this.oldTargets.push(ct);
|
||||
});
|
||||
if(this.hasSave) this.setPendingSaves();
|
||||
if(this.currentTargets.length) {
|
||||
if(!this.parent._id) return;
|
||||
const updates = await this.parent.update(
|
||||
{
|
||||
system: {
|
||||
oldTargets: this.oldTargets
|
||||
}
|
||||
if (this.hasSave) this.setPendingSaves();
|
||||
if (this.currentTargets.length) {
|
||||
if (!this.parent._id) return;
|
||||
const updates = await this.parent.update({
|
||||
system: {
|
||||
oldTargets: this.oldTargets
|
||||
}
|
||||
);
|
||||
if(!updates && ui.chat.collection.get(this.parent.id))
|
||||
ui.chat.updateMessage(this.parent);
|
||||
});
|
||||
if (!updates && ui.chat.collection.get(this.parent.id)) ui.chat.updateMessage(this.parent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
registerTargetHook() {
|
||||
if(this.targetSelection && this.targetHook !== null) {
|
||||
Hooks.off("targetToken", this.targetHook);
|
||||
if (this.targetSelection && this.targetHook !== null) {
|
||||
Hooks.off('targetToken', this.targetHook);
|
||||
this.targetHook = null;
|
||||
} else if(!this.targetSelection && this.targetHook === null) {
|
||||
this.targetHook = Hooks.on("targetToken", foundry.utils.debounce(this.updateTargets.bind(this), 50));
|
||||
} else if (!this.targetSelection && this.targetHook === null) {
|
||||
this.targetHook = Hooks.on('targetToken', foundry.utils.debounce(this.updateTargets.bind(this), 50));
|
||||
}
|
||||
}
|
||||
|
||||
prepareDerivedData() {
|
||||
if(this.hasTarget) {
|
||||
if (this.hasTarget) {
|
||||
this.hasHitTarget = this.targets.filter(t => t.hit === true).length > 0;
|
||||
this.updateTargets();
|
||||
this.registerTargetHook();
|
||||
if(this.targetSelection === true) {
|
||||
this.targetShort = this.targets.reduce((a,c) => {
|
||||
if(c.hit) a.hit += 1;
|
||||
else a.miss += 1;
|
||||
return a;
|
||||
}, {hit: 0, miss: 0})
|
||||
if (this.targetSelection === true) {
|
||||
this.targetShort = this.targets.reduce(
|
||||
(a, c) => {
|
||||
if (c.hit) a.hit += 1;
|
||||
else a.miss += 1;
|
||||
return a;
|
||||
},
|
||||
{ hit: 0, miss: 0 }
|
||||
);
|
||||
}
|
||||
if(this.hasSave) this.setPendingSaves();
|
||||
if (this.hasSave) this.setPendingSaves();
|
||||
}
|
||||
|
||||
|
||||
this.canViewSecret = this.parent.speakerActor?.testUserPermission(game.user, 'OBSERVER');
|
||||
}
|
||||
|
||||
getTargetList() {
|
||||
return this.targetSelection !== true
|
||||
? Array.from(game.user.targets).map(t =>{
|
||||
const target = game.system.api.fields.ActionFields.TargetField.formatTarget(t),
|
||||
oldTarget = this.targets.find(ot => ot.actorId === target.actorId) ?? this.oldTargets.find(ot => ot.actorId === target.actorId);
|
||||
if(oldTarget) return oldTarget;
|
||||
return target;
|
||||
})
|
||||
? Array.from(game.user.targets).map(t => {
|
||||
const target = game.system.api.fields.ActionFields.TargetField.formatTarget(t),
|
||||
oldTarget =
|
||||
this.targets.find(ot => ot.actorId === target.actorId) ??
|
||||
this.oldTargets.find(ot => ot.actorId === target.actorId);
|
||||
if (oldTarget) return oldTarget;
|
||||
return target;
|
||||
})
|
||||
: this.targets;
|
||||
}
|
||||
|
||||
setPendingSaves() {
|
||||
this.pendingSaves = this.targetSelection
|
||||
? this.targets.filter(
|
||||
target => target.hit && target.saved.success === null
|
||||
).length > 0
|
||||
: this.currentTargets.filter(
|
||||
target => target.saved.success === null
|
||||
).length > 0;
|
||||
? this.targets.filter(target => target.hit && target.saved.success === null).length > 0
|
||||
: this.currentTargets.filter(target => target.saved.success === null).length > 0;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,8 @@ export default class RangeField extends fields.StringField {
|
|||
const options = {
|
||||
choices: CONFIG.DH.GENERAL.range,
|
||||
required: false,
|
||||
blank: true
|
||||
blank: true,
|
||||
label: "DAGGERHEART.GENERAL.range"
|
||||
};
|
||||
super(options, context);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ export class DHActionRollData extends foundry.abstract.DataModel {
|
|||
static defineSchema() {
|
||||
return {
|
||||
type: new fields.StringField({ nullable: true, initial: null, choices: CONFIG.DH.GENERAL.rollTypes }),
|
||||
trait: new fields.StringField({ nullable: true, initial: null, choices: CONFIG.DH.ACTOR.abilities }),
|
||||
trait: new fields.StringField({ nullable: true, initial: null, choices: CONFIG.DH.ACTOR.abilities, label: "DAGGERHEART.GENERAL.Trait.single" }),
|
||||
difficulty: new fields.NumberField({ nullable: true, initial: null, integer: true, min: 0 }),
|
||||
bonus: new fields.NumberField({ nullable: true, initial: null, integer: true }),
|
||||
advState: new fields.StringField({
|
||||
|
|
|
|||
|
|
@ -147,4 +147,8 @@ export default class DHArmor extends AttachableItem {
|
|||
const labels = [`${game.i18n.localize('DAGGERHEART.ITEMS.Armor.baseScore')}: ${this.baseScore}`];
|
||||
return labels;
|
||||
}
|
||||
|
||||
get itemFeatures() {
|
||||
return this.armorFeatures;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -106,6 +106,10 @@ export default class BaseDataItem extends foundry.abstract.TypeDataModel {
|
|||
return this.actions;
|
||||
}
|
||||
|
||||
get itemFeatures() {
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtain a data object used to evaluate any dice rolls associated with this Item Type
|
||||
* @param {object} [options] - Options which modify the getRollData method.
|
||||
|
|
|
|||
|
|
@ -20,7 +20,8 @@ export default class DHSubclass extends BaseDataItem {
|
|||
choices: CONFIG.DH.ACTOR.abilities,
|
||||
integer: false,
|
||||
nullable: true,
|
||||
initial: null
|
||||
initial: null,
|
||||
label: "DAGGERHEART.ITEMS.Subclass.spellcastingTrait"
|
||||
}),
|
||||
features: new ItemLinkFields(),
|
||||
featureState: new fields.NumberField({ required: true, initial: 1, min: 1 }),
|
||||
|
|
|
|||
|
|
@ -18,12 +18,12 @@ export default class DHWeapon extends AttachableItem {
|
|||
const fields = foundry.data.fields;
|
||||
return {
|
||||
...super.defineSchema(),
|
||||
tier: new fields.NumberField({ required: true, integer: true, initial: 1, min: 1 }),
|
||||
tier: new fields.NumberField({ required: true, integer: true, initial: 1, min: 1, label: "DAGGERHEART.GENERAL.Tiers.singular" }),
|
||||
equipped: new fields.BooleanField({ initial: false }),
|
||||
|
||||
//SETTINGS
|
||||
secondary: new fields.BooleanField({ initial: false }),
|
||||
burden: new fields.StringField({ required: true, choices: CONFIG.DH.GENERAL.burden, initial: 'oneHanded' }),
|
||||
secondary: new fields.BooleanField({ initial: false, label: "DAGGERHEART.ITEMS.Weapon.secondaryWeapon" }),
|
||||
burden: new fields.StringField({ required: true, choices: CONFIG.DH.GENERAL.burden, initial: 'oneHanded', label: "DAGGERHEART.GENERAL.burden" }),
|
||||
weaponFeatures: new fields.ArrayField(
|
||||
new fields.SchemaField({
|
||||
value: new fields.StringField({
|
||||
|
|
@ -234,4 +234,8 @@ export default class DHWeapon extends AttachableItem {
|
|||
|
||||
return labels;
|
||||
}
|
||||
|
||||
get itemFeatures() {
|
||||
return this.weaponFeatures;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue