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 11, 2024
1 parent 0b45861 commit 36b2cdc
Show file tree
Hide file tree
Showing 8 changed files with 33 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 { Migration927ClassBackgroundBattleFormSkillLongform } from "@module/migr
import { Migration928CharacterSkillsLongform } from "@module/migration/migrations/928-character-skills-longform.ts";
import { Migration929RemoveSkillAbbreviations } from "@module/migration/migrations/929-remove-skill-abbreviations.ts";
import { Migration930ChoiceSetMedium } from "@module/migration/migrations/930-choice-set-medium.ts";
import { Migration931ExpandREPermissions } from "@module/migration/migrations/931-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 Migration928CharacterSkillsLongform(),
new Migration929RemoveSkillAbbreviations(),
new Migration930ChoiceSetMedium(),
new Migration931ExpandREPermissions(),
];

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"): 1 | 2 | 3 | 4;
get(module: "pf2e", setting: "nathMode"): boolean;
get(module: "pf2e", setting: "seenRemasterJournalEntry"): boolean;
get(module: "pf2e", setting: "statusEffectType"): StatusEffectIconTheme;
Expand Down
2 changes: 1 addition & 1 deletion src/module/item/base/sheet/sheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,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: game.user.role >= game.settings.get("pf2e", "minimumRulesUI"),
ruleEditing: !!this.editingRuleElement,
rules: {
selection: {
Expand Down
12 changes: 12 additions & 0 deletions src/module/migration/migrations/931-expand-re-permissions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { MigrationBase } from "../base.ts";

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

override async migrate(): Promise<void> {
// If player access is enabled, set minimumRulesUI to Player. Otherwise, set to the old default of Assistant GM.
const playerAccess = game.settings.storage.get("world").getItem("pf2e.enabledRulesUI");
game.settings.set("pf2e", "minimumRulesUI", playerAccess ? 1 : 3);
}
}
1 change: 1 addition & 0 deletions src/module/migration/migrations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,3 +229,4 @@ export { Migration927ClassBackgroundBattleFormSkillLongform } from "./927-class-
export { Migration928CharacterSkillsLongform } from "./928-character-skills-longform.ts";
export { Migration929RemoveSkillAbbreviations } from "./929-remove-skill-abbreviations.ts";
export { Migration930ChoiceSetMedium } from "./930-choice-set-medium.ts";
export { Migration931ExpandREPermissions } from "./931-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.93;
static LATEST_SCHEMA_VERSION = 0.931;

static MINIMUM_SAFE_VERSION = 0.7;

Expand Down
16 changes: 11 additions & 5 deletions src/module/system/settings/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,19 @@ 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: 4,
type: Number,
choices: {
1: "USER.RolePlayer",
2: "USER.RoleTrusted",
3: "USER.RoleAssistant",
4: "USER.RoleGamemaster",
},
onChange: () => {
const itemSheets = Object.values(ui.windows).filter(
(w): w is ItemSheetPF2e<ItemPF2e> => w instanceof ItemSheetPF2e,
Expand Down
8 changes: 4 additions & 4 deletions static/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -3277,10 +3277,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 @@ -3409,6 +3405,10 @@
"Name": "Tokens Determine NPC Name Visibility"
}
},
"MinimumRulesUI": {
"Hint": "The minimum role required to see and utilize the rule elements panel on item sheets.",
"Name": "Minimum Rule Elements Access Role"
},
"NathMode": {
"Hint": "Use better default token icons",
"Name": "Nath Mode"
Expand Down

0 comments on commit 36b2cdc

Please sign in to comment.