Skip to content

Commit

Permalink
Clean up formatting and fix typos
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisWhisker committed Jul 9, 2024
1 parent ca49843 commit 20726dc
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 121 deletions.
112 changes: 56 additions & 56 deletions app/filter.ts
Original file line number Diff line number Diff line change
@@ -1,70 +1,70 @@
import Word from './word';
import Message from './message';
import wordCategories from './wordCategories';
import { ButtonRenderer } from './buttons';
import Word from "./word";
import Message from "./message";
import wordCategories from "./wordCategories";
import { ButtonRenderer } from "./buttons";

interface WordCategory {
word: string;
keywords: string;
word: string;
keywords: string;
}

export default class Filter {
// Search query
static query: string = "";
// Array to store search results
static results: Word[] = [];
// Search query
static query: string = "";
// Array to store search results
static results: Word[] = [];

// Refilter function to be used within the class
public static refilter(): void {
Filter.filterWords(Filter.query);
};
// Refilter function to be used within the class
public static refilter(): void {
Filter.filterWords(Filter.query);
}

// Check if a word can be added based on the category
private static canAddWord(category: string): boolean {
const instance = Message.getInstance();
switch (category) {
case "Templates":
return !instance.template1 || !instance.template2;
case "Conjunctions":
return !instance.conjunction;
default:
return !instance.clause1 || !instance.clause2;
}
};
// Check if a word can be added based on the category
private static canAddWord(category: string): boolean {
const instance = Message.getInstance();
switch (category) {
case "Templates":
return !instance.template1 || !instance.template2;
case "Conjunctions":
return !instance.conjunction;
default:
return !instance.clause1 || !instance.clause2;
}
}

// Add a single word to the results array
private static addWord(category: string, word: WordCategory): void {
if (Filter.canAddWord(category)) {
const wordObj = new Word(category, word.word);
// Check for duplicates before adding
if (!wordObj.isInArray(Filter.results)) {
Filter.results.push(wordObj);
}
}
};
// Add a single word to the results array
private static addWord(category: string, word: WordCategory): void {
if (Filter.canAddWord(category)) {
const wordObj = new Word(category, word.word);
// Check for duplicates before adding
if (!wordObj.isInArray(Filter.results)) {
Filter.results.push(wordObj);
}
}
}

// Add all words from a category to results array
private static addWordsFromCategory(category: string): void {
for (const word of wordCategories[category]) {
Filter.addWord(category, word);
}
};
// Add all words from a category to results array
private static addWordsFromCategory(category: string): void {
for (const word of wordCategories[category]) {
Filter.addWord(category, word);
}
}

// Filter words based on the query
static filterWords(newQuery: string | null = null): void {
// Clear the results array
Filter.results = [];
// Ensure query is not null and convert to lowercase
Filter.query = newQuery ? newQuery.trim().toLowerCase() : "";
// Filter words based on the query
static filterWords(newQuery: string | null = null): void {
// Clear the results array
Filter.results = [];
// Ensure query is not null and convert to lowercase
Filter.query = newQuery ? newQuery.trim().toLowerCase() : "";

// If query is empty, add all words from all categories
if (!Filter.query) {
for (const category in wordCategories) {
Filter.addWordsFromCategory(category);
}
} else {
// Split the query into individual words
const queryWords = Filter.query.split(" ");
// If query is empty, add all words from all categories
if (!Filter.query) {
for (const category in wordCategories) {
Filter.addWordsFromCategory(category);
}
} else {
// Split the query into individual words
const queryWords = Filter.query.split(" ");

// Search for each query word in all categories
for (const category in wordCategories) {
Expand Down
6 changes: 3 additions & 3 deletions app/message.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Define the type for the message
import Word from './word';
import Filter from './filter';
import { Button } from './buttons';
import Word from "./word";
import Filter from "./filter";
import { Button } from "./buttons";

export default class Message {
// Words that make up a message
Expand Down
102 changes: 51 additions & 51 deletions app/word.ts
Original file line number Diff line number Diff line change
@@ -1,64 +1,64 @@
// Define the type for the object containing word and category
export default class Word {
category: string;
text: string;
id: number;
category: string;
text: string;
id: number;

static nextId: number = 0;
static nextId: number = 0;

constructor(category: string, text: string) {
// Initialize Word with category and text
this.category = category;
this.text = text;
this.id = Word.nextId++;
}
constructor(category: string, text: string) {
// Initialize Word with category and text
this.category = category;
this.text = text;
this.id = Word.nextId++;
}

// Override the toString method to return a unique value for each Word
toString(): string {
// Concatenate category and text to form a unique identifier
return `${this.category}:${this.text}/${this.id}`;
}
// Override the toString method to return a unique value for each Word
toString(): string {
// Concatenate category and text to form a unique identifier
return `${this.category}:${this.text}/${this.id}`;
}

// Compare objects based on their properties
equivalent(other: Word | null): boolean {
// Check if toString representations of both objects are equal
return !!other && this.toString() === other.toString();
}
// Compare objects based on their properties
equivalent(other: Word | null): boolean {
// Check if toString representations of both objects are equal
return !!other && this.toString() === other.toString();
}

// Compare objects based on their properties and id
identical(other: Word | null): boolean {
return !!other && this.equivalent(other) && this.id === other.id;
}
// Compare objects based on their properties and id
identical(other: Word | null): boolean {
return !!other && this.equivalent(other) && this.id === other.id;
}

// Check if the Word is in an array
// Use this instead of arr.includes(this)
isInArray(arr: Word[]): boolean {
// Check if the Word exists in the array
return this.indexInArray(arr) !== -1;
}
// Check if the Word is in an array
// Use this instead of arr.includes(this)
isInArray(arr: Word[]): boolean {
// Check if the Word exists in the array
return this.indexInArray(arr) !== -1;
}

// Get the index of the Word in an array or -1 if not found
indexInArray(arr: Word[]): number {
// Iterate through the array to find the index of the Word
for (let i = 0; i < arr.length; i++) {
if (this.equivalent(arr[i])) {
// Return the index if Word is found
return i;
}
}
// Return -1 if Word is not found in the array
return -1;
// Get the index of the Word in an array or -1 if not found
indexInArray(arr: Word[]): number {
// Iterate through the array to find the index of the Word
for (let i = 0; i < arr.length; i++) {
if (this.equivalent(arr[i])) {
// Return the index if Word is found
return i;
}
}
// Return -1 if Word is not found in the array
return -1;
}

// Remove the Word from an array, if present
removeFromArray(arr: Word[]): boolean {
// Get the index of the Word in the array
const index = this.indexInArray(arr);
if (index !== -1) {
// Remove the Word from the array if found
arr.splice(index, 1);
return true; // Return true indicating successful removal
}
return false; // Return false if Word is not found in the array
// Remove the Word from an array, if present
removeFromArray(arr: Word[]): boolean {
// Get the index of the Word in the array
const index = this.indexInArray(arr);
if (index !== -1) {
// Remove the Word from the array if found
arr.splice(index, 1);
return true; // Return true indicating successful removal
}
return false; // Return false if Word is not found in the array
}
}
22 changes: 11 additions & 11 deletions app/wordCategories.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const wordcategories: any = {
const wordCategories: any = {
"Templates": [
{ word: "ahh, ****...", keywords: "ooh, ohh aha wow woah whoa dot sex" },
{ word: "be wary of ****", keywords: "cautious careful watchful look out for" },
Expand All @@ -9,11 +9,11 @@ const wordcategories: any = {
{ word: "if only i had a ****...", keywords: "wish i had a desire for a want need dot" },
{ word: "let there be ****", keywords: "make way for grant shall should" },
{ word: "likely ****", keywords: "probably high chance of most" },
{ word: "no **** ahead", keywords: "nothing no in sight absent absense not here" },
{ word: "no **** ahead", keywords: "nothing no in sight absent absence not here" },
{ word: "offer ****", keywords: "provide give present" },
{ word: "praise the ****!", keywords: "hail applaud worship" },
{ word: "seek ****", keywords: "search for look for seek out watch out find hidden" },
{ word: "still no ****...", keywords: "no yet none nothing no in sight absent absense not here dot" },
{ word: "still no ****...", keywords: "no yet none nothing no in sight absent absence not here dot" },
{ word: "time for ****", keywords: "it's time now clock" },
{ word: "try ****", keywords: "attempt give it a shot why not" },
{ word: "visions of ****...", keywords: "images thoughts pictures dreams dot" },
Expand Down Expand Up @@ -83,7 +83,7 @@ const wordcategories: any = {
{ word: "hero", keywords: "protagonist savior champion good super tarnished" },
{ word: "invisible sort", keywords: "unseen hidden hiding clear transparent" },
{ word: "knight", keywords: "warrior champion paladin cavalier sir shining armor" },
{ word: "laggardly sort", keywords: "slowpoke sluggish lazy lathargic" },
{ word: "laggardly sort", keywords: "slowpoke sluggish lazy lethargic" },
{ word: "liar", keywords: "deceiver fibber fabricator lies untrustworthy" },
{ word: "lovable sort", keywords: "adorable woman charming girl endearing" },
{ word: "lover", keywords: "romantic partner paramour beloved sex woman girl maiden" },
Expand All @@ -108,7 +108,7 @@ const wordcategories: any = {
{ word: "swordfighter", keywords: "duelist fencer master" },
{ word: "teacher", keywords: "educator instructor tutor wise wisdom knowledge" },
{ word: "thief", keywords: "burglar robber pickpocket steal stolen take" },
{ word: "traitor", keywords: "betrayer turncoat renegade trader untrustworthy wvil bad" },
{ word: "traitor", keywords: "betrayer turncoat renegade trader untrustworthy evil bad" },
{ word: "trio", keywords: "three group 3 threesome" },
{ word: "tarnished", keywords: "stained fallen damaged soul PC player character you me" },
{ word: "unfathomable sort", keywords: "mysterious enigmatic baffling impenetrable incomprehensible indecipherable inexplicable unknowable" },
Expand Down Expand Up @@ -164,7 +164,7 @@ const wordcategories: any = {
],
"Battle Tactics": [
{ word: "brief respite", keywords: "short break momentary pause rest quick breather sanctuary" },
{ word: "circling around", keywords: "encircling surrounding moving around backstab" },
{ word: "circling around", keywords: "encircling surrounding moving around back stab" },
{ word: "close-quarters battle", keywords: "hand-to-hand combat melee close-range fight" },
{ word: "confusion", keywords: "chaos disarray bewilderment muddle" },
{ word: "dashing through", keywords: "running speeding darting rushing" },
Expand Down Expand Up @@ -200,7 +200,7 @@ const wordcategories: any = {
{ word: "running attack", keywords: "charging attack sprinting attack quick attack" },
{ word: "rolling", keywords: "evading dodging tumbling rolling away" },
{ word: "skill", keywords: "technique ability proficiency mastery git gud" },
{ word: "sorcery", keywords: "magic wizardry spellcraft enchantment" },
{ word: "sorcery", keywords: "magic wizardry spellcraft spells enchantment" },
{ word: "summoning", keywords: "calling forth aid spirit ashes help friend conjuring" },
{ word: "throwing", keywords: "tossing hurling pitching away" },
{ word: "two-handing", keywords: "dual-wielding both hands double 2" },
Expand All @@ -219,7 +219,7 @@ const wordcategories: any = {
{ word: "danger", keywords: "risk peril hazard threat" },
{ word: "dark spot", keywords: "shadowy area dim corner unlit place hide hidden" },
{ word: "dead end", keywords: "cul-de-sac no exit impasse blind alley" },
{ word: "defensible spot", keywords: "fortifiable position stronghold secure location" },
{ word: "defensible spot", keywords: "fortified position stronghold secure location" },
{ word: "detour", keywords: "quick route direct path detour bypass shortcut road closed" },
{ word: "explosion", keywords: "burst blast detonation eruption" },
{ word: "evening", keywords: "dusk sunset nightfall twilight" },
Expand Down Expand Up @@ -410,9 +410,9 @@ const wordcategories: any = {
{ word: "keep moving", keywords: "go forward keep going don't stop" },
{ word: "look carefully", keywords: "watch out seek search" },
{ word: "listen carefully", keywords: "hear heed" },
{ word: "not here!", keywords: "absent absense" },
{ word: "not here!", keywords: "absent absence" },
{ word: "seems familiar...", keywords: "deja vu been here before repeat repetitive" },
{ word: "so lonely...", keywords: "alone solitude lonely lonelyness" },
{ word: "so lonely...", keywords: "alone solitude lonely loneliness" },
{ word: "stay calm", keywords: "relax chill" },
{ word: "think carefully", keywords: "consider ponder" },
{ word: "too high up", keywords: "climb ladder fall death die cliff" },
Expand All @@ -434,4 +434,4 @@ const wordcategories: any = {
]
};

export default wordcategories;
export default wordCategories;

0 comments on commit 20726dc

Please sign in to comment.