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 user isn't a GM, don't continue if (!game.user.isGM) 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') // Gather all documents in the current directory let collection = obj.constructor.collection; // Interate through each directory list item. for (let li of html.find("li.directory-item.document")) { // Match it to the corresponding document li = $(li) let document = collection.get(li.attr("data-document-id")) let users = [] // Iterate through each ownership definition on the document for (let id in document.ownership) { let ownership = document.ownership[id] // If the ownership definition isn't 'None'... if (ownership >= CONST.DOCUMENT_OWNERSHIP_LEVELS.LIMITED) { let bg_color = "transparent" // And if the ownership definition isn't 'All Players' (default) or a GM, set 'bg_color' to the user's color if (id != "default") { const user = game.users.get(id) if (user) { if (user.isGM) continue; bg_color = user.color; } else { continue; } } // Create the div for this ownership definition, with the appropriate class based on the ownership level let user_div = $('
') user_div.attr("data-user-id", id) if (ownership === CONST.DOCUMENT_OWNERSHIP_LEVELS.LIMITED) { user_div.addClass("ownership-viewer-limited") } else if (ownership === CONST.DOCUMENT_OWNERSHIP_LEVELS.OBSERVER) { user_div.addClass("ownership-viewer-observer") } else if (ownership === CONST.DOCUMENT_OWNERSHIP_LEVELS.OWNER) { user_div.addClass("ownership-viewer-owner") } if (id == "default") { user_div.addClass("ownership-viewer-all") } else { user_div.addClass("ownership-viewer-user") } user_div.css({'background-color': bg_color}) // Store the resulting div and keep iterating through the other ownership definitions on the document users.push(user_div) } } let 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($('