Skip to content

Commit

Permalink
Massive refactor, almost gotten rid of legacy themes
Browse files Browse the repository at this point in the history
  • Loading branch information
Dorako committed Nov 24, 2023
1 parent 2591999 commit ebf8bad
Show file tree
Hide file tree
Showing 37 changed files with 3,605 additions and 2,266 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# 3.1.0 / WIP

- (New) Massive refactor.
- (New) New theme settings.
- (Fix) Fixed custom css not working.

# 3.0.6

- (Refinement) Adjusted styling for the daily crafting button and alt-weapon-usage hints on PC sheets.
Expand Down
47 changes: 2 additions & 45 deletions esmodules/consts.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,6 @@ export const MODULE_NAME = "pf2e-dorako-ui";

// THEMING

// prettier-ignore
export const darkThemeCompatibleCoreFoundryApplications = ["CombatTrackerConfig","InvitationLinks","SupportDetails","ToursManagement","WorldConfig","KeybindingsConfig", "FilePicker", "SettingsConfig", "PermissionConfig", "AVConfig", "DefaultTokenConfig", "FontConfig", "FolderConfig", "RollTableConfig", "PlaylistConfig", "CombatantConfig", "MeasuredTemplateConfig", "DocumentOwnershipConfig", "DocumentSheetConfig", "ModuleManagement", "MacroConfig", "Compendium", "CardsConfig", "WallConfig", "AmbientLightConfig", "AmbientSoundConfig", "TileConfig", "DrawingConfig"];
// prettier-ignore
export const darkThemeCompatiblePf2eApplications = ["CreatureSheetPF2e","NPCSheetPF2e","CharacterSheetPF2e","TokenConfigPF2e", "HomebrewElements", "VariantRulesSettings", "AutomationSettings", "MetagameSettings", "WorldClockSettings", "PersistentDamageDialog", "SceneConfigPF2e"];
// prettier-ignore
export const darkThemeCompatibleModuleApplications = ["PartyOverviewApp","RollPrompt", "SavingThrowApp", "AssignXPApp", "ContestedRollApp", "ActiveTileConfig", "DFChatEditor"];
// prettier-ignore
export const dorakoUiApplications = ["AvatarSettings","MiscSettings","ThemeSettings","UXSettings"]
// prettier-ignore
export const darkThemeIncompatibleApplications = ["SceneActorsLayer","HarrowReadingSheet","KingmakerJournalSheet","ClockAddDialog","ImprovedJournalSheet","WindowTabs","Ye","SwadeVehicleSheet","SwadeNPCSheet","JournalSheet","CharacterSheet","Tokenizer","JournalTextTinyMCESheetPF2e","JournalTextPageSheet","AbilityBuilderPopup","AttributeBuilder","TokenActionHUD","CustomHotbar","SceneDarknessAdjuster","EffectsPanel","Notifications", "Pause","TokenHUD","HeadsUpDisplay","Sidebar","HotbarPF2e","SceneNavigation", "SceneControls","PlayerList", "ImagePopout","EnhancedJournal","JournalSheetPF2e"]
// prettier-ignore
Expand All @@ -27,47 +19,12 @@ export const baseThemePf2eSheets = ["KingdomSheetPF2e","CreatureSheetPF2e","Part
export const baseThemeModuleApplications = ["SmallTimeApp","SearchApp","ControlManager","HUD","ItemPileConfig","PinCushionHUD","CombatCarousel","CommonToolbar","MonksHotbarExpansion","CustomHotbar"];

// prettier-ignore
export const baseThemeApplications = [...baseThemeCoreFoundryApplications,...baseThemePf2eApplications,...baseThemeModuleApplications, ...dorakoUiApplications];

// prettier-ignore
export const foundry2RestrictedApplications = ["KingdomSheetPF2e","CreatureSheetPF2e", "CharacterSheetPF2e", "PartySheetPF2e", "NPCSheetPF2e", "VehicleSheetPF2e", "HUD"];
export const baseThemeApplications = [...baseThemeCoreFoundryApplications,...baseThemePf2eApplications,...baseThemeModuleApplications];

// prettier-ignore
export const darkThemeCompatibleApplications = [...darkThemeCompatibleCoreFoundryApplications, ...darkThemeCompatibleModuleApplications, ...darkThemeCompatiblePf2eApplications, ...dorakoUiApplications]
export const limitedScopeApplications = ["KingdomSheetPF2e","CreatureSheetPF2e", "CharacterSheetPF2e", "PartySheetPF2e", "NPCSheetPF2e", "VehicleSheetPF2e", "HUD"];

// prettier-ignore
export const premiumModuleSelector = ".pf2e-yom, .pf2e-ii, .pf2e-woii, .seasonofghosts, .seasonofghosts-wrapper, .skykingstomb-wrapper, .skykingstomb, .stolenfate-wrapper, .stolenfate, .harrow-reading, .harrow, .pf2e-km, .kingdom-app, .swpf-sheet, .swpf-wrapper, .pf2e-av, .pf2e-bb, .gatewalkers-wrapper, .gatewalkers, .outlaws-wrapper, .outlaws, .bloodlords-wrapper, .bloodlords, .kingmaker-wrapper, .kingmaker"; //
// SWPFSheet
// SWPFJournalSheet

// CLASSES
export class Avatar {
constructor(name, image) {
this.name = name;
this.image = image;
this.type = "avatar";
}
}

export class CombatantAvatar extends Avatar {
constructor(name, image) {
super(name, image);
this.type = "combatant";
}
}

export class ActorAvatar extends Avatar {
constructor(name, image) {
super(name, image);
this.type = "actor";
}
}

export class TokenAvatar extends Avatar {
constructor(name, image, scale, isSmall) {
super(name, image);
this.type = "token";
this.scale = scale;
this.isSmall = isSmall;
}
}
254 changes: 127 additions & 127 deletions esmodules/dark-theme-hooks.js
Original file line number Diff line number Diff line change
@@ -1,137 +1,137 @@
import {
darkThemeIncompatibleApplications,
exclusivelyDarkApplications,
darkThemeCompatibleApplications,
baseThemePf2eSheets,
MODULE_NAME,
premiumModuleSelector,
} from "./consts.js";
// import {
// darkThemeIncompatibleApplications,
// exclusivelyDarkApplications,
// darkThemeCompatibleApplications,
// baseThemePf2eSheets,
// MODULE_NAME,
// premiumModuleSelector,
// } from "./consts.js";

// Supported dark theme
function markAsDarkTheme(app, html) {
const theme = game.settings.get("pf2e-dorako-ui", "theme.application-theme");
if (theme === "no-theme" || theme === "light-theme" || theme === "foundry2-theme") return;
let html0 = html[0];
if (html0.matches(premiumModuleSelector)) {
console.debug(
`${MODULE_NAME} | render${app.constructor.name} | matches premiumModuleSelector => do not add .dorako-ui`
);
return;
}
console.debug(`${MODULE_NAME} | render${app.constructor.name} | theme: ${theme}`);
html0.classList.add("dorako-ui");
html0.classList.add("dark-theme");
}
// // Supported dark theme
// function markAsDarkTheme(app, html) {
// const theme = game.settings.get("pf2e-dorako-ui", "theme.application-theme");
// if (theme === "no-theme" || theme === "light-theme" || theme === "foundry2-theme") return;
// let html0 = html[0];
// if (html0.matches(premiumModuleSelector)) {
// console.debug(
// `${MODULE_NAME} | render${app.constructor.name} | matches premiumModuleSelector => do not add .dorako-ui`
// );
// return;
// }
// console.debug(`${MODULE_NAME} | render${app.constructor.name} | theme: ${theme}`);
// html0.classList.add("dorako-ui");
// html0.classList.add("dark-theme");
// }

// Critical hit/fumble deck
Hooks.on("renderJournalSheetPF2e", (app, html) => {
const theme = game.settings.get("pf2e-dorako-ui", "theme.application-theme");
if (theme === "no-theme" || theme === "foundry2-theme") return;
if (!html[0].id.includes("JournalSheetPF2e-Compendium-pf2e-criticaldeck")) return;
console.debug(
`${MODULE_NAME} | renderJournalSheetPF2e | critical-hit-fumble-deck | theme: ${theme} => add .dorako-ui .dark-theme`
);
html.closest(".app").find(".journal-entry-content").addClass("dorako-ui dark-theme");
});
// // Critical hit/fumble deck
// Hooks.on("renderJournalSheetPF2e", (app, html) => {
// const theme = game.settings.get("pf2e-dorako-ui", "theme.application-theme");
// if (theme === "no-theme" || theme === "foundry2-theme") return;
// if (!html[0].id.includes("JournalSheetPF2e-Compendium-pf2e-criticaldeck")) return;
// console.debug(
// `${MODULE_NAME} | renderJournalSheetPF2e | critical-hit-fumble-deck | theme: ${theme} => add .dorako-ui .dark-theme`
// );
// html.closest(".app").find(".journal-entry-content").addClass("dorako-ui dark-theme");
// });

// Add .dorako-ui to all .journal-entry Applications
// This hook is used to give modules (AV) a chance to add their own classes first
Hooks.on("renderApplication", (app, html, data) => {
let html0 = html[0];
if (!html0.classList.contains("journal-entry")) return;
if (html0.matches(premiumModuleSelector)) {
console.debug(
`${MODULE_NAME} | render${app.constructor.name} | matches premiumModuleSelector => do not add .dorako-ui`
);
return;
}
const isDarkJournals = game.settings.get("pf2e-dorako-ui", "theme.enable-dark-theme-journals");
const theme = game.settings.get("pf2e-dorako-ui", "theme.application-theme");
if (theme === "foundry2-theme") return;
if (!isDarkJournals) {
html.closest(".app").find(".journal-entry-content").addClass("dorako-ui light-theme");
return;
}
if (html0.matches(premiumModuleSelector)) {
console.debug(
`${MODULE_NAME} | render${app.constructor.name} | matches premiumModuleSelector => do not add .dorako-ui or .dark-theme`
);
return;
}
html.closest(".app").find(".journal-entry-content").addClass("dorako-ui dark-theme");
console.debug(
`${MODULE_NAME} | render${app.constructor.name} | enable-dark-theme-journals: ${isDarkJournals} => add .dorako-ui .dark-theme to .journal-entry-content`
);
});
// // Add .dorako-ui to all .journal-entry Applications
// // This hook is used to give modules (AV) a chance to add their own classes first
// Hooks.on("renderApplication", (app, html, data) => {
// let html0 = html[0];
// if (!html0.classList.contains("journal-entry")) return;
// if (html0.matches(premiumModuleSelector)) {
// console.debug(
// `${MODULE_NAME} | render${app.constructor.name} | matches premiumModuleSelector => do not add .dorako-ui`
// );
// return;
// }
// const isDarkJournals = game.settings.get("pf2e-dorako-ui", "theme.enable-dark-theme-journals");
// const theme = game.settings.get("pf2e-dorako-ui", "theme.application-theme");
// if (theme === "foundry2-theme") return;
// if (!isDarkJournals) {
// html.closest(".app").find(".journal-entry-content").addClass("dorako-ui light-theme");
// return;
// }
// if (html0.matches(premiumModuleSelector)) {
// console.debug(
// `${MODULE_NAME} | render${app.constructor.name} | matches premiumModuleSelector => do not add .dorako-ui or .dark-theme`
// );
// return;
// }
// html.closest(".app").find(".journal-entry-content").addClass("dorako-ui dark-theme");
// console.debug(
// `${MODULE_NAME} | render${app.constructor.name} | enable-dark-theme-journals: ${isDarkJournals} => add .dorako-ui .dark-theme to .journal-entry-content`
// );
// });

// Add .dorako-ui.dark-theme to the page if it is not a page included in a premium module-styled journal
Hooks.on("renderJournalTextPageSheet", (app, html, data) => {
let journalFrame = app?.object?.parent?.sheet;
if (!journalFrame) return;
let frameHtml = journalFrame?.element;
if (!frameHtml || frameHtml.length == 0) return;
// if (frameHtml[0].matches(premiumModuleSelector)) return;
const isDarkJournals = game.settings.get("pf2e-dorako-ui", "theme.enable-dark-theme-journals");
const theme = game.settings.get("pf2e-dorako-ui", "theme.application-theme");
if (theme === "foundry2-theme") return;
if (!isDarkJournals) {
html.closest(".app").find(".journal-entry-content").addClass("dorako-ui light-theme");
return;
}
console.debug(
`${MODULE_NAME} | render${app.constructor.name} | enable-dark-theme-journals: ${isDarkJournals} => add .dorako-ui .dark-theme to .journal-entry-content`
);
frameHtml.closest(".app").find(".journal-entry-content").addClass("dorako-ui dark-theme");
});
// // Add .dorako-ui.dark-theme to the page if it is not a page included in a premium module-styled journal
// Hooks.on("renderJournalTextPageSheet", (app, html, data) => {
// let journalFrame = app?.object?.parent?.sheet;
// if (!journalFrame) return;
// let frameHtml = journalFrame?.element;
// if (!frameHtml || frameHtml.length == 0) return;
// // if (frameHtml[0].matches(premiumModuleSelector)) return;
// const isDarkJournals = game.settings.get("pf2e-dorako-ui", "theme.enable-dark-theme-journals");
// const theme = game.settings.get("pf2e-dorako-ui", "theme.application-theme");
// if (theme === "foundry2-theme") return;
// if (!isDarkJournals) {
// html.closest(".app").find(".journal-entry-content").addClass("dorako-ui light-theme");
// return;
// }
// console.debug(
// `${MODULE_NAME} | render${app.constructor.name} | enable-dark-theme-journals: ${isDarkJournals} => add .dorako-ui .dark-theme to .journal-entry-content`
// );
// frameHtml.closest(".app").find(".journal-entry-content").addClass("dorako-ui dark-theme");
// });

for (const app of ["Application", ...baseThemePf2eSheets]) {
Hooks.on("render" + app, (app, html, data) => {
const theme = game.settings.get("pf2e-dorako-ui", "theme.application-theme");
if (theme !== "dark-theme") return;
if (darkThemeIncompatibleApplications.includes(app?.constructor?.name)) return;
let html0 = html[0];
if (html0.matches(premiumModuleSelector)) {
console.debug(
`${MODULE_NAME} | render${app.constructor.name} | matches premiumModuleSelector => do not add .dorako-ui or .dark-theme`
);
return;
}
if (!html0.classList.contains("app")) return;
console.debug(`${MODULE_NAME} | render${app.constructor.name} | theme: ${theme}`);
html0.classList.add("dorako-ui");
html0.classList.add("dark-theme");
});
}
// for (const app of ["Application", ...baseThemePf2eSheets]) {
// Hooks.on("render" + app, (app, html, data) => {
// const theme = game.settings.get("pf2e-dorako-ui", "theme.application-theme");
// if (theme !== "dark-theme") return;
// if (darkThemeIncompatibleApplications.includes(app?.constructor?.name)) return;
// let html0 = html[0];
// if (html0.matches(premiumModuleSelector)) {
// console.debug(
// `${MODULE_NAME} | render${app.constructor.name} | matches premiumModuleSelector => do not add .dorako-ui or .dark-theme`
// );
// return;
// }
// if (!html0.classList.contains("app")) return;
// console.debug(`${MODULE_NAME} | render${app.constructor.name} | theme: ${theme}`);
// html0.classList.add("dorako-ui");
// html0.classList.add("dark-theme");
// });
// }

Hooks.on("renderSvelteApplication", (app) => {
const theme = game.settings.get("pf2e-dorako-ui", "theme.application-theme");
if (theme !== "dark-theme") return;
if (darkThemeIncompatibleApplications.includes(app?.constructor?.name)) return;
console.debug(`${MODULE_NAME} | render${app.constructor.name} | theme: ${theme}`);
app.element[0].classList.add("dorako-ui");
app.element[0].classList.add("dark-theme");
});
// Hooks.on("renderSvelteApplication", (app) => {
// const theme = game.settings.get("pf2e-dorako-ui", "theme.application-theme");
// if (theme !== "dark-theme") return;
// if (darkThemeIncompatibleApplications.includes(app?.constructor?.name)) return;
// console.debug(`${MODULE_NAME} | render${app.constructor.name} | theme: ${theme}`);
// app.element[0].classList.add("dorako-ui");
// app.element[0].classList.add("dark-theme");
// });

function markAsNativelyDarkTheme(app, html) {
let html0 = html[0];
console.debug(`${MODULE_NAME} | renderApplication (${app.constructor.name}) | forced dark theme`);
html0.classList.add("dorako-ui");
html0.classList.add("dark-theme");
}
// function markAsNativelyDarkTheme(app, html) {
// let html0 = html[0];
// console.debug(`${MODULE_NAME} | renderApplication (${app.constructor.name}) | forced dark theme`);
// html0.classList.add("dorako-ui");
// html0.classList.add("dark-theme");
// }

for (const document of [...darkThemeCompatibleApplications]) {
Hooks.on("render" + document, markAsDarkTheme);
}
// for (const document of [...darkThemeCompatibleApplications]) {
// Hooks.on("render" + document, markAsDarkTheme);
// }

for (const document of [...exclusivelyDarkApplications]) {
Hooks.on("render" + document, markAsNativelyDarkTheme);
}
// for (const document of [...exclusivelyDarkApplications]) {
// Hooks.on("render" + document, markAsNativelyDarkTheme);
// }

// filepicker-plus natively uses dark mode, but doesn't use its own document type
Hooks.on("renderFilePicker", (app, html) => {
let html0 = html[0];
if (!game.modules.get("filepicker-plus")?.active) return;
console.debug(`${MODULE_NAME} | renderApplication (${app.constructor.name}) | forced dark theme`);
html0.classList.add("dorako-ui");
html0.classList.add("dark-theme");
});
// // filepicker-plus natively uses dark mode, but doesn't use its own document type
// Hooks.on("renderFilePicker", (app, html) => {
// let html0 = html[0];
// if (!game.modules.get("filepicker-plus")?.active) return;
// console.debug(`${MODULE_NAME} | renderApplication (${app.constructor.name}) | forced dark theme`);
// html0.classList.add("dorako-ui");
// html0.classList.add("dark-theme");
// });
Loading

0 comments on commit ebf8bad

Please sign in to comment.