Skip to content

Commit

Permalink
Holy fucksticks it COMPILED!
Browse files Browse the repository at this point in the history
  • Loading branch information
Eunomiac committed Feb 11, 2024
1 parent f1fe86a commit 805f9b7
Show file tree
Hide file tree
Showing 40 changed files with 7,409 additions and 4,330 deletions.
4 changes: 2 additions & 2 deletions module/BladesActor.js
Original file line number Diff line number Diff line change
Expand Up @@ -745,8 +745,8 @@ class BladesActor extends Actor {
get isSubActor() { return this.parentActor !== undefined; }
// #endregion
// #region BladesRoll Implementation ~
get rollModsData() {
return BladesRollMod.ParseDocRollMods(this);
get rollModsSchemaSet() {
return BladesRollMod.ParseDocModsToSchemaSet(this);
}
get rollFactors() {
const factorData = {
Expand Down
9 changes: 4 additions & 5 deletions module/BladesItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,9 @@ class BladesItem extends Item {
return this.type;
}
get rollPrimaryImg() { return this.img; }
get rollModsData() {
// Const rollModData = BladesRollMod.ParseDocRollMods(this);
get rollModsSchemaSet() {
// Add roll mods from COHORT harm
return BladesRollMod.ParseDocRollMods(this);
return BladesRollMod.ParseDocModsToSchemaSet(this);
}
async applyHarm(amount, _name) {
if (BladesItem.IsType(this, BladesItemType.cohort_expert, BladesItemType.cohort_gang)) {
Expand Down Expand Up @@ -241,7 +240,7 @@ class BladesItem extends Item {
}
return this.type;
}
get rollOppModsData() { return []; }
get rollOppModsSchemaSet() { return []; }
// #endregion
// #region BladesRoll.ParticipantDoc Implementation
get rollParticipantID() { return this.id; }
Expand All @@ -258,7 +257,7 @@ class BladesItem extends Item {
}
return this.type;
}
get rollParticipantModsData() { return []; }
get rollParticipantModsSchemaSet() { return []; }
// #endregion
// #endregion
// #region PREPARING DERIVED DATA
Expand Down
459 changes: 38 additions & 421 deletions module/blades.js

Large diffs are not rendered by default.

156 changes: 104 additions & 52 deletions module/classes/BladesChat.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,20 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
// #region IMPORTS ~
import { ApplyTooltipAnimations, ApplyConsequenceAnimations } from "../core/gsap.js";
import { Position, RollResult } from "../core/constants.js";
import C, { RollType, Position, RollResult } from "../core/constants.js";
import U from "../core/utilities.js";
import BladesRoll from "./BladesRoll.js";
import BladesConsequence from "./BladesConsequence.js";
class BladesChat extends ChatMessage {
// static override defineSchema() {
// return Object.assign(super.defineSchema(), {
// csqData: new foundry.data.fields.ObjectField()
// });
// }
static Initialize() {
// let lastMessageID: string|false = Array.from(game.messages).pop()?.id ?? "";
Hooks.on("renderChatMessage", (msg, html) => {
ApplyTooltipAnimations(html);
if (msg.isRollResult) {
const { rollData } = msg.flagData;
if (rollData) {
ApplyConsequenceAnimations(html);
BladesConsequence.ApplyChatListeners(html);
}
html.addClass("display-ok");
// if (lastMessageID && _msg.id === lastMessageID) {
// setTimeout(() => {
// $(document).find("#chat .chat-message:not([class*='-roll'])")
// .remove();
// }, 500);
// lastMessageID = false;
// }
});
return loadTemplates([
"systems/eunos-blades/templates/chat/roll-result/action.hbs",
Expand All @@ -40,30 +30,43 @@ class BladesChat extends ChatMessage {
"systems/eunos-blades/templates/chat/roll-result/fortune-engagement.hbs",
"systems/eunos-blades/templates/chat/roll-result/indulgevice.hbs",
"systems/eunos-blades/templates/chat/roll-result/resistance.hbs",
"systems/eunos-blades/templates/chat/components/inline-resistance.hbs",
"systems/eunos-blades/templates/chat/components/die.hbs"
]);
}
static async ConstructRollOutput(rollInst) {
// Expand rollInst flag data to include results & consequences
const { flagData, finalPosition, finalEffect, rollResult, rollTraitVerb, rollTraitPastVerb, finalDiceData, resultChatTemplate } = rollInst;
const rollFlags = {
template: resultChatTemplate,
...flagData,
finalPosition,
finalEffect,
rollResult,
rollTraitVerb: rollTraitVerb ?? "",
rollTraitPastVerb: rollTraitPastVerb ?? rollTraitVerb ?? "",
finalDiceData
};
return await BladesChat.create({
speaker: rollInst.getSpeaker(BladesChat.getSpeaker()),
content: await renderTemplate(resultChatTemplate, rollFlags),
type: CONST.CHAT_MESSAGE_TYPES.ROLL,
flags: rollFlags
});
// static async ConstructRollOutput(rollInst: BladesRoll): Promise<BladesChat> {
// const rollData = {
// ...rollInst.data,
// rollTraitVerb: rollInst.rollTraitVerb ?? "",
// rollTraitPastVerb: rollInst.rollTraitPastVerb ?? rollInst.rollTraitVerb ?? ""
// };
// return await BladesChat.create({
// speaker: rollInst.getSpeaker(BladesChat.getSpeaker()),
// content: await renderTemplate(rollInst.template, rollData),
// type: CONST.CHAT_MESSAGE_TYPES.ROLL,
// flags: {
// "eunos-blades": {
// template: rollInst.template,
// rollData
// }
// }
// }) as BladesChat;
// }
static IsNewestRollResult(rollInst) {
const lastRollResultID = $("#chat-log .chat-message .blades-roll:not(.inline-roll)")
.last()
.attr("id");
return typeof lastRollResultID === "string"
&& lastRollResultID === rollInst.id;
}
get flagData() {
return this.flags["eunos-blades"];
}
get rollData() { return this.flagData.rollData; }
async setFlagVal(scope, key, val) {
return await this.setFlag(C.SYSTEM_ID, `${scope}.${key}`, val);
}
get allRollConsequencesData() {
get allRollConsequences() {
const returnData = {
[Position.controlled]: {
[RollResult.critical]: {},
Expand All @@ -84,46 +87,95 @@ class BladesChat extends ChatMessage {
[RollResult.fail]: {}
}
};
const { consequenceData } = this.flags;
const { consequenceData } = this.flagData.rollData ?? {};
if (!consequenceData) {
return returnData;
}
Object.entries(consequenceData)
.forEach(([position, positionData]) => {
Object.entries(positionData)
.forEach(([rollResult, csqData]) => {
returnData[position][rollResult] = csqData;
.forEach(([rollResult, csqDataSet]) => {
returnData[position][rollResult] = Object.fromEntries(Object.entries(csqDataSet)
.filter(([id, cData]) => cData.id)
.map(([id, cData]) => [
id,
game.eunoblades.Consequences.get(cData.id) ?? new BladesConsequence(cData)
]));
});
});
return returnData;
}
get rollConsequencesData() {
if (!this.isRollResult) {
get rollConsequences() {
if (!this.parentRoll) {
return [];
}
const { rollPositionFinal, rollResult, consequenceData } = this.parentRoll.data;
if (!rollPositionFinal || !rollResult || !consequenceData) {
return [];
}
const { finalPosition, rollResult, consequenceData } = this.flags;
if (typeof rollResult !== "string" || ![RollResult.partial, RollResult.fail].includes(rollResult)) {
return [];
}
const activeConsequences = consequenceData?.[finalPosition]?.[rollResult] ?? {};
return Object.values(activeConsequences);
const activeConsequences = consequenceData?.[rollPositionFinal]?.[rollResult] ?? {};
return Object.values(activeConsequences)
.map((cData) => game.eunoblades.Consequences.get(cData.id) ?? new BladesConsequence(cData));
}
get elem$() {
return $("#chat-log")
.find(`.chat-message[data-message-id="${this.id}"]`);
}
get elem() { return this.elem$[0]; }
get isRollResult() { return "rollData" in this.flagData; }
get parentRoll() {
if (!this.isRollResult) {
return undefined;
}
const { rollData } = this.flagData;
if (!rollData) {
return undefined;
}
return game.eunoblades.Rolls.get(rollData.id ?? "") ?? new BladesRoll({
...rollData,
isScopingById: false
});
}
get roll$() {
return this.parentRoll ? this.elem$.find(`#${this.parentRoll.id}`) : undefined;
}
get elem() { return $("#chat-log").find(`.chat-message[data-message-id="${this.id}"]`)[0]; }
get isRollResult() { return this.type === CONST.CHAT_MESSAGE_TYPES.ROLL; }
async regenerateFromFlags() {
await this.update({ content: await renderTemplate(this.flags.template, this.flags) });
if (this.isRollResult) {
await this.update({ content: await renderTemplate(this.flagData.template, this) });
}
}
async render(force) {
await super.render(force);
if (!this.elem) {
await this.activateListeners();
}
async activateListeners() {
if (!this.elem$) {
eLog.error("BladesChat", `No BladesChat.elem found for id ${this.id}.`);
return;
}
const elem$ = $(this.elem);
ApplyTooltipAnimations(elem$);
ApplyConsequenceAnimations(elem$);
BladesConsequence.ApplyChatListeners(elem$);
elem$.addClass("display-ok");
ApplyTooltipAnimations(this.elem$);
ApplyConsequenceAnimations(this.elem$);
BladesConsequence.ApplyChatListeners(this.elem$);
if (this.parentRoll) {
this.elem$.addClass(`${this.parentRoll.rollType.toLowerCase()}-roll`);
if (this.parentRoll.rollType === RollType.Action && this.rollConsequences.some((csq) => !csq.isAccepted)) {
this.elem$.addClass("unresolved-action-roll");
}
else {
this.elem$.removeClass("unresolved-action-roll");
}
if (BladesChat.IsNewestRollResult(this.parentRoll)) {
$("#chat-log .chat-message").removeClass("active-chat-roll");
this.elem$.addClass("active-chat-roll");
}
else {
this.elem$.removeClass("active-chat-roll");
}
}
U.gsap.to(this.elem$, { autoAlpha: 1, duration: 0.15, ease: "none" });
}
}
export default BladesChat;
Loading

0 comments on commit 805f9b7

Please sign in to comment.