feat: display talent rank with roman numerals in character sheet

This commit is contained in:
Johannes Loher 2022-11-10 04:00:48 +01:00
parent 1e7492073e
commit e89f03f81d
2 changed files with 61 additions and 1 deletions

View file

@ -13,4 +13,64 @@ const helpers = {
},
isEmpty: (input: Array<unknown> | null | undefined): boolean => (input?.length ?? 0) === 0,
toRomanNumerals,
};
function toRomanNumerals(number: number): string {
return toRomanNumeralsRecurse(number, numerals) ?? "";
}
function toRomanNumeralsRecurse(number: number, numerals: number[]): string | undefined {
if (number === 0) {
return undefined;
}
const currentNumeral = numerals[0];
if (currentNumeral === undefined) {
return undefined;
}
const quotient = number / currentNumeral;
const remainder = number % currentNumeral;
const numberAsNumerals = numeralLookup[currentNumeral]?.repeat(quotient);
if (numberAsNumerals === undefined) {
return undefined;
}
const [, ...remainingNumerals] = numerals;
return numberAsNumerals + (toRomanNumeralsRecurse(remainder, remainingNumerals) ?? "");
}
const numeralLookup: Record<number, string> = {
1: "I",
2: "II",
3: "III",
4: "IV",
5: "V",
6: "VI",
7: "VII",
8: "VIII",
9: "IX",
10: "X",
20: "XX",
30: "XXX",
40: "XL",
50: "L",
60: "LX",
70: "LXX",
80: "LXXX",
90: "XC",
100: "C",
200: "CC",
300: "CCC",
400: "CD",
500: "D",
600: "DC",
700: "DCC",
800: "DCCC",
900: "CM",
1000: "M",
};
const numerals = [
1000, 900, 800, 700, 600, 500, 400, 300, 200, 100, 90, 80, 70, 60, 50, 40, 30, 20, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1,
];

View file

@ -18,7 +18,7 @@ SPDX-License-Identifier: MIT
{{#each itemsByType.talent as |itemData id|}}
{{#> systems/ds4/templates/sheets/actor/components/item-list-entry.hbs itemData=itemData}}
{{!-- rank --}}
<div>{{itemData.data.rank.total}}</div>
<div>{{toRomanNumerals itemData.data.rank.total}}</div>
{{/systems/ds4/templates/sheets/actor/components/item-list-entry.hbs}}
{{/each}}
</ol>