mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2026-03-27 01:27:23 +01:00
fix: PR feedback
This commit is contained in:
parent
41b36d42fa
commit
7dbe647270
26 changed files with 47 additions and 42 deletions
|
|
@ -1,2 +0,0 @@
|
|||
import "./coa-generator";
|
||||
import "./coa-renderer";
|
||||
|
|
@ -5,14 +5,14 @@ import { lineWeights } from "./lineWeights";
|
|||
import { ordinaries } from "./ordinaries";
|
||||
import { positions } from "./positions";
|
||||
import { shields } from "./shields";
|
||||
import { tinctures } from "./tinctures";
|
||||
import { createTinctures } from "./tinctures";
|
||||
import { typeMapping } from "./typeMapping";
|
||||
|
||||
declare global {
|
||||
var COA: COAGeneratorModule;
|
||||
var COA: EmblemGeneratorModule;
|
||||
}
|
||||
|
||||
export interface CoatOfArmsCharge {
|
||||
export interface EmblemCharge {
|
||||
charge: string;
|
||||
t: string;
|
||||
p: string;
|
||||
|
|
@ -24,7 +24,7 @@ export interface CoatOfArmsCharge {
|
|||
divided?: string;
|
||||
}
|
||||
|
||||
export interface CoatOfArmsOrdinary {
|
||||
export interface EmblemOrdinary {
|
||||
ordinary: string;
|
||||
t: string;
|
||||
line?: string;
|
||||
|
|
@ -32,28 +32,28 @@ export interface CoatOfArmsOrdinary {
|
|||
above?: boolean;
|
||||
}
|
||||
|
||||
export interface CoatOfArmsDivision {
|
||||
export interface EmblemDivision {
|
||||
division: string;
|
||||
t: string;
|
||||
line?: string;
|
||||
}
|
||||
|
||||
export interface CoatOfArms {
|
||||
export interface Emblem {
|
||||
t1: string;
|
||||
shield?: string;
|
||||
division?: CoatOfArmsDivision;
|
||||
ordinaries?: CoatOfArmsOrdinary[];
|
||||
charges?: CoatOfArmsCharge[];
|
||||
division?: EmblemDivision;
|
||||
ordinaries?: EmblemOrdinary[];
|
||||
charges?: EmblemCharge[];
|
||||
custom?: boolean;
|
||||
}
|
||||
|
||||
class COAGeneratorModule {
|
||||
class EmblemGeneratorModule {
|
||||
generate(
|
||||
parent: CoatOfArms | null,
|
||||
parent: Emblem | null,
|
||||
kinship: number | null,
|
||||
dominion: number | null,
|
||||
type?: string,
|
||||
): CoatOfArms {
|
||||
): Emblem {
|
||||
if (!parent || parent.custom) {
|
||||
parent = null;
|
||||
kinship = 0;
|
||||
|
|
@ -67,7 +67,7 @@ class COAGeneratorModule {
|
|||
? parent!.t1
|
||||
: this.getTincture("field", usedTinctures, null);
|
||||
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 linedOrdinary =
|
||||
|
|
@ -157,8 +157,8 @@ class COAGeneratorModule {
|
|||
})();
|
||||
const chargeDataEntry = charges.data[charge] || {};
|
||||
|
||||
let p = "e";
|
||||
let t = "gules";
|
||||
let p: string;
|
||||
let t: string;
|
||||
|
||||
const ordinaryData = ordinaries.data[ordinary!];
|
||||
const tOrdinary = coa.ordinaries ? coa.ordinaries[0].t : null;
|
||||
|
|
@ -214,7 +214,7 @@ class COAGeneratorModule {
|
|||
)
|
||||
t = chargeDataEntry.natural;
|
||||
|
||||
const item: CoatOfArmsCharge = { charge: charge, t, p };
|
||||
const item: EmblemCharge = { charge: charge, t, p };
|
||||
const colors = chargeDataEntry.colors || 1;
|
||||
if (colors > 1)
|
||||
item.t2 = P(0.25)
|
||||
|
|
@ -226,7 +226,7 @@ class COAGeneratorModule {
|
|||
: t;
|
||||
coa.charges = [item];
|
||||
|
||||
if (p === "ABCDEFGHIKL" && P(0.95)) {
|
||||
if (p === "ABCDEFGHIJKL" && P(0.95)) {
|
||||
// add central charge if charge is in bordure
|
||||
coa.charges[0].charge = rw(charges.conventional);
|
||||
const chargeNew = this.selectCharge(charges.single);
|
||||
|
|
@ -333,7 +333,7 @@ class COAGeneratorModule {
|
|||
const t = invert
|
||||
? this.getTincture("division", usedTinctures, coa.t1)
|
||||
: parent.t1;
|
||||
const canton: CoatOfArmsOrdinary = { ordinary: "canton", t };
|
||||
const canton: EmblemOrdinary = { ordinary: "canton", t };
|
||||
|
||||
if (coa.charges) {
|
||||
for (let i = coa.charges.length - 1; i >= 0; i--) {
|
||||
|
|
@ -379,6 +379,7 @@ class COAGeneratorModule {
|
|||
RoT: string | null,
|
||||
): string {
|
||||
const base = RoT ? (RoT.includes("-") ? RoT.split("-")[1] : RoT) : null;
|
||||
const tinctures = createTinctures();
|
||||
|
||||
let type = rw(tinctures[element]); // metals, colours, stains, patterns
|
||||
if (RoT && type !== "patterns")
|
||||
|
|
@ -407,7 +408,7 @@ class COAGeneratorModule {
|
|||
private defineChargeAttributes(
|
||||
ordinary: string | null,
|
||||
division: string | null,
|
||||
c: CoatOfArmsCharge,
|
||||
c: EmblemCharge,
|
||||
): void {
|
||||
// define size
|
||||
c.size = (c.size || 1) * this.getSize(c.p, ordinary, division);
|
||||
|
|
@ -422,6 +423,7 @@ class COAGeneratorModule {
|
|||
|
||||
private getType(t: string): string | undefined {
|
||||
const tinc = t.includes("-") ? t.split("-")[1] : t;
|
||||
const tinctures = createTinctures();
|
||||
if (Object.keys(tinctures.metals).includes(tinc)) return "metals";
|
||||
if (Object.keys(tinctures.colours).includes(tinc)) return "colours";
|
||||
if (Object.keys(tinctures.stains).includes(tinc)) return "stains";
|
||||
|
|
@ -433,6 +435,7 @@ class COAGeneratorModule {
|
|||
}
|
||||
|
||||
private typeOf(tinc: string): string {
|
||||
const tinctures = createTinctures();
|
||||
if (Object.keys(tinctures.metals).includes(tinc)) return "metals";
|
||||
if (Object.keys(tinctures.colours).includes(tinc)) return "colours";
|
||||
if (Object.keys(tinctures.stains).includes(tinc)) return "stains";
|
||||
|
|
@ -502,6 +505,7 @@ class COAGeneratorModule {
|
|||
pattern = `${pattern}_of_${this.selectCharge(charges.semy)}`;
|
||||
|
||||
if (!t1 || !t2) {
|
||||
const tinctures = createTinctures();
|
||||
const startWithMetal = P(0.7);
|
||||
t1 = startWithMetal ? rw(tinctures.metals) : rw(tinctures.colours);
|
||||
t2 = startWithMetal ? rw(tinctures.colours) : rw(tinctures.metals);
|
||||
|
|
@ -520,6 +524,7 @@ class COAGeneratorModule {
|
|||
private replaceTincture(t: string): string {
|
||||
const type = this.getType(t);
|
||||
let n: string | null = null;
|
||||
const tinctures = createTinctures();
|
||||
while (!n || n === t) {
|
||||
n = rw(
|
||||
tinctures[type as keyof typeof tinctures] as Record<string, number>,
|
||||
|
|
@ -568,11 +573,11 @@ class COAGeneratorModule {
|
|||
return "heater";
|
||||
}
|
||||
|
||||
toString(coa: CoatOfArms): string {
|
||||
toString(coa: Emblem): string {
|
||||
return JSON.stringify(coa).replaceAll("#", "%23");
|
||||
}
|
||||
|
||||
copy(coa: CoatOfArms): CoatOfArms {
|
||||
copy(coa: Emblem): Emblem {
|
||||
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();
|
||||
2
src/modules/emblem/index.ts
Normal file
2
src/modules/emblem/index.ts
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
import "./generator";
|
||||
import "./renderer";
|
||||
|
|
@ -8,7 +8,7 @@ import { shieldSize } from "./size";
|
|||
import { templates } from "./templates";
|
||||
|
||||
declare global {
|
||||
var COArenderer: COARenderModule;
|
||||
var COArenderer: EmblemRenderModule;
|
||||
}
|
||||
|
||||
interface Division {
|
||||
|
|
@ -37,7 +37,7 @@ interface Charge {
|
|||
p: number[]; // position on shield from 1 to 9
|
||||
}
|
||||
|
||||
interface CoatOfArms {
|
||||
interface Emblem {
|
||||
shield: string;
|
||||
t1: string;
|
||||
division?: Division;
|
||||
|
|
@ -46,7 +46,7 @@ interface CoatOfArms {
|
|||
custom?: boolean; // if true, coa will not be rendered
|
||||
}
|
||||
|
||||
class COARenderModule {
|
||||
class EmblemRenderModule {
|
||||
get shieldPaths() {
|
||||
return shieldPaths;
|
||||
}
|
||||
|
|
@ -87,7 +87,7 @@ class COARenderModule {
|
|||
return fetched;
|
||||
}
|
||||
|
||||
private async getCharges(coa: CoatOfArms, id: string, shieldPath: string) {
|
||||
private async getCharges(coa: Emblem, id: string, shieldPath: string) {
|
||||
const charges = coa.charges
|
||||
? coa.charges.map((charge) => charge.charge)
|
||||
: []; // add charges
|
||||
|
|
@ -122,7 +122,7 @@ class COARenderModule {
|
|||
return 1;
|
||||
}
|
||||
|
||||
private getPatterns(coa: CoatOfArms, id: string) {
|
||||
private getPatterns(coa: Emblem, id: string) {
|
||||
const isPattern = (string: string) => string.includes("-");
|
||||
const patternsToAdd = [];
|
||||
if (coa.t1.includes("-")) patternsToAdd.push(coa.t1); // add field pattern
|
||||
|
|
@ -165,7 +165,7 @@ class COARenderModule {
|
|||
.join("");
|
||||
}
|
||||
|
||||
private async draw(id: string, coa: CoatOfArms) {
|
||||
private async draw(id: string, coa: Emblem) {
|
||||
const { shield = "heater", division, ordinaries = [], charges = [] } = coa;
|
||||
|
||||
const ordinariesRegular = ordinaries.filter((o) => !o.above);
|
||||
|
|
@ -243,7 +243,7 @@ class COARenderModule {
|
|||
if (ordinary.ordinary === "bordure")
|
||||
svg += `<path d="${shieldPath}" fill="none" stroke="${fill}" stroke-width="16.7%"/>`;
|
||||
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);
|
||||
return `${svg}</g>`;
|
||||
};
|
||||
|
|
@ -340,13 +340,13 @@ class COARenderModule {
|
|||
}
|
||||
|
||||
// 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.custom) return console.warn("Cannot render custom emblem", 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 g: HTMLElement = document.getElementById(
|
||||
`${type}Emblems`,
|
||||
|
|
@ -360,4 +360,4 @@ class COARenderModule {
|
|||
if (layerIsOn("toggleEmblems")) this.trigger(id, coa);
|
||||
}
|
||||
}
|
||||
window.COArenderer = new COARenderModule();
|
||||
window.COArenderer = new EmblemRenderModule();
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
import { P } from "../../utils";
|
||||
|
||||
export const tinctures = {
|
||||
export const createTinctures = () => ({
|
||||
field: { metals: 3, colours: 4, 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 },
|
||||
|
|
@ -40,4 +40,4 @@ export const tinctures = {
|
|||
maily: 2,
|
||||
honeycombed: 1,
|
||||
},
|
||||
};
|
||||
});
|
||||
|
|
@ -13,4 +13,4 @@ import "./states-generator";
|
|||
import "./zones-generator";
|
||||
import "./religions-generator";
|
||||
import "./provinces-generator";
|
||||
import "./coat-of-arms";
|
||||
import "./emblem";
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue