Final v0.0.2
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import KHDiceRoller from "../helpers/dice-helper.js"
|
||||
import ActorHelpers from "../helpers/actor-helper.js";
|
||||
|
||||
/**
|
||||
* Extend the basic ActorSheet with some very simple modifications
|
||||
@@ -9,12 +10,23 @@ export class ActorSheetKH extends ActorSheet {
|
||||
|
||||
/** @override */
|
||||
static get defaultOptions() {
|
||||
if(game.settings.get("kopparhavet", "gameSystem") === "hjaltarnas-tid") {
|
||||
return mergeObject(super.defaultOptions, {
|
||||
classes: ["kopparhavet", "sheet", "actor"],
|
||||
template: "systems/kopparhavet/templates/actors/ht-character-sheet.html",
|
||||
width: 710,
|
||||
height: 650,
|
||||
tabs: [{ navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "main" }],
|
||||
scrollY: [".skills-tab .skills", ".talent-tab .items"],
|
||||
});
|
||||
}
|
||||
|
||||
return mergeObject(super.defaultOptions, {
|
||||
classes: ["kopparhavet", "sheet", "actor"],
|
||||
template: "systems/kopparhavet/templates/actors/character-sheet.html",
|
||||
width: 710,
|
||||
height: 650,
|
||||
tabs: [{ navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "skills" }],
|
||||
tabs: [{ navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "main" }],
|
||||
scrollY: [".skills-tab .skills", ".talent-tab .items"],
|
||||
});
|
||||
}
|
||||
@@ -22,7 +34,13 @@ export class ActorSheetKH extends ActorSheet {
|
||||
/** @override */
|
||||
get template() {
|
||||
const path = "systems/kopparhavet/templates/actors";
|
||||
return `${path}/${this.actor.data.type}-sheet.html`;
|
||||
let prefix = "";
|
||||
|
||||
if(game.settings.get("kopparhavet", "gameSystem") === "hjaltarnas-tid") {
|
||||
prefix = "ht-";
|
||||
}
|
||||
|
||||
return `${path}/${prefix}${this.actor.data.type}-sheet.html`;
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
@@ -278,15 +296,17 @@ export class ActorSheetKH extends ActorSheet {
|
||||
let defence = armor.data.data.defence.value;
|
||||
let hasHelmet = false;
|
||||
|
||||
this.actor.items.map((i) => {
|
||||
if(i.type === "armor") {
|
||||
if(i.data.data.equipable.equipped && i.data.data.helmet.value) {
|
||||
if(CONFIG.KH.armor_types[i.data.data.type.value]?.ac >= CONFIG.KH.armor_types[armor.data.data.type.value]?.ac) {
|
||||
hasHelmet = true
|
||||
if(game.settings.get("kopparhavet", "gameSystem") === "kopparhavet") {
|
||||
this.actor.items.map((i) => {
|
||||
if (i.type === "armor") {
|
||||
if (i.data.data.equipable.equipped && i.data.data.helmet.value) {
|
||||
if (CONFIG.KH.armor_types[i.data.data.type.value]?.ac >= CONFIG.KH.armor_types[armor.data.data.type.value]?.ac) {
|
||||
hasHelmet = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
let regex = /([0-9]*)t([0-9]*)/g;
|
||||
let regexMatch;
|
||||
@@ -314,8 +334,6 @@ export class ActorSheetKH extends ActorSheet {
|
||||
const li = $(ev.currentTarget).parents(".item");
|
||||
let skillValue = li.data("ability");
|
||||
|
||||
console.log(skillValue)
|
||||
|
||||
let skillName = "ITEM.ATTACK";
|
||||
|
||||
this.khRoller.rollSkillInChat(skillName, skillValue, false, this.actor)
|
||||
@@ -357,6 +375,104 @@ export class ActorSheetKH extends ActorSheet {
|
||||
this.khRoller.rollArmorInChat(regexMatch[1], hasHelmet, this.actor)
|
||||
}
|
||||
});
|
||||
|
||||
// Add or Remove relationship
|
||||
html.find(".learning-control").click(this._onClickLearningControl.bind(this));
|
||||
html.find(".learning-click").click(this._onClickLearingLearned.bind(this));
|
||||
|
||||
/* Hjältarnas Tid specefic */
|
||||
if(game.settings.get("kopparhavet", "gameSystem") === "hjaltarnas-tid") {
|
||||
// Add or Remove relationship
|
||||
html.find(".relation-control").click(this._onClickRelationshipControl.bind(this));
|
||||
html.find(".relation-click").click(this._onClickRelationshipUsed.bind(this));
|
||||
}
|
||||
}
|
||||
|
||||
async _onClickLearingLearned(event) {
|
||||
event.stopPropagation();
|
||||
const li1 = $(event.currentTarget);
|
||||
const li2 = $(event.currentTarget).parents(".learning");
|
||||
let box = li1.data("num")
|
||||
let learingKey = li2.data("attribute");
|
||||
|
||||
const clickedValue = (this.actor.data.data.learning[learingKey][box] == undefined ? false : this.actor.data.data.learning[learingKey][box]);
|
||||
let dataName = "data.learning." + learingKey + "." + box
|
||||
let tempData = {}
|
||||
|
||||
tempData[dataName] = !clickedValue
|
||||
|
||||
this.actor.update(tempData);
|
||||
|
||||
this._render();
|
||||
}
|
||||
|
||||
async _onClickLearningControl(event) {
|
||||
event.preventDefault();
|
||||
const a = event.currentTarget;
|
||||
const action = a.dataset.action;
|
||||
const attrs = this.object.data.data.learning;
|
||||
const form = this.form;
|
||||
|
||||
// Add new modification
|
||||
if (action === "create") {
|
||||
const nk = new Date().getTime();
|
||||
let newKey = document.createElement("div");
|
||||
|
||||
newKey.innerHTML = `<input class="learning-key" type="text" name="data.learning.attr${nk}.key" value="attr${nk}" style="display: none;" /><input class="learning-key" type="text" name="data.learning.attr${nk}.value" value="" style="display: none;" />`;
|
||||
|
||||
form.appendChild(newKey);
|
||||
await this._onSubmit(event);
|
||||
}
|
||||
|
||||
// Remove existing modification
|
||||
else if (action === "delete") {
|
||||
const li = a.closest(".learning");
|
||||
li.parentElement.removeChild(li);
|
||||
await this._onSubmit(event);
|
||||
}
|
||||
}
|
||||
|
||||
async _onClickRelationshipControl(event) {
|
||||
event.preventDefault();
|
||||
const a = event.currentTarget;
|
||||
const action = a.dataset.action;
|
||||
const attrs = this.object.data.data.relationships;
|
||||
const form = this.form;
|
||||
|
||||
// Add new modification
|
||||
if (action === "create") {
|
||||
const nk = new Date().getTime();
|
||||
let newKey = document.createElement("div");
|
||||
|
||||
newKey.innerHTML = `<input class="relation-key" type="text" name="data.relationships.attr${nk}.key" value="attr${nk}" style="display: none;" /><input class="relation-key" type="text" name="data.relationships.attr${nk}.value" value="" style="display: none;" />`;
|
||||
|
||||
form.appendChild(newKey);
|
||||
await this._onSubmit(event);
|
||||
}
|
||||
|
||||
// Remove existing modification
|
||||
else if (action === "delete") {
|
||||
const li = a.closest(".relation");
|
||||
li.parentElement.removeChild(li);
|
||||
await this._onSubmit(event);
|
||||
}
|
||||
}
|
||||
|
||||
async _onClickRelationshipUsed(event) {
|
||||
event.stopPropagation();
|
||||
|
||||
const li = $(event.currentTarget).parents(".relation");
|
||||
let relationshipKey = li.data("attribute");
|
||||
|
||||
const clickedValue = (this.actor.data.data.relationships[relationshipKey].check == undefined ? false : this.actor.data.data.relationships[relationshipKey].check);
|
||||
let dataName = "data.relationships." + relationshipKey + ".check"
|
||||
let tempData = {}
|
||||
|
||||
tempData[dataName] = !clickedValue
|
||||
|
||||
this.actor.update(tempData);
|
||||
|
||||
this._render();
|
||||
}
|
||||
|
||||
async _toggleEquippedItem(event) {
|
||||
@@ -469,6 +585,13 @@ export class ActorSheetKH extends ActorSheet {
|
||||
}
|
||||
}
|
||||
|
||||
/** @override */
|
||||
_updateObject(event, formData) {
|
||||
const actorUpdate = ActorHelpers.actorUpdate.bind(this);
|
||||
|
||||
actorUpdate(event, formData);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send details of an item to chat.
|
||||
* @private
|
||||
|
||||
Reference in New Issue
Block a user