Added the NPC Actor

This commit is contained in:
WBHarry 2026-05-30 19:20:15 +02:00
parent 2bc1c04c93
commit f24d37e935
21 changed files with 461 additions and 1 deletions

View file

@ -196,6 +196,11 @@ Hooks.once('init', () => {
makeDefault: true, makeDefault: true,
label: sheetLabel('TYPES.Actor.environment') label: sheetLabel('TYPES.Actor.environment')
}); });
Actors.registerSheet(SYSTEM.id, applications.sheets.actors.NPC, {
types: ['npc'],
makeDefault: true,
label: sheetLabel('TYPES.Actor.npc')
});
Actors.registerSheet(SYSTEM.id, applications.sheets.actors.Party, { Actors.registerSheet(SYSTEM.id, applications.sheets.actors.Party, {
types: ['party'], types: ['party'],
makeDefault: true, makeDefault: true,

View file

@ -23,6 +23,7 @@
"companion": "Companion", "companion": "Companion",
"adversary": "Adversary", "adversary": "Adversary",
"environment": "Environment", "environment": "Environment",
"npc": "NPC",
"party": "Party" "party": "Party"
} }
}, },
@ -333,6 +334,13 @@
}, },
"newAdversary": "New Adversary" "newAdversary": "New Adversary"
}, },
"NPC": {
"FIELDS": {
"difficulty": { "label": "Difficulty" },
"motive": { "label": "Motive" },
"description": { "label": "Description" }
}
},
"Party": { "Party": {
"Subtitle": { "Subtitle": {
"character": "{community} {ancestry} | {subclass} {class}", "character": "{community} {ancestry} | {subclass} {class}",

View file

@ -2,6 +2,7 @@ export { default as ActionConfig } from './action-config.mjs';
export { default as ActionSettingsConfig } from './action-settings-config.mjs'; export { default as ActionSettingsConfig } from './action-settings-config.mjs';
export { default as CharacterSettings } from './character-settings.mjs'; export { default as CharacterSettings } from './character-settings.mjs';
export { default as AdversarySettings } from './adversary-settings.mjs'; export { default as AdversarySettings } from './adversary-settings.mjs';
export { default as NPCSettings } from './npc-settings.mjs';
export { default as CompanionSettings } from './companion-settings.mjs'; export { default as CompanionSettings } from './companion-settings.mjs';
export { default as SettingFeatureConfig } from './setting-feature-config.mjs'; export { default as SettingFeatureConfig } from './setting-feature-config.mjs';
export { default as EnvironmentSettings } from './environment-settings.mjs'; export { default as EnvironmentSettings } from './environment-settings.mjs';

View file

@ -0,0 +1,85 @@
import DHBaseActorSettings from '../sheets/api/actor-setting.mjs';
/**@typedef {import('@client/applications/_types.mjs').ApplicationClickAction} ApplicationClickAction */
export default class DHNPCSettings extends DHBaseActorSettings {
/**@inheritdoc */
static DEFAULT_OPTIONS = {
classes: ['npc-settings'],
position: { width: 455, height: 'auto' },
actions: {},
dragDrop: [
{ dragSelector: null, dropSelector: '.tab.features' },
{ dragSelector: '.feature-item', dropSelector: null }
]
};
/**@override */
static PARTS = {
header: {
id: 'header',
template: 'systems/daggerheart/templates/sheets-settings/npc-settings/header.hbs'
},
tabs: { template: 'systems/daggerheart/templates/sheets/global/tabs/tab-navigation.hbs' },
details: {
id: 'details',
template: 'systems/daggerheart/templates/sheets-settings/npc-settings/details.hbs'
},
features: {
id: 'features',
template: 'systems/daggerheart/templates/sheets-settings/npc-settings/features.hbs'
}
};
/** @override */
static TABS = {
primary: {
tabs: [{ id: 'details' }, { id: 'features' }],
initial: 'details',
labelPrefix: 'DAGGERHEART.GENERAL.Tabs'
}
};
async _prepareContext(options) {
const context = await super._prepareContext(options);
const featureForms = ['passive', 'action', 'reaction'];
context.features = context.document.system.features.sort((a, b) =>
a.system.featureForm !== b.system.featureForm
? featureForms.indexOf(a.system.featureForm) - featureForms.indexOf(b.system.featureForm)
: a.sort - b.sort
);
return context;
}
/* -------------------------------------------- */
async _onDragStart(event) {
const featureItem = event.currentTarget.closest('.feature-item');
if (featureItem) {
const feature = this.actor.items.get(featureItem.id);
const featureData = { type: 'Item', uuid: feature.uuid, fromInternal: true };
event.dataTransfer.setData('text/plain', JSON.stringify(featureData));
event.dataTransfer.setDragImage(featureItem.querySelector('img'), 60, 0);
}
}
async _onDrop(event) {
event.stopPropagation();
const data = foundry.applications.ux.TextEditor.implementation.getDragEventData(event);
const item = await fromUuid(data.uuid);
if (item?.type === 'feature') {
if (data.fromInternal && item.parent?.uuid === this.actor.uuid) {
return;
}
const itemData = item.toObject();
delete itemData._id;
await this.actor.createEmbeddedDocuments('Item', [itemData]);
}
}
}

View file

@ -2,4 +2,5 @@ export { default as Adversary } from './adversary.mjs';
export { default as Character } from './character.mjs'; export { default as Character } from './character.mjs';
export { default as Companion } from './companion.mjs'; export { default as Companion } from './companion.mjs';
export { default as Environment } from './environment.mjs'; export { default as Environment } from './environment.mjs';
export { default as NPC } from './npc.mjs';
export { default as Party } from './party.mjs'; export { default as Party } from './party.mjs';

View file

@ -0,0 +1,132 @@
import DHBaseActorSheet from '../api/base-actor.mjs';
export default class NPCSheet extends DHBaseActorSheet {
/** @inheritDoc */
static DEFAULT_OPTIONS = {
classes: ['npc'],
position: { width: 660, height: 600 },
window: { resizable: true },
actions: {},
window: {
resizable: true,
controls: [
{
icon: 'fa-solid fa-signature',
label: 'DAGGERHEART.UI.Tooltip.configureAttribution',
action: 'editAttribution'
}
]
},
dragDrop: [
{
dragSelector: '[data-item-id][draggable="true"], [data-item-id] [draggable="true"]',
dropSelector: null
}
]
};
static PARTS = {
header: { template: 'systems/daggerheart/templates/sheets/actors/npc/header.hbs' },
tabs: { template: 'systems/daggerheart/templates/sheets/actors/npc/navigation.hbs' },
features: {
template: 'systems/daggerheart/templates/sheets/actors/npc/features.hbs',
scrollable: ['.feature-section']
},
notes: {
template: 'systems/daggerheart/templates/sheets/actors/npc/notes.hbs'
}
};
/** @inheritdoc */
static TABS = {
primary: {
tabs: [{ id: 'notes' }, { id: 'features' }],
initial: 'notes',
labelPrefix: 'DAGGERHEART.GENERAL.Tabs'
}
};
/**@inheritdoc */
async _prepareContext(options) {
const context = await super._prepareContext(options);
return context;
}
/**@inheritdoc */
async _preparePartContext(partId, context, options) {
context = await super._preparePartContext(partId, context, options);
switch (partId) {
case 'header':
await this._prepareHeaderContext(context, options);
break;
case 'features':
await this._prepareFeaturesContext(context, options);
break;
case 'notes':
await this._prepareNotesContext(context, options);
break;
}
return context;
}
/**
* Prepare render context for the Header part.
* @param {ApplicationRenderContext} context
* @param {ApplicationRenderOptions} options
* @returns {Promise<void>}
* @protected
*/
async _prepareHeaderContext(context, _options) {
const { system } = this.document;
const { TextEditor } = foundry.applications.ux;
context.description = await TextEditor.implementation.enrichHTML(system.description, {
secrets: this.document.isOwner,
relativeTo: this.document
});
}
async _prepareFeaturesContext(context, _options) {
const featureForms = ['passive', 'action', 'reaction'];
context.features = this.document.system.features.sort((a, b) =>
a.system.featureForm !== b.system.featureForm
? featureForms.indexOf(a.system.featureForm) - featureForms.indexOf(b.system.featureForm)
: a.sort - b.sort
);
}
/**
* Prepare render context for the Biography part.
* @param {ApplicationRenderContext} context
* @param {ApplicationRenderOptions} options
* @returns {Promise<void>}
* @protected
*/
async _prepareNotesContext(context, _options) {
const { system } = this.document;
const { TextEditor } = foundry.applications.ux;
const paths = {
notes: 'notes'
};
for (const [key, path] of Object.entries(paths)) {
const value = foundry.utils.getProperty(system, path);
context[key] = {
field: system.schema.getField(path),
value,
enriched: await TextEditor.implementation.enrichHTML(value, {
secrets: this.document.isOwner,
relativeTo: this.document
})
};
}
}
/**@inheritdoc */
_attachPartListeners(partId, htmlElement, options) {
super._attachPartListeners(partId, htmlElement, options);
}
}

View file

@ -1,15 +1,17 @@
import DhCharacter from './character.mjs'; import DhCharacter from './character.mjs';
import DhCompanion from './companion.mjs'; import DhCompanion from './companion.mjs';
import DhAdversary from './adversary.mjs'; import DhAdversary from './adversary.mjs';
import DhNPC from './npc.mjs';
import DhEnvironment from './environment.mjs'; import DhEnvironment from './environment.mjs';
import DhParty from './party.mjs'; import DhParty from './party.mjs';
export { DhCharacter, DhCompanion, DhAdversary, DhEnvironment, DhParty }; export { DhCharacter, DhCompanion, DhAdversary, DhNPC, DhEnvironment, DhParty };
export const config = { export const config = {
character: DhCharacter, character: DhCharacter,
companion: DhCompanion, companion: DhCompanion,
adversary: DhAdversary, adversary: DhAdversary,
npc: DhNPC,
environment: DhEnvironment, environment: DhEnvironment,
party: DhParty party: DhParty
}; };

38
module/data/actor/npc.mjs Normal file
View file

@ -0,0 +1,38 @@
import DHNPCSettings from '../../applications/sheets-configs/npc-settings.mjs';
import BaseDataActor from './base.mjs';
export default class DhpNPC extends BaseDataActor {
static LOCALIZATION_PREFIXES = ['DAGGERHEART.ACTORS.NPC'];
static get metadata() {
return foundry.utils.mergeObject(super.metadata, {
label: 'TYPES.Actor.npc',
type: 'npc',
settingSheet: DHNPCSettings,
hasResistances: false,
hasAttribution: true
});
}
static defineSchema() {
const fields = foundry.data.fields;
return {
...super.defineSchema(),
difficulty: new fields.NumberField({ nullable: true, initial: null, integer: true }),
description: new fields.StringField(),
motive: new fields.StringField(),
notes: new fields.HTMLField()
};
}
/**@inheritdoc */
static DEFAULT_ICON = 'systems/daggerheart/assets/icons/documents/actors/dragon-head.svg';
get features() {
return this.parent.items.filter(x => x.type === 'feature');
}
isItemValid(source) {
return super.isItemValid(source) || source.type === 'feature';
}
}

View file

@ -109,6 +109,14 @@ export default class DhpActor extends Actor {
}); });
} }
if (this.type === 'npc') {
Object.assign(update, {
prototypeToken: {
disposition: CONST.TOKEN_DISPOSITIONS.FRIENDLY
}
});
}
this.updateSource(update); this.updateSource(update);
} }

