-
Notifications
You must be signed in to change notification settings - Fork 1
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
0773706
commit 2211390
Showing
6 changed files
with
106 additions
and
37 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
{ | ||
"tasks": { | ||
"watch": "deno run --watch --allow-net --allow-env --allow-read --allow-write main.ts", | ||
"start": "deno run --allow-net --allow-env --allow-read --allow-write main.ts", | ||
"compile": "deno compile --allow-net --allow-env --allow-read --allow-write -o coeiroink-v2-bridge main.ts" | ||
"watch": "deno run --watch --allow-net --allow-run --allow-env --allow-read --allow-write main.ts", | ||
"start": "deno run --allow-net --allow-run --allow-env --allow-read --allow-write main.ts", | ||
"compile": "deno compile --allow-net --allow-run --allow-env --allow-read --allow-write -o coeiroink-v2-bridge main.ts" | ||
}, | ||
"lock": false | ||
} |
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 was deleted.
Oops, something went wrong.
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,49 @@ | ||
import { homeDir } from "./deps.ts"; | ||
|
||
type SpeakerMap = [number, [string, number]][]; | ||
type Store = { | ||
speakerMap: SpeakerMap; | ||
enginePath: string | undefined; | ||
}; | ||
|
||
const filePath = homeDir + "/.coeiroink-v2.json"; | ||
export let store: Store = { speakerMap: [], enginePath: undefined }; | ||
const oldFilePath = homeDir + "/.coeiroink-v2-bridge-map.json"; | ||
if (await Deno.stat(oldFilePath).catch(() => null)) { | ||
console.log("Migrating old speaker map..."); | ||
store.speakerMap.push(...JSON.parse(await Deno.readTextFile(oldFilePath))); | ||
await Deno.remove(oldFilePath); | ||
} | ||
if (await Deno.stat(filePath).catch(() => null)) { | ||
console.log("Loading store..."); | ||
store = JSON.parse(await Deno.readTextFile(filePath)); | ||
} | ||
|
||
export const getSpeakerFromId = (id: number) => { | ||
return store.speakerMap.find(([id_, _]) => id_ === id)?.[1]; | ||
}; | ||
|
||
export const getIdFromSpeaker = (speakerUuid: string, styleId: number) => { | ||
return store.speakerMap.find( | ||
([_, [speakerUuid_, styleId_]]) => | ||
speakerUuid_ === speakerUuid && styleId_ === styleId, | ||
)?.[0]; | ||
}; | ||
|
||
export const getOrAppendSpeaker = async ( | ||
speakerUuid: string, | ||
styleId: number, | ||
) => { | ||
const speakerId = getIdFromSpeaker(speakerUuid, styleId); | ||
if (speakerId !== undefined) { | ||
return speakerId; | ||
} | ||
const speakerCount = store.speakerMap.length; | ||
store.speakerMap.push([speakerCount, [speakerUuid, styleId]]); | ||
await saveStore(); | ||
return speakerCount; | ||
}; | ||
|
||
export const saveStore = async () => { | ||
await Deno.writeTextFile(filePath, JSON.stringify(store)); | ||
}; |