Skip to content

Commit

Permalink
Slowly getting BladesRollCollab back
Browse files Browse the repository at this point in the history
  • Loading branch information
Eunomiac committed Oct 6, 2023
1 parent b434fae commit 68f5d9f
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 105 deletions.
73 changes: 36 additions & 37 deletions module/BladesRollCollab.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
Expand All @@ -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; }
Expand Down Expand Up @@ -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 }) {
Expand All @@ -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 {
Expand All @@ -600,7 +600,7 @@ class BladesRollPrimary {
this.rollPrimaryName = rollPrimaryName;
this.rollPrimaryType = rollPrimaryType;
this.rollPrimaryImg = rollPrimaryImg;
this.rollModsData = rollModsData ?? [];
this._rollModsData = rollModsData ?? [];
this.rollFactors = rollFactors;
}
}
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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 });
Expand Down Expand Up @@ -1042,23 +1046,23 @@ 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;
break;
}
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;
break;
}
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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
Expand All @@ -2151,21 +2155,21 @@ 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));
}
}
});
html.find("[data-action='tradeEffect']").on({
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));
}
}
});
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
6 changes: 3 additions & 3 deletions module/sheets/actor/BladesActorSheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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;
}
}
Expand Down
11 changes: 6 additions & 5 deletions module/sheets/item/BladesScoreSheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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];
}
Expand All @@ -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();
Expand Down Expand Up @@ -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) {
Expand All @@ -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),
Expand Down Expand Up @@ -286,4 +286,5 @@ class BladesScoreSheet extends BladesItemSheet {
return submitData;
}
}
export { BladesTipGenerator };
export default BladesScoreSheet;
20 changes: 10 additions & 10 deletions ts/@types/blades-roll.d.ts
Original file line number Diff line number Diff line change
@@ -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 {

Expand All @@ -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
}
}

Expand Down
Loading

0 comments on commit 68f5d9f

Please sign in to comment.