Skip to content

Commit

Permalink
Populate wordCategories from csv
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisWhisker committed Apr 21, 2024
1 parent f638de2 commit a7b9796
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 17 deletions.
14 changes: 14 additions & 0 deletions categores.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Templates,**** ahead,No **** ahead,**** required ahead,Be wary of ****,Try ****,Likely ****,"First off, ****",Seek ****,Still no ****...,Why is it always ****?,If only I had a ****...,Didn't expect ****...,Visions of ****...,Could this be a ****?,Time for ****,"****, O ****","Behold, ****!",Offer ****,Praise the ****!,Let there be ****,"Ahh, ****...",****,****!,****?,****...,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
Enemies,enemy,weak foe,strong foe,monster,dragon,boss,sentry,group,pack,decoy,undead,soldier,knight,cavalier,archer,sniper,mage,ordnance,monarch,lord,demi-human,outsider,giant,horse,dog,wolf,rat,beast,bird,raptor,snake,crab,prawn,octopus,bug,scarab,slug,wraith,skeleton,monstrosity,ill-omened creature,,,,,,,,,,,,,,,,,,
People,Tarnished,warrior,swordfighter,knight,samurai,sorcerer,cleric,sage,merchant,teacher,master,friend,lover,old dear,old codger,angel,fat coinpurse,pauper,good sort,wicked sort,plump sort,skinny sort,lovable sort,pathetic sort,strange sort,nimble sort,laggardly sort,invisible sort,unfathomable sort,giant sort,sinner,thief,liar,dastard,traitor,pair,trio,noble,aristocrat,hero,champion,monarch,lord,god,,,,,,,,,,,,,,,
Things,item,necessary item,precious item,something,something incredible,treasure chest,corpse,coffin,trap,armament,shield,bow,projectile weapon,armor,talisman,skill,sorcery,incantation,map,material,flower,grass,tree,fruit,seed,mushroom,tear,crystal,butterfly,bug,dung,grace,door,key,ladder,lever,lift,spiritspring,sending gate,stone astrolabe,Birdseye Telescope,message,bloodstain,Erdtree,Elden Ring,,,,,,,,,,,,,,
Battle Tactics,close-quarters battle,ranged battle,horseback battle,luring out,defeating one-by-one,taking on all at once,rushing in,stealth,mimicry,confusion,pursuit,fleeing,summoning,circling around,jumping off,dashing through,brief respite,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
Actions,attacking,jump attack,running attack,critical hit,two-handing,blocking,parrying,guard counter,sorcery,incantation,skill,summoning,throwing,healing,running,rolling,backstepping,jumping,crouching,target lock,item crafting,gesturing,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
Situations,morning,noon,evening,night,clear sky,overcast,rain,storm,mist,snow,patrolling,procession,crowd,surprise attack,ambush,pincer attack,beating to a pulp,battle,reinforcements,ritual,explosion,high spot,defensible spot,climbable spot,bright spot,dark spot,open area,cramped area,hiding place,sniping spot,recon spot,safety,danger,gorgeous view,detour,hidden path,secret passage,shortcut,dead end,looking away,unnoticed,out of stamina,,,,,,,,,,,,,,,,,
Places,high road,checkpoint,bridge,castle,fort,city,ruins,church,tower,camp site,house,cemetery,underground tomb,tunnel,cave,evergaol,great tree,cellar,surface,underground,forest,river,lake,bog,mountain,valley,cliff,waterside,nest,hole,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
Directions,east,west,south,north,ahead,behind,left,right,center,up,down,edge,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
Body Parts,head,stomach,back,arms,legs,rump,tail,core,fingers,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
Affinities,physical,standard,striking,slashing,piercing,fire,lightning,magic,holy,poison,toxic,scarlet rot,blood loss,frost,sleep,madness,death,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
Concepts,life,Death,light,dark,stars,fire,Order,chaos,joy,wrath,suffering,sadness,comfort,bliss,misfortune,good fortune,bad luck,hope,despair,victory,defeat,research,faith,abundance,rot,loyalty,injustice,secret,opportunity,pickle,clue,friendship,love,bravery,vigor,fortitude,confidence,distracted,unguarded,introspection,regret,resignation,futility,on the brink,betrayal,revenge,destruction,recklessness,calmness,vigilance,tranquility,sound,tears,sleep,depths,dregs,fear,sacrifice,ruin
Phrases,good luck,look carefully,listen carefully,think carefully,well done,I did it!,I've failed...,here!,not here!,don't you dare!,do it!,I can't take this...,don't think,so lonely...,here again...,just getting started,stay calm,keep moving,turn back,give up,don't give up,help me...,I don't believe it...,too high up,I want to go home...,it's like a dream...,seems familiar...,beautiful...,you don't have the right,are you ready?,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
Conjunctions,and then,or,but,therefore,in short,except,by the way,so to speak,all the more,",",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
74 changes: 57 additions & 17 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,36 @@ var buttonContainer;
document.addEventListener("DOMContentLoaded", function () {
buttonContainer = document.getElementById("buttonContainer");

loadCSV("categories.csv");
// Call the createButtons function initially
search("");
});

const wordCategories = {
"Category1": ["word1", "word2", "word3"],
"Category2": ["word4", "word5"],
"Category3": ["word6", "word7", "word8"],
"Category4": ["word9"],
"Category5": ["word10", "word11", "word12"]
};
// Define wordCategories as an empty object
const wordCategories = {};

function loadCSV(url) {
fetch(url)
.then(response => response.text())
.then(data => {
// Parse the CSV data
const rows = data.split("\n");
for (const row of rows) {
const columns = row.split(",");
const category = columns[0].trim(); // Get the category name from the first column
const words = columns.slice(1).map(word => word.trim()); // Get the words for the category

// Add the category and its words to wordCategories
wordCategories[category] = words;
}

// Call the createButtons function
createButtons([]);
})
.catch(error => {
console.error("Error loading CSV:", error);
});
}

function createButtons(strings) {
// Check if buttonContainer exists
Expand All @@ -28,7 +47,10 @@ function createButtons(strings) {

// If strings is provided and not empty, create buttons for the provided strings
if (strings && strings.length > 0) {
strings.forEach(str => {
// Filter out duplicate strings
const uniqueStrings = [...new Set(strings)];

uniqueStrings.forEach(str => {
const button = document.createElement("button");
button.textContent = str;
buttonContainer.appendChild(button);
Expand All @@ -46,27 +68,45 @@ function createButtons(strings) {
}
}

// Find all words that contain the query
function search(query) {
const results = [];
query = query.toLowerCase();

for (const category in wordCategories) {
// Search the category name
if (category.includes(query)) {

// If the query is empty or null, display buttons for all words
if (!query || query.trim() === "") {
for (const category in wordCategories) {
for (const word of wordCategories[category]) {
results.push(word);
}
}
} else {
// Search for matching words
let found = false;
for (const category in wordCategories) {
// Search the category name
if (category.toLowerCase().includes(query)) {
for (const word of wordCategories[category]) {
results.push(word);
found = true;
}
}

// Search the words in the category
for (const word of wordCategories[category]) {
if (word.includes(query)) {
results.push(word);
// Search the words in the category
for (const word of wordCategories[category]) {
if (word.toLowerCase().includes(query)) {
results.push(word);
found = true;
}
}
}

// If no words match the query, do not display any buttons
if (!found) {
createButtons([]);
return;
}
}

createButtons(results);
}

0 comments on commit a7b9796

Please sign in to comment.