DIvers rework de CSS/LESS et améliorations de messages/layout
This commit is contained in:
@@ -3,6 +3,8 @@ import { LesOubliesUtility } from "./les-oublies-utility.js"
|
||||
import { LesOubliesRolls } from "./les-oublies-rolls.js"
|
||||
|
||||
export class LesOubliesActor extends Actor {
|
||||
static CREATION_ITEM_TYPES = new Set(["race", "tribu", "metier"])
|
||||
|
||||
prepareDerivedData() {
|
||||
super.prepareDerivedData()
|
||||
|
||||
@@ -43,6 +45,12 @@ export class LesOubliesActor extends Actor {
|
||||
}
|
||||
|
||||
getCreationItem(type) {
|
||||
if (!LesOubliesActor.CREATION_ITEM_TYPES.has(type)) return this.items.find((item) => item.type === type) ?? null
|
||||
const referenceId = this.system.references?.[`${type}Id`] ?? ""
|
||||
if (referenceId) {
|
||||
const referencedItem = this.items.get(referenceId)
|
||||
if (referencedItem?.type === type) return referencedItem
|
||||
}
|
||||
return this.items.find((item) => item.type === type) ?? null
|
||||
}
|
||||
|
||||
@@ -51,6 +59,40 @@ export class LesOubliesActor extends Actor {
|
||||
return LesOubliesUtility.sortByName(items)
|
||||
}
|
||||
|
||||
async assignCreationItem(sourceItem) {
|
||||
if (!sourceItem || !LesOubliesActor.CREATION_ITEM_TYPES.has(sourceItem.type)) return null
|
||||
|
||||
const itemData = sourceItem.toObject()
|
||||
delete itemData._id
|
||||
|
||||
const existingIds = this.getEmbeddedItems(sourceItem.type).map((item) => item.id)
|
||||
if (existingIds.length) {
|
||||
await this.deleteEmbeddedDocuments("Item", existingIds, { renderSheet: false })
|
||||
}
|
||||
|
||||
const [createdItem] = await this.createEmbeddedDocuments("Item", [itemData], { renderSheet: false })
|
||||
if (!createdItem) return null
|
||||
|
||||
await this.update({
|
||||
[`system.references.${sourceItem.type}Id`]: createdItem.id,
|
||||
})
|
||||
|
||||
return createdItem
|
||||
}
|
||||
|
||||
async clearCreationItem(type) {
|
||||
if (!LesOubliesActor.CREATION_ITEM_TYPES.has(type)) return
|
||||
|
||||
const existingIds = this.getEmbeddedItems(type).map((item) => item.id)
|
||||
if (existingIds.length) {
|
||||
await this.deleteEmbeddedDocuments("Item", existingIds, { renderSheet: false })
|
||||
}
|
||||
|
||||
await this.update({
|
||||
[`system.references.${type}Id`]: "",
|
||||
})
|
||||
}
|
||||
|
||||
getCompagnie() {
|
||||
const compagnieId = this.system.references?.compagnieId
|
||||
return compagnieId ? game.actors.get(compagnieId) ?? null : null
|
||||
@@ -83,6 +125,7 @@ export class LesOubliesActor extends Actor {
|
||||
getGroupedCompetences() {
|
||||
return LESOUBLIES_CONFIG.profiles.map((profile) => ({
|
||||
...profile,
|
||||
profileValue: this.getProfileValue(profile.id),
|
||||
items: this.getCompetences().filter((entry) => entry.item.system.profileKey === profile.id),
|
||||
}))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user