View file

@ -0,0 +1,54 @@
.application.sheet.daggerheart.actor.dh-style.npc {
.npc-header-sheet {
width: 100%;
display: flex;
.portrait {
cursor: pointer;
width: 275px;
img {
height: 275px;
}
}
.info-section {
flex: 1;
padding: 0 15px;
padding-top: var(--header-height);
display: flex;
flex-direction: column;
gap: 8px;
.name-row {
display: flex;
gap: 5px;
align-items: center;
justify-content: space-between;
h1 {
display: flex;
flex: 1;
padding: 6px 0 0 0;
font-size: var(--font-size-32);
text-align: start;
border: 1px solid transparent;
outline: 2px solid transparent;
transition: all 0.3s ease;
word-break: break-word;
&:hover {
outline: 2px solid light-dark(@dark, @golden);
}
}
}
.npc-info {
display: flex;
flex-direction: column;
gap: 12px;
padding: 16px 0;
}
}
}
}

View file

@ -0,0 +1,13 @@
.application.sheet.daggerheart.actor.dh-style.npc {
.window-content {
display: grid;
grid-template-rows: auto auto 1fr;
}
.npc-navigation {
padding: 0 15px;
display: flex;
gap: 8px;
align-items: center;
}
}

View file

@ -8,6 +8,9 @@
@import './actors/adversary/sidebar.less'; @import './actors/adversary/sidebar.less';
@import './actors/adversary/effects.less'; @import './actors/adversary/effects.less';
@import './actors/npc/sheet.less';
@import './actors/npc/header.less';
@import './actors/character/biography.less'; @import './actors/character/biography.less';
@import './actors/character/effects.less'; @import './actors/character/effects.less';
@import './actors/character/features.less'; @import './actors/character/features.less';

