Skip to content

Commit

Permalink
v0.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Moerill committed Dec 17, 2020
1 parent 60a00e6 commit cc8c03c
Show file tree
Hide file tree
Showing 17 changed files with 301 additions and 163 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# v0.2

- Tooltips for everything! (or at least *more* tooltips to help find what can actually be toggled using right-click)
- Faster animations, buttons inside the chat card are now visible when hovering it.

# v0.1.2

- *Fix* fumbles still being able to hit, although they shouldn't.
Expand Down
4 changes: 2 additions & 2 deletions html/chat/dmg.hbs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div class="mars5e-action damage {{#if critical}}critical{{/if}}">
<div class="mars5e-action damage mars5e-toggleable {{#if critical}}critical{{/if}}">
<label>{{localize 'DND5E.Damage'}}</label>
<div class="mars5e-apply-dmg-menu versatile" style="height: 19px;">
<div class="mars5e-apply-dmg-menu" style="height: 19px;">
<button class="mars5e-apply" data-amount="0"><i class="fas fa-fist-raised"></i></button>
{{#if @root.versatile}}
<button class="mars5e-apply-versatile" data-amount="0"><i class="fas fa-sign-language"></i></button>
Expand Down
4 changes: 2 additions & 2 deletions html/chat/targets.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
{{/if}}
</div>
{{#if data.hasAttack}}
<div class="mars5e-action attack ">
<div class="mars5e-action attack mars5e-toggleable">
<label>{{localize 'DND5E.Attack'}}</label>
<a class="rollable roll-d20" title="{{data.attack.flavor}}" data-advantage="{{data.attack.advantage}}">{{data.attack.mod}}</a>
</div>
{{/if}}
{{!-- {{else}} --}}
{{#if data.hasSave}}
<div class="mars5e-action save">
<div class="mars5e-action save mars5e-toggleable">
<label>{{localize 'DND5E.SavingThrow'}} ({{data.labels.saveAbi}})</label>
<a class="rollable roll-d20" data-dc="{{data.data.save.dc}}" data-ability="{{data.data.save.ability}}">{{data.labels.save}}</a>
</div>
Expand Down
6 changes: 5 additions & 1 deletion html/definitions.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@
--mars5e-versatile-label: '{{localize "DND5E.Versatile"}}';
{{!-- {{ localize "MARS5E.label.hit"}} --}}
{{!-- {{ localize "MARS5E.label.miss" }} --}}
--mars5e-dice-anim-time: 0.6s;
--mars5e-tooltip-resistance-toggle: '{{toggleResistanceTooltip}}';
--mars5e-tooltip-success-toggle: '{{toggleSuccessTooltip}}';
--mars5e-tooltip-advantage-toggle: '{{toggleAdvantageTooltip}}';
--mars5e-dice-color: #222;
--mars5e-font-color: #c2c2c2;
Expand Down
2 changes: 1 addition & 1 deletion html/item-card.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<div class="mars5e-targets">
{{#if toolCheck}}
<div class='mars5e-target'>
<div class='mars5e-action'>
<div class='mars5e-action tool mars5e-toggleable'>
<label>{{ localize "DND5E.Use" }} {{item.name}}</label>
<a class='rollable' title="{{toolCheck.flavorFormula}}">{{toolCheck.formula}}</a>
</div>
Expand Down
1 change: 0 additions & 1 deletion js/actor/entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ export default function initActorClass() {
const rollMode = game.settings.get("core", "rollMode");
if (["gmroll", "blindroll"].includes(rollMode))
chatData["whisper"] = ChatMessage.getWhisperRecipients("GM");
console.log(rollMode);
if (rollMode === "blindroll") chatData["blind"] = true;

return ChatMessage.create(chatData);
Expand Down
78 changes: 23 additions & 55 deletions js/chat/message.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,32 +156,34 @@ export default class Mars5eMessage extends ChatMessage {
}

_toggleAdv(ev) {
const target = ev.target.closest(".attack .roll-d20, .save .roll-d20");
const target = ev.target.closest(".attack, .save, .tool-check");

if (!target) return false;
if (
!target ||
this._getTarget(target)?.actor.permission <
CONST.ENTITY_PERMISSIONS.OBSERVER
target.querySelector(".mars5e-result")

// || this._getTarget(target)?.actor.permission <
// CONST.ENTITY_PERMISSIONS.OBSERVER
)
return false;

ev.preventDefault();
ev.stopPropagation();

const adv = Number(target.dataset.advantage ?? 1);
target.dataset.advantage = (adv + 1) % 3;
const roll = target.querySelector(".rollable");
const adv = Number(roll.dataset.advantage ?? 1);
roll.dataset.advantage = (adv + 1) % 3;

return true;
}

_toggleHit(ev) {
const target = ev.target.closest(".attack label, .save label");
if (!target || target.querySelector(".mars5e-result")) return false;
const target = ev.target.closest(".attack, .save");
if (!target || !target.querySelector(".mars5e-result")) return false;

ev.preventDefault();
ev.stopPropagation();

const action = target.closest(".mars5e-action");
const action = target;
const success = action.classList.toggle("mars5e-success");
action.classList.toggle("mars5e-fail");
if (action.classList.contains("attack"))
Expand All @@ -191,9 +193,8 @@ export default class Mars5eMessage extends ChatMessage {
}

_toggleCrit(ev) {
const target = ev.target.closest(".damage label");
if (!target || target.parentNode.querySelector(".mars5e-result"))
return false;
const target = ev.target.closest(".damage");
if (!target || target.querySelector(".mars5e-result")) return false;
ev.preventDefault();
ev.stopPropagation();

Expand Down Expand Up @@ -290,8 +291,10 @@ export default class Mars5eMessage extends ChatMessage {
}
}
resultDiv.dataset.advantage = adv.toString();
const attack = resultDiv.closest(".attack");
const targetId = resultDiv.closest(".mars5e-target").dataset.targetId;
if (!targetId) {
attack.classList.add("mars5e-success");
await this._renderDmg(resultDiv, critical);
return resultDiv;
}
Expand All @@ -303,7 +306,6 @@ export default class Mars5eMessage extends ChatMessage {
// const actor = token.actor;
const actor = await this._getTarget(resultDiv)?.actor;
const ac = actor.data.data.attributes.ac.value;
const attack = resultDiv.closest(".attack");
if (critical || (r.total >= ac && !fumble)) {
attack.classList.add("mars5e-success");
await this._renderDmg(resultDiv, critical);
Expand Down Expand Up @@ -395,7 +397,6 @@ export default class Mars5eMessage extends ChatMessage {
}

async _onRoll(rollable) {
console.log(rollable.dataset.flavorFormula);
const r = new Roll(rollable.dataset.flavorFormula);
r.roll();
return this._renderResult(rollable, r);
Expand All @@ -410,7 +411,6 @@ export default class Mars5eMessage extends ChatMessage {

async _renderDmg(resultDiv, critical = false) {
if (!this.item.hasDamage) return null;

const targetDiv = resultDiv.closest(".mars5e-target");

const targets = resultDiv.closest(".mars5e-targets");
Expand Down Expand Up @@ -456,7 +456,10 @@ export default class Mars5eMessage extends ChatMessage {

const spellLevel = parseInt(this.card.dataset.spellLevel) || null;

let data = await this.item.rollDamage({ critical, spellLevel });
let data = await this.item.rollDamage({
options: { critical },
spellLevel,
});
data.critical = critical;

const target = await this._getTarget(resultDiv)?.actor;
Expand Down Expand Up @@ -530,8 +533,10 @@ export default class Mars5eMessage extends ChatMessage {
if (resistance) resultDiv.dataset.resistance = resistance;
if (versatile) resultDiv.classList.add("versatile");
if (isNonVersatileMainRoll) resultDiv.classList.add("non-versatile");
resultDiv.querySelector(".result-total").classList.add("mars5e-toggleable");

const actionDiv = resultDiv.closest(".damage");
actionDiv.classList.remove("mars5e-toggleable");
if (actionDiv.parentNode.classList.contains("mars5e-area-dmg"))
await this._applyAreaDmg(actionDiv);
this._updateApplyDmgAmount(actionDiv);
Expand All @@ -542,6 +547,7 @@ export default class Mars5eMessage extends ChatMessage {
}

async _applyAreaDmg(dmgDiv) {
dmgDiv.querySelector(".result-total").classList.remove("mars5e-toggleable");
const card = dmgDiv.closest(".mars5e-targets");
const targetDivs = Array.from(
card.querySelectorAll(".mars5e-target:not(.mars5e-area-dmg")
Expand Down Expand Up @@ -589,41 +595,6 @@ export default class Mars5eMessage extends ChatMessage {
this._updateApplyDmgAmount(div);
resultDivs.push(div);
}
// const target = dmgDiv.closest(".mars5e-target");
// target.style.overflow = "hidden";
// resultDivs.forEach((e) => {
// console.log(e);
// e.style.overflow = "hidden";
// });
// return new Promise((resolve, reject) =>
// TweenMax.from(resultDivs, 0.3, {
// height: 0,
// onComplete: () => {
// resultDivs.forEach((e) => (e.style.overflow = null));
// resolve();
// },
// })
// );
// return Promise.all([
// new Promise((resolve, reject) =>
// TweenMax.to(target, 0.3, {
// height: 0,
// onComplete: () => {
// target.remove();
// resolve();
// },
// })
// ),
// new Promise((resolve, reject) =>
// TweenMax.from(resultDivs, 0.3, {
// height: 0,
// onComplete: () => {
// resultDivs.forEach((e) => (e.style.overflow = null));
// resolve();
// },
// })
// ),
// ]);
}

_onClickToggleVisibility(ev) {
Expand Down Expand Up @@ -681,7 +652,6 @@ export default class Mars5eMessage extends ChatMessage {
const tooltip = await roll.getTooltip();
result.insertAdjacentHTML("beforeend", tooltip);
div.replaceWith(result);

return result;
}

Expand Down Expand Up @@ -793,9 +763,7 @@ export default class Mars5eMessage extends ChatMessage {
}

mars5eUpdate(div) {
console.log(this);
if (this.data.user === game.user.id || game.user.isGM) {
console.log("updating");
this.update({ content: this.card.parentNode.innerHTML });
} else {
const targetDiv = div.closest(".mars5e-target");
Expand Down
23 changes: 16 additions & 7 deletions js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,21 +135,30 @@ function isTokenViewable(div) {

Hooks.on("init", () => {
loadTemplates([
// "modules/mars-5e/html/dice/d4.hbs",
// "modules/mars-5e/html/dice/d6.hbs",
// "modules/mars-5e/html/dice/d8.hbs",
// "modules/mars-5e/html/dice/d10.hbs",
// "modules/mars-5e/html/dice/d12.hbs",
// "modules/mars-5e/html/dice/d20.hbs",
"modules/mars-5e/html/chat/targets.hbs",
"modules/mars-5e/html/chat/dmg.hbs",
]);
});

Hooks.on("ready", async () => {
const translationData = {
toggle: game.i18n.localize("MARS5E.tool-tip.toggle"),
"right-click": game.i18n.localize("MARS5E.tool-tip.right-click"),
};
const data = {
toggleResistanceTooltip: game.i18n.format(
"MARS5E.tool-tip.toggle-resistance",
translationData
),
toggleSuccessTooltip: game.i18n.format(
"MARS5E.tool-tip.success",
translationData
),
toggleAdvantageTooltip: game.i18n.format("MARS5E.tool-tip.advantage"),
};
document.head.insertAdjacentHTML(
"beforeend",
await renderTemplate("modules/mars-5e/html/definitions.hbs", {})
await renderTemplate("modules/mars-5e/html/definitions.hbs", data)
);
templateAutotargeting();
});
Expand Down
2 changes: 0 additions & 2 deletions js/item/entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,6 @@ export default function initItemClass() {
...adv,
});
this.data.data.consume = consume;
console.log(attackRoll);
const mod = attackRoll.shortenedFormula.replace(
/[12]?d20(k[hl])?\s/,
""
Expand Down Expand Up @@ -386,7 +385,6 @@ export default function initItemClass() {
this.data.data.damage.parts = [parts[0]];

const roll = await super.rollDamage({ spellLevel, options });
console.log(roll.shortenedFormula);
roll.dmgType = parts[0][1];
if (roll.dmgType === "healing") {
roll.dmgTypeLabel = game.i18n.localize("DND5E.Healing");
Expand Down
4 changes: 4 additions & 0 deletions js/rolls/number-term.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,8 @@ export default class NumberTerm extends DiceTerm {
alter() {
return this;
}

get expression() {
return this.number;
}
}
7 changes: 7 additions & 0 deletions lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@
},
"errors": {
"userNotOnline": "Cannot roll, owner of this chat card is not online."
},
"tool-tip": {
"right-click": "Right-click",
"toggle": "toggle",
"toggle-resistance": "{right-click} to {toggle} resistance multiplier.",
"success": "{right-click} to {toggle} Success/Fail.",
"advantage": "{right-click} to {toggle} (Dis-)Advantage."
}
}
}
Loading

0 comments on commit cc8c03c

Please sign in to comment.