Skip to content

Commit

Permalink
Add trait broadcasting
Browse files Browse the repository at this point in the history
  • Loading branch information
StasTserk committed Dec 4, 2020
1 parent 7ad29f9 commit fd69840
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 2 deletions.
2 changes: 1 addition & 1 deletion module/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,5 @@ export async function simpleBroadcast(data: SimpleBroadcastMessageData, actor: B
export interface SimpleBroadcastMessageData {
title: string;
mainText: string;
extraData?: { title?: string, text: string }[]
extraData?: { title?: string, text?: string }[]
}
54 changes: 53 additions & 1 deletion module/items/trait.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { RollModifier } from "../actors/BWActor.js";
import { simpleBroadcast, SimpleBroadcastMessageData } from "../chat.js";
import { BWActor, RollModifier } from "../actors/BWActor.js";
import { ItemType, HasPointCost, BWItemData, BWItem } from "./item.js";

export class Trait extends BWItem {
Expand All @@ -23,6 +24,57 @@ export class Trait extends BWItem {
};
}

async generateChatMessage(actor: BWActor): Promise<Entity> {
const extraData: { title?: string, text?: string }[] = [];
if (this.data.data.traittype === "call-on") {
extraData.push({
title: "Call-on For",
text: this.data.data.callonTarget
});
} else if (this.data.data.traittype === "die") {
if (this.data.data.hasAptitudeModifier) {
extraData.push({
title: "Affects Aptitude",
text: `${this.data.data.aptitudeTarget.trim()} : ${this.data.data.aptitudeModifier}`
});
}
if (this.data.data.hasDieModifier) {
extraData.push({
title: "Adds Dice",
text: `${this.data.data.dieModifierTarget} : ${this.data.data.dieModifier >= 0 ? '+' + this.data.data.dieModifier : this.data.data.dieModifier}D`
});
}
if (this.data.data.hasObModifier) {
extraData.push({
title: "Changed Obstacle",
text: `${this.data.data.obModifierTarget} : ${this.data.data.obModifier >= 0 ? '+' + this.data.data.obModifier : this.data.data.obModifier} Ob`
});
}
if (this.data.data.addsAffiliation) {
extraData.push({
title: "Adds an Affiliation",
text: `${this.data.data.affiliationDice}D with ${this.data.data.affiliationName}`
});
}
if (this.data.data.addsReputation) {
extraData.push({
title: "Adds a Reputation",
text: `${this.data.data.reputationDice}D ${this.data.data.reputationInfamous ? "infamous " : ""}reputation as ${this.data.data.reputationName}`
});
}
}
extraData.push({
title: `${this.data.data.traittype.titleCase()} Trait`
});

const data: SimpleBroadcastMessageData = {
title: this.name,
mainText: this.data.data.text || "No Description Given",
extraData
};
return simpleBroadcast(data, actor);
}

get type(): ItemType { return super.type as ItemType; }

data: TraitDataRoot;
Expand Down
3 changes: 3 additions & 0 deletions templates/character-sheet.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@
<div class="trait" data-item-id="{{trait._id}}" draggable="true" data-id="{{trait._id}}">
<h3>
{{ trait.name }}
<i class="fas fa-comment" data-action="broadcast" data-id="{{trait._id}}"></i>
<i class="fas fa-trash" data-action="delItem" data-id="{{trait._id}}"></i>
<i class="fas fa-edit" data-action="editItem" data-id="{{trait._id}}"></i>
</h3>
Expand All @@ -143,6 +144,7 @@
<label for="{{trait._id}}-toggle">
<h3>
{{ trait.name }}
<i class="fas fa-comment" data-action="broadcast" data-id="{{trait._id}}"></i>
<i class="fas fa-trash" data-action="delItem" data-id="{{trait._id}}"></i>
<i class="fas fa-edit" data-action="editItem" data-id="{{trait._id}}"></i>
</h3>
Expand All @@ -161,6 +163,7 @@
<label for="{{trait._id}}-toggle">
<h3>
{{ trait.name }}
<i class="fas fa-comment" data-action="broadcast" data-id="{{trait._id}}"></i>
<i class="fas fa-trash" data-action="delItem" data-id="{{trait._id}}"></i>
<i class="fas fa-edit" data-action="editItem" data-id="{{trait._id}}"></i>
</h3>
Expand Down
2 changes: 2 additions & 0 deletions templates/chat/simple-broadcast.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
{{#if d.title}}
<div class="roll-full-width roll-title">{{{d.title}}}</div>
{{/if}}
{{#if d.text}}
<div class="roll-full-width roll-extra-info">{{{d.text}}}</div>
{{/if}}
{{/each}}
</div>

0 comments on commit fd69840

Please sign in to comment.