class OwnershipViewer { // Creates and applies the OwnershipViewer div to each document in a directory - called when each directory renders. static directoryRendered(obj, html, data) { if (!game.user.isGM || !obj._getEntryContextOptions) return; // Get the current directory's right-click context options, then tore the ownership config option const contextOptions = obj._getEntryContextOptions(); const ownershipOption = contextOptions.find((e) => e.name === "OWNERSHIP.Configure"); // Determine if we are working with a directory or a journal sheet const isJournalSheet = obj.constructor.name === "JournalSheet"; // Gather all documents in the current directory or journal const collection = isJournalSheet ? obj.object.collections.pages : obj.constructor.collection; const documentList = html.find(`li.directory-item${isJournalSheet ? ".level1" : ".document"}`); // Interate through each directory list item. for (let li of documentList) { // Match it to the corresponding document li = $(li); const document = collection.get(li.attr(`data-${isJournalSheet ? "page" : "document"}-id`)); const users = []; // Iterate through each ownership definition on the document for (let id in document.ownership) { const ownership = document.ownership[id] ?? 0; // If the ownership definition isn't 'None'... if (ownership !== CONST.DOCUMENT_OWNERSHIP_LEVELS.NONE) { // Create the div for this ownership definition, with the appropriate class based on the ownership level const user_div = $(`
`); // And if the ownership definition isn't 'All Players' (default) or a GM, set 'bg_color' to the user's color const user = game.users.get(id); if (id !== "default") { if (user && !user.isGM) { user_div.css({ "background-color": user.color }); user_div.attr("data-tooltip", user.name); } else { continue; } } const ownerships = invertObject(CONST.DOCUMENT_OWNERSHIP_LEVELS); user_div.addClass(`ownership-viewer-${ownerships[ownership].toLowerCase()}`); user_div.attr( "data-tooltip", `${user ? user.name + ": " : ""} ${game.i18n.localize("OWNERSHIP." + ownerships[ownership])}` ); user_div.attr("data-tooltip-direction", "UP"); if (id == "default") { user_div.addClass("ownership-viewer-all"); } else { user_div.addClass("ownership-viewer-user"); } // Store the resulting div and keep iterating through the other ownership definitions on the document users.push(user_div); } } const div = $(''); // Append the collection of divs to the document's list item, or add the 'none set' icon if empty if (ownershipOption) { if (users.length === 0) { users.push($('