Skip to content

Commit

Permalink
refactor: Update ChoiceMenuOptionsType to accept generic props parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
BlackRam-oss committed May 18, 2024
1 parent b3d92a4 commit 0476ec0
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
7 changes: 4 additions & 3 deletions src/functions/DialogueUtility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { DialogueData } from "../classes/DialogueBaseModel";
import { getLabelTypeByClassName } from "../decorators/LabelDecorator";
import { IDialogueHistory } from "../interface";
import { GameStepManager, GameStorageManager } from "../managers";
import { StorageObjectType } from "../types";
import { ChoiceMenuOptionsType } from "../types/ChoiceMenuOptionsType";

/**
Expand Down Expand Up @@ -94,17 +95,17 @@ export function setChoiceMenuOptions(options: ChoiceMenuOptionsType): void {
* Get the options to be shown in the game
* @returns Options to be shown in the game
*/
export function getChoiceMenuOptions(): ChoiceMenuOptionsType | undefined {
export function getChoiceMenuOptions<T extends StorageObjectType = {}>(): ChoiceMenuOptionsType<T> | undefined {
let d = GameStorageManager.getVariable<IStoratedChoiceMenuOptionLabel[]>(GameStorageManager.keysSystem.CURRENT_MENU_OPTIONS_MEMORY_KEY)
if (d) {
let options: ChoiceMenuOptionsType = []
let options: ChoiceMenuOptionsType<T> = []
d.forEach((option) => {
let label = getLabelTypeByClassName(option.label)
if (label) {
options.push({
...option,
label: label
})
} as any)
}
})
return options
Expand Down
3 changes: 2 additions & 1 deletion src/types/ChoiceMenuOptionsType.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { ChoiceMenuOptionLabel } from "../classes";
import { StorageObjectType } from "./StorageElementType";

/**
* Munu is a type that contains a list of Label that a player can choose from.
* For Ren'py this is the equivalent of a menu.
*/
export type ChoiceMenuOptionsType = ChoiceMenuOptionLabel[]
export type ChoiceMenuOptionsType<T extends StorageObjectType = {}> = ChoiceMenuOptionLabel<T>[]
4 changes: 2 additions & 2 deletions src/types/StorageElementType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ type StorageElementInternalType = StorageElementPrimaryType | Record<string | nu
/**
* StorageElementType are all the types that can be stored in the storage
*/
export type StorageElementType = StorageElementInternalType | Record<string | number | symbol, StorageElementInternalType> | { [key: string | number | symbol]: StorageElementType }
export type StorageElementType = StorageElementInternalType | Record<string | number | symbol, StorageElementInternalType> | { [key: string | number | symbol]: StorageElementType } | StorageObjectType[]
/**
* StorageObjectType are all the types that can be stored in the storage
*/
export type StorageObjectType = Record<string | number | symbol, StorageElementType>
export type StorageObjectType = Record<string | number | symbol, StorageElementType>

0 comments on commit 0476ec0

Please sign in to comment.