Skip to content

Commit

Permalink
feat: Add random spells and optimize code.
Browse files Browse the repository at this point in the history
  • Loading branch information
Starciad committed Jan 28, 2024
1 parent 96fc706 commit bfce9cf
Show file tree
Hide file tree
Showing 4 changed files with 176 additions and 53 deletions.
7 changes: 5 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
<script src="scripts/collections/background/important_locations_collection.js" type="module"></script>
<script src="scripts/collections/background/characteristics_collection.js" type="module"></script>
<script src="scripts/collections/background/phobias_collection.js" type="module"></script>
<script src="scripts/collections/background/manias_collection.js" type="module"></script>
<!-- #endregion -->

<!-- Core -->
Expand Down Expand Up @@ -885,8 +886,10 @@ <h3>Collection</h3>
<div>
<h2>Manias</h2>

<h3>Listing</h3>
<p>Empty.</p>
<h3>Collection</h3>
<div class="app-items-collection" id="cs-background-manias-collection">
<!-- PROCEDURAL LIST -->
</div>
</div>
</section>

Expand Down
110 changes: 110 additions & 0 deletions scripts/collections/background/manias_collection.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
import { Random } from "../../math/random.js";

export const ManiasCollection = Object.freeze({
manias: [
{ name: "Ablutomania", description: "Compulsion to wash oneself." },
{ name: "Abulomania", description: "Pathological indecision." },
{ name: "Acluomania", description: "Excessive fondness for darkness." },
{ name: "Acromania", description: "Compulsion for high places." },
{ name: "Agatomania", description: "Pathological kindness." },
{ name: "Agromania", description: "Intense desire to be in open spaces." },
{ name: "Aichmomania", description: "Obsession with sharp or pointed objects." },
{ name: "Algomania", description: "Obsession with pain." },
{ name: "Alliomania", description: "Obsession with garlic." },
{ name: "Amaxomania", description: "Obsession with being in vehicles." },
{ name: "Amenomania", description: "Irrational joy." },
{ name: "Antomania", description: "Obsession with flowers." },
{ name: "Aritmomania", description: "Obsessive concern with numbers." },
{ name: "Asoticamania", description: "Impulsive or reckless spending." },
{ name: "Automania", description: "Excessive fondness for solitude." },
{ name: "Baletomania", description: "Abnormal affection for ballet." },
{ name: "Bibliocleptomania", description: "Compulsion to steal books." },
{ name: "Bibliomania", description: "Obsession with books and/or reading." },
{ name: "Bruxomania", description: "Compulsion to grind teeth." },
{ name: "Cacodemomania", description: "Pathological belief of being possessed by an evil spirit." },
{ name: "Calomania", description: "Obsession with one's own beauty." },
{ name: "Cartacoethes", description: "Uncontrollable compulsion to see maps everywhere." },
{ name: "Catapedamania", description: "Obsession with jumping from high places." },
{ name: "Cheimatomania", description: "Abnormal desire for cold and/or icy things." },
{ name: "Clazomania", description: "Irrational compulsion to shout." },
{ name: "Cleptomania", description: "Irrational compulsion to steal." },
{ name: "Clinomania", description: "Excessive desire to stay in bed." },
{ name: "Coimetromania", description: "Obsession with cemeteries." },
{ name: "Coloromania", description: "Obsession with a specific color." },
{ name: "Coreomania", description: "Mania for dancing or uncontrollable frenzy." },
{ name: "Coulromania", description: "Obsession with clowns." },
{ name: "Countermania", description: "Compulsion to confront fearful situations." },
{ name: "Dacnomania", description: "Obsession with killing." },
{ name: "Demonomania", description: "Pathological belief of being possessed by demons." },
{ name: "Dermatilomania", description: "Compulsion to pick, scratch, or touch one's own or others' skin." },
{ name: "Dikemania", description: "Obsession with seeing justice being done." },
{ name: "Dipsomania", description: "Abnormal desire for alcohol." },
{ name: "Doramania", description: "Obsession with owning animal skins." },
{ name: "Doromania", description: "Obsession with giving gifts." },
{ name: "Drapetomania", description: "Compulsion to flee." },
{ name: "Ecdemomania", description: "Compulsion to wander." },
{ name: "Egomania", description: "Irrational self-centered or self-worshipping attitude." },
{ name: "Eluromania", description: "Abnormal affection for cats." },
{ name: "Empleomania", description: "Insatiable desire to hold a public office." },
{ name: "Enosimania", description: "Pathological belief that someone has sinned." },
{ name: "Epistemomania", description: "Obsession with acquiring knowledge." },
{ name: "Eremiomania", description: "Compulsion for quietness." },
{ name: "Eteromania", description: "Desire for ether." },
{ name: "Fantasmomania", description: "Obsession with ghosts." },
{ name: "Fonomania", description: "Pathological tendency to commit murder." },
{ name: "Fotomania", description: "Pathological desire for light." },
{ name: "Gamomania", description: "Obsession with strange marriage proposals." },
{ name: "Geliomania", description: "Uncontrollable compulsion to laugh." },
{ name: "Gimnomania", description: "Compulsion for nudity." },
{ name: "Goetomania", description: "Obsession with witches and witchcraft." },
{ name: "Grafomania", description: "Obsession with writing or taking notes." },
{ name: "Habromania", description: "Abnormal tendency to create pleasant delusions (despite reality)." },
{ name: "Helmintomania", description: "Intense fascination with worms." },
{ name: "Hidromania", description: "Irrational desire for water." },
{ name: "Hoplomania", description: "Obsession with firearms." },
{ name: "Iconomania", description: "Obsession with icons or portraits." },
{ name: "Ictiomania", description: "Obsession with fish." },
{ name: "Idolomania", description: "Obsession or devotion to an idol." },
{ name: "Infomania", description: "Excessive devotion to accumulating facts." },
{ name: "Ligiromania", description: "Uncontrollable compulsion to make loud or strident noises." },
{ name: "Linonomania", description: "Obsession with ropes or cords." },
{ name: "Lipemania", description: "Abnormal tendency toward deep melancholy." },
{ name: "Loterimania", description: "Extreme desire to participate in lotteries." },
{ name: "Question-Asking Mania", description: "Compulsive desire to ask questions." },
{ name: "Megalitomania", description: "Abnormal tendency to compose strange ideas when in the presence of circles." },
{ name: "Melomania", description: "Obsession with music or a specific melody." },
{ name: "Metromania", description: "Insatiable desire to write verses." },
{ name: "Misomania", description: "Hatred of everything, obsession with hating a subject or group." },
{ name: "Mitomania", description: "Lying or exaggerating in abnormal amounts." },
{ name: "Monomania", description: "Abnormal obsession with a single thought or idea." },
{ name: "Nosomania", description: "Delusions of suffering from an imagined illness." },
{ name: "Notomania", description: "Compulsion to record everything (e.g., with photographs)." },
{ name: "Onicotilomania", description: "Compulsion to pick, bite, or tear nails." },
{ name: "Onomamania", description: "Obsession with names (people, places, things)." },
{ name: "Onomatomania", description: "Irresistible desire to repeat certain words." },
{ name: "Opsomania", description: "Abnormal fondness for a certain type of food." },
{ name: "Paramania", description: "Abnormal pleasure in complaining." },
{ name: "Personamania", description: "Compulsion to wear masks." },
{ name: "Piromania", description: "Compulsion to start fires." },
{ name: "Planomania", description: "Abnormal desire to disobey social norms." },
{ name: "Plutomania", description: "Obsessive desire for wealth." },
{ name: "Pseudomania", description: "Irrational compulsion to lie." },
{ name: "Doodling Mania", description: "Obsession with doodling/drawing to keep hands busy." },
{ name: "Rinotilexomania", description: "Compulsive desire to pick the nose or clean the nose with the finger." },
{ name: "Siderodromomania", description: "Intense fascination with trains and railway travel." },
{ name: "Sophomania", description: "The illusion of being incredibly intelligent." },
{ name: "Tanatomania", description: "Belief that someone is cursed by death magic." },
{ name: "Technomania", description: "Obsession with new technologies." },
{ name: "Teomania", description: "Belief that one is a god." },
{ name: "Tiflomania", description: "Pathological blindness." },
{ name: "Titilomania", description: "Compulsion to scratch oneself." },
{ name: "Tomomania", description: "Irrational preference for undergoing surgeries or operations." },
{ name: "Trichotillomania", description: "Desire to pull out one's own hair." },
{ name: "Xenomania", description: "Obsession with foreign things." },
{ name: "Zoomania", description: "Insane fondness for animals." }
],

getRandomMania: function () {
return Random.getRandomArrayElement(this.manias);
},
});
48 changes: 25 additions & 23 deletions scripts/generator/routine/scsg_data.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { Random } from "../../math/random.js";
import { BelovedBelongingsCollection } from "../../collections/background/beloved_belongings_collection.js";
import { CharacteristicsCollection } from "../../collections/background/characteristics_collection.js";
import { PhobiasCollection } from "../../collections/background/phobias_collection.js";
import { ManiasCollection } from "../../collections/background/manias_collection.js";

