Skip to content

Commit

Permalink
Merge pull request #171 from DRincs-Productions/170-improve-end-game-…
Browse files Browse the repository at this point in the history
…management

170 improve end game management
  • Loading branch information
BlackRam-oss authored Aug 9, 2024
2 parents a79cd5e + 1a8f6a7 commit b9db43b
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/classes/LabelJson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ export default class LabelJson<T extends {} = {}> extends LabelAbstract<LabelJso
}

if (step.end === "game_end") {
// TODO end game
console.warn("[Pixi'VN] Game end not implemented")
GameStepManager.closeAllLabels()
GameStepManager.goNext(props)
}
else if (step.end === "label_end") {
GameStepManager.closeCurrentLabel()
Expand Down
14 changes: 14 additions & 0 deletions src/managers/StepManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,9 @@ export default class GameStepManager {
}
else {
GameStepManager.restorLastLabelList()
if (GameStepManager.gameEnd) {
return await GameStepManager.gameEnd(props)
}
console.error("[Pixi'VN] The end of the game is not managed, so the game is blocked. Read this documentation to know how to manage the end of the game: https://pixi-vn.web.app/start/labels.html#how-manage-the-end-of-the-game")
return
}
Expand Down Expand Up @@ -650,4 +653,15 @@ export default class GameStepManager {
console.error("[Pixi'VN] Error importing data", e)
}
}

/**
* Function to be executed at the end of the game. It should be set in the game initialization.
* @example
* ```typescript
* GameStepManager.gameEnd = async (props) => {
* props.navigate("/end")
* }
* ```
*/
static gameEnd: StepLabelType | undefined = undefined
}
40 changes: 39 additions & 1 deletion src/types/StepLabelJsonType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,58 @@ import { LabelIdType } from "./LabelIdType"
* Step label JSON type
*/
type StepLabelJsonType = {
/**
* Variable used to display a choice menu.
*/
currentChoiceMenuOptions?: {
/**
* The text to be displayed.
*/
text: string
/**
* The label id to be opened.
*/
label: LabelIdType
/**
* Label opening mode
*/
type: LabelRunModeType
/**
* The properties to be passed to the label.
*/
props: StorageObjectType
}[]
/**
* Variable used to display a dialog.
*/
dialog?: {
/**
* The character id that will speak.
*/
character: string,
/**
* The text to be displayed.
*/
text: string,
} | string
/**
* Variable used to open a label.
*/
labelToOpen?: {
/**
* The id of the label to open.
*/
labelId: string,
type: "jump" | "call",
/**
* Label opening mode
*/
type: LabelRunModeType,
}
/**
* Variable used to end some elements of the narrative.
* - game_end: ends the game
* - label_end: ends the label
*/
end?: "game_end" | "label_end"
}

Expand Down

0 comments on commit b9db43b

Please sign in to comment.