Skip to content

Commit

Permalink
onStepError
Browse files Browse the repository at this point in the history
  • Loading branch information
BlackRam-oss committed Aug 20, 2024
1 parent efc4d39 commit 2665291
Showing 1 changed file with 35 additions and 13 deletions.
48 changes: 35 additions & 13 deletions src/managers/StepManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export default class GameStepManager {
* **Attention**: if the step index is edited or the code of step is edited, the counter will be reset.
* You can restart the counter in this way:
* ```typescript
* GameStepManager.currentStepTimesCounter = 0
* narration.currentStepTimesCounter = 0
* ```
*/
static get currentStepTimesCounter(): number {
Expand Down Expand Up @@ -457,7 +457,7 @@ export default class GameStepManager {
* ```typescript
* function nextOnClick() {
* setLoading(true)
* GameStepManager.goNext(yourParams)
* narration.goNext(yourParams)
* .then((result) => {
* setUpdate((p) => p + 1)
* setLoading(false)
Expand Down Expand Up @@ -511,10 +511,19 @@ export default class GameStepManager {
if (!stepSha) {
console.warn("[Pixi'VN] stepSha not found")
}
let result = await step(props)
GameStepManager.addLabelHistory(currentLabel.id, currentLabelStepIndex, stepSha || "error", choiseMade)
GameStepManager.addStepHistory(stepSha || "error", choiseMade)
return result
try {
let result = await step(props)
GameStepManager.addLabelHistory(currentLabel.id, currentLabelStepIndex, stepSha || "error", choiseMade)
GameStepManager.addStepHistory(stepSha || "error", choiseMade)
return result
}
catch (e) {
console.error("[Pixi'VN] Error running step", e)
if (GameStepManager._onStepError) {
GameStepManager._onStepError(e)
}
return
}
}
else if (GameStepManager.openedLabels.length > 1) {
GameStepManager.closeCurrentLabel()
Expand All @@ -537,7 +546,7 @@ export default class GameStepManager {
* @returns StepLabelResultType or undefined.
* @example
* ```typescript
* GameStepManager.callLabel(startLabel, yourParams).then((result) => {
* narration.callLabel(startLabel, yourParams).then((result) => {
* if (result) {
* // your code
* }
Expand All @@ -546,7 +555,7 @@ export default class GameStepManager {
* @example
* ```typescript
* // if you use it in a step label you should return the result.
* return GameStepManager.callLabel(startLabel).then((result) => {
* return narration.callLabel(startLabel).then((result) => {
* return result
* })
* ```
Expand Down Expand Up @@ -599,7 +608,7 @@ export default class GameStepManager {
* @returns StepLabelResultType or undefined.
* @example
* ```typescript
* GameStepManager.jumpLabel(startLabel, yourParams).then((result) => {
* narration.jumpLabel(startLabel, yourParams).then((result) => {
* if (result) {
* // your code
* }
Expand All @@ -608,7 +617,7 @@ export default class GameStepManager {
* @example
* ```typescript
* // if you use it in a step label you should return the result.
* return GameStepManager.jumpLabel(startLabel).then((result) => {
* return narration.jumpLabel(startLabel).then((result) => {
* return result
* })
* ```
Expand Down Expand Up @@ -662,7 +671,7 @@ export default class GameStepManager {
* @returns StepLabelResultType or undefined.
* @example
* ```typescript
* GameStepManager.closeChoiceMenu(yourParams).then((result) => {
* narration.closeChoiceMenu(yourParams).then((result) => {
* if (result) {
* // your code
* }
Expand Down Expand Up @@ -691,7 +700,7 @@ export default class GameStepManager {
* @example
* ```typescript
* export function goBack(navigate: (path: string) => void, afterBack?: () => void) {
* GameStepManager.goBack(navigate)
* narration.goBack(navigate)
* afterBack && afterBack()
* }
* ```
Expand Down Expand Up @@ -834,10 +843,23 @@ export default class GameStepManager {
* Function to be executed at the end of the game. It should be set in the game initialization.
* @example
* ```typescript
* GameStepManager.gameEnd = async (props) => {
* narration.gameEnd = async (props) => {
* props.navigate("/end")
* }
* ```
*/
static gameEnd: StepLabelType | undefined = undefined
private static _onStepError: (error: any) => void | undefined
/**
* Function to be executed when an error occurs in the step.
* @example
* ```typescript
* narration.onStepError = (error) => {
* // error report
* }
* ```
*/
public static set onStepError(onStepError: (error: Error) => void) {
GameStepManager._onStepError = onStepError
}
}

0 comments on commit 2665291

Please sign in to comment.