fix: PR feedback

This commit is contained in:
Marc Emmanuel 2026-02-15 10:22:22 +01:00
parent 41b36d42fa
commit 7dbe647270
26 changed files with 47 additions and 42 deletions

View file

@ -1,2 +0,0 @@
import "./coa-generator";
import "./coa-renderer";

View file

@ -5,14 +5,14 @@ import { lineWeights } from "./lineWeights";
import { ordinaries } from "./ordinaries"; import { ordinaries } from "./ordinaries";
import { positions } from "./positions"; import { positions } from "./positions";
import { shields } from "./shields"; import { shields } from "./shields";
import { tinctures } from "./tinctures"; import { createTinctures } from "./tinctures";
import { typeMapping } from "./typeMapping"; import { typeMapping } from "./typeMapping";
declare global { declare global {
var COA: COAGeneratorModule; var COA: EmblemGeneratorModule;
} }
export interface CoatOfArmsCharge { export interface EmblemCharge {
charge: string; charge: string;
t: string; t: string;
p: string; p: string;
@ -24,7 +24,7 @@ export interface CoatOfArmsCharge {
divided?: string; divided?: string;
} }
export interface CoatOfArmsOrdinary { export interface EmblemOrdinary {
ordinary: string; ordinary: string;
t: string; t: string;
line?: string; line?: string;
@ -32,28 +32,28 @@ export interface CoatOfArmsOrdinary {
above?: boolean; above?: boolean;
} }
export interface CoatOfArmsDivision { export interface EmblemDivision {
division: string; division: string;
t: string; t: string;
line?: string; line?: string;
} }
export interface CoatOfArms { export interface Emblem {
t1: string; t1: string;
shield?: string; shield?: string;
division?: CoatOfArmsDivision; division?: EmblemDivision;
ordinaries?: CoatOfArmsOrdinary[]; ordinaries?: EmblemOrdinary[];
charges?: CoatOfArmsCharge[]; charges?: EmblemCharge[];
custom?: boolean; custom?: boolean;
} }
class COAGeneratorModule { class EmblemGeneratorModule {
generate( generate(
parent: CoatOfArms | null, parent: Emblem | null,
kinship: number | null, kinship: number | null,
dominion: number | null, dominion: number | null,
type?: string, type?: string,
): CoatOfArms { ): Emblem {
if (!parent || parent.custom) { if (!parent || parent.custom) {
parent = null; parent = null;
kinship = 0; kinship = 0;
@ -67,7 +67,7 @@ class COAGeneratorModule {
? parent!.t1 ? parent!.t1
: this.getTincture("field", usedTinctures, null); : this.getTincture("field", usedTinctures, null);
if (t1.includes("-")) usedPattern = t1; if (t1.includes("-")) usedPattern = t1;
const coa: CoatOfArms = { t1 }; const coa: Emblem = { t1 };
const addCharge = P(usedPattern ? 0.5 : 0.93); // 80% for charge const addCharge = P(usedPattern ? 0.5 : 0.93); // 80% for charge
const linedOrdinary = const linedOrdinary =
@ -157,8 +157,8 @@ class COAGeneratorModule {
})(); })();
const chargeDataEntry = charges.data[charge] || {}; const chargeDataEntry = charges.data[charge] || {};
let p = "e"; let p: string;
let t = "gules"; let t: string;
const ordinaryData = ordinaries.data[ordinary!]; const ordinaryData = ordinaries.data[ordinary!];
const tOrdinary = coa.ordinaries ? coa.ordinaries[0].t : null; const tOrdinary = coa.ordinaries ? coa.ordinaries[0].t : null;
@ -214,7 +214,7 @@ class COAGeneratorModule {
) )
t = chargeDataEntry.natural; t = chargeDataEntry.natural;
const item: CoatOfArmsCharge = { charge: charge, t, p }; const item: EmblemCharge = { charge: charge, t, p };
const colors = chargeDataEntry.colors || 1; const colors = chargeDataEntry.colors || 1;
if (colors > 1) if (colors > 1)
item.t2 = P(0.25) item.t2 = P(0.25)
@ -226,7 +226,7 @@ class COAGeneratorModule {
: t; : t;
coa.charges = [item]; coa.charges = [item];
if (p === "ABCDEFGHIKL" && P(0.95)) { if (p === "ABCDEFGHIJKL" && P(0.95)) {
// add central charge if charge is in bordure // add central charge if charge is in bordure
coa.charges[0].charge = rw(charges.conventional); coa.charges[0].charge = rw(charges.conventional);
const chargeNew = this.selectCharge(charges.single); const chargeNew = this.selectCharge(charges.single);
@ -333,7 +333,7 @@ class COAGeneratorModule {
const t = invert const t = invert
? this.getTincture("division", usedTinctures, coa.t1) ? this.getTincture("division", usedTinctures, coa.t1)
: parent.t1; : parent.t1;
const canton: CoatOfArmsOrdinary = { ordinary: "canton", t }; const canton: EmblemOrdinary = { ordinary: "canton", t };
if (coa.charges) { if (coa.charges) {
for (let i = coa.charges.length - 1; i >= 0; i--) { for (let i = coa.charges.length - 1; i >= 0; i--) {
@ -379,6 +379,7 @@ class COAGeneratorModule {
RoT: string | null, RoT: string | null,
): string { ): string {
const base = RoT ? (RoT.includes("-") ? RoT.split("-")[1] : RoT) : null; const base = RoT ? (RoT.includes("-") ? RoT.split("-")[1] : RoT) : null;
const tinctures = createTinctures();
let type = rw(tinctures[element]); // metals, colours, stains, patterns let type = rw(tinctures[element]); // metals, colours, stains, patterns
if (RoT && type !== "patterns") if (RoT && type !== "patterns")
@ -407,7 +408,7 @@ class COAGeneratorModule {
private defineChargeAttributes( private defineChargeAttributes(
ordinary: string | null, ordinary: string | null,
division: string | null, division: string | null,
c: CoatOfArmsCharge, c: EmblemCharge,
): void { ): void {
// define size // define size
c.size = (c.size || 1) * this.getSize(c.p, ordinary, division); c.size = (c.size || 1) * this.getSize(c.p, ordinary, division);
@ -422,6 +423,7 @@ class COAGeneratorModule {
private getType(t: string): string | undefined { private getType(t: string): string | undefined {
const tinc = t.includes("-") ? t.split("-")[1] : t; const tinc = t.includes("-") ? t.split("-")[1] : t;
const tinctures = createTinctures();
if (Object.keys(tinctures.metals).includes(tinc)) return "metals"; if (Object.keys(tinctures.metals).includes(tinc)) return "metals";
if (Object.keys(tinctures.colours).includes(tinc)) return "colours"; if (Object.keys(tinctures.colours).includes(tinc)) return "colours";
if (Object.keys(tinctures.stains).includes(tinc)) return "stains"; if (Object.keys(tinctures.stains).includes(tinc)) return "stains";
@ -433,6 +435,7 @@ class COAGeneratorModule {
} }
private typeOf(tinc: string): string { private typeOf(tinc: string): string {
const tinctures = createTinctures();
if (Object.keys(tinctures.metals).includes(tinc)) return "metals"; if (Object.keys(tinctures.metals).includes(tinc)) return "metals";
if (Object.keys(tinctures.colours).includes(tinc)) return "colours"; if (Object.keys(tinctures.colours).includes(tinc)) return "colours";
if (Object.keys(tinctures.stains).includes(tinc)) return "stains"; if (Object.keys(tinctures.stains).includes(tinc)) return "stains";
@ -502,6 +505,7 @@ class COAGeneratorModule {
pattern = `${pattern}_of_${this.selectCharge(charges.semy)}`; pattern = `${pattern}_of_${this.selectCharge(charges.semy)}`;
if (!t1 || !t2) { if (!t1 || !t2) {
const tinctures = createTinctures();
const startWithMetal = P(0.7); const startWithMetal = P(0.7);
t1 = startWithMetal ? rw(tinctures.metals) : rw(tinctures.colours); t1 = startWithMetal ? rw(tinctures.metals) : rw(tinctures.colours);
t2 = startWithMetal ? rw(tinctures.colours) : rw(tinctures.metals); t2 = startWithMetal ? rw(tinctures.colours) : rw(tinctures.metals);
@ -520,6 +524,7 @@ class COAGeneratorModule {
private replaceTincture(t: string): string { private replaceTincture(t: string): string {
const type = this.getType(t); const type = this.getType(t);
let n: string | null = null; let n: string | null = null;
const tinctures = createTinctures();
while (!n || n === t) { while (!n || n === t) {
n = rw( n = rw(
tinctures[type as keyof typeof tinctures] as Record<string, number>, tinctures[type as keyof typeof tinctures] as Record<string, number>,
@ -568,11 +573,11 @@ class COAGeneratorModule {
return "heater"; return "heater";
} }
toString(coa: CoatOfArms): string { toString(coa: Emblem): string {
return JSON.stringify(coa).replaceAll("#", "%23"); return JSON.stringify(coa).replaceAll("#", "%23");
} }
copy(coa: CoatOfArms): CoatOfArms { copy(coa: Emblem): Emblem {
return JSON.parse(JSON.stringify(coa)); return JSON.parse(JSON.stringify(coa));
} }
@ -581,6 +586,6 @@ class COAGeneratorModule {
} }
} }
export default COAGeneratorModule; export default EmblemGeneratorModule;
window.COA = new COAGeneratorModule(); window.COA = new EmblemGeneratorModule();

View file

@ -0,0 +1,2 @@
import "./generator";
import "./renderer";

View file

@ -8,7 +8,7 @@ import { shieldSize } from "./size";
import { templates } from "./templates"; import { templates } from "./templates";
declare global { declare global {
var COArenderer: COARenderModule; var COArenderer: EmblemRenderModule;
} }
interface Division { interface Division {
@ -37,7 +37,7 @@ interface Charge {
p: number[]; // position on shield from 1 to 9 p: number[]; // position on shield from 1 to 9
} }
interface CoatOfArms { interface Emblem {
shield: string; shield: string;
t1: string; t1: string;
division?: Division; division?: Division;
@ -46,7 +46,7 @@ interface CoatOfArms {
custom?: boolean; // if true, coa will not be rendered custom?: boolean; // if true, coa will not be rendered
} }
class COARenderModule { class EmblemRenderModule {
get shieldPaths() { get shieldPaths() {
return shieldPaths; return shieldPaths;
} }
@ -87,7 +87,7 @@ class COARenderModule {
return fetched; return fetched;
} }
private async getCharges(coa: CoatOfArms, id: string, shieldPath: string) { private async getCharges(coa: Emblem, id: string, shieldPath: string) {
const charges = coa.charges const charges = coa.charges
? coa.charges.map((charge) => charge.charge) ? coa.charges.map((charge) => charge.charge)
: []; // add charges : []; // add charges
@ -122,7 +122,7 @@ class COARenderModule {
return 1; return 1;
} }
private getPatterns(coa: CoatOfArms, id: string) { private getPatterns(coa: Emblem, id: string) {
const isPattern = (string: string) => string.includes("-"); const isPattern = (string: string) => string.includes("-");
const patternsToAdd = []; const patternsToAdd = [];
if (coa.t1.includes("-")) patternsToAdd.push(coa.t1); // add field pattern if (coa.t1.includes("-")) patternsToAdd.push(coa.t1); // add field pattern
@ -165,7 +165,7 @@ class COARenderModule {
.join(""); .join("");
} }
private async draw(id: string, coa: CoatOfArms) { private async draw(id: string, coa: Emblem) {
const { shield = "heater", division, ordinaries = [], charges = [] } = coa; const { shield = "heater", division, ordinaries = [], charges = [] } = coa;
const ordinariesRegular = ordinaries.filter((o) => !o.above); const ordinariesRegular = ordinaries.filter((o) => !o.above);
@ -243,7 +243,7 @@ class COARenderModule {
if (ordinary.ordinary === "bordure") if (ordinary.ordinary === "bordure")
svg += `<path d="${shieldPath}" fill="none" stroke="${fill}" stroke-width="16.7%"/>`; svg += `<path d="${shieldPath}" fill="none" stroke="${fill}" stroke-width="16.7%"/>`;
else if (ordinary.ordinary === "orle") else if (ordinary.ordinary === "orle")
svg += `<path d="${shieldPath}" fill="none" stroke="${fill}" stroke-width="5%" transform="scale(.85)" transform-origin="center">`; svg += `<path d="${shieldPath}" fill="none" stroke="${fill}" stroke-width="5%" transform="scale(.85)" transform-origin="center"/>`;
else svg += this.getTemplate(ordinary.ordinary, ordinary.line); else svg += this.getTemplate(ordinary.ordinary, ordinary.line);
return `${svg}</g>`; return `${svg}</g>`;
}; };
@ -340,13 +340,13 @@ class COARenderModule {
} }
// render coa if does not exist // render coa if does not exist
async trigger(id: string, coa: CoatOfArms) { async trigger(id: string, coa: Emblem) {
if (!coa) return console.warn(`Emblem ${id} is undefined`); if (!coa) return console.warn(`Emblem ${id} is undefined`);
if (coa.custom) return console.warn("Cannot render custom emblem", coa); if (coa.custom) return console.warn("Cannot render custom emblem", coa);
if (!document.getElementById(id)) return this.draw(id, coa); if (!document.getElementById(id)) return this.draw(id, coa);
} }
async add(type: string, i: number, coa: CoatOfArms, x: number, y: number) { async add(type: string, i: number, coa: Emblem, x: number, y: number) {
const id = `${type}COA${i}`; const id = `${type}COA${i}`;
const g: HTMLElement = document.getElementById( const g: HTMLElement = document.getElementById(
`${type}Emblems`, `${type}Emblems`,
@ -360,4 +360,4 @@ class COARenderModule {
if (layerIsOn("toggleEmblems")) this.trigger(id, coa); if (layerIsOn("toggleEmblems")) this.trigger(id, coa);
} }
} }
window.COArenderer = new COARenderModule(); window.COArenderer = new EmblemRenderModule();

View file

@ -1,6 +1,6 @@
import { P } from "../../utils"; import { P } from "../../utils";
export const tinctures = { export const createTinctures = () => ({
field: { metals: 3, colours: 4, stains: +P(0.03), patterns: 1 }, field: { metals: 3, colours: 4, stains: +P(0.03), patterns: 1 },
division: { metals: 5, colours: 8, stains: +P(0.03), patterns: 1 }, division: { metals: 5, colours: 8, stains: +P(0.03), patterns: 1 },
charge: { metals: 2, colours: 3, stains: +P(0.05), patterns: 0 }, charge: { metals: 2, colours: 3, stains: +P(0.05), patterns: 0 },
@ -40,4 +40,4 @@ export const tinctures = {
maily: 2, maily: 2,
honeycombed: 1, honeycombed: 1,
}, },
}; });

View file

@ -13,4 +13,4 @@ import "./states-generator";
import "./zones-generator"; import "./zones-generator";
import "./religions-generator"; import "./religions-generator";
import "./provinces-generator"; import "./provinces-generator";
import "./coat-of-arms"; import "./emblem";

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long