feat: route - generate names

This commit is contained in:
Azgaar 2024-05-04 15:51:52 +02:00
parent 865c10cec6
commit 6936f37f9f
3 changed files with 166 additions and 37 deletions

View file

@ -2899,15 +2899,10 @@
<div id="routeEditor" class="dialog" style="display: none">
<div id="routeBody" style="padding-bottom: 0.3em">
<div>
<div class="label" style="width: 4.8em">Name:</div>
<span
id="routeNameCulture"
data-tip="Generate culture-specific name for the route"
class="icon-book pointer"
></span>
<span id="routeNameRandom" data-tip="Generate random name for the route" class="icon-globe pointer"></span>
<div class="label">Name:</div>
<input id="routeName" data-tip="Type to rename the route" autocorrect="off" spellcheck="false" />
<span data-tip="Speak the name. You can change voice and language in options" class="speaker">🔊</span>
<span id="routeGenerateName" data-tip="Generate route name" class="icon-globe pointer"></span>
</div>
<div data-tip="Select route group">

View file

@ -362,5 +362,164 @@ window.Routes = (function () {
);
}
return {generate, isConnected, areConnected, getRoute, hasRoad, isCrossroad};
// name generator data
const models = {
roads: {burg_suffix: 3, prefix_suffix: 6, the_descriptor_prefix_suffix: 2, the_descriptor_burg_suffix: 1},
trails: {burg_suffix: 8, prefix_suffix: 1, the_descriptor_burg_suffix: 1},
searoutes: {burg_suffix: 4, prefix_suffix: 2, the_descriptor_prefix_suffix: 1}
};
const prefixes = [
"King",
"Queen",
"Military",
"Old",
"New",
"Ancient",
"Royal",
"Imperial",
"Great",
"Grand",
"High",
"Silver",
"Dragon",
"Shadow",
"Star",
"Mystic",
"Whisper",
"Eagle",
"Golden",
"Crystal",
"Enchanted",
"Frost",
"Moon",
"Sun",
"Thunder",
"Phoenix",
"Sapphire",
"Celestial",
"Wandering",
"Echo",
"Twilight",
"Crimson",
"Serpent",
"Iron",
"Forest",
"Flower",
"Whispering",
"Eternal",
"Frozen",
"Rain",
"Luminous",
"Stardust",
"Arcane",
"Glimmering",
"Jade",
"Ember",
"Azure",
"Gilded",
"Divine",
"Shadowed",
"Cursed",
"Moonlit",
"Sable",
"Everlasting",
"Amber",
"Nightshade",
"Wraith",
"Scarlet",
"Platinum",
"Whirlwind",
"Obsidian",
"Ethereal",
"Ghost",
"Spike",
"Dusk",
"Raven",
"Spectral",
"Burning",
"Verdant",
"Copper",
"Velvet",
"Falcon",
"Enigma",
"Glowing",
"Silvered",
"Molten",
"Radiant",
"Astral",
"Wild",
"Flame",
"Amethyst",
"Aurora",
"Shadowy",
"Solar",
"Lunar",
"Whisperwind",
"Fading",
"Titan",
"Dawn",
"Crystalline",
"Jeweled",
"Sylvan",
"Twisted",
"Ebon",
"Thorn",
"Cerulean",
"Halcyon",
"Infernal",
"Storm",
"Eldritch",
"Sapphire",
"Crimson",
"Tranquil",
"Paved"
];
const descriptors = [
"Great",
"Shrouded",
"Sacred",
"Fabled",
"Frosty",
"Winding",
"Echoing",
"Serpentine",
"Breezy",
"Misty",
"Rustic",
"Silent",
"Cobbled",
"Cracked",
"Shaky",
"Obscure"
];
const suffixes = {
roads: {road: 3, route: 1, way: 1, highway: 1},
trails: {trail: 3, path: 1, track: 1, pass: 1},
searoutes: {"sea route": 3, lane: 2, passage: 1, seaway: 1}
};
function generateName({group, cells}) {
const model = rw(models[group]);
const suffix = rw(suffixes[group]);
if (model === "burg_suffix") return `${getBurgName()} ${suffix}`;
if (model === "prefix_suffix") return `${ra(prefixes)} ${suffix}`;
if (model === "the_descriptor_prefix_suffix") return `The ${ra(descriptors)} ${ra(prefixes)} ${suffix}`;
if (model === "the_descriptor_burg_suffix") return `The ${ra(descriptors)} ${getBurgName()} ${suffix}`;
return "Unnamed route";
function getBurgName() {
const priority = [cells.at(-1), cells.at(0), cells.slice(1, -1).reverse()];
for (const cellId of priority) {
const burgId = pack.cells.burg[cellId];
if (burgId) return getAdjective(pack.burgs[burgId].name);
}
return "Unnamed";
}
}
return {generate, isConnected, areConnected, getRoute, hasRoad, isCrossroad, generateName};
})();

View file

@ -41,8 +41,7 @@ function editRoute(id) {
byId("routeRemove").on("click", removeRoute);
byId("routeName").on("input", changeName);
byId("routeGroup").on("input", changeGroup);
byId("routeNameCulture").on("click", generateNameCulture);
byId("routeNameRandom").on("click", generateNameRandom);
byId("routeGenerateName").on("click", generateName);
function getRoute() {
const routeId = +elSelected.attr("id").slice(5);
@ -53,7 +52,7 @@ function editRoute(id) {
function updateRouteData() {
const route = getRoute();
route.name = route.name || generateRouteName(route);
route.name = route.name || Routes.generateName(route);
byId("routeName").value = route.name;
const routeGroup = byId("routeGroup");
@ -68,23 +67,6 @@ function editRoute(id) {
byId("routeElevationProfile").style.display = isWater ? "none" : "inline-block";
}
function generateRouteName(route) {
const {cells, burgs} = pack;
const burgName = (() => {
const priority = [route.cells.at(-1), route.cells.at(0), route.cells.slice(1, -1).reverse()];
for (const cellId of priority) {
const burgId = cells.burg[cellId];
if (burgId) return burgs[burgId].name;
}
})();
const type = route.group.replace(/s$/, "");
if (burgName) return `${getAdjective(burgName)} ${type}`;
return "Unnamed route";
}
function updateRouteLength(route) {
route.length = rn(elSelected.node().getTotalLength() / 2, 2);
const lengthUI = `${rn(route.length * distanceScaleInput.value)} ${distanceUnitInput.value}`;
@ -239,16 +221,9 @@ function editRoute(id) {
getRoute().group = group;
}
function generateNameCulture() {
function generateName() {
const route = getRoute();
const cell = ra(route.cells);
const cultureId = pack.cells.culture[cell];
route.name = routeName.value = Names.getCulture(cultureId);
}
function generateNameRandom() {
const route = getRoute();
route.name = routeName.value = Names.getBase(rand(nameBases.length - 1));
route.name = routeName.value = Routes.generateName(route);
}
function showRouteElevationProfile() {