Skip to content

Commit

Permalink
refactor: Update ChoiceMenuOptionLabel to use CloseLabel for close op…
Browse files Browse the repository at this point in the history
…tion
  • Loading branch information
BlackRam-oss committed May 19, 2024
1 parent b570892 commit 8976d16
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/classes/ChoiceMenuOption.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { CloseType, LabelRunModeType, StorageElementType, StorageObjectType } from "../types"
import { LabelIdType } from "../types/LabelIdType"
import CloseLabel from "./CloseLabel"
import Label from "./Label"

/**
Expand Down Expand Up @@ -54,7 +55,7 @@ export class ChoiceMenuOptionClose {
/**
* Label to be opened when the option is selected
*/
label: Label = new Label() // to edit
label: Label = new CloseLabel()
/**
* Text to be displayed in the menu
*/
Expand Down
3 changes: 3 additions & 0 deletions src/classes/CloseLabel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import Label from "./Label"

export default class CloseLabel extends Label { }
5 changes: 3 additions & 2 deletions src/functions/DialogueUtility.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { CharacterBaseModel, DialogueBaseModel, Label } from "../classes";
import { CharacterBaseModel, DialogueBaseModel } from "../classes";
import { ChoiceMenuOptionClose, IStoratedChoiceMenuOptionLabel } from "../classes/ChoiceMenuOption";
import CloseLabel from "../classes/CloseLabel";
import { DialogueData } from "../classes/DialogueBaseModel";
import { getLabelTypeByClassName } from "../decorators/LabelDecorator";
import { IDialogueHistory } from "../interface";
Expand Down Expand Up @@ -107,7 +108,7 @@ export function getChoiceMenuOptions<TChoice extends ChoiceMenuOptionsType = Cho
let options: ChoiceMenuOptionsType = []
d.forEach((option, index) => {
if (option.type === Close) {
let itemLabel = new Label() // to edit
let itemLabel = new CloseLabel()
itemLabel.choiseIndex = index
options.push({
text: option.text,
Expand Down
7 changes: 7 additions & 0 deletions src/managers/StepManager.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { diff } from "deep-diff"
import { DialogueBaseModel, Label } from "../classes"
import { IStoratedChoiceMenuOptionLabel } from "../classes/ChoiceMenuOption"
import CloseLabel from "../classes/CloseLabel"
import { getLabelInstanceByClassName } from "../decorators/LabelDecorator"
import { getDialogue } from "../functions"
import { restoreDeepDiffChanges } from "../functions/DiffUtility"
Expand Down Expand Up @@ -312,6 +313,9 @@ export default class GameStepManager {
public static async callLabel<T extends {}>(label: typeof Label<T> | Label<T>, props?: StepLabelPropsType<T>): Promise<StepLabelResultType> {
let choiseMade: number | undefined = undefined
try {
if (label instanceof CloseLabel) {
return GameStepManager.runNextStep(props)
}
if (label instanceof Label) {
choiseMade = label.choiseIndex
label = label.constructor as typeof Label<T>
Expand Down Expand Up @@ -350,6 +354,9 @@ export default class GameStepManager {
public static async jumpLabel<T extends {}>(label: typeof Label<T> | Label<T>, props?: StepLabelPropsType<T>): Promise<StepLabelResultType> {
GameStepManager.closeAllLabels()
try {
if (label instanceof CloseLabel) {
return GameStepManager.runNextStep(props)
}
if (label instanceof Label) {
label = label.constructor as typeof Label<T>
}
Expand Down

0 comments on commit 8976d16

Please sign in to comment.