ShoyuVanilla / FoundryVTT-Chat-Portrait

Other
14 stars 24 forks source link
foundry-vtt foundryvtt hacktoberfest

Chat Portrait

Latest Release Download Count

Forge Installs

Foundry Core Compatible Version

Latest Version

Foundry Hub Endorsements

GitHub all releases

THE PROJECT IS BEEN TRANSFERED HERE WITH FVTT 10 PLEASE OPEN YOUR ISSUES THERE

A Foundry VTT module that displays the Actor's portrait images on the chat messages.

This is a upgrade of the project Chat Portrait by ShoyuVanilla ty to ShoyuVanilla

Settings

Preview

NOTE: If you are a javascript developer and not a typescript developer, you can just use the javascript files under the dist folder

Installation

It's always easiest to install modules from the in game add-on browser.

To install this module manually:

  1. Inside the Foundry "Configuration and Setup" screen, click "Add-on Modules"
  2. Click "Install Module"
  3. In the "Manifest URL" field, paste the following url: https://raw.githubusercontent.com/ShoyuVanilla/FoundryVTT-Chat-Portrait/master/src/module.json
  4. Click 'Install' and wait for installation to complete
  5. Don't forget to enable the module in game using the "Manage Module" button

How help to make the Integration multisystem for my system ?

Since version 0.7.0, the module has been rewritten to allow for each system to have a css file to define the style and a description file of the mapping for the "ImageReplacer" feature.

Now the community can "come" to me a little, testing the css on their browser and help me understand which combination is the best, i file css si trovano nella directory degli styles, here a example for the dnd5e system

So the steps to follow to create or update a system are:

1) Creation or update of the style file in the styles directory the file must respect the chat-portrait-style-XXX.css nomenclature where XXX is the system id e.g. "dnd5e". 2) Creation or update of the typescript file for the mapping of the "ImageReplacer" feature if you do not want to use this feature create the file as empty and I'll take care of integrating the version with the empty arrays. In the minimal case you just need to copy the contents of the file generic.ts and insert the id of your system in the property "SYSTEM_ID" remember that you have to rename the file with the system id. 3) Insert the system if absent in the configuration file systems.ts 4) Open a pr on contact me in some way, by open a issue ecc.

NOTE: You can use other modules like Custom CSS for manage the css classes, the module help you by defining two css classes you can customize for the purpose of this module chat-portrait-text-size-name for the text chat message (the 'Setup additional custom styling on the text chat message' setting) and chat-portrait-image-size-name for the image prepend the text chat message (the 'Setup additional custom styling on the image prepend the text chat message' setting)

The module will continue to allow the use of custom CSS if desired.

Known Issue\Limitation

Hooks

ChatPortraitEnabled is called before the interaction with the chat is executed. When any of executed hooks return false the interaction is aborted with the default one of foundry.

ChatPortraitReplaceData is called like a replacement to the standard chat portrait recovery image, so any system or GM can use a customized version for a specific module.

Chat Portrait Custom Data


const chatPortraitCustomData = {
    // url or file string reference to the image portrait path
    customIconPortraitImage,
    // [DEPRECATED use instead the 'customImageReplacerData'] Customize your own imageReplacer (Record<string,string>)
    customImageReplacer,
    // Customize your own imageReplacer ( array of {  name: string; icon: string;})
    customImageReplacerData: imageReplacerData, 
}

/// WARNING: internal data - do not use if possible
// data schema is defined in: src/module/ChatPortraitModels.ts (or module/ChatPortraitModels.js)

Example

Use your own code to enable/disable the module chat-portrait...


Hooks.call('ChatPortraitEnabled');
// DO SOME CHECK 'BEFORE' APPLY THE CHAT PORTRAIT STYLING

How you can use this on your code....


Hooks.on('ChatPortraitEnabled', () => {

    // DO SOMETHING AND RETURN OR TRUE OR FALSE FOR ENABLE THE MODULE CHAT PORTRAIT
})

Use your own code for give me a customized image reference to put on the portrait , if you want you can give me a specific image reference for the 'Image Replacer" feature.


const chatPortraitCustomData = { 
  customIconPortraitImage: "http://myimageurl/test.png", // url or file string reference to the image portrait path
  customImageReplacer: imageReplacer, // [DEPRECATED use instead the 'customImageReplacerData'] Customize your own imageReplacer (Record<string,string>)
  customImageReplacerData: imageReplacerData, // Customize your own imageReplacer ( array of {  name: string; icon: string;})
}; 

Hooks.call('ChatPortraitReplaceData', chatPortraitCustomData, chatMessage);

// and then i'll do something with `chatPortraitCustomData`

const blabla = chatPortraitCustomData;

How you can use this on your code....


