Add skills as items

This commit is contained in:
mstein
2022-06-07 00:58:21 +02:00
parent ab59b19e56
commit c7f6a38acf
13 changed files with 399 additions and 136 deletions
+61 -5
View File
@@ -1,5 +1,7 @@
import Logger from "../../utils/Logger"
import M5Character, { M5Attribute } from "../actors/M5Character"
import { M5Character } from "../actors/M5Character"
import { M5Item } from "../items/M5Item"
import { M5SkillLearned, M5SkillUnlearned } from "../M5Base"
export default class M5CharacterSheet extends ActorSheet {
@@ -27,7 +29,7 @@ export default class M5CharacterSheet extends ActorSheet {
context.actor = actorData;
context.data = actorData.data;
//console.log("Sheet Promise", context)
//console.log("Sheet Promise", context.actor, context.data)
return context
})
}
@@ -35,8 +37,29 @@ export default class M5CharacterSheet extends ActorSheet {
override activateListeners(html: JQuery) {
super.activateListeners(html)
html.find(".roll-button").on("click", async (event) => {
html.find(".edit-skill").on("click", async (event) => {
const row = event.target.parentElement
let skillId = row.dataset["skill"]
const context = this.actor.data
const item = context.items.get(skillId)
item.sheet.render(true)
})
html.find(".roll-learned-button").on("click", async (event) => {
const row = event.target.parentElement.parentElement
let skillId = row.dataset["skill"]
const actor = this.actor as any
const context = this.actor.data
const data = context.data
const item = context.items.get(skillId) as M5Item
await item.roll()
})
html.find(".roll-general-button").on("click", async (event) => {
const row = event.target.parentElement.parentElement
let skillName = row.dataset["skill"]
const actor = this.actor as M5Character
@@ -45,10 +68,10 @@ export default class M5CharacterSheet extends ActorSheet {
const skill = data.skills.general[skillName]
const attribute = data.attributes[skill.attribute]
console.log(skill, attribute)
//console.log(skill, attribute)
const r = new Roll("1d20 + @fw + @bonus", {
fw: skill.fw + 12,
fw: skill.fw,
bonus: M5Character.attributeBonus(attribute)
})
await r.evaluate().then(value => {
@@ -62,5 +85,38 @@ export default class M5CharacterSheet extends ActorSheet {
return ChatMessage.create(chatData)
})
})
html.find(".learn-button").on("click", async (event) => {
const row = event.target.parentElement.parentElement
let skillName = row.dataset["skill"]
const data = this.actor.data.data
const unlearnedSkill = data.skills.general[skillName] as M5SkillUnlearned
const itemData = {
name: (game as Game).i18n.localize("midgard5." + skillName),
type: "skill",
data: {
fw: unlearnedSkill.initial,
attribute: unlearnedSkill.attribute,
skill: skillName,
type: "general"
} as M5SkillLearned
}
this.actor.createEmbeddedDocuments("Item", [itemData]).then(docs => {
const item = docs[0]
//console.log("createEmbeddedDocuments", item.data)
})
})
// Drag & Drop
// const dragDropSkill = new DragDrop({
// dragSelector: ".items-list .item",
// dropSelector: ".sheet-body",
// permissions: { dragstart: this._canDragStart.bind(this), drop: this._canDragDrop.bind(this) },
// callbacks: { dragstart: this._onTransferItemDragStart.bind(this), drop: this._onTransferItemDrop.bind(this) },
// })
// dragDrop.bind(html[0])
}
}
+29 -3
View File
@@ -1,14 +1,40 @@
export default class M5ItemSheet extends ItemSheet {
export class M5ItemSheet extends ItemSheet {
static get defaultOptions() {
return mergeObject(super.defaultOptions, {
width: 530,
height: 340,
classes: ["midgard5", "sheet", "item"]
});
})
}
get template() {
return 'systems/midgard5/templates/sheets/m5Item-Sheet.hbs';
//console.log("M5ItemSheet", this.item.data.type)
const path = "systems/midgard5/templates/sheets/item"
return `${path}/${this.item.data.type}.hbs`
}
override getData(options?: Partial<ItemSheet.Options>): ItemSheet.Data<ItemSheet.Options> | Promise<ItemSheet.Data<ItemSheet.Options>> {
return Promise.resolve(super.getData()).then(value => {
const context = value as any
// Use a safe clone of the item data for further operations.
const itemData = context.item.data
// Retrieve the roll data for TinyMCE editors.
context.rollData = {}
let actor = this.object?.parent ?? null
if (actor) {
context.rollData = actor.getRollData()
}
// Add the actor's data to context.data for easier access, as well as flags.
context.data = itemData.data
context.flags = itemData.flags
return context
})
}
}