diff --git a/module/BladesRollCollab.js b/module/BladesRollCollab.js index a9c82e22..48825d0a 100644 --- a/module/BladesRollCollab.js +++ b/module/BladesRollCollab.js @@ -26,7 +26,7 @@ function isModStatus(str) { return typeof str === "string" && str in RollModStatus; } -export class BladesRollMod { +class BladesRollMod { static ParseDocRollMods(doc) { const { roll_mods } = doc.system; if (!roll_mods || roll_mods.length === 0) { @@ -148,7 +148,7 @@ export class BladesRollMod { return; } if (!val || val === this.baseStatus) { - this.rollInstance.document.unsetFlag(...this.flagParams); + this.rollInstance.document.unsetFlag(...this.flagParams).then(() => socketlib.system.executeForEveryone("renderRollCollab", this.rollInstance.rollID)); } else { if ([RollModStatus.ForcedOn, RollModStatus.ForcedOff, RollModStatus.Hidden].includes(val) @@ -159,7 +159,7 @@ export class BladesRollMod { && !game.user.isGM) { return; } - this.rollInstance.document.setFlag(...this.flagParams, val); + this.rollInstance.document.setFlag(...this.flagParams, val).then(() => socketlib.system.executeForEveryone("renderRollCollab", this.rollInstance.rollID)); } } get sourceName() { return this._sourceName; } @@ -557,7 +557,10 @@ class BladesRollPrimary { rollPrimaryName; rollPrimaryType; rollPrimaryImg; - rollModsData; + _rollModsData; + get rollModsData() { + return this.rollPrimaryDoc?.rollModsData ?? this._rollModsData ?? []; + } rollFactors; constructor(rollInstance, { rollPrimaryID, rollPrimaryDoc, rollPrimaryName, rollPrimaryType, rollPrimaryImg, rollModsData, rollFactors }) { @@ -577,10 +580,7 @@ class BladesRollPrimary { this.rollPrimaryName = rollPrimaryName ?? this.rollPrimaryDoc.rollPrimaryName; this.rollPrimaryType = this.rollPrimaryDoc.rollPrimaryType; this.rollPrimaryImg = rollPrimaryImg ?? this.rollPrimaryDoc.rollPrimaryImg ?? ""; - this.rollModsData = [ - ...rollModsData ?? [], - ...this.rollPrimaryDoc.rollModsData ?? [] - ]; + this._rollModsData = rollModsData ?? []; this.rollFactors = Object.assign(this.rollPrimaryDoc.rollFactors, rollFactors ?? {}); } else { @@ -600,7 +600,7 @@ class BladesRollPrimary { this.rollPrimaryName = rollPrimaryName; this.rollPrimaryType = rollPrimaryType; this.rollPrimaryImg = rollPrimaryImg; - this.rollModsData = rollModsData ?? []; + this._rollModsData = rollModsData ?? []; this.rollFactors = rollFactors; } } @@ -794,6 +794,7 @@ class BladesRollCollab extends DocumentSheet { ]); } static InitSockets() { + socketlib.system.register("constructRollCollab", BladesRollCollab.ConstructRollCollab); socketlib.system.register("renderRollCollab", BladesRollCollab.RenderRollCollab); socketlib.system.register("closeRollCollab", BladesRollCollab.CloseRollCollab); } @@ -982,11 +983,14 @@ class BladesRollCollab extends DocumentSheet { static set Active(val) { BladesRollCollab._Active = val; } - static async RenderRollCollab({ userID, rollID, rollPermission }) { + static async ConstructRollCollab({ userID, rollID, rollPermission }) { const rollInst = new BladesRollCollab(userID, rollID, rollPermission); - eLog.checkLog3("rollCollab", "RenderRollCollab()", { params: { userID, rollID, rollPermission }, rollInst }); + eLog.checkLog3("rollCollab", "ConstructRollCollab()", { params: { userID, rollID, rollPermission }, rollInst }); await rollInst._render(true); } + static RenderRollCollab(rollID) { + BladesRollCollab.Current[rollID]?.render(); + } static async CloseRollCollab(rollID) { eLog.checkLog3("rollCollab", "CloseRollCollab()", { rollID }); await BladesRollCollab.Current[rollID]?.close({ rollID }); @@ -1042,7 +1046,7 @@ class BladesRollCollab extends DocumentSheet { } case RollType.Action: { if (!(rollTrait in { ...ActionTrait, ...Factor })) { - eLog.error("rollCollab", `[RenderRollCollab()] Bad RollTrait for Action Roll: ${rollTrait}`, config); + eLog.error("rollCollab", `[ConstructRollCollab()] Bad RollTrait for Action Roll: ${rollTrait}`, config); return; } flagUpdateData.rollTrait = rollTrait; @@ -1050,7 +1054,7 @@ class BladesRollCollab extends DocumentSheet { } case RollType.Fortune: { if (!(rollTrait in { ...ActionTrait, ...AttributeTrait, ...Factor } || U.isInt(rollTrait))) { - eLog.error("rollCollab", `[RenderRollCollab()] Bad RollTrait for Fortune Roll: ${rollTrait}`, config); + eLog.error("rollCollab", `[ConstructRollCollab()] Bad RollTrait for Fortune Roll: ${rollTrait}`, config); return; } flagUpdateData.rollTrait = rollTrait; @@ -1058,7 +1062,7 @@ class BladesRollCollab extends DocumentSheet { } case RollType.Resistance: { if (!(rollTrait in AttributeTrait)) { - eLog.error("rollCollab", `[RenderRollCollab()] Bad RollTrait for Resistance Roll: ${rollTrait}`, config); + eLog.error("rollCollab", `[ConstructRollCollab()] Bad RollTrait for Resistance Roll: ${rollTrait}`, config); return; } break; @@ -1125,10 +1129,10 @@ class BladesRollCollab extends DocumentSheet { userIDs.participants.push(...participantUsers); userIDs.observers = userIDs.observers.filter((uID) => !userIDs.participants.includes(uID)); } - socketlib.system.executeForAllGMs("renderRollCollab", { userID: rollUser.id, rollID, rollPermission: RollPermissions.GM }); - socketlib.system.executeForUsers("renderRollCollab", userIDs.primary, { userID: rollUser.id, rollID, rollPermission: RollPermissions.Primary }); - socketlib.system.executeForUsers("renderRollCollab", userIDs.participants, { userID: rollUser.id, rollID, rollPermission: RollPermissions.Participant }); - socketlib.system.executeForUsers("renderRollCollab", userIDs.observers, { userID: rollUser.id, rollID, rollPermission: RollPermissions.Observer }); + socketlib.system.executeForAllGMs("constructRollCollab", { userID: rollUser.id, rollID, rollPermission: RollPermissions.GM }); + socketlib.system.executeForUsers("constructRollCollab", userIDs.primary, { userID: rollUser.id, rollID, rollPermission: RollPermissions.Primary }); + socketlib.system.executeForUsers("constructRollCollab", userIDs.participants, { userID: rollUser.id, rollID, rollPermission: RollPermissions.Participant }); + socketlib.system.executeForUsers("constructRollCollab", userIDs.observers, { userID: rollUser.id, rollID, rollPermission: RollPermissions.Observer }); } rollID; @@ -1280,13 +1284,13 @@ class BladesRollCollab extends DocumentSheet { return this.flagData?.rollPositionInitial ?? Position.risky; } set initialPosition(val) { - this.document.setFlag(C.SYSTEM_ID, "rollCollab.rollPositionInitial", val); + this.document.setFlag(C.SYSTEM_ID, "rollCollab.rollPositionInitial", val).then(() => socketlib.system.executeForEveryone("renderRollCollab", this.rollID)); } get initialEffect() { return this.flagData?.rollEffectInitial ?? Effect.standard; } set initialEffect(val) { - this.document.setFlag(C.SYSTEM_ID, "rollCollab.rollEffectInitial", val); + this.document.setFlag(C.SYSTEM_ID, "rollCollab.rollEffectInitial", val).then(() => socketlib.system.executeForEveryone("renderRollCollab", this.rollID)); } get rollConsequence() { return this.flagData?.rollConsequence; @@ -2052,7 +2056,7 @@ class BladesRollCollab extends DocumentSheet { const elem$ = $(event.currentTarget); const target = elem$.data("target").replace(/flags\.eunos-blades\./, ""); const value = elem$.data("value"); - await this.document.setFlag(C.SYSTEM_ID, target, value); + await this.document.setFlag(C.SYSTEM_ID, target, value).then(() => socketlib.system.executeForEveryone("renderRollCollab", this.rollID)); } async _gmControlResetTarget(event) { event.preventDefault(); @@ -2061,7 +2065,7 @@ class BladesRollCollab extends DocumentSheet { } const elem$ = $(event.currentTarget); const target = elem$.data("target").replace(/flags\.eunos-blades\./, ""); - await this.document.unsetFlag(C.SYSTEM_ID, target); + await this.document.unsetFlag(C.SYSTEM_ID, target).then(() => socketlib.system.executeForEveryone("renderRollCollab", this.rollID)); } _gmControlReset(event) { event.preventDefault(); @@ -2108,17 +2112,17 @@ class BladesRollCollab extends DocumentSheet { await Promise.all(Object.values(Factor).map((factor) => { if (factor === thisFactor) { eLog.checkLog3("toggleFactor", `_gmControlToggleFactor - Checking ${factor} === ${thisFactor} === TRUE`, { factor, thisFactor, target, customTarget: `rollCollab.rollFactorToggles.${thisSource}.${factor}.isPrimary` }); - return this.document.setFlag(C.SYSTEM_ID, `rollCollab.rollFactorToggles.${thisSource}.${factor}.isPrimary`, true); + return this.document.setFlag(C.SYSTEM_ID, `rollCollab.rollFactorToggles.${thisSource}.${factor}.isPrimary`, true).then(() => socketlib.system.executeForEveryone("renderRollCollab", this.rollID)); } else { eLog.checkLog3("toggleFactor", `_gmControlToggleFactor - Checking ${factor} === ${thisFactor} === FALSE`, { factor, thisFactor, target, customTarget: `rollCollab.rollFactorToggles.${thisSource}.${factor}.isPrimary` }); - return this.document.setFlag(C.SYSTEM_ID, `rollCollab.rollFactorToggles.${thisSource}.${factor}.isPrimary`, false); + return this.document.setFlag(C.SYSTEM_ID, `rollCollab.rollFactorToggles.${thisSource}.${factor}.isPrimary`, false).then(() => socketlib.system.executeForEveryone("renderRollCollab", this.rollID)); } })); eLog.checkLog3("toggleFactor", "_gmControlToggleFactor - ALL DONE", { flags: this.document.getFlag(C.SYSTEM_ID, "rollCollab.rollFactorToggles") }); } else { - this.document.setFlag(C.SYSTEM_ID, `rollCollab.${target}`, value); + this.document.setFlag(C.SYSTEM_ID, `rollCollab.${target}`, value).then(() => socketlib.system.executeForEveryone("renderRollCollab", this.rollID)); } } async _gmControlResetFactor(event) { @@ -2128,7 +2132,7 @@ class BladesRollCollab extends DocumentSheet { } const elem$ = $(event.currentTarget); const target = elem$.data("target"); - await this.document.unsetFlag(C.SYSTEM_ID, `rollCollab.${target}`); + await this.document.unsetFlag(C.SYSTEM_ID, `rollCollab.${target}`).then(() => socketlib.system.executeForEveryone("renderRollCollab", this.rollID)); } get resistanceStressCost() { const dieVals = this.dieVals; @@ -2151,10 +2155,10 @@ class BladesRollCollab extends DocumentSheet { click: (event) => { const curVal = `${$(event.currentTarget).data("value")}`; if (curVal === "false") { - this.document.setFlag(C.SYSTEM_ID, "rollCollab.rollPosEffectTrade", "effect"); + this.document.setFlag(C.SYSTEM_ID, "rollCollab.rollPosEffectTrade", "effect").then(() => socketlib.system.executeForEveryone("renderRollCollab", this.rollID)); } else { - this.document.setFlag(C.SYSTEM_ID, "rollCollab.rollPosEffectTrade", false); + this.document.setFlag(C.SYSTEM_ID, "rollCollab.rollPosEffectTrade", false).then(() => socketlib.system.executeForEveryone("renderRollCollab", this.rollID)); } } }); @@ -2162,10 +2166,10 @@ class BladesRollCollab extends DocumentSheet { click: (event) => { const curVal = `${$(event.currentTarget).data("value")}`; if (curVal === "false") { - this.document.setFlag(C.SYSTEM_ID, "rollCollab.rollPosEffectTrade", "position"); + this.document.setFlag(C.SYSTEM_ID, "rollCollab.rollPosEffectTrade", "position").then(() => socketlib.system.executeForEveryone("renderRollCollab", this.rollID)); } else { - this.document.setFlag(C.SYSTEM_ID, "rollCollab.rollPosEffectTrade", false); + this.document.setFlag(C.SYSTEM_ID, "rollCollab.rollPosEffectTrade", false).then(() => socketlib.system.executeForEveryone("renderRollCollab", this.rollID)); } } }); @@ -2227,7 +2231,7 @@ class BladesRollCollab extends DocumentSheet { if (options.rollID) { return super.close({}); } - this.document.setFlag(C.SYSTEM_ID, "rollCollab", null); + await this.document.setFlag(C.SYSTEM_ID, "rollCollab", null); socketlib.system.executeForEveryone("closeRollCollab", this.rollID); return undefined; } @@ -2239,10 +2243,5 @@ class BladesRollCollab extends DocumentSheet { } } -export const BladesRollCollabComps = { - Mod: BladesRollMod, - Primary: BladesRollPrimary, - Opposition: BladesRollOpposition, - Participant: BladesRollParticipant -}; +export { BladesRollMod, BladesRollPrimary, BladesRollOpposition, BladesRollParticipant }; export default BladesRollCollab; \ No newline at end of file diff --git a/module/sheets/actor/BladesActorSheet.js b/module/sheets/actor/BladesActorSheet.js index 79d7cb21..99facd5e 100644 --- a/module/sheets/actor/BladesActorSheet.js +++ b/module/sheets/actor/BladesActorSheet.js @@ -14,7 +14,7 @@ import BladesActor from "../../BladesActor.js"; import BladesItem from "../../BladesItem.js"; import BladesSelectorDialog from "../../BladesDialog.js"; import BladesActiveEffect from "../../BladesActiveEffect.js"; -import BladesRollCollab, { BladesRollCollabComps } from "../../BladesRollCollab.js"; +import BladesRollCollab, { BladesRollPrimary, BladesRollOpposition } from "../../BladesRollCollab.js"; class BladesActorSheet extends ActorSheet { getData() { const context = super.getData(); @@ -376,10 +376,10 @@ class BladesActorSheet extends ActorSheet { } } if (game.user.isGM) { - if (BladesRollCollabComps.Primary.IsDoc(this.actor)) { + if (BladesRollPrimary.IsDoc(this.actor)) { rollData.rollPrimaryData = this.actor; } - else if (BladesRollCollabComps.Opposition.IsDoc(this.actor)) { + else if (BladesRollOpposition.IsDoc(this.actor)) { rollData.rollOppData = this.actor; } } diff --git a/module/sheets/item/BladesScoreSheet.js b/module/sheets/item/BladesScoreSheet.js index 34a2989a..510fec56 100644 --- a/module/sheets/item/BladesScoreSheet.js +++ b/module/sheets/item/BladesScoreSheet.js @@ -10,7 +10,7 @@ import { BladesActorType, BladesPhase, Tag, Randomizers } from "../../core/const import BladesItemSheet from "./BladesItemSheet.js"; import { BladesActor } from "../../documents/BladesActorProxy.js"; import { BladesScore } from "../../documents/BladesItemProxy.js"; -import BladesRollCollab, { BladesRollCollabComps } from "../../BladesRollCollab.js"; +import BladesRollCollab, { BladesRollOpposition } from "../../BladesRollCollab.js"; export var BladesTipContext; (function (BladesTipContext) { BladesTipContext["DiceRoll"] = "DiceRoll"; @@ -107,7 +107,7 @@ class BladesScoreSheet extends BladesItemSheet { }; Object.keys(randomData).forEach((cat) => { const _cat = cat; - Object.entries(randomData[_cat]).forEach(([index, randData]) => { + Object.keys(randomData[_cat]).forEach((index) => { if (this.document.system.randomizers?.[_cat][index].isLocked) { finalRandomData[_cat][index] = this.document.system.randomizers[_cat][index]; } @@ -116,7 +116,7 @@ class BladesScoreSheet extends BladesItemSheet { } }); }); - this.document.update({ "system.randomizers": finalRandomData }); + await this.document.update({ "system.randomizers": finalRandomData }); } getData() { const context = super.getData(); @@ -194,7 +194,7 @@ class BladesScoreSheet extends BladesItemSheet { const oppId = elem$.data("oppId"); this.document.update({ "system.oppositionSelected": oppId }); if (BladesScore.Active?.id === this.document.id && BladesRollCollab.Active) { - BladesRollCollab.Active.rollOpposition = new BladesRollCollabComps.Opposition(BladesRollCollab.Active, this.document.system.oppositions[oppId]); + BladesRollCollab.Active.rollOpposition = new BladesRollOpposition(BladesRollCollab.Active, this.document.system.oppositions[oppId]); } } _triggerRandomize(event) { @@ -218,7 +218,7 @@ class BladesScoreSheet extends BladesItemSheet { await actor.update({ "system.gm_notes": updateText }); eLog.checkLog3("scoreSheet", "Updated!", { gm_notes: actor.system.gm_notes }); } - async activateListeners(html) { + activateListeners(html) { super.activateListeners(html); html.find("[data-action='select-image']").on({ click: this._selectImage.bind(this), @@ -286,4 +286,5 @@ class BladesScoreSheet extends BladesItemSheet { return submitData; } } +export { BladesTipGenerator }; export default BladesScoreSheet; \ No newline at end of file diff --git a/ts/@types/blades-roll.d.ts b/ts/@types/blades-roll.d.ts index 1460004e..d6bed392 100644 --- a/ts/@types/blades-roll.d.ts +++ b/ts/@types/blades-roll.d.ts @@ -1,7 +1,7 @@ import {BladesActorType, BladesItemType, RollType, RollSubType, ConsequenceType, RollModStatus, RollModSection, ActionTrait, DowntimeAction, AttributeTrait, Position, Effect, Factor} from "../core/constants.js"; import BladesActor from "../BladesActor.js"; import BladesItem from "../BladesItem.js"; -import {BladesRollMod, BladesRollCollabComps} from "../BladesRollCollab.js"; +import {BladesRollMod, BladesRollPrimary, BladesRollOpposition, BladesRollParticipant} from "../BladesRollCollab.js"; declare global { @@ -27,19 +27,19 @@ declare global { export interface RollParticipantDocs { [RollModSection.roll]?: { - Assist?: BladesRollCollabComps.Participant, - Group_1?: BladesRollCollabComps.Participant, - Group_2?: BladesRollCollabComps.Participant, - Group_3?: BladesRollCollabComps.Participant, - Group_4?: BladesRollCollabComps.Participant, - Group_5?: BladesRollCollabComps.Participant, - Group_6?: BladesRollCollabComps.Participant, + Assist?: BladesRollParticipant, + Group_1?: BladesRollParticipant, + Group_2?: BladesRollParticipant, + Group_3?: BladesRollParticipant, + Group_4?: BladesRollParticipant, + Group_5?: BladesRollParticipant, + Group_6?: BladesRollParticipant, }, [RollModSection.position]?: { - Setup?: BladesRollCollabComps.Participant + Setup?: BladesRollParticipant }, [RollModSection.effect]?: { - Setup?: BladesRollCollabComps.Participant + Setup?: BladesRollParticipant } } diff --git a/ts/BladesRollCollab.ts b/ts/BladesRollCollab.ts index a62f5689..917562fa 100644 --- a/ts/BladesRollCollab.ts +++ b/ts/BladesRollCollab.ts @@ -1,3 +1,7 @@ +// typedoc --out ./docs5 --hideGenerator --categorizeByGroup --groupOrder "Static methods,*" --includes ./node_modules/@league-of-foundry-developers/foundry-vtt-types --entryPointStrategy expand --exclude **/*.d.ts ./ts +// typedoc --out ./docs6 --hideGenerator --hideParameterTypesInTitle --navigation --sort source-order --categorizeByGroup --groupOrder "Static methods,*" --includes ./node_modules/@league-of-foundry-developers/foundry-vtt-types --entryPointStrategy expand --exclude **/*.d.ts ./ts +// typedoc --out ./docs7 --hideGenerator --navigation --sort source-order --includes ./node_modules/@league-of-foundry-developers/foundry-vtt-types --entryPointStrategy expand --exclude **/*.d.ts ./ts + // #region IMPORTS ~ import U from "./core/utilities.js"; import C, {BladesActorType, BladesItemType, RollPermissions, RollType, RollSubType, RollModStatus, RollModSection, ActionTrait, DowntimeAction, AttributeTrait, Position, Effect, Factor, RollResult, ConsequenceType} from "./core/constants.js"; @@ -24,7 +28,7 @@ function isModStatus(str: unknown): str is RollModStatus { // #endregion // #region *** CLASS *** BladesRollMod -export class BladesRollMod { +class BladesRollMod { static ParseDocRollMods(doc: BladesDoc): BladesRollCollab.RollModData[] { @@ -127,13 +131,13 @@ export class BladesRollMod { set userStatus(val: RollModStatus | undefined) { if (val === this.userStatus) { return } if (!val || val === this.baseStatus) { - this.rollInstance.document.unsetFlag(...this.flagParams); + this.rollInstance.document.unsetFlag(...this.flagParams).then(() => socketlib.system.executeForEveryone("renderRollCollab", this.rollInstance.rollID)); } else { if ([RollModStatus.ForcedOn, RollModStatus.ForcedOff, RollModStatus.Hidden].includes(val) && !game.user.isGM) { return } if (this.userStatus && [RollModStatus.ForcedOn, RollModStatus.ForcedOff, RollModStatus.Hidden].includes(this.userStatus) && !game.user.isGM) { return } - this.rollInstance.document.setFlag(...this.flagParams, val); + this.rollInstance.document.setFlag(...this.flagParams, val).then(() => socketlib.system.executeForEveryone("renderRollCollab", this.rollInstance.rollID)); } } @@ -557,7 +561,10 @@ class BladesRollPrimary implements BladesRollCollab.PrimaryDocData { rollPrimaryName: string; rollPrimaryType: string; rollPrimaryImg: string; - rollModsData: BladesRollCollab.RollModData[]; + _rollModsData: BladesRollCollab.RollModData[]; + get rollModsData(): BladesRollCollab.RollModData[] { + return this.rollPrimaryDoc?.rollModsData ?? this._rollModsData ?? []; + } rollFactors: Partial>; // #region Constructor ~ @@ -581,10 +588,7 @@ class BladesRollPrimary implements BladesRollCollab.PrimaryDocData { this.rollPrimaryName = rollPrimaryName ?? this.rollPrimaryDoc.rollPrimaryName; this.rollPrimaryType = this.rollPrimaryDoc.rollPrimaryType; this.rollPrimaryImg = rollPrimaryImg ?? this.rollPrimaryDoc.rollPrimaryImg ?? ""; - this.rollModsData = [ - ...rollModsData ?? [], - ...this.rollPrimaryDoc.rollModsData ?? [] - ]; + this._rollModsData = rollModsData ?? []; this.rollFactors = Object.assign( this.rollPrimaryDoc.rollFactors, rollFactors ?? {} @@ -599,7 +603,7 @@ class BladesRollPrimary implements BladesRollCollab.PrimaryDocData { this.rollPrimaryName = rollPrimaryName; this.rollPrimaryType = rollPrimaryType; this.rollPrimaryImg = rollPrimaryImg; - this.rollModsData = rollModsData ?? []; + this._rollModsData = rollModsData ?? []; this.rollFactors = rollFactors; } } @@ -805,6 +809,7 @@ class BladesRollCollab extends DocumentSheet { ]); } static InitSockets() { + socketlib.system.register("constructRollCollab", BladesRollCollab.ConstructRollCollab); socketlib.system.register("renderRollCollab", BladesRollCollab.RenderRollCollab); socketlib.system.register("closeRollCollab", BladesRollCollab.CloseRollCollab); } @@ -994,12 +999,16 @@ class BladesRollCollab extends DocumentSheet { BladesRollCollab._Active = val; } - static async RenderRollCollab({userID, rollID, rollPermission}: {userID: string, rollID: string, rollPermission: RollPermissions}) { + static async ConstructRollCollab({userID, rollID, rollPermission}: {userID: string, rollID: string, rollPermission: RollPermissions}) { const rollInst = new BladesRollCollab(userID, rollID, rollPermission); - eLog.checkLog3("rollCollab", "RenderRollCollab()", {params: {userID, rollID, rollPermission}, rollInst}); + eLog.checkLog3("rollCollab", "ConstructRollCollab()", {params: {userID, rollID, rollPermission}, rollInst}); await rollInst._render(true); } + static RenderRollCollab(rollID: string) { + BladesRollCollab.Current[rollID]?.render(); + } + static async CloseRollCollab(rollID: string) { eLog.checkLog3("rollCollab", "CloseRollCollab()", {rollID}); await BladesRollCollab.Current[rollID]?.close({rollID}); @@ -1076,7 +1085,7 @@ class BladesRollCollab extends DocumentSheet { } case RollType.Action: { if (!(rollTrait in {...ActionTrait, ...Factor})) { - eLog.error("rollCollab", `[RenderRollCollab()] Bad RollTrait for Action Roll: ${rollTrait}`, config); + eLog.error("rollCollab", `[ConstructRollCollab()] Bad RollTrait for Action Roll: ${rollTrait}`, config); return; } flagUpdateData.rollTrait = rollTrait as ActionTrait | Factor; @@ -1084,7 +1093,7 @@ class BladesRollCollab extends DocumentSheet { } case RollType.Fortune: { if (!(rollTrait in {...ActionTrait, ...AttributeTrait, ...Factor} || U.isInt(rollTrait))) { - eLog.error("rollCollab", `[RenderRollCollab()] Bad RollTrait for Fortune Roll: ${rollTrait}`, config); + eLog.error("rollCollab", `[ConstructRollCollab()] Bad RollTrait for Fortune Roll: ${rollTrait}`, config); return; } flagUpdateData.rollTrait = rollTrait as ActionTrait | AttributeTrait | Factor | int; @@ -1092,7 +1101,7 @@ class BladesRollCollab extends DocumentSheet { } case RollType.Resistance: { if (!(rollTrait in AttributeTrait)) { - eLog.error("rollCollab", `[RenderRollCollab()] Bad RollTrait for Resistance Roll: ${rollTrait}`, config); + eLog.error("rollCollab", `[ConstructRollCollab()] Bad RollTrait for Resistance Roll: ${rollTrait}`, config); return; } break; @@ -1169,10 +1178,10 @@ class BladesRollCollab extends DocumentSheet { } // Send out socket calls to all users to see the roll. - socketlib.system.executeForAllGMs("renderRollCollab", {userID: rollUser.id, rollID, rollPermission: RollPermissions.GM}); - socketlib.system.executeForUsers("renderRollCollab", userIDs.primary, {userID: rollUser.id, rollID, rollPermission: RollPermissions.Primary}); - socketlib.system.executeForUsers("renderRollCollab", userIDs.participants, {userID: rollUser.id, rollID, rollPermission: RollPermissions.Participant}); - socketlib.system.executeForUsers("renderRollCollab", userIDs.observers, {userID: rollUser.id, rollID, rollPermission: RollPermissions.Observer}); + socketlib.system.executeForAllGMs("constructRollCollab", {userID: rollUser.id, rollID, rollPermission: RollPermissions.GM}); + socketlib.system.executeForUsers("constructRollCollab", userIDs.primary, {userID: rollUser.id, rollID, rollPermission: RollPermissions.Primary}); + socketlib.system.executeForUsers("constructRollCollab", userIDs.participants, {userID: rollUser.id, rollID, rollPermission: RollPermissions.Participant}); + socketlib.system.executeForUsers("constructRollCollab", userIDs.observers, {userID: rollUser.id, rollID, rollPermission: RollPermissions.Observer}); } // #endregion @@ -1337,13 +1346,13 @@ class BladesRollCollab extends DocumentSheet { return this.flagData?.rollPositionInitial ?? Position.risky; } set initialPosition(val: Position) { - this.document.setFlag(C.SYSTEM_ID, "rollCollab.rollPositionInitial", val); + this.document.setFlag(C.SYSTEM_ID, "rollCollab.rollPositionInitial", val).then(() => socketlib.system.executeForEveryone("renderRollCollab", this.rollID)); } get initialEffect(): Effect { return this.flagData?.rollEffectInitial ?? Effect.standard; } set initialEffect(val: Effect) { - this.document.setFlag(C.SYSTEM_ID, "rollCollab.rollEffectInitial", val); + this.document.setFlag(C.SYSTEM_ID, "rollCollab.rollEffectInitial", val).then(() => socketlib.system.executeForEveryone("renderRollCollab", this.rollID)); } get rollConsequence(): BladesRollCollab.ConsequenceData | undefined { return this.flagData?.rollConsequence; @@ -2244,7 +2253,7 @@ class BladesRollCollab extends DocumentSheet { const target = elem$.data("target").replace(/flags\.eunos-blades\./, ""); const value = elem$.data("value"); - await this.document.setFlag(C.SYSTEM_ID, target, value); + await this.document.setFlag(C.SYSTEM_ID, target, value).then(() => socketlib.system.executeForEveryone("renderRollCollab", this.rollID)); } async _gmControlResetTarget(event: ClickEvent) { @@ -2253,7 +2262,7 @@ class BladesRollCollab extends DocumentSheet { const elem$ = $(event.currentTarget); const target = elem$.data("target").replace(/flags\.eunos-blades\./, ""); - await this.document.unsetFlag(C.SYSTEM_ID, target); + await this.document.unsetFlag(C.SYSTEM_ID, target).then(() => socketlib.system.executeForEveryone("renderRollCollab", this.rollID)); } _gmControlReset(event: ClickEvent) { @@ -2299,15 +2308,15 @@ class BladesRollCollab extends DocumentSheet { await Promise.all(Object.values(Factor).map((factor) => { if (factor === thisFactor) { eLog.checkLog3("toggleFactor", `_gmControlToggleFactor - Checking ${factor} === ${thisFactor} === TRUE`, {factor, thisFactor, target, customTarget: `rollCollab.rollFactorToggles.${thisSource}.${factor}.isPrimary`}); - return this.document.setFlag(C.SYSTEM_ID, `rollCollab.rollFactorToggles.${thisSource}.${factor}.isPrimary`, true); + return this.document.setFlag(C.SYSTEM_ID, `rollCollab.rollFactorToggles.${thisSource}.${factor}.isPrimary`, true).then(() => socketlib.system.executeForEveryone("renderRollCollab", this.rollID)); } else { eLog.checkLog3("toggleFactor", `_gmControlToggleFactor - Checking ${factor} === ${thisFactor} === FALSE`, {factor, thisFactor, target, customTarget: `rollCollab.rollFactorToggles.${thisSource}.${factor}.isPrimary`}); - return this.document.setFlag(C.SYSTEM_ID, `rollCollab.rollFactorToggles.${thisSource}.${factor}.isPrimary`, false); + return this.document.setFlag(C.SYSTEM_ID, `rollCollab.rollFactorToggles.${thisSource}.${factor}.isPrimary`, false).then(() => socketlib.system.executeForEveryone("renderRollCollab", this.rollID)); } })); eLog.checkLog3("toggleFactor", "_gmControlToggleFactor - ALL DONE", {flags: this.document.getFlag(C.SYSTEM_ID, "rollCollab.rollFactorToggles")}); } else { - this.document.setFlag(C.SYSTEM_ID, `rollCollab.${target}`, value); + this.document.setFlag(C.SYSTEM_ID, `rollCollab.${target}`, value).then(() => socketlib.system.executeForEveryone("renderRollCollab", this.rollID)); } } @@ -2316,7 +2325,7 @@ class BladesRollCollab extends DocumentSheet { if (!game.user.isGM) { return } const elem$ = $(event.currentTarget); const target = elem$.data("target"); - await this.document.unsetFlag(C.SYSTEM_ID, `rollCollab.${target}`); + await this.document.unsetFlag(C.SYSTEM_ID, `rollCollab.${target}`).then(() => socketlib.system.executeForEveryone("renderRollCollab", this.rollID)); } get resistanceStressCost(): number { @@ -2341,9 +2350,9 @@ class BladesRollCollab extends DocumentSheet { click: (event) => { const curVal = `${$(event.currentTarget).data("value")}`; if (curVal === "false") { - this.document.setFlag(C.SYSTEM_ID, "rollCollab.rollPosEffectTrade", "effect"); + this.document.setFlag(C.SYSTEM_ID, "rollCollab.rollPosEffectTrade", "effect").then(() => socketlib.system.executeForEveryone("renderRollCollab", this.rollID)); } else { - this.document.setFlag(C.SYSTEM_ID, "rollCollab.rollPosEffectTrade", false); + this.document.setFlag(C.SYSTEM_ID, "rollCollab.rollPosEffectTrade", false).then(() => socketlib.system.executeForEveryone("renderRollCollab", this.rollID)); } } }); @@ -2351,9 +2360,9 @@ class BladesRollCollab extends DocumentSheet { click: (event) => { const curVal = `${$(event.currentTarget).data("value")}`; if (curVal === "false") { - this.document.setFlag(C.SYSTEM_ID, "rollCollab.rollPosEffectTrade", "position"); + this.document.setFlag(C.SYSTEM_ID, "rollCollab.rollPosEffectTrade", "position").then(() => socketlib.system.executeForEveryone("renderRollCollab", this.rollID)); } else { - this.document.setFlag(C.SYSTEM_ID, "rollCollab.rollPosEffectTrade", false); + this.document.setFlag(C.SYSTEM_ID, "rollCollab.rollPosEffectTrade", false).then(() => socketlib.system.executeForEveryone("renderRollCollab", this.rollID)); } } }); @@ -2423,9 +2432,8 @@ class BladesRollCollab extends DocumentSheet { override async close(options: FormApplication.CloseOptions & { rollID?: string } = {}) { if (options.rollID) { return super.close({}) } - this.document.setFlag(C.SYSTEM_ID, "rollCollab", null); + await this.document.setFlag(C.SYSTEM_ID, "rollCollab", null); socketlib.system.executeForEveryone("closeRollCollab", this.rollID); - return undefined; } @@ -2442,12 +2450,6 @@ interface BladesRollCollab { } // #region EXPORTS ~ -export const BladesRollCollabComps = { - Mod: BladesRollMod, - Primary: BladesRollPrimary, - Opposition: BladesRollOpposition, - Participant: BladesRollParticipant -}; - +export {BladesRollMod, BladesRollPrimary, BladesRollOpposition, BladesRollParticipant}; export default BladesRollCollab; // #endregion diff --git a/ts/sheets/actor/BladesActorSheet.ts b/ts/sheets/actor/BladesActorSheet.ts index 60cf8905..9e1f79f6 100644 --- a/ts/sheets/actor/BladesActorSheet.ts +++ b/ts/sheets/actor/BladesActorSheet.ts @@ -8,7 +8,7 @@ import BladesActor from "../../BladesActor.js"; import BladesItem from "../../BladesItem.js"; import BladesSelectorDialog, {SelectionCategory} from "../../BladesDialog.js"; import BladesActiveEffect from "../../BladesActiveEffect.js"; -import BladesRollCollab, {BladesRollCollabComps} from "../../BladesRollCollab.js"; +import BladesRollCollab, {BladesRollPrimary, BladesRollOpposition} from "../../BladesRollCollab.js"; // #endregion // #region TYPES: BladesCompData ~ type BladesCompData = { @@ -465,9 +465,9 @@ class BladesActorSheet extends ActorSheet { } if (game.user.isGM) { - if (BladesRollCollabComps.Primary.IsDoc(this.actor)) { + if (BladesRollPrimary.IsDoc(this.actor)) { rollData.rollPrimaryData = this.actor; - } else if (BladesRollCollabComps.Opposition.IsDoc(this.actor)) { + } else if (BladesRollOpposition.IsDoc(this.actor)) { rollData.rollOppData = this.actor; } } diff --git a/ts/sheets/item/BladesScoreSheet.ts b/ts/sheets/item/BladesScoreSheet.ts index c524c37b..dac8af41 100644 --- a/ts/sheets/item/BladesScoreSheet.ts +++ b/ts/sheets/item/BladesScoreSheet.ts @@ -4,7 +4,7 @@ import BladesItemSheet from "./BladesItemSheet.js"; import {BladesActor, BladesPC} from "../../documents/BladesActorProxy.js"; import {BladesScore} from "../../documents/BladesItemProxy.js"; -import BladesRollCollab, {BladesRollCollabComps} from "../../BladesRollCollab.js"; +import BladesRollCollab, {BladesRollOpposition} from "../../BladesRollCollab.js"; /* #region BladesTipGenerator */ @@ -59,7 +59,7 @@ class BladesScoreSheet extends BladesItemSheet { async generateRandomizerData(category?: RandomCat) { // Generate full set of random data. - const randomData: Record>> = { + const randomData: Record>> = { Bargains: Object.fromEntries(Object.entries(U.sample(Randomizers.GM.Bargains .filter((bData) => !Object.values(this.document.system.randomizers.Bargains) .some((_bData) => _bData.name === bData.name || _bData.effect === bData.effect)), 3, true, (e, a) => a @@ -109,7 +109,7 @@ class BladesScoreSheet extends BladesItemSheet { } // Combine locked data stored in system with randomly-generated data - const finalRandomData: Record>> = { + const finalRandomData: Record>> = { Bargains: {}, Obstacles: {}, NPCs: {}, @@ -119,7 +119,7 @@ class BladesScoreSheet extends BladesItemSheet { // Iterate through all randomizer categories. If system entry isLocked, use that, or use newly-generated data Object.keys(randomData).forEach((cat: string) => { const _cat = cat as RandomCat; - Object.entries(randomData[_cat]).forEach(([index, randData]) => { + Object.keys(randomData[_cat]).forEach((index) => { if (this.document.system.randomizers?.[_cat][index].isLocked) { finalRandomData[_cat][index] = this.document.system.randomizers[_cat][index]; } else { @@ -129,7 +129,7 @@ class BladesScoreSheet extends BladesItemSheet { }); // Overwrite stored data with newly generated & merged randomizer data - this.document.update({"system.randomizers": finalRandomData}); + await this.document.update({"system.randomizers": finalRandomData}); } override getData() { @@ -225,7 +225,7 @@ class BladesScoreSheet extends BladesItemSheet { const oppId = elem$.data("oppId"); this.document.update({"system.oppositionSelected": oppId}); if (BladesScore.Active?.id === this.document.id && BladesRollCollab.Active) { - BladesRollCollab.Active.rollOpposition = new BladesRollCollabComps.Opposition(BladesRollCollab.Active, this.document.system.oppositions[oppId]); + BladesRollCollab.Active.rollOpposition = new BladesRollOpposition(BladesRollCollab.Active, this.document.system.oppositions[oppId]); } } @@ -249,7 +249,7 @@ class BladesScoreSheet extends BladesItemSheet { eLog.checkLog3("scoreSheet", "Updated!", {gm_notes: actor.system.gm_notes}); } - override async activateListeners(html: JQuery) { + override activateListeners(html: JQuery) { super.activateListeners(html); html.find("[data-action='select-image']").on({ @@ -274,7 +274,7 @@ class BladesScoreSheet extends BladesItemSheet { }); } - override async _onSubmit(event: OnSubmitEvent, params: List = {}) { + override async _onSubmit(event: OnSubmitEvent, params: List = {}) { eLog.checkLog3("scoreSheet", "_onSubmit()", {event, params, elemText: event.currentTarget.innerHTML}); let isForcingRender = true; @@ -338,4 +338,5 @@ declare interface BladesScoreSheet { get document(): BladesScore } +export {BladesTipGenerator}; export default BladesScoreSheet; \ No newline at end of file