mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-04-21 23:13:39 +02:00
Added updating for other players
This commit is contained in:
parent
86f3da8ac7
commit
d3437ffa7b
2 changed files with 68 additions and 25 deletions
|
|
@ -685,6 +685,8 @@
|
||||||
"insufficientHope": "The initiating character doesn't have enough hope",
|
"insufficientHope": "The initiating character doesn't have enough hope",
|
||||||
"createTagTeam": "Create TagTeam Roll",
|
"createTagTeam": "Create TagTeam Roll",
|
||||||
"chatMessageRollTitle": "Roll",
|
"chatMessageRollTitle": "Roll",
|
||||||
|
"cancelConfirmTitle": "Cancel TagTeam Roll",
|
||||||
|
"cancelConfirmText": "Are you sure you want to cancel the TagTeam Roll? This will close it for all other players too.",
|
||||||
"hints": {
|
"hints": {
|
||||||
"completeRolls": "Set up and complete the rolls for the characters",
|
"completeRolls": "Set up and complete the rolls for the characters",
|
||||||
"selectRoll": "Select which roll value to be used for the Tagteam"
|
"selectRoll": "Select which roll value to be used for the Tagteam"
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
import { MemberData } from '../../data/tagTeamData.mjs';
|
import { MemberData } from '../../data/tagTeamData.mjs';
|
||||||
import { getCritDamageBonus } from '../../helpers/utils.mjs';
|
import { getCritDamageBonus } from '../../helpers/utils.mjs';
|
||||||
|
import { RefreshType, socketEvent } from '../../systemRegistration/socket.mjs';
|
||||||
import Party from '../sheets/actors/party.mjs';
|
import Party from '../sheets/actors/party.mjs';
|
||||||
|
|
||||||
const { HandlebarsApplicationMixin, ApplicationV2 } = foundry.applications.api;
|
const { HandlebarsApplicationMixin, ApplicationV2 } = foundry.applications.api;
|
||||||
|
|
@ -22,6 +23,8 @@ export default class TagTeamDialog extends HandlebarsApplicationMixin(Applicatio
|
||||||
this.tabGroups.application = Object.keys(party.system.tagTeam.members).length
|
this.tabGroups.application = Object.keys(party.system.tagTeam.members).length
|
||||||
? 'tagTeamRoll'
|
? 'tagTeamRoll'
|
||||||
: 'initialization';
|
: 'initialization';
|
||||||
|
|
||||||
|
Hooks.on(socketEvent.Refresh, this.tagTeamRefresh.bind());
|
||||||
}
|
}
|
||||||
|
|
||||||
get title() {
|
get title() {
|
||||||
|
|
@ -163,8 +166,40 @@ export default class TagTeamDialog extends HandlebarsApplicationMixin(Applicatio
|
||||||
static async updateData(_event, _, formData) {
|
static async updateData(_event, _, formData) {
|
||||||
const { initiator, ...partyData } = foundry.utils.expandObject(formData.object);
|
const { initiator, ...partyData } = foundry.utils.expandObject(formData.object);
|
||||||
this.initiator = initiator;
|
this.initiator = initiator;
|
||||||
await this.party.update(partyData);
|
this.updatePartyData(partyData);
|
||||||
this.render(true);
|
}
|
||||||
|
|
||||||
|
async updatePartyData(updata, options = { render: true }) {
|
||||||
|
await this.party.update(updata);
|
||||||
|
|
||||||
|
if (options.render) {
|
||||||
|
this.render(true);
|
||||||
|
game.socket.emit(`system.${CONFIG.DH.id}`, {
|
||||||
|
action: socketEvent.Refresh,
|
||||||
|
data: { refreshType: RefreshType.TagTeamRoll, action: 'refresh' }
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tagTeamRefresh = ({ refreshType, action }) => {
|
||||||
|
if (refreshType !== RefreshType.TagTeamRoll) return;
|
||||||
|
|
||||||
|
switch (action) {
|
||||||
|
case 'refresh':
|
||||||
|
this.render();
|
||||||
|
break;
|
||||||
|
case 'close':
|
||||||
|
this.close();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
async close(options = {}) {
|
||||||
|
/* Opt out of Foundry's standard behavior of closing all application windows marked as UI when Escape is pressed */
|
||||||
|
if (options.closeKey) return;
|
||||||
|
|
||||||
|
Hooks.off(socketEvent.Refresh, this.tagTeamRefresh);
|
||||||
|
return super.close(options);
|
||||||
}
|
}
|
||||||
|
|
||||||
//#region Initialization
|
//#region Initialization
|
||||||
|
|
@ -220,26 +255,22 @@ export default class TagTeamDialog extends HandlebarsApplicationMixin(Applicatio
|
||||||
}
|
}
|
||||||
|
|
||||||
async updateRollType(event) {
|
async updateRollType(event) {
|
||||||
await this.party.update({
|
this.updatePartyData({
|
||||||
[`system.tagTeam.members.${event.target.dataset.member}`]: {
|
[`system.tagTeam.members.${event.target.dataset.member}`]: {
|
||||||
rollType: event.target.value,
|
rollType: event.target.value,
|
||||||
rollChoice: null
|
rollChoice: null
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
this.render();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static async #removeRoll(_, button) {
|
static async #removeRoll(_, button) {
|
||||||
await this.party.update({
|
this.updatePartyData({
|
||||||
[`system.tagTeam.members.${button.dataset.member}`]: {
|
[`system.tagTeam.members.${button.dataset.member}`]: {
|
||||||
rollData: null,
|
rollData: null,
|
||||||
rollChoice: null,
|
rollChoice: null,
|
||||||
selected: false
|
selected: false
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
this.render();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static async #makeRoll(event, button) {
|
static async #makeRoll(event, button) {
|
||||||
|
|
@ -262,10 +293,9 @@ export default class TagTeamDialog extends HandlebarsApplicationMixin(Applicatio
|
||||||
|
|
||||||
const rollData = result.messageRoll.toJSON();
|
const rollData = result.messageRoll.toJSON();
|
||||||
delete rollData.options.messageRoll;
|
delete rollData.options.messageRoll;
|
||||||
await this.party.update({
|
this.updatePartyData({
|
||||||
[`system.tagTeam.members.${member}.rollData`]: rollData
|
[`system.tagTeam.members.${member}.rollData`]: rollData
|
||||||
});
|
});
|
||||||
this.render();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async makeTraitRoll(memberKey) {
|
async makeTraitRoll(memberKey) {
|
||||||
|
|
@ -310,7 +340,7 @@ export default class TagTeamDialog extends HandlebarsApplicationMixin(Applicatio
|
||||||
diceType
|
diceType
|
||||||
);
|
);
|
||||||
const rollData = parsedRoll.toJSON();
|
const rollData = parsedRoll.toJSON();
|
||||||
await this.party.update({
|
this.updatePartyData({
|
||||||
[`system.tagTeam.members.${member}.rollData`]: {
|
[`system.tagTeam.members.${member}.rollData`]: {
|
||||||
...rollData,
|
...rollData,
|
||||||
options: {
|
options: {
|
||||||
|
|
@ -319,7 +349,6 @@ export default class TagTeamDialog extends HandlebarsApplicationMixin(Applicatio
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
this.render();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static async #makeDamageRoll(_, button) {
|
static async #makeDamageRoll(_, button) {
|
||||||
|
|
@ -344,7 +373,7 @@ export default class TagTeamDialog extends HandlebarsApplicationMixin(Applicatio
|
||||||
const damage = config.isCritical ? await this.getNonCriticalDamage(config, actor) : config.damage;
|
const damage = config.isCritical ? await this.getNonCriticalDamage(config, actor) : config.damage;
|
||||||
|
|
||||||
const current = this.party.system.tagTeam.members[memberKey].rollData;
|
const current = this.party.system.tagTeam.members[memberKey].rollData;
|
||||||
await this.party.update({
|
await this.updatePartyData({
|
||||||
[`system.tagTeam.members.${memberKey}.rollData`]: {
|
[`system.tagTeam.members.${memberKey}.rollData`]: {
|
||||||
...current,
|
...current,
|
||||||
options: {
|
options: {
|
||||||
|
|
@ -353,14 +382,12 @@ export default class TagTeamDialog extends HandlebarsApplicationMixin(Applicatio
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
this.render();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static async #removeDamageRoll(_, button) {
|
static async #removeDamageRoll(_, button) {
|
||||||
const { memberKey } = button.dataset;
|
const { memberKey } = button.dataset;
|
||||||
const current = this.party.system.tagTeam.members[memberKey].rollData;
|
const current = this.party.system.tagTeam.members[memberKey].rollData;
|
||||||
await this.party.update({
|
this.updatePartyData({
|
||||||
[`system.tagTeam.members.${memberKey}.rollData`]: {
|
[`system.tagTeam.members.${memberKey}.rollData`]: {
|
||||||
...current,
|
...current,
|
||||||
options: {
|
options: {
|
||||||
|
|
@ -369,8 +396,6 @@ export default class TagTeamDialog extends HandlebarsApplicationMixin(Applicatio
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
this.render();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async getCriticalDamage(damage) {
|
async getCriticalDamage(damage) {
|
||||||
|
|
@ -421,7 +446,7 @@ export default class TagTeamDialog extends HandlebarsApplicationMixin(Applicatio
|
||||||
|
|
||||||
static async #selectRoll(_, button) {
|
static async #selectRoll(_, button) {
|
||||||
const { memberKey } = button.dataset;
|
const { memberKey } = button.dataset;
|
||||||
await this.party.update({
|
this.updatePartyData({
|
||||||
[`system.tagTeam.members`]: Object.entries(this.party.system.tagTeam.members).reduce(
|
[`system.tagTeam.members`]: Object.entries(this.party.system.tagTeam.members).reduce(
|
||||||
(acc, [key, member]) => {
|
(acc, [key, member]) => {
|
||||||
acc[key] = { selected: key === memberKey ? !member.selected : false };
|
acc[key] = { selected: key === memberKey ? !member.selected : false };
|
||||||
|
|
@ -430,7 +455,6 @@ export default class TagTeamDialog extends HandlebarsApplicationMixin(Applicatio
|
||||||
{}
|
{}
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
this.render();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async getJoinedRoll({ overrideIsCritical, displayVersion } = {}) {
|
async getJoinedRoll({ overrideIsCritical, displayVersion } = {}) {
|
||||||
|
|
@ -473,13 +497,30 @@ export default class TagTeamDialog extends HandlebarsApplicationMixin(Applicatio
|
||||||
}
|
}
|
||||||
|
|
||||||
static async #cancelRoll() {
|
static async #cancelRoll() {
|
||||||
await this.party.update({
|
const confirmed = await foundry.applications.api.DialogV2.confirm({
|
||||||
'system.==tagTeam': {
|
window: {
|
||||||
initiator: null,
|
title: game.i18n.localize('DAGGERHEART.APPLICATIONS.TagTeamSelect.cancelConfirmTitle')
|
||||||
members: {}
|
},
|
||||||
}
|
content: game.i18n.localize('DAGGERHEART.APPLICATIONS.TagTeamSelect.cancelConfirmText')
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (!confirmed) return;
|
||||||
|
|
||||||
|
await this.updatePartyData(
|
||||||
|
{
|
||||||
|
'system.==tagTeam': {
|
||||||
|
initiator: null,
|
||||||
|
members: {}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{ render: false }
|
||||||
|
);
|
||||||
|
|
||||||
this.close();
|
this.close();
|
||||||
|
game.socket.emit(`system.${CONFIG.DH.id}`, {
|
||||||
|
action: socketEvent.Refresh,
|
||||||
|
data: { refreshType: RefreshType.TagTeamRoll, action: 'close' }
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
static async #finishRoll() {
|
static async #finishRoll() {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue