Skip to content

Commit

Permalink
Expand enabledRulesUI to role choice
Browse files Browse the repository at this point in the history
  • Loading branch information
jfn4th committed Jun 2, 2024
1 parent 84251ee commit eabfe87
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 12 deletions.
2 changes: 2 additions & 0 deletions build/run-migration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { Migration926RemoveVisionFeatureLinks } from "@module/migration/migratio
import { Migration927ClassBackgroundBattleFormSkillLongform } from "@module/migration/migrations/927-class-background-skill-longform.ts";
import { Migration928CharacterSkillsLongform } from "@module/migration/migrations/928-character-skills-longform.ts";
import { Migration929RemoveSkillAbbreviations } from "@module/migration/migrations/929-more-skills-longform.ts";
import { Migration930ExpandREPermissions } from "@module/migration/migrations/930-expand-re-permissions.ts";
// ^^^ don't let your IDE use the index in these imports. you need to specify the full path ^^^

const { window } = new JSDOM();
Expand Down Expand Up @@ -58,6 +59,7 @@ const migrations: MigrationBase[] = [
new Migration927ClassBackgroundBattleFormSkillLongform(),
new Migration928CharacterSkillsLongform(),
new Migration929RemoveSkillAbbreviations(),
new Migration930ExpandREPermissions(),
];

const packsDataPath = path.resolve(process.cwd(), "packs");
Expand Down
2 changes: 1 addition & 1 deletion src/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -321,9 +321,9 @@ declare global {
get(module: "pf2e", setting: "critRule"): "doubledamage" | "doubledice";
get(module: "pf2e", setting: "deathIcon"): ImageFilePath;
get(module: "pf2e", setting: "drawCritFumble"): boolean;
get(module: "pf2e", setting: "enabledRulesUI"): boolean;
get(module: "pf2e", setting: "gmVision"): boolean;
get(module: "pf2e", setting: "identifyMagicNotMatchingTraditionModifier"): 0 | 2 | 5 | 10;
get(module: "pf2e", setting: "minimumRulesUI"): "gm" | "trustedPlayer" | "player";
get(module: "pf2e", setting: "nathMode"): boolean;
get(module: "pf2e", setting: "seenRemasterJournalEntry"): boolean;
get(module: "pf2e", setting: "statusEffectType"): StatusEffectIconTheme;
Expand Down
8 changes: 7 additions & 1 deletion src/module/item/base/sheet/sheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,12 @@ class ItemSheetPF2e<TItem extends ItemPF2e> extends ItemSheet<TItem, ItemSheetOp
? createTagifyTraits(itemTraits, { sourceTraits, record: validTraits })
: null;

const minimumRulesUI = game.settings.get("pf2e", "minimumRulesUI");
const enabledRulesUI =
game.user.isGM ||
(minimumRulesUI === "trustedPlayer" && game.user.isTrusted) ||
minimumRulesUI === "player";

return {
itemType: null,
showTraits: !R.isEmpty(this.validTraits),
Expand Down Expand Up @@ -145,7 +151,7 @@ class ItemSheetPF2e<TItem extends ItemPF2e> extends ItemSheet<TItem, ItemSheetOp
rarities: CONFIG.PF2E.rarityTraits,
traits,
traitTagifyData,
enabledRulesUI: game.user.isGM || game.settings.get("pf2e", "enabledRulesUI"),
enabledRulesUI,
ruleEditing: !!this.editingRuleElement,
rules: {
selection: {
Expand Down
14 changes: 14 additions & 0 deletions src/module/migration/migrations/930-expand-re-permissions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { MigrationBase } from "../base.ts";

/** Migrate from boolean "enabledRulesUI" to "minimumRulesUI" choices. */
export class Migration930ExpandREPermissions extends MigrationBase {
static override version = 0.93;

override async migrate(): Promise<void> {
// If player access is disabled or hasn't been set, don't change anything.
const playerAccess = game.settings.storage.get("world").getItem("pf2e.enabledRulesUI");
if (!playerAccess) return;

game.settings.set("pf2e", "minimumRulesUI", "player");
}
}
1 change: 1 addition & 0 deletions src/module/migration/migrations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,3 +228,4 @@ export { Migration926RemoveVisionFeatureLinks } from "./926-remove-vision-featur
export { Migration927ClassBackgroundBattleFormSkillLongform } from "./927-class-background-skill-longform.ts";
export { Migration928CharacterSkillsLongform } from "./928-character-skills-longform.ts";
export { Migration929RemoveSkillAbbreviations } from "./929-more-skills-longform.ts";
export { Migration930ExpandREPermissions } from "./930-expand-re-permissions.ts";
2 changes: 1 addition & 1 deletion src/module/migration/runner/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ interface CollectionDiff<T extends foundry.documents.ActiveEffectSource | ItemSo
export class MigrationRunnerBase {
migrations: MigrationBase[];

static LATEST_SCHEMA_VERSION = 0.929;
static LATEST_SCHEMA_VERSION = 0.93;

static MINIMUM_SAFE_VERSION = 0.7;

Expand Down
15 changes: 10 additions & 5 deletions src/module/system/settings/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,18 @@ export function registerSettings(): void {
},
});

game.settings.register("pf2e", "enabledRulesUI", {
name: "PF2E.SETTINGS.EnabledRulesUI.Name",
hint: "PF2E.SETTINGS.EnabledRulesUI.Hint",
game.settings.register("pf2e", "minimumRulesUI", {
name: "PF2E.SETTINGS.MinimumRulesUI.Name",
hint: "PF2E.SETTINGS.MinimumRulesUI.Hint",
scope: "world",
config: true,
default: false,
type: Boolean,
default: "gm",
type: String,
choices: {
gm: "PF2E.SETTINGS.MinimumRulesUI.Choices.GM",
trustedPlayer: "PF2E.SETTINGS.MinimumRulesUI.Choices.TrustedPlayer",
player: "PF2E.SETTINGS.MinimumRulesUI.Choices.Player",
},
onChange: () => {
const itemSheets = Object.values(ui.windows).filter(
(w): w is ItemSheetPF2e<ItemPF2e> => w instanceof ItemSheetPF2e,
Expand Down
13 changes: 9 additions & 4 deletions static/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -3274,10 +3274,6 @@
"Default": "World Default ({worldDefault})",
"Disabled": "Disabled"
},
"EnabledRulesUI": {
"Hint": "When enabled, players are able to see and utilize the rule elements panel on item sheets.",
"Name": "Player Rule Elements Access"
},
"Homebrew": {
"BaseWeapons": {
"Hint": "The bottom level of Pathfinder 2e weapon taxonomy (e.g, Heavy Crossbow, Longsword)",
Expand Down Expand Up @@ -3406,6 +3402,15 @@
"Name": "Tokens Determine NPC Name Visibility"
}
},
"MinimumRulesUI": {
"Choices": {
"GM": "Game Master/Assistant GM",
"TrustedPlayer": "Trusted Player",
"Player": "Player"
},
"Hint": "The minimum role required to see and utilize the rule elements panel on item sheets.",
"Name": "Minimum Role for Rule Elements Access"
},
"NathMode": {
"Hint": "Use better default token icons",
"Name": "Nath Mode"
Expand Down

0 comments on commit eabfe87

Please sign in to comment.