Skip to content

Commit

Permalink
Merge pull request #146 from juanferrer/master
Browse files Browse the repository at this point in the history
Add support for relics
  • Loading branch information
ClipplerBlood committed Nov 29, 2023
2 parents 89b4b8e + 12499fb commit d294ecc
Show file tree
Hide file tree
Showing 15 changed files with 189 additions and 8 deletions.
Binary file added src/assets/ui/thumbnail.webp
Binary file not shown.
5 changes: 5 additions & 0 deletions src/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"language": "Language",
"path": "Path",
"profession": "Profession",
"relic": "Relic",
"specialaction": "Special action",
"spell": "Spell",
"talent": "Talent",
Expand Down Expand Up @@ -86,6 +87,7 @@
"DL.TabsTalents": "Talents",
"DL.TabsMagic": "Magic",
"DL.TabsItems": "Items",
"DL.TabsRelics": "Relics",
"DL.TabsInventory": "Inventory",
"DL.TabsBackground": "Background",
"DL.TabsAttributes": "Attributes",
Expand Down Expand Up @@ -315,6 +317,9 @@
"DL.ItemName": "Item name",
"DL.ItemAmount": "Amount",
"DL.ItemValue": "Price",
"DL.ItemAddRelic": "Add relic",
"DL.ItemEditRelic": "Edit relic",
"DL.ItemDeleteRelic": "Delete relic",
"DL.ItemEnchantment": "Enchantment",
"DL.ItemDamage": "Damage",
"DL.ItemDefenseModifier": "Defense Modifier",
Expand Down
5 changes: 5 additions & 0 deletions src/lang/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"language": "Idioma",
"path": "Senda",
"profession": "Profesión",
"relic": "Reliquia",
"specialaction": "Acción Especial",
"spell": "Conjuro",
"talent": "Talento",
Expand Down Expand Up @@ -86,6 +87,7 @@
"DL.TabsTalents": "Talentos",
"DL.TabsMagic": "Magia",
"DL.TabsItems": "Objetos",
"DL.TabsRelics": "Reliquias",
"DL.TabsInventory": "Inventario",
"DL.TabsBackground": "Trasfondo",
"DL.TabsAttributes": "Atributos",
Expand Down Expand Up @@ -312,6 +314,9 @@
"DL.ItemName": "Nombre del objeto",
"DL.ItemAmount": "Cantidad",
"DL.ItemValue": "Precio",
"DL.ItemAddRelic": "Añadir Reliquia",
"DL.ItemEditRelic": "Editar Reliquia",
"DL.ItemDeleteRelic": "Borrar Reliquia",
"DL.ItemEnchantment": "Encantamiento",
"DL.ItemDamage": "Daño",
"DL.ItemDefenseModifier": "Modificador de Defensa",
Expand Down
6 changes: 4 additions & 2 deletions src/module/actor/actor.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
postSpellToChat,
postTalentToChat,
} from '../chat/roll-messages'
import {handleCreateAncestry, handleCreatePath, handleCreateRole } from '../item/nested-objects'
import {handleCreateAncestry, handleCreatePath, handleCreateRole, handleCreateRelic } from '../item/nested-objects'
import {TokenManager} from '../pixi/token-manager'
import {findAddEffect, findDeleteEffect} from "../demonlord";

Expand Down Expand Up @@ -186,7 +186,7 @@ export class DemonlordActor extends Actor {
// Final armor computation
system.characteristics.defense += system.bonuses.armor.defense
system.characteristics.defense = system.bonuses.armor.override || system.characteristics.defense
for (let change of effectChanges.filter(e => e.key.includes("defense") && !e.key.startsWith("system.characteristics"))) {
for (let change of effectChanges.filter(e => e.key.includes("defense") && (this.type === 'character' ? e.key.startsWith("system.characteristics") : false))) {
const result = change.effect.apply(this, change)
if (result !== null) this.overrides[change.key] = result
}
Expand Down Expand Up @@ -252,6 +252,8 @@ export class DemonlordActor extends Actor {
await handleCreatePath(this, doc)
} else if (doc.type === 'creaturerole') {
await handleCreateRole(this, doc)
} else if (doc.type === 'relic') {
await handleCreateRelic(this, doc)
}

await DLActiveEffects.embedActiveEffects(this, doc, 'create')
Expand Down
15 changes: 15 additions & 0 deletions src/module/actor/sheets/character-sheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ export default class DLCharacterSheet extends DLBaseActorSheet {
data.itemEffects = prepareActiveEffectCategories(
this.actor.effects.filter(effect => effect.flags?.sourceType === 'creaturerole'),
)
data.itemEffects = prepareActiveEffectCategories(
this.actor.effects.filter(effect => effect.flags?.sourceType === 'relic'),
)
this.prepareItems(data)
return data
}
Expand All @@ -74,6 +77,7 @@ export default class DLCharacterSheet extends DLBaseActorSheet {
const m = sheetData._itemsByType
const actorData = sheetData.actor
actorData.gear = m.get('item') || []
actorData.relics = m.get('relic') || []
actorData.armor = m.get('armor') || []
actorData.ammo = m.get('ammo') || []
actorData.ancestry = m.get('ancestry') || []
Expand Down Expand Up @@ -139,6 +143,14 @@ export default class DLCharacterSheet extends DLBaseActorSheet {
else if (ev.button == 2) await role.delete({ parent: this.actor })
}

async _onRelicEdit(ev) {
const div = $(ev.currentTarget)
const role = this.actor.getEmbeddedDocument('Item', div.data('itemId'))

if (ev.button == 0) role.sheet.render(true)
else if (ev.button == 2) await role.delete({ parent: this.actor })
}

/* -------------------------------------------- */

async _updateObject(event, formData) {
Expand Down Expand Up @@ -237,6 +249,9 @@ export default class DLCharacterSheet extends DLBaseActorSheet {
// Role edit
html.on('mousedown', '.role-edit', async ev => await this._onRoleEdit(ev))

// Relic edit
html.on('mousedown', '.relic-edit', async ev => await this._onRelicEdit(ev))

// Wealth edit
html
.find('.wealth-edit')
Expand Down
2 changes: 1 addition & 1 deletion src/module/actor/sheets/creature-sheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export default class DLCreatureSheet extends DLBaseActorSheet {

/** @override */
async checkDroppedItem(itemData) {
if (['armor', 'ammo', 'ancestry', 'path', 'profession', 'item', 'language'].includes(itemData.type)) return false
if (['armor', 'ammo', 'ancestry', 'path', 'profession', 'item', 'language', 'relic'].includes(itemData.type)) return false
return true
}

Expand Down
2 changes: 1 addition & 1 deletion src/module/actor/sheets/vehicle-sheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export default class DLVehicleSheet extends DLBaseActorSheet {

/** @override */
async checkDroppedItem(itemData) {
if (['armor', 'ammo', 'ancestry', 'path', 'profession', 'item', 'language', 'creaturerole'].includes(itemData.type)) return false
if (['armor', 'ammo', 'ancestry', 'path', 'profession', 'item', 'language', 'creaturerole', 'relic'].includes(itemData.type)) return false
return true
}

Expand Down
1 change: 1 addition & 0 deletions src/module/demonlord.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ Hooks.once('init', async function () {
'weapon',
'armor',
'ammo',
'relic',
'specialaction',
'endoftheround',
'profession',
Expand Down
6 changes: 3 additions & 3 deletions src/module/item/item.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ export class DemonlordItem extends Item {
_onUpdate(changed, options, userId) {
super._onUpdate(changed, options, userId)
// Search for open path/ancestry/role sheets and re-render them. This allows the nested objects to fetch new values
if (!['path', 'ancestry', 'creaturerole', 'item'].includes(this.type)) {
if (!['path', 'ancestry', 'creaturerole', 'item', 'relic'].includes(this.type)) {
// eslint-disable-next-line no-prototype-builtins
let openSheets = Object.entries(ui.windows).map(i => i[1]).filter(i => Item.prototype.isPrototypeOf(i.object))
openSheets = openSheets.filter(s => ['path', 'ancestry', 'creaturerole', 'item'].includes(s.object.type))
openSheets = openSheets.filter(s => ['path', 'ancestry', 'creaturerole', 'item', 'relic'].includes(s.object.type))
openSheets.forEach(s => s.render())
}
}
Expand Down Expand Up @@ -53,7 +53,7 @@ export class DemonlordItem extends Item {
}

// Delete nested objects if ancestry, path or role
if (['ancestry', 'path', 'creaturerole'].includes(this.type)) await deleteActorNestedItems(this.parent, this.id, null)
if (['ancestry', 'path', 'creaturerole', 'relic'].includes(this.type)) await deleteActorNestedItems(this.parent, this.id, null)
return await Promise.resolve()
}

Expand Down
9 changes: 9 additions & 0 deletions src/module/item/nested-objects.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,15 @@ export async function handleCreateRole(actor, roleItem) {
return await Promise.resolve()
}

export async function handleCreateRelic(actor, relicItem) {
const relicData = relicItem.system
const talents = await Promise.all(relicData.contents.map(t => {
return fromUuid(t.uuid)
}))
await createActorNestedItems(actor, talents, relicItem.id)
return await Promise.resolve()
}

export async function handleLevelChange(actor, newLevel, curLevel = undefined) {
curLevel = parseInt(curLevel ?? actor.system.level)
newLevel = parseInt(newLevel)
Expand Down
19 changes: 18 additions & 1 deletion src/module/item/sheets/base-item-sheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,24 @@ export default class DLBaseItemSheet extends ItemSheet {
if (itemData.type === 'Item') {
let actor
const item = await fromUuid(itemData.uuid)
if (!item || !['ammo', 'armor', 'item', 'weapon'].includes(item.type)) return

let acceptedItemTypes = []

// Filter drops depending on the item type
switch (this.item.type) {
case 'item':
acceptedItemTypes = ['ammo', 'armor', 'item', 'weapon']
break
case 'relic':
acceptedItemTypes = ['talent']
break
default:
acceptedItemTypes = []
break
}

if (!item && !acceptedItemTypes.includes(item.type)) return

const itemUpdate = {'_id': item._id}
if (itemData.uuid.startsWith('Actor.')) {
actor = item.parent
Expand Down
1 change: 1 addition & 0 deletions src/system.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"name": "Ferrer"
}
],
"background": "systems/demonlord/assets/ui/thumbnail.webp",
"compatibility": {
"minimum": 11,
"verified": 11
Expand Down
4 changes: 4 additions & 0 deletions src/template.json
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@
"language",
"path",
"profession",
"relic",
"specialaction",
"spell",
"talent",
Expand Down Expand Up @@ -254,6 +255,9 @@
"feature": {
"templates": ["base"]
},
"relic": {
"templates": ["base", "container"]
},
"spell": {
"tradition": "",
"edit": false,
Expand Down
86 changes: 86 additions & 0 deletions src/templates/item/item-relic-sheet.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<form class="{{cssClass}} item-form dl-item-form" autocomplete="off">
{{> "systems/demonlord/templates/item/partial/item-sheet-header.hbs" item=item placeholderName="Relic Name"}}

{{!-- Sheet Tab Navigation --}}
<nav class="sheet-tabs tabs" data-group="primary">
<a class="item" data-tab="attributes">{{localize "DL.TabsAttributes"}}</a>
<a class="item" data-tab="description">{{localize "DL.TabsDescription"}}</a>
{{#if effects}}<a class="item" data-tab="effects">{{localize "DL.TabsEffects"}}</a>{{/if}}
</nav>

{{!-- Sheet Body --}}
<section class="sheet-body">
<section class="sheet-content">
{{!-- Attributes Tab --}}
<div class="tab" data-group="primary" data-tab="attributes">

<div class="dl-item-section-header row">
<div class="col-12" style="margin-top: 4px">
<b>{{item.name}}</b>
</div>
</div>
<hr>

<div class="dl-item-section-section margin">
<div>
<b>{{localize "DL.SpellRequirements"}}</b>
<div>
{{dlDropdownValue "system.requirement.attribute" system.requirement.attribute "system.requirement.minvalue" system.requirement.minvalue }}
</div>
</div>
</div>
<hr>

{{#if system.description}}
<div class="dl-item-section-description">
<div><b>{{localize "DL.TabsDescription"}}</b></div>
<div>
{{{system.enrichedDescription}}}
</div>
</div>
<hr>
{{/if}}

{{#if system.contents}}
<div class="dl-item-section-contents">
<div class="dl-text-header-upper dl-underline-red dl-item-row-header">
<div class="col-11">{{localize "DL.TabsEffects"}}</div>
</div>
{{#each item.system.contents as |content index|}}
<div class="dl-item-row dl-nested-item dropitem" data-item-index="{{index}}" data-item-id="{{content._id}}">
<div class="row">
<div class="col-11">
<img class='dl-clickable edit-nested-item' src="{{content.img}}" title="{{content.name}}" width="32"
height="32"/>
<label class="dl-clickable-nored item-roll">{{content.name}}</label>
<div class="dl-clickable dlToggleInfoBtn">
<i class="fas fa-angle-right"></i> {{localize "DL.ItemShowInfo"}}
</div>
</div>
<div class="col-1 dl-clickable" style="padding-top: 3px">
<a class="dl-clickable item-delete" title="{{localize 'DL.ItemDeleteRelic'}}"
style="margin-left: 2px; margin-top: 3px;">
<i class="fas fa-times"></i>
</a>
</div>
</div>
{{#if content.system.description}}
<div class="row dlInfo" style="display: none; text-align: left">
<div class="col-12" style="padding: 2px 4px 4px;">
{{{content.system.enrichedDescription}}}
</div>
</div>
{{/if}}
</div>
{{/each}}
</div>
<hr>
{{/if}}
</div>

{{> "systems/demonlord/templates/item/partial/item-description.hbs"}}

{{#if effects}}{{> "systems/demonlord/templates/item/partial/item-effects.hbs"}}{{/if}}
</section>
</section>
</form>
36 changes: 36 additions & 0 deletions src/templates/tabs/item.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,39 @@
{{/if}}
</div>
{{/each}}

<!-- RELICS -->
<div class="dl-text-header-upper dl-underline-red dl-item-row-header">
<div class="col-11">{{localize "DL.TabsRelics"}}</div>
<div class="col-1">
<a class="item-create" title="{{localize 'DL.ItemAddRelic'}}" data-type="relic"><i class="fas fa-plus"></i></a>
</div>
</div>

{{#each actor.relics as |item id|}}
<div class="dl-item-row dropitem" data-item-id="{{item._id}}">
<div class="row">
<div class="col-11">
<img class='dl-clickable item-edit' src="{{item.img}}" title="{{item.name}}" width="32"
height="32"/>
<label class="dl-clickable item-roll">{{item.name}}</label>
<div class="dl-clickable dlToggleInfoBtn">
<i class="fas fa-angle-right"></i> {{localize "DL.ItemShowInfo"}}
</div>
</div>
<div class="col-1 dl-clickable" style="padding-top: 3px">
<a class="dl-clickable item-delete" title="{{localize 'DL.ItemDeleteRelic'}}"
style="margin-left: 2px; margin-top: 3px;">
<i class="fas fa-times"></i>
</a>
</div>
</div>
{{#if item.system.description}}
<div class="row dlInfo" style="display: none; text-align: left">
<div class="col-12" style="padding: 2px 4px 4px;">
{{{item.system.description}}}
</div>
</div>
{{/if}}
</div>
{{/each}}

0 comments on commit d294ecc

Please sign in to comment.