Added Custom Adversary Types (#1048)

This commit is contained in:
WBHarry 2025-08-23 02:18:25 +02:00 committed by GitHub
parent ee786544c7
commit d5f7e17339
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 156 additions and 10 deletions

View file

@ -1900,7 +1900,8 @@
"tier4": "tier 4",
"domains": "Domains",
"downtime": "Downtime",
"rules": "Rules"
"rules": "Rules",
"types": "Types"
},
"Tiers": {
"singular": "Tier",
@ -2230,6 +2231,10 @@
"deleteDomain": "Delete Domain",
"deleteDomainText": "Are you sure you want to delete the {name} domain? It will be immediately removed from all Actors in this world where it's currently used. Compendiums are not cleared.",
"duplicateDomain": "There is already a domain with this identification."
},
"adversaryType": {
"title": "Custom Adversary Types",
"newType": "Adversary Type"
}
},
"Menu": {

View file

@ -1,5 +1,6 @@
import { DhHomebrew } from '../../data/settings/_module.mjs';
import { slugify } from '../../helpers/utils.mjs';
const { HandlebarsApplicationMixin, ApplicationV2 } = foundry.applications.api;
export default class DhHomebrewSettings extends HandlebarsApplicationMixin(ApplicationV2) {
@ -10,11 +11,14 @@ export default class DhHomebrewSettings extends HandlebarsApplicationMixin(Appli
game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Homebrew).toObject()
);
this.selected = {
domain: null
};
this.selected = this.#getDefaultAdversaryType();
}
#getDefaultAdversaryType = () => ({
domain: null,
adversaryType: null
});
get title() {
return game.i18n.localize('DAGGERHEART.SETTINGS.Menu.title');
}
@ -35,6 +39,9 @@ export default class DhHomebrewSettings extends HandlebarsApplicationMixin(Appli
addDomain: this.addDomain,
toggleSelectedDomain: this.toggleSelectedDomain,
deleteDomain: this.deleteDomain,
addAdversaryType: this.addAdversaryType,
deleteAdversaryType: this.deleteAdversaryType,
selectAdversaryType: this.selectAdversaryType,
save: this.save,
reset: this.reset
},
@ -45,6 +52,7 @@ export default class DhHomebrewSettings extends HandlebarsApplicationMixin(Appli
tabs: { template: 'systems/daggerheart/templates/sheets/global/tabs/tab-navigation.hbs' },
settings: { template: 'systems/daggerheart/templates/settings/homebrew-settings/settings.hbs' },
domains: { template: 'systems/daggerheart/templates/settings/homebrew-settings/domains.hbs' },
types: { template: 'systems/daggerheart/templates/settings/homebrew-settings/types.hbs' },
downtime: { template: 'systems/daggerheart/templates/settings/homebrew-settings/downtime.hbs' },
footer: { template: 'systems/daggerheart/templates/settings/homebrew-settings/footer.hbs' }
};
@ -52,12 +60,19 @@ export default class DhHomebrewSettings extends HandlebarsApplicationMixin(Appli
/** @inheritdoc */
static TABS = {
main: {
tabs: [{ id: 'settings' }, { id: 'domains' }, { id: 'downtime' }],
tabs: [{ id: 'settings' }, { id: 'domains' }, { id: 'types' }, { id: 'downtime' }],
initial: 'settings',
labelPrefix: 'DAGGERHEART.GENERAL.Tabs'
}
};
changeTab(tab, group, options) {
super.changeTab(tab, group, options);
this.selected = this.#getDefaultAdversaryType();
this.render();
}
async _prepareContext(_options) {
const context = await super._prepareContext(_options);
context.settingFields = this.settings;
@ -79,6 +94,11 @@ export default class DhHomebrewSettings extends HandlebarsApplicationMixin(Appli
context.configDomains = CONFIG.DH.DOMAIN.domains;
context.homebrewDomains = this.settings.domains;
break;
case 'types':
context.selectedAdversaryType = this.selected.adversaryType
? { id: this.selected.adversaryType, ...this.settings.adversaryTypes[this.selected.adversaryType] }
: null;
break;
}
return context;
@ -301,6 +321,32 @@ export default class DhHomebrewSettings extends HandlebarsApplicationMixin(Appli
this.render();
}
static async addAdversaryType(_, target) {
const newId = foundry.utils.randomID();
await this.settings.updateSource({
[`adversaryTypes.${newId}`]: {
id: newId,
label: game.i18n.localize('DAGGERHEART.SETTINGS.Homebrew.adversaryType.newType')
}
});
this.selected.adversaryType = newId;
this.render();
}
static async deleteAdversaryType(_, target) {
const { key } = target.dataset;
await this.settings.updateSource({ [`adversaryTypes.-=${key}`]: null });
this.selected.adversaryType = this.selected.adversaryType === key ? null : this.selected.adversaryType;
this.render();
}
static async selectAdversaryType(_, target) {
this.selected.adversaryType = this.selected.adversaryType === target.dataset.type ? null : target.dataset.type;
this.render();
}
static async save() {
await game.settings.set(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Homebrew, this.settings.toObject());
this.close();

View file

@ -56,6 +56,7 @@ export default class AdversarySheet extends DHBaseActorSheet {
async _prepareContext(options) {
const context = await super._prepareContext(options);
context.systemFields.attack.fields = this.document.system.attack.schema.fields;
return context;
}
@ -65,6 +66,9 @@ export default class AdversarySheet extends DHBaseActorSheet {
switch (partId) {
case 'header':
await this._prepareHeaderContext(context, options);
const adversaryTypes = CONFIG.DH.ACTOR.allAdversaryTypes();
context.adversaryType = game.i18n.localize(adversaryTypes[this.document.system.type].label);
break;
case 'notes':
await this._prepareNotesContext(context, options);

View file

@ -157,6 +157,11 @@ export const adversaryTypes = {
}
};
export const allAdversaryTypes = () => ({
...adversaryTypes,
...game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Homebrew).adversaryTypes
});
export const environmentTypes = {
exploration: {
label: 'DAGGERHEART.CONFIG.EnvironmentType.exploration.label',

View file

@ -27,7 +27,7 @@ export default class DhpAdversary extends BaseDataActor {
}),
type: new fields.StringField({
required: true,
choices: CONFIG.DH.ACTOR.adversaryTypes,
choices: CONFIG.DH.ACTOR.allAdversaryTypes,
initial: CONFIG.DH.ACTOR.adversaryTypes.standard.id
}),
motivesAndTactics: new fields.StringField(),

View file

@ -108,6 +108,13 @@ export default class DhHomebrew extends foundry.abstract.DataModel {
}),
description: new fields.HTMLField()
})
),
adversaryTypes: new fields.TypedObjectField(
new fields.SchemaField({
id: new fields.StringField({ required: true }),
label: new fields.StringField({ required: true, label: 'DAGGERHEART.GENERAL.label' }),
description: new fields.StringField()
})
)
};
}

