@drincs/pixi-vn-ink
Version:
Pixi'VN gives you the ability to write your own narrative using Ink
62 lines (60 loc) • 2.25 kB
text/typescript
/**
* This function is called after the {@link onInkTranslate} function is called.
* It will replace the text between curly braces.
* It can be used for example to replace the character id with the character name:
* If there are a character with a name "John" and id "john", and the text is "Hello, my name is [john]",
* the following function will return "Hello, my name is John"
* @param getTextToReplace The function to get the text to replace
* @example
* ```ts
* import { onReplaceTextAfterTranslation } from 'pixi-vn-ink'
* import { getCharacterById } from "@drincs/pixi-vn";
*
* onReplaceTextAfterTranslation((key) => {
* let character = getCharacterById(key)
* if (character) {
* return character.name
* }
*
* // if return undefined, the system will not replace the character id
* return undefined
* })
* ```
*/
declare function onReplaceTextAfterTranslation(getTextToReplace: (
/**
* The key to be replaced
*/
key: string) => string | undefined): void;
/**
* This function is called before the {@link onInkTranslate} function is called.
* It will replace the text between curly braces.
* It can be used for example to replace the normal method for replacing the text [key] with a new method to replace the text {{key}}.
* It can be used for example to optimize the text replacement with i18next, using the {@link onInkTranslate} function.
* If there are a text is "Hello, my name is [john]", the following function will return "Hello, my name is {{john}}"
* @param getTextToReplace The function to get the text to replace
* @example
* ```ts
* import { onReplaceTextBeforeTranslation, onInkTranslate } from 'pixi-vn-ink'
* import { useTranslation } from "react-i18next";
* import { john } from "../values/characters"
*
* const { t } = useTranslation(["narration"]);
*
* onInkTranslate((text) => {
* return t(text, {
* john: john.name
* })
* })
*
* onReplaceTextBeforeTranslation((key) => {
* return `{{${key}}}`
* })
* ```
*/
declare function onReplaceTextBeforeTranslation(getTextToReplace: (
/**
* The key to be replaced
*/
key: string) => string | undefined): void;
export { onReplaceTextAfterTranslation, onReplaceTextBeforeTranslation };