//#endregion

Expand Down Expand Up @@ -71,6 +72,7 @@ export function SCSGData(settings) {
let char_background_dear_belongings = backgroundGenerator.getRandomDarlingBelonging();
let char_background_dear_characteristic = backgroundGenerator.getRandomCharacteristic();
let char_background_dear_phobias = backgroundGenerator.getRandomPhobias();
let char_background_dear_manias = backgroundGenerator.getRandomManias();
//#endregion

return {
Expand Down Expand Up @@ -162,6 +164,7 @@ export function SCSGData(settings) {
},

phobias: char_background_dear_phobias,
manias: char_background_dear_manias,
},
};
}
Expand Down Expand Up @@ -339,36 +342,35 @@ const backgroundGenerator = Object.freeze({
},

getRandomPhobias: function () {
let phobias = [];
let phobiasAndIntensity = [];

let count = Random.getRandomNumber(0, 5);

for (let i = 0; i < count; i++) {
let phobiaSelected = PhobiasCollection.getRandomPhobia();

if (phobias.includes(phobiaSelected)) {
continue;
}
return this.getRandomItems(PhobiasCollection.phobias, Random.getRandomNumber(0, 5));
},

getRandomManias: function () {
return this.getRandomItems(ManiasCollection.manias, Random.getRandomNumber(0, 5));
},

phobias.push(phobiaSelected);
// Utilities
getRandomItems: function(collection, count) {
let items = new Set();

while (items.size < count) {
let selectedItem = Random.getRandomArrayElement(collection);
items.add(selectedItem);
}

phobias.forEach(phobia => {
return Array.from(items).map(item => {
let intensitySelected;

do {
intensitySelected = IntensityCollection.getRandomIntensity();
} while (intensitySelected === "None");

phobiasAndIntensity.push({
name: phobia.name,
description: phobia.description,
return {
name: item.name,
description: item.description,
intensity: intensitySelected
});
};
});

return phobiasAndIntensity;
},
}
});
//#endregion
64 changes: 36 additions & 28 deletions scripts/generator/routine/scsg_updater.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ let cs_background_important_location;
let cs_background_dear_belongings;
let cs_background_characteristic;
let cs_background_phobias_collection;
let cs_background_manias_collection;

// ======================================== //
// Main
Expand Down Expand Up @@ -74,6 +75,7 @@ export function SCSGQueryElements() {
cs_background_dear_belongings = document.querySelector("#cs-background-dear-belongings");
cs_background_characteristic = document.querySelector("#cs-background-characteristic");
cs_background_phobias_collection = document.querySelector("#cs-background-phobias-collection");
cs_background_manias_collection = document.querySelector("#cs-background-manias-collection");
}

export function SCSGUpdater(characterInfos) {
Expand Down Expand Up @@ -156,35 +158,10 @@ function updateBackground(characterInfos) {
cs_background_characteristic.innerHTML = characterInfos.background.characteristics.target;

// Phobias
cs_background_phobias_collection.replaceChildren();
createCollectionItems(characterInfos.background.phobias, cs_background_phobias_collection);

if (characterInfos.background.phobias.length > 0) {
characterInfos.background.phobias.forEach(phobia => {
let phobia_item = document.createElement("div");
let title = document.createElement("span");
let description = document.createElement("span");

phobia_item.classList.add("app-item-square");
title.classList.add("app-item-square-title");
description.classList.add("app-item-square-description");

phobia_item.appendChild(title);
phobia_item.appendChild(description);

title.innerHTML = `${phobia.name} (${phobia.intensity})`;
description.innerHTML = phobia.description;

cs_background_phobias_collection.appendChild(phobia_item);
});
}
else {
let empty_item = document.createElement("div");
empty_item.classList.add("app-item-square");

empty_item.innerHTML = "The character does not have phobias.";

cs_background_phobias_collection.appendChild(empty_item);
}
// Manias
createCollectionItems(characterInfos.background.manias, cs_background_manias_collection);
}

// ================================ //
Expand All @@ -194,4 +171,35 @@ function getFormattedDate(date) {
return date.day.toString().padStart(2, '0') + "/" +
date.month.toString().padStart(2, '0') + "/" +
date.year + " (day/month/year)";
}

function createCollectionItems(collection, container) {
container.replaceChildren();

if (collection.length > 0) {
collection.forEach(item => {
let itemElement = document.createElement("div");
let title = document.createElement("span");
let description = document.createElement("span");

itemElement.classList.add("app-item-square");
title.classList.add("app-item-square-title");
description.classList.add("app-item-square-description");

itemElement.appendChild(title);
itemElement.appendChild(description);

title.innerHTML = `${item.name} (${item.intensity})`;
description.innerHTML = item.description;

container.appendChild(itemElement);
});
} else {
let emptyItem = document.createElement("div");
emptyItem.classList.add("app-item-square");

emptyItem.innerHTML = "There are no items in the respective collection.";

container.appendChild(emptyItem);
}
}

0 comments on commit bfce9cf

Please sign in to comment.