import SETTINGS from "../../../common/Settings" ; export default class PlayerColor { static readonly PREF_TINT_BG = 'PlayerColor_TintBackground' ; static readonly FLAG_CHAT_COLOR = 'chat-color' ; static init ( ) { SETTINGS . register ( PlayerColor . PREF_TINT_BG , { config : true , name : 'DF_CHAT_PLAYER_COLOR.SettingTintBackgroundName' , hint : 'DF_CHAT_PLAYER_COLOR.SettingTintBackgroundHint' , scope : 'world' , type : Boolean , default : false } ) ; Hooks . on ( 'renderUserConfig' , ( app , html , data ) => { const color = data . user . getFlag ( SETTINGS . MOD_NAME , PlayerColor . FLAG_CHAT_COLOR ) ?? '' ; html . find ( 'input[name="color"]' ) . parent ( ) . after ( `
<div class="form-group">
	<label for="chat-color">${ 'DF_CHAT_PLAYER_COLOR.Label' . localize ( ) }</label>
	<input id="chat-color" type="text" name="chat-color" value="${ color }" style="flex:1.35">
	<input type="color" value="${ color }" data-edit="chat-color">
</div>` ) ; const chatField = html . find ( '#chat-color' ) ; const chatPicker = html . find ( '[data-edit="chat-color"]' ) ; chatField . on ( 'change' , ( ) => chatPicker . val ( chatField . val ( ) ) ) ; app . element [ 0 ] . style . height = '' ; app . setPosition ( { } ) ; } ) ; libWrapper . register ( SETTINGS . MOD_NAME , 'UserConfig.prototype._updateObject' , async function ( this , wrapped , event , formData ) { await this . object . setFlag ( SETTINGS . MOD_NAME , PlayerColor . FLAG_CHAT_COLOR , formData [ "chat-color" ] ) ; await wrapped ( event , formData ) ; } , 'WRAPPER' ) ; libWrapper . register ( SETTINGS . MOD_NAME , 'ChatMessage.prototype.getHTML' , async function ( this , wrapper , ... args ) { const html = await wrapper ( ... args ) ; let chatColor = ( < string > this . user . getFlag ( SETTINGS . MOD_NAME , PlayerColor . FLAG_CHAT_COLOR ) ) ?. trim ( ) ; if ( ! chatColor || ! /#[a-fA-F0-9]{6,8}/ . test ( chatColor ) ) chatColor = this . user . color ; if ( game . userId === this . data . user || SETTINGS . get ( PlayerColor . PREF_TINT_BG ) ) html [ 0 ] . style . borderColor = chatColor ; else html [ 0 ] . style . borderColor = '#6f6c66' ; html [ 0 ] . style . setProperty ( '--dfce-mc-border-color' , html [ 0 ] . style . borderColor ) ; if ( SETTINGS . get ( PlayerColor . PREF_TINT_BG ) ) { html [ 0 ] . style . backgroundColor = chatColor ; html [ 0 ] . style . backgroundImage = 'url(../ui/parchment.jpg)' ; html [ 0 ] . style . backgroundRepeat = 'repeat' ; html [ 0 ] . style . backgroundBlendMode = 'screen' ; } return html ; } , 'WRAPPER' ) ; } }