Skip to content

Commit

Permalink
Merge pull request #365 from mrkwnzl/develop
Browse files Browse the repository at this point in the history
Update 2.15.0
  • Loading branch information
mrkwnzl authored Jul 14, 2024
2 parents 46311e1 + c5cb163 commit 0de5e69
Show file tree
Hide file tree
Showing 85 changed files with 823 additions and 147 deletions.
11 changes: 10 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,16 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [unreleased]
## [2.15.0] - 2024-07-14
### Added
- Items can no be favorited by holding alt and clicking the appearing star icon. Favorited items are always at the top of the list. Items at the top of the list show the star button unless they are hidden in the character settings.
- Scripting macros executing when rolling can now be executed with GM permissions.

### Fixed
- Armor data and attack modifiers are now calculated in the right place, improving performance of actor sheet updates.
- Scripting macros for tags and recursions now only fire when the tag/recursion is enabled, not when it’s disabled.

## [2.14.0] - 2024-05-18
### Added
- Items with roll buttons now can execute macros when rolling. Specify a macro uuid (right-click the ID button in the header of the item sheet) in the item settings and it will be executed when a roll is made. `rollData` provides all the data of the roll for use in the macro.
- Tags and recursions can also execeute macros when they are enabled. It works the same as for rolls, but the data is provided as `taggingData` to the macros.
Expand Down
15 changes: 15 additions & 0 deletions css/cyphersystem.css
Original file line number Diff line number Diff line change
Expand Up @@ -886,6 +886,21 @@ li.folder.collapsed > .folder-header h3 {
line-height: 1.4;
}

.cyphersystem .item-favorite,
.cyphersystem .item-favorite.alt {
text-indent: 0px;
font-size: smaller;
}

.cyphersystem .item-favorite.alt {
visibility: hidden;
}

/* .cyphersystem .item:hover .item-favorite .fa-regular.fa-star {
visibility: visible;
opacity: 1;
} */

.cyphersystem .items-list .item-quantity {
-webkit-box-flex: 0;
-ms-flex: 0 0 80px;
Expand Down
6 changes: 5 additions & 1 deletion lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,7 @@
"CYPHERSYSTEM.ExecuteMacro": "Execute macro on roll",
"CYPHERSYSTEM.ExecuteMacroTag": "Execute macro when tag is enabled",
"CYPHERSYSTEM.ExecuteMacroRecursion": "Execute macro when recursion is enabled",
"CYPHERSYSTEM.ExecuteMacroAsGM": "Execute macro with GM permissions",
"CYPHERSYSTEM.macroUuid": "Macro UUID",
"CYPHERSYSTEM.MacroNotFound": "Macro not found. Cannot roll.",
"CYPHERSYSTEM.MacroUsed": "Macro: {macro}.",
Expand All @@ -674,5 +675,8 @@
"CYPHERSYSTEM.CostTotalFourthPoolPoints": "Cost: {totalCost} {label} points",
"CYPHERSYSTEM.FourthPoolBaseCostPoint": "Base cost: {baseCost} point",
"CYPHERSYSTEM.FourthPoolBaseCostPoints": "Base cost: {baseCost} points",
"CYPHERSYSTEM.XPLeft": "XP left: {quantity}"
"CYPHERSYSTEM.XPLeft": "XP left: {quantity}",
"CYPHERSYSTEM.Favorite": "Favorite",
"CYPHERSYSTEM.ItemFavorite": "Pin Item at the Top",
"CYPHERSYSTEM.HideFavoriteButton": "Hide Favorite Button"
}
21 changes: 20 additions & 1 deletion lang/pt_BR.json
Original file line number Diff line number Diff line change
Expand Up @@ -656,5 +656,24 @@
"CYPHERSYSTEM.RemoveRecursionFromItem": "Remover Recursão do item",
"CYPHERSYSTEM.SettingRollButtonsDisabled": "Desabilitado",
"CYPHERSYSTEM.SettingRollButtonsEnabled": "Habilitado",
"CYPHERSYSTEM.SettingRollButtonsOnlyStats": "Habilitado em estatísticas e rolagens de recuperação"
"CYPHERSYSTEM.SettingRollButtonsOnlyStats": "Habilitado em estatísticas e rolagens de recuperação",
"CYPHERSYSTEM.ExecuteMacroRecursion": "Executar macro quando recursão esta ativa",
"CYPHERSYSTEM.ExecuteMacroTag": "Executar macro quando tag esta ativa",
"CYPHERSYSTEM.macroUuid": "UUID da Macro",
"CYPHERSYSTEM.MacroUsed": "Macro: {macro}.",
"CYPHERSYSTEM.NoAmmo": "Municão esgotada.",
"CYPHERSYSTEM.AmmoLeft": "{name} restante: {quantity}",
"CYPHERSYSTEM.FourthPoolNotActive": "A quarta Reserva não esta ativa.",
"CYPHERSYSTEM.CostTotalFourthPoolPoint": "Custo: {totalCost} ponto de {label}",
"CYPHERSYSTEM.FourthPoolBaseCostPoint": "Custo base: {baseCost} ponto",
"CYPHERSYSTEM.FourthPoolBaseCostPoints": "Custo base: {baseCost} pontos",
"CYPHERSYSTEM.XPLeft": "XP restante: {quantity}",
"CYPHERSYSTEM.NotAmmo": "O tipo do item especificado não é municão.",
"CYPHERSYSTEM.TheCostIsAlreadyPaid": "O custo do ponto de Reserva já foi pago.",
"CYPHERSYSTEM.CantUseAnotherPCsPool": "Você não pode usar pontos de Reserva de outro PJ.",
"CYPHERSYSTEM.FourthPoolNoEdge": "A quarta Reserva não possui um valor de Margem.",
"CYPHERSYSTEM.CostTotalFourthPoolPoints": "Custo: {totalCost} pontos de {label}",
"CYPHERSYSTEM.Scripting": "Scripting",
"CYPHERSYSTEM.ExecuteMacro": "Executar macro na rolagem",
"CYPHERSYSTEM.MacroNotFound": "Macro não encontrada. Não pode rolar."
}
60 changes: 59 additions & 1 deletion module/actor/actor-sheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import {
bySkillRating,
byArchiveStatus,
byIdentifiedStatus,
byItemLevel
byItemLevel,
byFavoriteStatus
} from "../utilities/sorting.js";
import {useRecoveries} from "../utilities/actor-utilities.js";
import {taggingEngineMain} from "../utilities/tagging-engine/tagging-engine-main.js";
Expand Down Expand Up @@ -292,6 +293,40 @@ export class CypherActorSheet extends ActorSheet {
cyphers.sort(byIdentifiedStatus);
artifacts.sort(byIdentifiedStatus);

// Sort by favorite status
equipment.sort(byFavoriteStatus);
equipmentTwo.sort(byFavoriteStatus);
equipmentThree.sort(byFavoriteStatus);
equipmentFour.sort(byFavoriteStatus);
abilities.sort(byFavoriteStatus);
abilitiesTwo.sort(byFavoriteStatus);
abilitiesThree.sort(byFavoriteStatus);
abilitiesFour.sort(byFavoriteStatus);
spells.sort(byFavoriteStatus);
skills.sort(byFavoriteStatus);
skillsTwo.sort(byFavoriteStatus);
skillsThree.sort(byFavoriteStatus);
skillsFour.sort(byFavoriteStatus);
attacks.sort(byFavoriteStatus);
armor.sort(byFavoriteStatus);
lastingDamage.sort(byFavoriteStatus);
powerShifts.sort(byFavoriteStatus);
cyphers.sort(byFavoriteStatus);
artifacts.sort(byFavoriteStatus);
oddities.sort(byFavoriteStatus);
teenSkills.sort(byFavoriteStatus);
teenAbilities.sort(byFavoriteStatus);
teenAttacks.sort(byFavoriteStatus);
teenArmor.sort(byFavoriteStatus);
teenLastingDamage.sort(byFavoriteStatus);
materials.sort(byFavoriteStatus);
ammo.sort(byFavoriteStatus);
recursions.sort(byFavoriteStatus);
tags.sort(byFavoriteStatus);
tagsTwo.sort(byFavoriteStatus);
tagsThree.sort(byFavoriteStatus);
tagsFour.sort(byFavoriteStatus);

// Sort by archive status
equipment.sort(byArchiveStatus);
equipmentTwo.sort(byArchiveStatus);
Expand Down Expand Up @@ -733,6 +768,29 @@ export class CypherActorSheet extends ActorSheet {
* General sheet functions
*/

// Toggle item visibility
$(document).ready(function () {
const itemFavorite = html.find('.item-favorite.alt');

if (game.keyboard.isModifierActive("Alt")) {
itemFavorite.css('visibility', 'visible');
}

$(document).keydown(function (event) {
if (event.altKey) {
itemFavorite.css('visibility', 'visible');
itemFavorite.removeAttr('display');
}
});

$(document).keyup(function (event) {
if (!event.altKey) {
itemFavorite.css('visibility', 'hidden');
itemFavorite.attr('display', 'none');
}
});
});

// Send item description to chat
html.find(".item-description").click(clickEvent => {
if (game.keyboard.isModifierActive("Alt")) {
Expand Down
89 changes: 88 additions & 1 deletion module/actor/actor.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,92 @@
* @extends {Actor}
*/
export class CypherActor extends Actor {
static LOG_V10_COMPATIBILITY_WARNINGS = true;
/** @override */
prepareData() {
// Prepare data for the actor. Calling the super version of this executes
// the following, in order: data reset (to clear active effects),
// prepareBaseData(), prepareEmbeddedDocuments() (including active effects),
// prepareDerivedData().
super.prepareData();
}

/** @override */
prepareBaseData() {
// Data modifications in this step occur before processing embedded
// documents or derived data.
}

prepareDerivedData() {
const actorData = this;
const systemData = actorData.system;
const flags = actorData.flags.cyphersystem || {};

// Make separate methods for each Actor type (character, npc, etc.) to keep
// things organized.
this._preparePCData(actorData);
}

/**
* Prepare Character type specific data
*/
_preparePCData(actorData) {
if (actorData.type !== 'pc') return;

// Make modifications to data here.
const systemData = actorData.system;

// Update armor
let armorTotal = 0;
let speedCostTotal = 0;
let teenArmorTotal = 0;
let teenSpeedCostTotal = 0;

for (let piece of actorData.items) {
if (piece.type === "armor" && piece.system.active === true && piece.system.archived === false) {
if (piece.system.settings.general.unmaskedForm !== "Teen") {
armorTotal = armorTotal + piece.system.basic.rating;
speedCostTotal = speedCostTotal + piece.system.basic.cost;
} else {
teenArmorTotal = teenArmorTotal + piece.system.basic.rating;
teenSpeedCostTotal = teenSpeedCostTotal + piece.system.basic.cost;
}
}
}

systemData.combat.armor.ratingTotal = armorTotal;
systemData.combat.armor.costTotal = speedCostTotal;
systemData.teen.combat.armor.armorValueTotal = teenArmorTotal;
systemData.teen.combat.armor.speedCostTotal = teenSpeedCostTotal;

// Calculate total modifier of attacks
for (let i of actorData.items) {
if (i.type == 'attack') {

let skillRating = 0;
// parseInt to correct old error
let modifiedBy = parseInt(i.system.basic.steps);
let totalModifier = 0;
let totalModified = "";

if (i.system.basic.skillRating == "Inability") skillRating = -1;
if (i.system.basic.skillRating == "Trained") skillRating = 1;
if (i.system.basic.skillRating == "Specialized") skillRating = 2;

if (i.system.basic.modifier == "hindered") modifiedBy = modifiedBy * -1;

totalModifier = skillRating + modifiedBy;

if (totalModifier == 1) totalModified = game.i18n.localize("CYPHERSYSTEM.eased");
if (totalModifier >= 2) totalModified = game.i18n.format("CYPHERSYSTEM.easedBySteps", {amount: totalModifier});
if (totalModifier == -1) totalModified = game.i18n.localize("CYPHERSYSTEM.hindered");
if (totalModifier <= -2) totalModified = game.i18n.format("CYPHERSYSTEM.hinderedBySteps", {amount: Math.abs(totalModifier)});

// Assign and return
if (i.system.totalModified != totalModified) {
i.system.totalModified = totalModified;
this.actor.updateEmbeddedDocuments("Item", [i]);
}
}
}
}
}
66 changes: 7 additions & 59 deletions module/actor/pc-sheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,65 +53,6 @@ export class CypherActorSheetPC extends CypherActorSheet {

data.sheetSettings.disabledStaticStats = (this.actor.getFlag("cyphersystem", "disabledStaticStats") || this.actor.getFlag("cyphersystem", "multiRoll.active")) ? "disabled" : "";

for (let i of data.items) {
if (i.type == 'attack') {

let skillRating = 0;
// parseInt to correct old error
let modifiedBy = parseInt(i.system.basic.steps);
let totalModifier = 0;
let totalModified = "";

if (i.system.basic.skillRating == "Inability") skillRating = -1;
if (i.system.basic.skillRating == "Trained") skillRating = 1;
if (i.system.basic.skillRating == "Specialized") skillRating = 2;

if (i.system.basic.modifier == "hindered") modifiedBy = modifiedBy * -1;

totalModifier = skillRating + modifiedBy;

if (totalModifier == 1) totalModified = game.i18n.localize("CYPHERSYSTEM.eased");
if (totalModifier >= 2) totalModified = game.i18n.format("CYPHERSYSTEM.easedBySteps", {amount: totalModifier});
if (totalModifier == -1) totalModified = game.i18n.localize("CYPHERSYSTEM.hindered");
if (totalModifier <= -2) totalModified = game.i18n.format("CYPHERSYSTEM.hinderedBySteps", {amount: Math.abs(totalModifier)});

// Assign and return
if (i.system.totalModified != totalModified) {
i.system.totalModified = totalModified;
this.actor.updateEmbeddedDocuments("Item", [i]);
}
}
}

// Update armor
let armorTotal = 0;
let speedCostTotal = 0;
let teenArmorTotal = 0;
let teenSpeedCostTotal = 0;

for (let piece of data.itemLists.armor) {
if (piece.system.active === true && piece.system.archived === false) {
armorTotal = armorTotal + piece.system.basic.rating;
speedCostTotal = speedCostTotal + piece.system.basic.cost;
}
}

for (let piece of data.itemLists.teenArmor) {
if (piece.system.active === true && piece.system.archived === false) {
teenArmorTotal = teenArmorTotal + piece.system.basic.rating;
teenSpeedCostTotal = teenSpeedCostTotal + piece.system.basic.cost;
}
}

if (this.actor.system.combat.armor.ratingTotal != armorTotal || this.actor.system.combat.armor.costTotal != speedCostTotal || this.actor.system.teen.combat.armor.armorValueTotal != teenArmorTotal || this.actor.system.teen.combat.armor.speedCostTotal != teenSpeedCostTotal) {
this.actor.update({
"system.combat.armor.ratingTotal": armorTotal,
"system.combat.armor.costTotal": speedCostTotal,
"system.teen.combat.armor.armorValueTotal": teenArmorTotal,
"system.teen.combat.armor.speedCostTotal": teenSpeedCostTotal
});
}

return data;
}

Expand Down Expand Up @@ -467,5 +408,12 @@ export class CypherActorSheetPC extends CypherActorSheet {
let newValue = (item.system.basic.temporary) ? false : true;
item.update({"system.basic.temporary": newValue});
});

// Toggle Favorite
html.find('.item-favorite').click(clickEvent => {
const item = this.actor.items.get($(clickEvent.currentTarget).parents(".item").data("itemId"));
let newValue = (item.system.favorite) ? false : true;
item.update({"system.favorite": newValue});
});
}
}
14 changes: 12 additions & 2 deletions module/cyphersystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ import {
disasterModeMacro,
lockStaticStatsMacro,
migrateDataMacro,
selectedTokenRollMacro
selectedTokenRollMacro,
allInOneRollDialogV2
} from "./macros/macros.js";
import {
easedRollEffectiveMacro,
Expand Down Expand Up @@ -171,6 +172,7 @@ Hooks.once("init", async function () {
spendEffortMacro,
itemRollMacro,
allInOneRollDialog,
allInOneRollDialogV2,
toggleDragRuler,
resetDragRulerDefaults,
resetBarBrawlDefaults,
Expand Down Expand Up @@ -453,6 +455,12 @@ Hooks.on("preCreateItem", function (item, data, options, id) {
"flags.cyphersystem.recursions": []
});
};
if (item.system?.archived || item.system?.favorite) {
item.updateSource({
"system.archived": false,
"system.favorite": false
});
}
});

Hooks.on("preUpdateItem", async function (item, changes, options, userId) {
Expand All @@ -479,7 +487,9 @@ Hooks.on("preUpdateItem", async function (item, changes, options, userId) {
}
});

Hooks.on("updateItem", async function (item, changes, options, userId) {});
Hooks.on("updateItem", async function (item, changes, options, userId) {

});

Hooks.on("preCreateToken", function (document, data) {
if (!data.actorId) return;
Expand Down
Loading

0 comments on commit 0de5e69

Please sign in to comment.