View file

@ -244,6 +244,9 @@
"adversary": { "adversary": {
"htmlFields": ["notes", "description"] "htmlFields": ["notes", "description"]
}, },
"npc": {
"htmlFields": ["notes"]
},
"environment": { "environment": {
"htmlFields": ["notes", "description"] "htmlFields": ["notes", "description"]
}, },

View file

@ -0,0 +1,9 @@
<section
class='tab {{tabs.details.cssClass}} {{tabs.details.id}}'
data-tab='{{tabs.details.id}}'
data-group='{{tabs.details.group}}'
>
{{formField systemFields.description value=document._source.system.description}}
{{formField systemFields.motive value=document._source.system.motive}}
{{formGroup systemFields.difficulty value=document._source.system.difficulty localize=true}}
</section>

View file

@ -0,0 +1,29 @@
<section
class='tab {{tabs.features.cssClass}} {{tabs.features.id}}'
data-tab='{{tabs.features.id}}'
data-group='{{tabs.features.group}}'
>
<button type="button" class="add-feature-btn" data-action="createDoc" data-document-class="Item" data-type="feature">
{{localize "DOCUMENT.New" type=(localize "TYPES.Item.feature")}}
</button>
<fieldset>
<legend>{{localize tabs.features.label}}</legend>
<ul class="feature-list">
{{#each @root.features as |feature|}}
<li class="feature-item" id="{{feature.id}}" draggable="true">
<img src="{{feature.img}}" alt="">
<div class="label">
<span>{{feature.name}}</span>
</div>
<div class="controls">
<a data-action="editDoc" data-item-uuid="{{feature.uuid}}" data-tooltip="{{localize 'CONTROLS.CommonEdit'}}"><i class="fa-solid fa-pen-to-square"></i></a>
<a data-action="deleteDoc" data-item-uuid="{{feature.uuid}}" data-tooltip="{{localize 'CONTROLS.CommonDelete'}}"><i class="fa-solid fa-trash"></i></a>
</div>
</li>
{{/each}}
</ul>
<div class="features-dragger">
<span>{{localize "DAGGERHEART.GENERAL.dropFeaturesHere"}}</span>
</div>
</fieldset>
</section>

View file

@ -0,0 +1,3 @@
<header class="dialog-header">
<h1>{{document.name}}</h1>
</header>

View file

@ -0,0 +1,14 @@
<section class='tab {{tabs.features.cssClass}} {{tabs.features.id}}' data-tab='{{tabs.features.id}}'
data-group='{{tabs.features.group}}'>
<div class="feature-section">
{{> 'daggerheart.inventory-items'
title=tabs.features.label
type='feature'
collection=@root.features
hideContextMenu=true
hideModifyControls=true
canCreate=@root.editable
showActions=@root.editable
}}
</div>
</section>

View file

@ -0,0 +1,30 @@
<header class='npc-header-sheet'>
<div class="portrait">
<img src="{{source.img}}" alt="{{source.name}}" data-action='editImage' data-edit="img">
</div>
<div class="info-section">
<line-div></line-div>
<div class="name-row">
<h1
class="input actor-name"
contenteditable="plaintext-only"
data-property="name"
placeholder="{{localize "DAGGERHEART.GENERAL.actorName"}}"
autocomplete="off"
spellcheck="false"
>{{source.name}}</h1>
</div>
<line-div></line-div>
<div class="npc-info">
<span class="description">
<i>{{{description}}}</i>
</span>
<span class="motives-and-tatics">
<b>{{localize 'DAGGERHEART.ACTORS.NPC.FIELDS.motive.label'}}: </b>{{{source.system.motive}}}
</span>
</div>
</div>
</header>

View file

@ -0,0 +1,6 @@
<div class="npc-navigation">
{{> 'systems/daggerheart/templates/sheets/global/tabs/tab-navigation.hbs'}}
<button type="button" data-action="openSettings" data-tooltip-text="{{localize "DAGGERHEART.UI.Tooltip.openSheetSettings"}}">
<i class="fa-solid fa-wrench"></i>
</button>
</div>

View file

@ -0,0 +1,14 @@
<section
class='tab {{tabs.notes.cssClass}} {{tabs.notes.id}}'
data-tab='{{tabs.notes.id}}'
data-group='{{tabs.notes.group}}'
>
<fieldset class="fit-height">
<legend>{{localize tabs.notes.label}}</legend>
{{formInput notes.field value=notes.value enriched=notes.enriched toggled=true}}
</fieldset>
{{#if (and showAttribution document.system.attribution.artist)}}
<label class="artist-attribution">{{localize "DAGGERHEART.GENERAL.artistAttribution" artist=document.system.attribution.artist}}</label>
{{/if}}
</section>

View file

@ -6,6 +6,8 @@
<span>{{name}}</span> <span>{{name}}</span>
{{#if (or (eq type "adversary") (eq type "environment"))}} {{#if (or (eq type "adversary") (eq type "environment"))}}
<span class="entry-subtitle">{{localize "DAGGERHEART.UI.Sidebar.actorDirectory.tier" tier=system.tier type=(@root.getTypeLabel this)}}</span> <span class="entry-subtitle">{{localize "DAGGERHEART.UI.Sidebar.actorDirectory.tier" tier=system.tier type=(@root.getTypeLabel this)}}</span>
{{else if (eq type "npc")}}
<span class="entry-subtitle">{{localize "TYPES.Actor.npc"}}</span>
{{else if (eq type "character")}} {{else if (eq type "character")}}
<span class="entry-subtitle">{{localize "DAGGERHEART.UI.Sidebar.actorDirectory.character" level=system.levelData.level.current}}</span> <span class="entry-subtitle">{{localize "DAGGERHEART.UI.Sidebar.actorDirectory.character" level=system.levelData.level.current}}</span>
{{else if (eq type "companion")}} {{else if (eq type "companion")}}