View file

@ -21,3 +21,4 @@
@import './settings/settings.less';
@import './settings/homebrew-settings/domains.less';
@import './settings/homebrew-settings/types.less';

View file

@ -0,0 +1,52 @@
.theme-light .daggerheart.dh-style.setting.homebrew-settings .types.tab {
.adversary-types-container .adversary-type-container {
background-image: url('../assets/parchments/dh-parchment-light.png');
}
}
.daggerheart.dh-style.setting.homebrew-settings {
.types.tab {
.adversary-types-container {
width: 100%;
display: grid;
grid-template-columns: 1fr 1fr 1fr;
gap: 4px;
.adversary-type-container {
height: 2em;
display: flex;
align-items: center;
justify-content: space-between;
gap: 8px;
border: 1px solid;
border-radius: 6px;
padding: 0 8px;
border: 1px solid light-dark(@dark-blue, @golden);
color: light-dark(@dark, @beige);
background-image: url('../assets/parchments/dh-parchment-dark.png');
cursor: pointer;
opacity: 0.6;
&:hover {
opacity: 1;
}
&.active {
opacity: 1;
background: var(--color-warm-2);
}
}
}
.type-edit-container {
width: 100%;
display: flex;
flex-direction: column;
gap: 8px;
textarea {
width: 100%;
}
}
}
}

View file

@ -0,0 +1,28 @@
<section
class="tab {{tabs.types.cssClass}} {{tabs.types.id}}"
data-tab="{{tabs.types.id}}"
data-group="{{tabs.types.group}}"
>
<fieldset>
<legend>
<span>{{localize "DAGGERHEART.SETTINGS.Homebrew.adversaryType.title"}}</span>
<a data-action="addAdversaryType"><i class="fa-solid fa-plus"></i></a>
</legend>
<div class="adversary-types-container">
{{#each settingFields.adversaryTypes as |type key|}}
<div class="adversary-type-container {{#if (eq ../selectedAdversaryType.id key)}}active{{/if}}" data-action="selectAdversaryType" data-type="{{key}}">
<span>{{type.label}}</span>
<div data-action="deleteAdversaryType" data-key="{{key}}"><i class="fa-solid fa-trash"></i></div>
</div>
{{/each}}
</div>
{{#if selectedAdversaryType}}
<div class="type-edit-container">
{{formGroup settingFields.schema.fields.adversaryTypes.element.fields.label name=(concat "adversaryTypes." selectedAdversaryType.id ".label") value=selectedAdversaryType.label localize=true }}
<textarea name="{{concat "adversaryTypes." selectedAdversaryType.id ".description"}}">{{selectedAdversaryType.description}}</textarea>
</div>
{{/if}}
</fieldset>
</section>

View file

@ -13,9 +13,7 @@
</span>
</div>
<div class="tag">
<span>
{{localize (concat 'DAGGERHEART.CONFIG.AdversaryType.' source.system.type '.label')}}
</span>
<span>{{adversaryType}}</span>
</div>
{{#if (eq source.system.type 'horde')}}
<div class="tag">

View file

@ -12,7 +12,7 @@
</div>
<div class="tooltip-information">
<label>{{localize "Type"}}</label>
{{#with (lookup config.ACTOR.adversaryTypes item.system.type) as | type |}}
{{#with (lookup adversaryTypes item.system.type) as | type |}}
<div>{{localize type.label}}</div>
{{/with}}
</div>