theripper93 / combat-tracker-dock

6 stars 17 forks source link

Suggestion for improvements #2

Closed mclemente closed 1 year ago

mclemente commented 1 year ago

Turn defaultAttributesConfig into a function that returns an object

As it is, it is impossible to use calls to game.i18n.localize on it because it is loaded on load instead of when registerSettings is called.

Changing it from export const defaultAttributesConfig into export function defaultAttributesConfig() does it.

Move registerSettings to the setup hook

At init, localization isn't available. Pushing it back to setup allows for localization, such as setting then on defaultAttributesConfig to avoid copy-pasting localization from other systems in.

Set a way for systems to return their initiative

Some systems might not use the default D20 initiative. For example, SWADE uses cards, so something like "Red J" is being shown as a number, when the name is being saved as a flag instead. This would require some work.

theripper93 commented 1 year ago

Implemented suggestion 1 and 2

Implemented new getInitiativeDisplay() function that systems can customize in order to display non-default initiatives and customize images or icons

Included sample SWADE configuration to get contributors started (see image for final result)

        case "swade": {
            let suit = "";
            const cardString = combatant?.cardString ?? "";
            if (cardString.includes("♥")) suit = "fa-solid fa-heart";
            if (cardString.includes("♦")) suit = "fa-solid fa-diamond";
            if (cardString.includes("♣")) suit = "fa-solid fa-club";
            if (cardString.includes("♠")) suit = "fa-solid fa-spade";

            return {
                value: cardString.replace("♥", "").replace("♦", "").replace("♣", "").replace("♠", ""),
                icon: suit,
                rollIcon: "fa-regular fa-cards-blank",
            } 
        }

image

If you wish you can also use the card image as icon

        case "swade": {
            let suit = "";
            const getCardImage = (cardstr) => {
                return Array.from(game.cards.get(game.settings.get('swade', 'actionDeck')).cards).find(c => c.description === cardstr)?.img;
            }
            const cardString = combatant?.cardString ?? "";
            if (cardString.includes("♥")) suit = "fa-solid fa-heart";
            if (cardString.includes("♦")) suit = "fa-solid fa-diamond";
            if (cardString.includes("♣")) suit = "fa-solid fa-club";
            if (cardString.includes("♠")) suit = "fa-solid fa-spade";

            return {
                value: cardString.replace("♥", "").replace("♦", "").replace("♣", "").replace("♠", ""),
                icon: getCardImage(cardString) ?? suit,
                rollIcon: "fa-regular fa-cards-blank",
            } 
        }

image

Please, do send a PR with the attributes and the description configurations, when you do so, feel free to change my SWADE initiative implementation and chose the one you prefer