From e89bfc976a4a44eb88d1acfc64ffee723daee3b7 Mon Sep 17 00:00:00 2001 From: Daniel Stirba Date: Mon, 6 Feb 2023 22:53:52 +1100 Subject: [PATCH] added the ability to customise Settlements --- generators/city.ts | 8 +-- main.ts | 126 +++++++++++++++++++++++++++++++++++++++++++-- modal.ts | 10 ++-- styles.css | 22 ++++++-- 4 files changed, 152 insertions(+), 14 deletions(-) diff --git a/generators/city.ts b/generators/city.ts index f146bf7..9db5f5b 100644 --- a/generators/city.ts +++ b/generators/city.ts @@ -1,6 +1,8 @@ -export function generateCityName() { - const prefixes = ["camp", "castle", "east", "edge", "ever", "great", "mount", "new", "north", "red", "rose", "south", "west"]; - const suffixes = ["wood","avon","bank", "bark", "barrow", "bay", "beach", "bell", "borough","berg", "bourne", "broad", "bridge", "brook", "brough", "burgh", "burn", "bury", "by", "canyon", "caster", "chester", "cliffe", "combe", "cot, cott", "cote", "cove", "creek", "croft", "crook", "dale", "den", "din", "dine", "don", "downs", "falls", "field", "fin", "flats", "ford", "fork", "gate", "grove", "gum", "ham", "harbour", "heights", "hill", "holm", "hurst", "ing", "kirk", "land", "lake", "latch", "lea", "leigh", "ley", "marsh", "mere", "minster", "mond", "mont", "more", "ness", "park", "pilly", "pine", "point", "pond", "ridge", "river", "rock", "sett", "side", "son", "stead", "stoke", "stone", "stow", "terrace", "thorpe", "ton", "tor", "town", "vale", "valley", "view", "village", "ville", "water", "well", "wharf", "wick", "wood", "worth"]; +import { cityGeneratorSetting } from "main"; + +export function generateCityName(settings : cityGeneratorSetting) { + const prefixes = settings.prefixArray; + const suffixes = settings.suffixArray; const syllables = ["ab", "ac", "al", "am", "an", "ap", "apo", "ar", "arr", "as", "ast", "at", "ate", "au", "av", "ay", "aye", "ba", "be", "ben", "bo", "br", "bri", "bu", "bur", "ca", "cal", "car", "ce", "chi", "ci", "ck", "co", "com", "con", "cor", "cy", "d", "da", "dan", "dar", "de", "den", "di", "do", "dor", "du", "dur", "ed", "el", "en", "eon", "er", "es", "ey", "fa", "far", "fe", "fi", "fin", "fo", "for", "foy", "fr", "fu", "ga", "gal", "ge", "gi", "gil", "gin", "go", "gor", "gr", "gu", "ha", "han", "har", "he", "hi", "hin", "ho", "hoe", "hos", "hu", "ic", "il", "ill", "in", "ing", "ion", "ir", "irk", "is", "ja", "je", "jen", "jo", "ju", "ka", "ke", "ker", "ki", "kir", "ko", "la", "lan", "las", "le", "ler", "li", "lin", "lis", "lo", "lor", "loy", "lu", "ma", "mac", "mal", "man", "mas", "me", "mi", "mo", "mon", "mu", "mul", "mur", "na", "nal", "ne", "ni", "no", "nor", "nov", "nu", "och", "ode", "oka", "ol", "ome", "on", "op", "or", "ore", "os", "ou", "ous", "pa", "par", "pe", "pen", "pi", "po", "pol", "pon", "por", "pu", "qu", "ra", "re", "ri", "ro", "ru", "sa", "se", "si", "so", "su", "ta", "te", "ti", "to", "tu", "ul", "un", "ur", "us", "va", "ve", "vi", "vo", "vu", "wa", "we", "wi", "wo", "wu", "y", "ya", "ye", "yi", "yo", "yu", "za", "ze", "zi", "zo"]; diff --git a/main.ts b/main.ts index f8902fa..02d2226 100644 --- a/main.ts +++ b/main.ts @@ -8,14 +8,26 @@ export type currency = { rarity: string } +export type cityGeneratorSetting = { + prefixArray: string[], + suffixArray: string[] +} + interface MyPluginSettings { enableCurrency: boolean; + enableSettlementSettings: boolean; + citySettings: cityGeneratorSetting; currencyTypes: currency[]; currencyFrequency: number; } const DEFAULT_SETTINGS: MyPluginSettings = { enableCurrency: false, + enableSettlementSettings:false, + citySettings: { + prefixArray: ["camp", "castle", "east", "edge", "ever", "great", "mount", "new", "north", "red", "rose", "south", "west"], + suffixArray: ["wood","avon","bank", "bark", "barrow", "bay", "beach", "bell", "borough","berg", "bourne", "broad", "bridge", "brook", "brough", "burgh", "burn", "bury", "by", "canyon", "caster", "chester", "cliffe", "combe", "cot", "cott", "cote", "cove", "creek", "croft", "crook", "dale", "den", "din", "dine", "don", "downs", "falls", "field", "fin", "flats", "ford", "fork", "gate", "grove", "gum", "ham", "harbour", "heights", "hill", "holm", "hurst", "ing", "kirk", "land", "lake", "latch", "lea", "leigh", "ley", "marsh", "mere", "minster", "mond", "mont", "more", "ness", "park", "pilly", "pine", "point", "pond", "ridge", "river", "rock", "sett", "side", "son", "stead", "stoke", "stone", "stow", "terrace", "thorpe", "ton", "tor", "town", "vale", "valley", "view", "village", "ville", "water", "well", "wharf", "wick", "wood", "worth"], + }, currencyTypes: [{ "name": "GP", "rarity": "rare" @@ -96,12 +108,21 @@ class SampleSettingTab extends PluginSettingTab { this.plugin = plugin; } + convertStringToArray(string:string, arr:string[]): void { + const newString = string.replace(/\s/g, ''); + const array = newString.split(','); + array.forEach((el) => { + arr.push(el); + }) + } + display(): void { const {containerEl} = this; containerEl.empty(); - containerEl.createEl('h2', {text: 'Fantasy Content Generator'}); + containerEl.createEl('h2', { text: 'Fantasy Content Generator' }); + containerEl.createEl("h3", { text: "Currency Settings" }); new Setting(containerEl) .setName('Enable Currency for Loot Generation.') @@ -157,11 +178,14 @@ class SampleSettingTab extends PluginSettingTab { }) }) - containerEl.createEl("h3", { text: "Added Currency" }); + containerEl.createEl("h4", { text: "Added Currency" }); containerEl.createEl("p", { text: "Click remove on a currency you would like to removed" }); + const foldDiv = containerEl.createEl('details',{cls: "OFCGDetails"}); + foldDiv.createEl("summary", { text: "Currency", cls: "OFCGSummary" }); + for (let index = 0; index < this.plugin.settings.currencyTypes.length; index++) { - new Setting(containerEl) + new Setting(foldDiv) .setName(this.plugin.settings.currencyTypes[index].name) .addButton((btn) => btn .setCta() @@ -176,5 +200,101 @@ class SampleSettingTab extends PluginSettingTab { } } + + containerEl.createEl("h3", { text: "Settlement Settings" }); + + new Setting(containerEl) + .setName('Enable Custom Data for Settlement Generation.') + .setDesc('Want to give your own Custom settlement prefixes or suffixes this is the option for you') + .addToggle((toggle) => { + toggle.setValue(this.plugin.settings.enableSettlementSettings); + toggle.onChange(async (value) => { + this.plugin.settings.enableSettlementSettings = value; + this.display(); + await this.plugin.saveSettings(); + }) + }) + + if (this.plugin.settings.enableSettlementSettings) { + let preText = ""; + let sufText = ""; + containerEl.createEl("h4", { text: "Prefixes being used" }); + new Setting(containerEl) + .setName("New Prefix:") + .addTextArea((text) => { + text.onChange((value) => { + preText = value; + }) + }) + .addButton((btn) => { + btn.setCta().setButtonText("Add") + .onClick(async () => { + this.convertStringToArray(preText, this.plugin.settings.citySettings.prefixArray); + this.display(); + await this.plugin.saveSettings(); + }) + }) + + + containerEl.createEl("p", { text: "Click 'remove' on a prefix you would like to removed" }); + + const foldDiv = containerEl.createEl('details',{cls: "OFCGDetails"}); + foldDiv.createEl("summary", { text: "Prefixes", cls: "OFCGSummary" }); + + for (let index = 0; index < this.plugin.settings.citySettings.prefixArray.length; index++) { + new Setting(foldDiv) + .setName(this.plugin.settings.citySettings.prefixArray[index]) + .addButton((btn) => btn + .setCta() + .setButtonText("Remove") + .onClick(async() => { + this.plugin.settings.citySettings.prefixArray.splice(index, 1); + this.display(); + await this.plugin.saveSettings(); + }) + ) + + } + + containerEl.createEl('hr'); + + containerEl.createEl("h4", { text: "Suffixes being used" }); + new Setting(containerEl) + .setName("New Suffix:") + .addTextArea((text) => { + text.onChange((value) => { + sufText = value; + }) + }) + .addButton((btn) => { + btn.setCta().setButtonText("Add") + .onClick(async () => { + this.convertStringToArray(sufText, this.plugin.settings.citySettings.suffixArray); + this.display(); + await this.plugin.saveSettings(); + }) + }) + + + containerEl.createEl("p", { text: "Click 'remove' on a suffix you would like to removed" }); + + const foldDiv2 = containerEl.createEl('details',{cls: "OFCGDetails"}); + foldDiv2.createEl("summary", { text: "Suffixes", cls: "OFCGSummary" }); + + for (let index = 0; index < this.plugin.settings.citySettings.suffixArray.length; index++) { + new Setting(foldDiv2) + .setName(this.plugin.settings.citySettings.suffixArray[index]) + .addButton((btn) => btn + .setCta() + .setButtonText("Remove") + .onClick(async() => { + this.plugin.settings.citySettings.suffixArray.splice(index, 1); + this.display(); + await this.plugin.saveSettings(); + }) + ) + + } + } } } diff --git a/modal.ts b/modal.ts index c6d549d..1ea4ecc 100644 --- a/modal.ts +++ b/modal.ts @@ -18,9 +18,10 @@ import MyPlugin from "main"; import { generateInn } from "generators/inn"; import { generatePathfinderName } from "generators/Pathfinder/pathfinderName"; import { ISettlementDomainObject } from "fantasy-content-generator/dist/interfaces"; +import { generateMiscellaneousArtifacts } from "generators/artifact"; -const races: string[] = ["none","none", "inn", "settlement", "none", "airships", "drinks", "loot", "metals", "magicaltrees", "ship", "none", "animalgroups", "groups", "religion", "none", "aasimars", "catfolk", "fetchlings","halfelf","halforc","hobgoblin","ifrits","kobalds","oreads","ratfolk","sylphs","tengu","tians","tiefling","undines","angel", "cavePerson", "darkelf", "demon", "dragon", "drow", "dwarf", "elf", "fairy", "gnome", "goblin", "halfdemon", "halfling", "highelf", "highfairy", "human", "ogre", "orc"]; -const racesDisplayName: string[] = ["Select a Generator to Start","--[Settlements and Buildings]--", "Inn's & Taverns", "Settlement", "--[Objects and Vehicles]--", "Airships", "Drinks", "Loot And Treasure", "Metals", "Magical Trees", "Ship", "--[Groups and Religions]--", "Animal Groups", "Groups", "Religion", "--[Races]--", "Aasimars", "Catfolk", "Fetchlings","Half-Elf","Half-Orc","Hobgoblin","Ifrits","Kobalds","Oreads","Ratfolk","Sylphs","Tengu","Tians","Tiefling","Undines","Angel", "Cave Person", "Dark Elf", "Demon", "Dragon", "Drow", "Dwarf", "Elf", "Fairy", "Gnome", "Goblin", "Half Demon", "Halfling", "High Elf", "High Fairy", "Human", "Ogre", "Orc"]; +const races: string[] = ["none","none", "inn", "settlement", "none", "airships", "drinks","artifacts", "loot", "metals", "magicaltrees", "ship", "none", "animalgroups", "groups", "religion", "none", "aasimars", "catfolk", "fetchlings","halfelf","halforc","hobgoblin","ifrits","kobalds","oreads","ratfolk","sylphs","tengu","tians","tiefling","undines","angel", "cavePerson", "darkelf", "demon", "dragon", "drow", "dwarf", "elf", "fairy", "gnome", "goblin", "halfdemon", "halfling", "highelf", "highfairy", "human", "ogre", "orc"]; +const racesDisplayName: string[] = ["Select a Generator to Start","--[Settlements and Buildings]--", "Inn's & Taverns", "Settlement", "--[Objects and Vehicles]--", "Airships", "Drinks","Artifacts", "Loot And Treasure", "Metals", "Magical Trees", "Ship", "--[Groups and Religions]--", "Animal Groups", "Groups", "Religion", "--[Races]--", "Aasimars", "Catfolk", "Fetchlings","Half-Elf","Half-Orc","Hobgoblin","Ifrits","Kobalds","Oreads","Ratfolk","Sylphs","Tengu","Tians","Tiefling","Undines","Angel", "Cave Person", "Dark Elf", "Demon", "Dragon", "Drow", "Dwarf", "Elf", "Fairy", "Gnome", "Goblin", "Half Demon", "Halfling", "High Elf", "High Fairy", "Human", "Ogre", "Orc"]; const pathfinderFilter = ["aasimars", "catfolk", "fetchlings","halfelf","halforc","hobgoblin","ifrits","kobalds","oreads","ratfolk","sylphs","tengu","tians","tiefling","undines"]; let genSettings = { @@ -91,6 +92,9 @@ export class GeneratorModal extends Modal { case "loot": this.generatorLootSettings(optionsDiv, amountToGen, generateLoot, this.plugin.settings.enableCurrency, this.plugin.settings.currencyFrequency, this.plugin.settings.currencyTypes); break; + case "artifacts": + this.generatorCustomSettings(optionsDiv, amountToGen, generateMiscellaneousArtifacts); + break; case "none": optionsDiv.innerHTML = ""; break; @@ -251,7 +255,7 @@ export class GeneratorModal extends Modal { const shipName = generatorFunction(); console.log(shipName); - const name = generateCityName(); + const name = generateCityName(this.plugin.settings.citySettings); new Setting(settingsdiv) .addButton((btn) => { diff --git a/styles.css b/styles.css index 71cc60f..2acd5c4 100644 --- a/styles.css +++ b/styles.css @@ -1,8 +1,20 @@ -/* +.OFCGDetails { + border: 1px solid #aaa; + border-radius: 4px; + padding: 0.5em 0.5em 0.5em; +} -This CSS file will be included with your plugin, and -available in the app when your plugin is enabled. +.OFCGSSummary { + font-weight: bold; + margin: -0.5em -0.5em 0.5em; + padding: 0.5em; +} -If your plugin does not need CSS, delete this file. +.OFCGDetails[open] { + padding: 0.5em; +} -*/ +.OFCGDetails[open] summary { + border-bottom: 1px solid #aaa; + margin-bottom: 0.5em; +} \ No newline at end of file