Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into feat-add-ammo-ran…
Browse files Browse the repository at this point in the history
…ge-modifier
  • Loading branch information
marvin9257 committed Oct 8, 2024
2 parents 7606276 + 856f71a commit 7a72cbb
Show file tree
Hide file tree
Showing 33 changed files with 298 additions and 146 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## [5.8.6](https://github.com/xdy/twodsix-foundryvtt/compare/v5.8.5...v5.8.6) (2024-10-08)


### Bug Fixes

* button changes, component qty, and AE fixes ([#1653](https://github.com/xdy/twodsix-foundryvtt/issues/1653)) ([dc1db8f](https://github.com/xdy/twodsix-foundryvtt/commit/dc1db8fd12d632f0b64412e3499fafa554a9eaa6))

## [5.8.5](https://github.com/xdy/twodsix-foundryvtt/compare/v5.8.4...v5.8.5) (2024-10-01)


Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"name": "twodsix",
"version": "5.8.5",
"version": "5.8.6",
"description": "A 2d6 system",
"scripts": {
"build": "gulp build",
Expand Down
16 changes: 11 additions & 5 deletions src/module/entities/TwodsixActor.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-nocheck This turns off *all* typechecking, make sure to remove this once foundry-vtt-types are updated to cover v10.

import { calcModFor, getDamageTypes, getKeyByValue } from "../utils/sheetUtils";
import { calcModFor, getDamageTypes} from "../utils/sheetUtils";
import { getKeyByValue } from "../utils/utils";
import { TWODSIX } from "../config";
import { TwodsixRollSettings} from "../utils/TwodsixRollSettings";
import { TwodsixDiceRoll } from "../utils/TwodsixDiceRoll";
Expand Down Expand Up @@ -347,6 +348,8 @@ export default class TwodsixActor extends Actor {
if (this.overrides.system?.primaryArmor?.value) {
system.totalArmor += this.overrides.system.primaryArmor.value - baseArmor;
}
} else {
this.applyActiveEffectsCustom();
}
}
/**
Expand Down Expand Up @@ -904,7 +907,7 @@ export default class TwodsixActor extends Actor {
* @returns {Promise}
* @public
*/
public async modifyTokenAttribute(attribute, value, isDelta, isBar): Promise <any>{
public async modifyTokenAttribute(attribute: string, value: number, isDelta: boolean, isBar: boolean): Promise <any>{
if ( attribute === "hits" && ["traveller", "animal", "robot"].includes(this.type)) {
const hits = foundry.utils.getProperty(this.system, attribute);
const delta = isDelta ? (-1 * value) : (hits.value - value);
Expand All @@ -925,7 +928,7 @@ export default class TwodsixActor extends Actor {
* @returns {Promise} A boolean promise of whether the drop was sucessful
* @private
*/
private async _addDroppedSkills(skillData): Promise<boolean>{
private async _addDroppedSkills(skillData: any): Promise<boolean>{
// Handle item sorting within the same Actor SHOULD NEVER DO THIS
const sameActor = this.items.get(skillData._id);
if (sameActor) {
Expand Down Expand Up @@ -1133,7 +1136,9 @@ export default class TwodsixActor extends Actor {
derivedData.push(`system.skills.${simplifySkillName(skill.name)}`);
}
//Add specials
derivedData.push("system.encumbrance.max", "system.encumbrance.value", "system.primaryArmor.value", "system.secondaryArmor.value", "system.radiationProtection.value");
if (this.type === 'traveller') {
derivedData.push("system.encumbrance.max", "system.encumbrance.value", "system.primaryArmor.value", "system.secondaryArmor.value", "system.radiationProtection.value");
}

//Define derived data keys that can have active effects
const overrides = {};
Expand Down Expand Up @@ -1198,7 +1203,8 @@ export default class TwodsixActor extends Actor {
const returnObject = {};
const skillsArray:TwodsixItem[] = sortByItemName(this.itemTypes.skills);
for (const skill of skillsArray) {
if ((skill.system.value >= 0 || !game.settings.get('twodsix', 'hideUntrainedSkills')) || (skill.getFlag("twodsix", "untrainedSkill") === game.settings.get('twodsix', 'hideUntrainedSkills'))) {
if ((skill.system.value >= 0 || !game.settings.get('twodsix', 'hideUntrainedSkills') || this.system.skills[simplifySkillName(skill.name)] >= 0)
|| (skill.getFlag("twodsix", "untrainedSkill") === game.settings.get('twodsix', 'hideUntrainedSkills'))) {
Object.assign(returnObject, {[skill.uuid]: `${skill.name} (${this.system.skills[simplifySkillName(skill.name)]})`});
}
}
Expand Down
10 changes: 6 additions & 4 deletions src/module/entities/TwodsixItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,11 +230,13 @@ export default class TwodsixItem extends Item {
};

// Set characteristic from skill
const skill:TwodsixItem = this.actor?.items.get(weapon.skill) as TwodsixItem;
if (skill) {
tmpSettings.rollModifiers.characteristic = (<Skills>skill.system).characteristic || 'NONE';
tmpSettings.rollType = skill.system.rolltype || "Normal";
const skill:TwodsixItem | undefined = this.actor?.items.get(weapon.skill) ?? (game.settings.get("twodsix", "hideUntrainedSkills") ? this.actor?.getUntrainedSkill() : undefined);
if (!skill) {
ui.notifications.error(game.i18n.localize("TWODSIX.Errors.NoSkillForSkillRoll"));
return;
}
tmpSettings.rollModifiers.characteristic = (<Skills>skill.system).characteristic || 'NONE';
tmpSettings.rollType = skill.system.rolltype || "Normal";

// Get fire mode parameters
const { weaponType, isAutoFull, usedAmmo, numberOfAttacks } = this.getFireModeParams(rateOfFireCE, attackType, tmpSettings);
Expand Down
27 changes: 23 additions & 4 deletions src/module/handlebars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
// @ts-nocheck This turns off *all* typechecking, make sure to remove this once foundry-vtt-types are updated to cover v10.

/*import { advantageDisadvantageTerm } from "./i18n";*/
import { getKeyByValue } from "./utils/sheetUtils";
import { getKeyByValue} from "./utils/utils";
import { TWODSIX } from "./config";
import TwodsixItem from "./entities/TwodsixItem";
import TwodsixActor, { getPower, getWeight } from "./entities/TwodsixActor";
import { getCharacteristicList } from "./utils/TwodsixRollSettings";
import { simplifySkillName } from "./utils/utils";
import { calcModFor } from "./utils/sheetUtils";

export default function registerHandlebarsHelpers(): void {

Expand Down Expand Up @@ -309,11 +310,29 @@ export default function registerHandlebarsHelpers(): void {
if (actor) {
const modes = [`<i class="fa-regular fa-circle-question"></i>`, `<i class="fa-regular fa-circle-xmark"></i>`, `<i class="fa-solid fa-circle-plus"></i>`, `<i class="fa-regular fa-circle-down"></i>`, `<i class="fa-regular fa-circle-up"></i>`, `<i class="fa-solid fa-shuffle"></i>`];
if (foundry.utils.getProperty(actor.overrides, field) !== undefined) {
returnValue += field.includes('Armor') && actor.type === 'traveller' ? `- ` : ``;
returnValue += field.includes('Armor') ? `- ` : ``;
const baseText = game.i18n.localize("TWODSIX.ActiveEffects.BaseValue");
const modifierText = game.i18n.localize("TWODSIX.ActiveEffects.Modifiers");
const baseValue = foundry.utils.getProperty(actor._source, field);
returnValue += `${baseText}: ${baseValue > 0 ? baseValue : "?"}. ${modifierText}: `;
let baseValue = 0;
if (field.includes('skills')) {
const simplifiedName = field.replace('system.skills.', '');
if (simplifiedName) {
const coreSkill = actor.itemTypes.skills.find(sk => simplifySkillName(sk.name) === simplifiedName);
baseValue = coreSkill?.system.value;
}
} else if (field.includes('encumbrance.max')) {
baseValue = actor.getMaxEncumbrance();
} else if (field.includes('mod')) {
baseValue = calcModFor(foundry.utils.getProperty(actor._source, field.replace('mod', 'value')));
} else {
baseValue = foundry.utils.getProperty(actor._source, field);
}

if (baseValue === foundry.utils.getProperty(actor, field)) {
baseValue = undefined;
}

returnValue += `${baseText}: ${isNaN(baseValue) ? "?" : baseValue}. ${modifierText}: `;
const workingEffects = actor.appliedEffects;
for (const effect of workingEffects) {
const realChanges = effect.changes.filter(ch => ch.key === field);
Expand Down
4 changes: 2 additions & 2 deletions src/module/hooks/addGMControlButtons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {TWODSIX} from "../config";
import { getDifficultiesSelectObject, getRollTypeSelectObject } from "../utils/sheetUtils";
//import {DICE_ROLL_MODES} from "@league-of-foundry-developers/foundry-vtt-types/src/foundry/common/constants.mjs";
import { _genUntranslatedCharacteristicList } from "../utils/TwodsixRollSettings";
//import {getKeyByValue} from "./sheetUtils";
//import {getKeyByValue} from "./utils";
import { simplifySkillName, sortObj } from "../utils/utils.ts";

Hooks.on("getSceneControlButtons", (controls) => {
Expand Down Expand Up @@ -37,7 +37,7 @@ async function requestRoll(): Promise<void> {
} else {
flavor = flavor.replace("_TYPE_", game.i18n.localize("TWODSIX.Chat.Roll.normal"));
}
flavor += `<section class="card-buttons"><button data-action="abilityCheck" data-tooltip="${game.i18n.localize("TWODSIX.Chat.Roll.AbilityCheck")}"><i class="fa-solid fa-dice"></i></button><section>`;
flavor += `<section class="card-buttons"><button type="button" data-action="abilityCheck" data-tooltip="${game.i18n.localize("TWODSIX.Chat.Roll.AbilityCheck")}"><i class="fa-solid fa-dice"></i></button><section>`;
ChatMessage.create({
flavor: flavor,
flags: {
Expand Down
2 changes: 1 addition & 1 deletion src/module/hooks/diceTrayIntegration.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// DICE TRAY no longer supports custom buttons through a simple API as of V12
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-nocheck This turns off *all* typechecking, make sure to remove this once foundry-vtt-types are updated to cover v10.
/*import { getKeyByValue } from "../utils/sheetUtils";
/*import { getKeyByValue } from "../utils/utils";
import { simplifySkillName } from "../utils/utils";
import {TWODSIX} from "../config";
Expand Down
4 changes: 2 additions & 2 deletions src/module/sheets/AbstractTwodsixActorSheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -548,8 +548,8 @@ export abstract class AbstractTwodsixActorSheet extends ActorSheet {
const li = $(event.currentTarget).parents(".item");
const itemSelected = this.actor.items.get(li.data("itemId"));

if (itemSelected) {
if (itemSelected.type === "skills") {
if (itemSelected && Number.isInteger(newValue)) {
if (itemSelected.type === "skills" ) {
itemSelected.update({"system.value": newValue});
} else if (itemSelected.type === "consumable") {
itemSelected.update({"system.quantity": newValue});
Expand Down
10 changes: 8 additions & 2 deletions src/module/sheets/TwodsixVehicleSheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,15 @@ export class TwodsixVehicleSheet extends AbstractTwodsixActorSheet {
} else {
const li = $(event.currentTarget).parents(".item");
const itemSelected:Component = this.actor.items.get(li.data("itemId"));
if (itemSelected) {
if (!itemSelected) {
return;
}
const type = $(event.currentTarget).data("type");
if (type === "status") {
const newState = event.shiftKey ? (itemSelected.system.status === "off" ? "operational" : "off") : stateTransitions[itemSelected.system.status];
itemSelected?.update({"system.status": newState});
itemSelected.update({"system.status": newState});
} else if (type === "popup") {
itemSelected.update({"system.isExtended": !itemSelected.system.isExtended});
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/module/utils/TwodsixDiceRoll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {TWODSIX} from "../config";
import TwodsixActor from "../entities/TwodsixActor";
import TwodsixItem from "../entities/TwodsixItem";
import {advantageDisadvantageTerm} from "../i18n";
import {getKeyByValue} from "./sheetUtils";
import {getKeyByValue} from "./utils";
import {TwodsixRollSettings} from "./TwodsixRollSettings";
import Crit from "./crit";
import { simplifySkillName, addSign, capitalizeFirstLetter } from "./utils";
Expand Down Expand Up @@ -371,12 +371,12 @@ export class TwodsixDiceRoll {
}

//Add buttons
flavorText += `<section class="card-buttons"><button data-action="expand" data-tooltip="${game.i18n.localize("TWODSIX.Rolls.ToggleDetails")}"><i class="fa-solid fa-circle-question" style="margin-left: 3px;"></i></button>`;
flavorText += `<section class="card-buttons"><button type="button" data-action="expand" data-tooltip="${game.i18n.localize("TWODSIX.Rolls.ToggleDetails")}"><i class="fa-solid fa-circle-question" style="margin-left: 3px;"></i></button>`;
if (this.isSuccess() && !game.settings.get("twodsix", "automateDamageRollOnHit") && (this.item?.type === "weapon" || (this.item?.type === "component" && this.item?.system?.subtype === "armament"))) {
flavorText += `<button data-action="damage" data-tooltip="${game.i18n.localize("TWODSIX.Rolls.RollDamage")}"><i class="fa-solid fa-person-burst" style="margin-left: 3px;"></i></button>`;
flavorText += `<button type="button" data-action="damage" data-tooltip="${game.i18n.localize("TWODSIX.Rolls.RollDamage")}"><i class="fa-solid fa-person-burst" style="margin-left: 3px;"></i></button>`;
} else if (this.rollSettings.skillRoll && this.item?.type !== "weapon" && !(this.item?.type === "component" && this.item?.system?.subtype === "armament")) {
flavorText += `<button data-action="chain" data-tooltip="${game.i18n.localize("TWODSIX.Rolls.RollChain")}"><i class="fa-solid fa-link" style="margin-left: 3px;"></i></button>`;
flavorText += `<button data-action="opposed" data-tooltip="${game.i18n.localize("TWODSIX.Rolls.RollOpposed")}"><i class="fa-solid fa-down-left-and-up-right-to-center" style="margin-left: 3px;"></i></button>`;
flavorText += `<button type="button" data-action="chain" data-tooltip="${game.i18n.localize("TWODSIX.Rolls.RollChain")}"><i class="fa-solid fa-link" style="margin-left: 3px;"></i></button>`;
flavorText += `<button type="button" data-action="opposed" data-tooltip="${game.i18n.localize("TWODSIX.Rolls.RollOpposed")}"><i class="fa-solid fa-down-left-and-up-right-to-center" style="margin-left: 3px;"></i></button>`;
}

flavorText +=`</section></section>`;
Expand Down
3 changes: 2 additions & 1 deletion src/module/utils/TwodsixRollSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

import {CE_DIFFICULTIES, CEL_DIFFICULTIES, TWODSIX} from "../config";
import type TwodsixItem from "../entities/TwodsixItem";
import {getDifficultiesSelectObject, getKeyByValue, getRollTypeSelectObject} from "./sheetUtils";
import {getDifficultiesSelectObject, getRollTypeSelectObject} from "./sheetUtils";
import { getKeyByValue } from "./utils";
import {DICE_ROLL_MODES} from "@league-of-foundry-developers/foundry-vtt-types/src/foundry/common/constants.mjs";
import {Gear, Skills} from "../../types/template";
import TwodsixActor from "../entities/TwodsixActor";
Expand Down
7 changes: 2 additions & 5 deletions src/module/utils/sheetUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import { TWODSIX } from "../config";
import { advantageDisadvantageTerm } from "../i18n";
import { camelCase } from "../settings/settingsUtils";
import { simplifySkillName } from "./utils";

// export function pseudoHex(value:number):string {
// switch (value) {
Expand Down Expand Up @@ -188,10 +189,6 @@ export function calcModFor(characteristic:number):number {
// return calcModFor(characteristic);
// }

export function getKeyByValue(object:{ [x:string]:unknown; }, value:unknown):string {
//TODO This assumes I always find the value. Bad form really.
return <string>Object.keys(object).find(key => JSON.stringify(object[key]) === JSON.stringify(value));
}

export function getDataFromDropEvent(event:DragEvent):Record<string, any> {
try {
Expand Down Expand Up @@ -296,7 +293,7 @@ export async function deletePDFReference(event): Promise<void> {
export function isDisplayableSkill(skill:Skills): boolean {
if (skill.getFlag("twodsix", "untrainedSkill")) {
return false;
} else if (skill.system.trainingNotes !== "" || skill.system.value >= 0) {
} else if (skill.system.trainingNotes !== "" || skill.system.value >= 0 || skill.actor?.system.skills[simplifySkillName(skill.name)] > 0) {
return true;
} else if (!game.settings.get('twodsix', 'hideUntrainedSkills')) {
return true;
Expand Down
6 changes: 5 additions & 1 deletion src/module/utils/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-nocheck This turns off *all* typechecking, make sure to remove this once foundry-vtt-types are updated to cover v10.
import { getKeyByValue } from "./sheetUtils";

// https://stackoverflow.com/a/34749873
/**
Expand Down Expand Up @@ -195,3 +194,8 @@ export function roundToMaxDecimals(num:number, maxDecimals:number): number {
const decimalsToShow = Math.min(maxDecimals, Math.max(0, maxDecimals - Math.floor(Math.log10(Math.abs(num)))));
return roundToDecimal(num, decimalsToShow);
}

export function getKeyByValue(object:{ [x:string]:unknown; }, value:unknown):string {
//TODO This assumes I always find the value. Bad form really.
return <string>Object.keys(object).find(key => JSON.stringify(object[key]) === JSON.stringify(value));
}
Loading

0 comments on commit 7a72cbb

Please sign in to comment.