Skip to content

Commit

Permalink
Added Check pop ups
Browse files Browse the repository at this point in the history
  • Loading branch information
ChasarooniZ committed Sep 15, 2023
1 parent 623b632 commit c9145c9
Show file tree
Hide file tree
Showing 3 changed files with 139 additions and 26 deletions.
37 changes: 27 additions & 10 deletions languages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,23 @@
},
"font-size": {
"name": "Font Size",
"hint": "Default size of the font"
"hint": "Default size of the damage font"
},
"max-font-scale": {
"name": "Maximum Font Scale",
"hint": "Maximum Size to scale font to"
"hint": "Maximum Size to scale the damage font to"
},
"top-offset": {
"name": "% offset from top of token",
"hint": "Offset percentage from top of token, input as whole number (IE. 70 is 70%)"
"hint": "Offset percentage from top of token for the damage, input as whole number (IE. 70 is 70%)"
},
"jitter": {
"name": "Jitter",
"hint": "How much the text will move around its spawn point (0 = doesn't move, 1 is it could spawn on the edges of the token)"
"hint": "How much the damage text will move around its spawn point (0 = doesn't move, 1 is it could spawn on the edges of the token)"
},
"number-scale-type": {
"name": "Number Scale Type",
"hint": "Scaling type for the size of the RPG Numbers",
"hint": "Scaling type for the size of the damage RPG Numbers",
"choices": {
"percent-remaining-health": "% of Remaining HP",
"percent-max-health": "% of Max HP",
Expand All @@ -46,24 +46,41 @@
},
"duration": {
"name": "Text Duration",
"hint": "How long until the text despawns in seconds"
"hint": "How long until the damage text despawns in seconds"
},
"wait-time-between-numbers": {
"name": "Wait Time between numbers (ms)",
"hint": "How long in between each number should the game wait before spawning the next, in milliseconds."
"hint": "How long in between each damage number should the game wait before spawning the next, in milliseconds."
},
"show-only-GM": {
"name": "Show numbers only for GM",
"hint": "Show them only for the game if you like them, but not that much"
"hint": "Show the damage numbers only for the game if you like them, but not that much"
},
"animation-scale": {
"name": "Animation Scale",
"hint": "How far out from the token should the numbers move"
"hint": "How far out from the token should the damage numbers move"
},
"show-total": {
"name": "Show Total",
"hint": "Show total as a number in the center of the token in addition to other numbers"
"hint": "Show total as a number in the center of the token in addition to other damage numbers"
},
"check-enabled": {
"name": "Enable Checks",
"hint": "Show number pop ups when attempting checks"
},
"check-duration": {
"name": "Check Duration",
"hint": "Time for check number pop up to show"
},
"check-font-size": {
"name": "Check Font Size",
"hint": "Size of Check Font"
},
"dmg-enabled": {
"name": "Enable Damage Numbers",
"hint": "Show damage numbers"
}

}
}
}
71 changes: 63 additions & 8 deletions scripts/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,26 @@ Hooks.on("createChatMessage", async function (msg, status, id) {
debugLog({
msg
})
if (!msg.isDamageRoll || !game.user.isGM) return;
const dmg_list = getDamageList(msg.rolls);
const targets = getTargetList(msg);
debugLog({
targets,
dmg_list
})
generateDamageScroll(dmg_list, targets);
if (game.user.isGM) {
if (msg.isDamageRoll && game.settings.get("pf2e-rpg-numbers", 'dmg-enabled')) {
const dmg_list = getDamageList(msg.rolls);
const targets = getTargetList(msg);
debugLog({
targets,
dmg_list
})
generateDamageScroll(dmg_list, targets);
}
if (msg.isCheckRoll && game.settings.get("pf2e-rpg-numbers", 'checks-enabled')) {
const roll_deets = {
outcome: msg.flags.pf2e.context.outcome ?? 'none',
token: msg.token,
whisper: msg.whisper,
roll: msg.rolls[0]?.total ?? ''
}
generateRollScroll(roll_deets);
}
}
})

export function getTargetList(msg) {
Expand Down Expand Up @@ -171,6 +183,49 @@ export function generateDamageScroll(dmg_list, targets) {
}
}

/**
*
* @param {{outcome: 'none' | 'criticalFailure' | 'failure' | 'success' | 'criticalSuccess', token: token, whisper: string[] roll: number | ''}} roll_deets
*/
export function generateRollScroll(roll_deets) {
const fontSize = game.settings.get("pf2e-rpg-numbers", 'check-font-size');
const colors = {
none: 'white',
criticalFailure: 'rgb(255, 0, 0)',
failure: 'rgb(255, 69, 0)',
success: 'rgb(0, 0, 255)',
criticalSuccess: 'rgb(0, 128, 0)'

}
const style = {
"fill": colors[roll_deets.outcome],
"fontSize": fontSize,
align: "center",
dropShadow: true,
strokeThickness: 5,
}
const duration = game.settings.get("pf2e-rpg-numbers", 'check-duration') * 1000;
const seq = new Sequence();
seq.effect()
.atLocation(roll_deets.token, {
offset: {
y: 0.4 * roll_deets.token.texture.scaleY * roll_deets.document.width
},
gridUnits: true,
})
.text(`${roll_deets.roll}`, style)
.anchor({
x: 0.5,
y: 0.8
})
.duration(duration)
.scaleIn(0.5, duration / 3)
.fadeOut(duration / 3)
.zIndex(2)
.forUsers(game.users.filter(u => roll_deets.whisper.length === 0 || roll_deets.whisper.includes(u.id)))
.play()
}

export function getVisibleUsers(tok) {
let list = game.users.filter(u => u.isGM).map(u => u.id);
if (!tok.document.hidden) {
Expand Down
57 changes: 49 additions & 8 deletions scripts/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ Hooks.on("init", () => {
default: true,
type: Boolean,
});
game.settings.register("pf2e-rpg-numbers", "dmg-enabled", {
name: game.i18n.localize("pf2e-rpg-numbers.module-settings.dmg-enabled.name"),
hint: game.i18n.localize("pf2e-rpg-numbers.module-settings.dmg-enabled.hint"),
scope: "world",
config: true,
default: true,
type: Boolean,
});
game.settings.register("pf2e-rpg-numbers", "font-size", {
name: game.i18n.localize("pf2e-rpg-numbers.module-settings.font-size.name"),
hint: game.i18n.localize("pf2e-rpg-numbers.module-settings.font-size.hint"),
Expand Down Expand Up @@ -74,14 +82,6 @@ Hooks.on("init", () => {
["all"]: game.i18n.localize("pf2e-rpg-numbers.module-settings.damage-split.choices.all"),
},
});
game.settings.register("pf2e-rpg-numbers", "debug-mode", {
name: game.i18n.localize("pf2e-rpg-numbers.module-settings.debug-mode.name"),
hint: game.i18n.localize("pf2e-rpg-numbers.module-settings.debug-mode.hint"),
scope: "world",
config: true,
default: false,
type: Boolean,
});
game.settings.register("pf2e-rpg-numbers", "duration", {
name: game.i18n.localize("pf2e-rpg-numbers.module-settings.duration.name"),
hint: game.i18n.localize("pf2e-rpg-numbers.module-settings.duration.hint"),
Expand Down Expand Up @@ -143,4 +143,45 @@ Hooks.on("init", () => {
},
type: Number,
});
game.settings.register("pf2e-rpg-numbers", "check-font-size", {
name: game.i18n.localize("pf2e-rpg-numbers.module-settings.check-font-size.name"),
hint: game.i18n.localize("pf2e-rpg-numbers.module-settings.check-font-size.hint"),
scope: "world",
config: true,
default: 30,
type: Number,
});
game.settings.register("pf2e-rpg-numbers", "check-duration", {
name: game.i18n.localize("pf2e-rpg-numbers.module-settings.check-duration.name"),
hint: game.i18n.localize("pf2e-rpg-numbers.module-settings.check-duration.hint"),
scope: "world",
config: true,
default: 2,
range: {
min: 0,
max: 10,
step: 0.1
},
type: Number,
});
game.settings.register("pf2e-rpg-numbers", "check-enabled", {
name: game.i18n.localize("pf2e-rpg-numbers.module-settings.check-enabled.name"),
hint: game.i18n.localize("pf2e-rpg-numbers.module-settings.check-enabled.hint"),
scope: "world",
config: true,
default: true,
type: Boolean,
});




game.settings.register("pf2e-rpg-numbers", "debug-mode", {
name: game.i18n.localize("pf2e-rpg-numbers.module-settings.debug-mode.name"),
hint: game.i18n.localize("pf2e-rpg-numbers.module-settings.debug-mode.hint"),
scope: "world",
config: true,
default: false,
type: Boolean,
});
});

0 comments on commit c9145c9

Please sign in to comment.