Skip to content

Commit

Permalink
Remove changung token display name functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
Bartosz Karpiński authored and Bartosz Karpiński committed Jan 14, 2024
1 parent 10c932b commit e73fca7
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 63 deletions.
6 changes: 3 additions & 3 deletions scripts/main.js

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions scripts/main.js.map

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions src/actor.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { playersSeeName, refresh, toggleSeeName } from './api'
import { MODULE_ID, localize } from './module'
import { updateActorTokens } from './token'

export function getActorDirectoryEntryContext(html, entries) {
addSelectContextEntry({
Expand All @@ -27,7 +26,6 @@ export function onActorUpdate(actor, data) {
let needsRefresh = getProperty(data, `flags.${MODULE_ID}.showName}`) !== undefined

if ('ownership' in data) {
updateActorTokens(actor, actor.hasPlayerOwner)
needsRefresh = true
}

Expand Down
2 changes: 0 additions & 2 deletions src/api.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { capitalize, getFlag, getSetting, localize, setFlag } from './module'
import { updateActorTokens } from './token'

export function playersSeeName(doc) {
if (doc instanceof Combatant && doc.actor) doc = doc.actor
Expand All @@ -16,7 +15,6 @@ export async function toggleSeeName(doc) {
if (canvas.tokens.hud?.rendered) canvas.tokens.hud.render()

const actor = doc instanceof Actor ? doc : doc.actor
if (actor) updateActorTokens(actor, showName)

return showName
}
Expand Down
3 changes: 1 addition & 2 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { AnonymousNamesMenu } from './apps/names'
import { renderChatMessage } from './chat'
import { getCurrentModule, isGM, registerSetting, registerSettingMenu } from './module'
import { thirdPartyInitHooks, thirdPartyInitialization, thirdPartyReadyHooks } from './third'
import { preCreateToken, renderTokenHUD } from './token'
import { renderTokenHUD } from './token'
import { renderCombatTracker } from './tracker'

Hooks.once('init', () => {
Expand Down Expand Up @@ -84,5 +84,4 @@ Hooks.once('ready', () => {

Hooks.on('renderCombatTracker', renderCombatTracker)
Hooks.on('renderChatMessage', renderChatMessage)
Hooks.on('preCreateToken', preCreateToken)
Hooks.on('updateActor', onActorUpdate)
51 changes: 1 addition & 50 deletions src/token.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
import { playersSeeName, toggleSeeName } from './api'
import { getActorTokens, getSetting, localize } from './module'

export function updateActorTokens(actor, showName) {
if (actor.token) changeDisplayName(actor.token, showName)
else getActorTokens(actor, true).forEach(x => changeDisplayName(x, showName))
}
import { getActorTokens, localize } from './module'

export function renderTokenHUD(hud, html) {
const actor = hud.object.actor
Expand All @@ -15,13 +10,6 @@ export function renderTokenHUD(hud, html) {
html.find('.col.right').append(toggle)
}

export function preCreateToken(token) {
if (token.actor?.hasPlayerOwner) return
const displayName = token.displayName
const swap = swapToHide(displayName)
if (swap !== displayName) token._source.displayName = swap
}

function createToggle(actor) {
const tmp = document.createElement('template')
const toggled = playersSeeName(actor)
Expand All @@ -32,40 +20,3 @@ function createToggle(actor) {

return tmp.content.firstChild
}

function changeDisplayName(token, showName) {
if (showName) showTokenName(token)
else hideTokenName(token)
}

function showTokenName(token) {
const displayName = token.displayName
if (isShowing(displayName) || !getSetting('token')) return

let swap = displayName
if (swap === CONST.TOKEN_DISPLAY_MODES.OWNER_HOVER) swap = CONST.TOKEN_DISPLAY_MODES.HOVER
else if (swap === CONST.TOKEN_DISPLAY_MODES.OWNER) swap = CONST.TOKEN_DISPLAY_MODES.ALWAYS

token.update({ displayName: swap })
}

function hideTokenName(token) {
const displayName = token.displayName
if (isHidding(displayName)) return
const swap = swapToHide(displayName)
token.update({ displayName: swap })
}

function isHidding(displayName) {
return !isShowing(displayName)
}

function isShowing(displayName) {
return displayName === CONST.TOKEN_DISPLAY_MODES.HOVER || displayName === CONST.TOKEN_DISPLAY_MODES.ALWAYS
}

function swapToHide(displayName) {
if (displayName === CONST.TOKEN_DISPLAY_MODES.HOVER) return CONST.TOKEN_DISPLAY_MODES.OWNER_HOVER
if (displayName === CONST.TOKEN_DISPLAY_MODES.ALWAYS) return CONST.TOKEN_DISPLAY_MODES.OWNER
return displayName
}

0 comments on commit e73fca7

Please sign in to comment.