-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
638b89b
commit 801cbf9
Showing
17 changed files
with
461 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 83 additions & 19 deletions
102
...rontend/packages/renderer/src/components/Instances/InstanceMenu/InstanceSettings/Mods.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
export const filter = <T extends object>( | ||
array: T[], | ||
keyword: string, | ||
key: keyof T, | ||
alternativeKey?: keyof T, | ||
) => { | ||
console.time("filter"); | ||
const fuzzyRegex = new RegExp(keyword.split("").join(".*"), "i"); | ||
const startingRegex = new RegExp(`^${keyword}`, "i"); | ||
const containsRegex = new RegExp(`${keyword}`, "i"); | ||
const word = (item: T): string => { | ||
if (!alternativeKey) return item[key] as unknown as string; | ||
return (item[key] ?? item[alternativeKey]) as unknown as string; | ||
}; | ||
const weight = (item: T) => { | ||
const itemString = word(item); | ||
if (startingRegex.test(itemString)) { | ||
return 1; | ||
} | ||
if (containsRegex.test(itemString)) { | ||
return 2; | ||
} | ||
if (fuzzyRegex.test(itemString)) { | ||
return 3; | ||
} | ||
return 4; | ||
}; | ||
const filteredArray = array | ||
.filter((item) => fuzzyRegex.test(word(item))) | ||
// sort by weight and alphabetical order | ||
.sort((a, b) => { | ||
const weightA = weight(a); | ||
const weightB = weight(b); | ||
if (weightA === weightB) { | ||
return word(a).localeCompare(word(b)); | ||
} | ||
return weightA - weightB; | ||
}); | ||
console.timeEnd("filter"); | ||
return filteredArray; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1 @@ | ||
import { modrinthSource } from "./modrinth-source"; | ||
|
||
export const modSources = [modrinthSource]; | ||
export { modrinthSource } from "./modrinth-source"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { instanceManager } from "./instance-manager"; | ||
|
||
export const enableMod = async ({ | ||
instancePath, | ||
fileName, | ||
}: { | ||
instancePath: string; | ||
fileName: string; | ||
}) => { | ||
instanceManager.enableMod(instancePath, fileName); | ||
}; | ||
|
||
export const disableMod = async ({ | ||
instancePath, | ||
fileName, | ||
}: { | ||
instancePath: string; | ||
fileName: string; | ||
}) => { | ||
instanceManager.disableMod(instancePath, fileName); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import type { ModSource } from "./interfaces/ModSource"; | ||
|
||
class ModSourceManager { | ||
private modSources: ModSource[] = []; | ||
|
||
public registerModSource(modSource: ModSource): void { | ||
this.modSources.push(modSource); | ||
} | ||
|
||
public getModSources(): ModSource[] { | ||
return this.modSources; | ||
} | ||
|
||
public getModSource(id: string): ModSource | undefined { | ||
return this.modSources.find((modSource) => modSource.id === id); | ||
} | ||
} | ||
|
||
export const modSourceManager = new ModSourceManager(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { drizzle } from "drizzle-orm/better-sqlite3"; | ||
import Database from "better-sqlite3"; | ||
import getAppData from "./get-app-data"; | ||
import path from "path"; | ||
|
||
const sqlite = new Database(path.join(getAppData(), "cache.db"), { | ||
verbose: console.log, | ||
}); | ||
const db = drizzle(sqlite); | ||
|
||
export const cacheManager = {}; |
Oops, something went wrong.