mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-17 09:41:24 +01:00
fix: improve adjectives generation rules
This commit is contained in:
parent
55f8b2a491
commit
00ced6260b
4 changed files with 177 additions and 60 deletions
|
|
@ -13,64 +13,6 @@ function capitalize(string) {
|
|||
return string.charAt(0).toUpperCase() + string.slice(1);
|
||||
}
|
||||
|
||||
// check if char is vowel or can serve as vowel
|
||||
function vowel(c) {
|
||||
return `aeiouyɑ'əøɛœæɶɒɨɪɔɐʊɤɯаоиеёэыуюяàèìòùỳẁȁȅȉȍȕáéíóúýẃőűâêîôûŷŵäëïöüÿẅãẽĩõũỹąęįǫųāēīōūȳăĕĭŏŭǎěǐǒǔȧėȯẏẇạẹịọụỵẉḛḭṵṳ`.includes(c);
|
||||
}
|
||||
|
||||
// remove vowels from the end of the string
|
||||
function trimVowels(string) {
|
||||
while (string.length > 3 && vowel(last(string))) {
|
||||
string = string.slice(0, -1);
|
||||
}
|
||||
return string;
|
||||
}
|
||||
|
||||
// get adjective form from noun
|
||||
function getAdjective(string) {
|
||||
// special cases for some suffixes
|
||||
if (string.length > 8 && string.slice(-6) === "orszag") return string.slice(0, -6);
|
||||
if (string.length > 6 && string.slice(-4) === "stan") return string.slice(0, -4);
|
||||
if (P(0.5) && string.slice(-4) === "land") return string + "ic";
|
||||
if (string.slice(-4) === " Guo") string = string.slice(0, -4);
|
||||
|
||||
// don't change is name ends on suffix
|
||||
if (string.slice(-2) === "an") return string;
|
||||
if (string.slice(-3) === "ese") return string;
|
||||
if (string.slice(-1) === "i") return string;
|
||||
|
||||
const end = string.slice(-1); // last letter of string
|
||||
if (end === "a") return (string += "n");
|
||||
if (end === "o") return (string = trimVowels(string) + "an");
|
||||
if (vowel(end) || end === "c") return (string += "an"); // ceiuy
|
||||
if (end === "m" || end === "n") return (string += "ese");
|
||||
if (end === "q") return (string += "i");
|
||||
return trimVowels(string) + "ian";
|
||||
}
|
||||
|
||||
// get ordinal out of integer: 1 => 1st
|
||||
const nth = n => n + (["st", "nd", "rd"][((((n + 90) % 100) - 10) % 10) - 1] || "th");
|
||||
|
||||
// get two-letters code (abbreviation) from string
|
||||
function abbreviate(name, restricted = []) {
|
||||
const parsed = name.replace("Old ", "O ").replace(/[()]/g, ""); // remove Old prefix and parentheses
|
||||
const words = parsed.split(" ");
|
||||
const letters = words.join("");
|
||||
|
||||
let code = words.length === 2 ? words[0][0] + words[1][0] : letters.slice(0, 2);
|
||||
for (let i = 1; i < letters.length - 1 && restricted.includes(code); i++) {
|
||||
code = letters[0] + letters[i].toUpperCase();
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
// conjunct array: [A,B,C] => "A, B and C"
|
||||
function list(array) {
|
||||
if (!Intl.ListFormat) return array.join(", ");
|
||||
const conjunction = new Intl.ListFormat(window.lang || "en", {style: "long", type: "conjunction"});
|
||||
return conjunction.format(array);
|
||||
}
|
||||
|
||||
// split string into 2 almost equal parts not breaking words
|
||||
function splitInTwo(str) {
|
||||
const half = str.length / 2;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue