Skip to content

Commit

Permalink
Improve relics
Browse files Browse the repository at this point in the history
  • Loading branch information
juanferrer committed Nov 16, 2023
1 parent 459d50d commit 12499fb
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 37 deletions.
4 changes: 3 additions & 1 deletion 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 @@ -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
16 changes: 15 additions & 1 deletion 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,7 +77,7 @@ export default class DLCharacterSheet extends DLBaseActorSheet {
const m = sheetData._itemsByType
const actorData = sheetData.actor
actorData.gear = m.get('item') || []
actorData.relic = m.get('relic') || []
actorData.relics = m.get('relic') || []
actorData.armor = m.get('armor') || []
actorData.ammo = m.get('ammo') || []
actorData.ancestry = m.get('ancestry') || []
Expand Down Expand Up @@ -140,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 @@ -238,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
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
3 changes: 1 addition & 2 deletions src/template.json
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,7 @@
"templates": ["base"]
},
"relic": {
"templates": ["base", "action", "enchantment"],
"healingoption": "false"
"templates": ["base", "container"]
},
"spell": {
"tradition": "",
Expand Down
63 changes: 35 additions & 28 deletions src/templates/item/item-relic-sheet.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -21,33 +21,6 @@
</div>
<hr>

<div class="dl-item-section-section margin">
<div>
<b>{{localize "DL.TalentUses"}}</b>
<div>
<div class="dl-new-project-2 nohover uses">
<input type="number" name="system.uses.value" value="{{system.uses.value}}"
data-tippy-content="{{localize "DL.TalentUses"}}" placeholder="-" min="0" autosize/>
<span class="sep"></span>
<input type="number" name="system.uses.max" value="{{system.uses.max}}"
data-tippy-content="{{localize "DL.TalentUsesMax"}}" placeholder="-" min="0" autosize/>
</div>
</div>
</div>
</div>

<hr>

{{> "systems/demonlord/templates/item/partial/item-attacks.hbs" action=system.action actionId="system.action"}}

<hr>

<div class="dl-item-section-section margin">
{{> "systems/demonlord/templates/item/partial/item-challenge.hbs" action=system.action actionId="system.action"}}
</div>

<hr>

<div class="dl-item-section-section margin">
<div>
<b>{{localize "DL.SpellRequirements"}}</b>
Expand All @@ -68,7 +41,41 @@
<hr>
{{/if}}

{{> "systems/demonlord/templates/item/partial/item-measured-template.hbs"}}
{{#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"}}
Expand Down
2 changes: 1 addition & 1 deletion src/templates/tabs/item.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
</div>
</div>

{{#each actor.relic as |item id|}}
{{#each actor.relics as |item id|}}
<div class="dl-item-row dropitem" data-item-id="{{item._id}}">
<div class="row">
<div class="col-11">
Expand Down

0 comments on commit 12499fb

Please sign in to comment.