Hooks.on('ChatPortraitReplaceData', (chatPortraitCustomData, chatMessage) => {

    // Set your own image

    chatPortraitCustomData.customIconPortraitImage = ......

    // DO SOMETHING AND RETURN A NEW chatPortraitCustomData

    return chatPortraitCustomData; // this is blabla
})

Full Example

Hooks.on('ChatPortraitReplaceData', (chatPortraitCustomData, chatMessage) => {
    const speaker = ChatMessage.getSpeakerActor(chatMessage.data.speaker);
    if('KW_WarfareUnitSheet' === speaker?.sheet?.constructor.name) {
        chatPortraitCustomData.iconMainCustomReplacer = {
            "KW_WARFARE.Power": "systems/dnd5e/icons/skills/yellow_08.jpg",
            "KW_WARFARE.Attack": "systems/dnd5e/icons/skills/red_31.jpg",
            "KW_WARFARE.Morale": "systems/dnd5e/icons/skills/yellow_17.jpg",
            "KW_WARFARE.Command": "systems/dnd5e/icons/skills/ice_16.jpg"
        };
    }
    return chatPortraitCustomData;
});

hooks feature

Systems

For now the following system are the only one i tested

any other system need some fed back from the community

Features/Settings

avatar

background

img1img2

tag

Unknown

- [CSS CUSTOM SETTING] Setup the custom styling for the current system: Setup additional custom styling on message with CSS language based on the feedback of the community, Is a community effort for anyone don't know css language (note override any other prior property). If the settings 'Setup additional custom styling on the text chat message' or 'Setup additional custom styling on the image prepend the text chat message' is used (no blank text) this option even if true is ignored for the html elements involved. By default is true.

Here the table applied for the supported system :

| System id | Css for text message | Css for the image prepend the text | |:---:|:---:|:---:| | swade | height: auto; display:flex; | height: auto; display:flex; | | pf2e | display:block; margin: auto; | display:block; margin: auto; | | dnd5e | display:flex; margin: auto; | display:flex; margin: auto; |

For any correction or suggestion open a issue on this project.

NOTE: You can use other modules like Custom CSS for manage the css classes, the module help you by defining two css classes you can customize for the purpose of this module chat-portrait-text-size-name for the text chat message (the 'Setup additional custom styling on the text chat message' setting) and chat-portrait-image-size-name for the image prepend the text chat message (the 'Setup additional custom styling on the image prepend the text chat message' setting)

NOTE: You can use other modules like Custom CSS for manage the css classes, the module help you by defining two css classes you can customize for the purpose of this module chat-portrait-text-size-name for the text chat message (the 'Setup additional custom styling on the text chat message' setting) and chat-portrait-image-size-name for the image prepend the text chat message (the 'Setup additional custom styling on the image prepend the text chat message' setting)

chat_portrait_feature

If you want to add your own system it's very simple!!! you can just give to me a map of strings key=value of label and image, for a live example check out what i have done for d&d5e with the english language here a example for the dnd5e system ImageReplacer for dnd5e. It's ugly but it's simple to integrated.

replacer

[ON DEVELOPING SO ANY SUGGESTION IS WELCOME]

If you want to add your own system it's very simple!!! you can just give to me a map of strings key=value of label and image, for a live example check out what i have done for d&d5e with the english language here a example for the dnd5e system ImageReplacer for dnd5e. It's ugly but it's simple to integrated.

replacer_damage_types

Build

Install all packages

npm install

npm build scripts

build

will build the code and copy all necessary assets into the dist folder and make a symlink to install the result into your foundry data; create a foundryconfig.json file with your Foundry Data path.

{
  "dataPath": "~/.local/share/FoundryVTT/"
}

build will build and set up a symlink between dist and your dataPath.

npm run-script build

NOTE:

You don't need to build the foundryconfig.json file you can just copy the content of the dist folder on the module folder under modules of Foundry

build:watch

build:watch will build and watch for changes, rebuilding automatically.

npm run-script build:watch

clean

clean will remove all contents in the dist folder (but keeps the link from build:install).

npm run-script clean

lint and lintfix

lint launch the eslint process based on the configuration here

npm run-script lint

lintfix launch the eslint process with the fix argument

npm run-script lintfix

prettier-format

prettier-format launch the prettier plugin based on the configuration here

npm run-script prettier-format

package

package generates a zip file containing the contents of the dist folder generated previously with the build command. Useful for those who want to manually load the module or want to create their own release

npm run-script package

Changelog

Issues

Any issues, bugs, or feature requests are always welcome to be reported directly to the Issue Tracker, or using the Bug Reporter Module.

License

This package is under an MIT license and the Foundry Virtual Tabletop Limited License Agreement for module development.

Acknowledgements

Bootstrapped with League of Extraordinary FoundryVTT Developers foundry-vtt-types.

Mad props to the 'League of Extraordinary FoundryVTT Developers' community which helped me figure out a lot.

Credit

Thanks to anyone who helps me with this code! I appreciate the user community's feedback on this project!