Skip to content

Commit

Permalink
feat: handle gamepad switch on map button + add configurable custom g…
Browse files Browse the repository at this point in the history
…ame splash screen
  • Loading branch information
liana-p committed Jul 28, 2024
1 parent ba169aa commit 80d1d90
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 8 deletions.
15 changes: 10 additions & 5 deletions docs/features/scenes.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,8 @@ window.addEventListener('load', () => {
scripts,
config,
});
useScenes().addNewScene({ // [!code focus]
useScenes().addNewScene({
// [!code focus]
id: 'my-scene', // [!code focus]
component: shallowRef(GameplayScene), // [!code focus]
props: {}, // [!code focus]
Expand All @@ -194,14 +195,18 @@ To do so, the new `scenes` option is available in `common.yaml`:

```yaml
scenes:
startMenuScene: my-custom-start-scene
gameScene: my-custom-game-scene
startMenuScene: my-custom-start-scene # The scene to load instead of the start menu with the "Press start to continue"
gameScene: my-custom-game-scene # The scene to load instead of the normal gameplay scene when starting a game
gameSplashScene: my-custom-splash-scene # The scene to load instead of the splash screen that shows before the start menu
```
When those options are present, instead of going to the normal game scene, the game will go to the custom scenes defined in the config.
::: tip
A custom start menu scene or game scene will probably want to eventually go back to the normal start menu or game scene. To do so, use the `goToGameScene` and `goToStartMenuScene` methods from `useScenes()` (the sample scene above does this).
::: warn
It is important to go back to the relevant splash screen scenes or start menu after running your custom scene, as they contain important engine initialization logic. If you override any of those scenes, you should make your new scene go to the expected "default" scene afterwards
:::
To do so, use the `goToGameScene` and `goToStartMenuScene` methods from `useScenes()` (the sample scene above does this).

For example, in your scene component, the following code examples are good ways to go to various narrat scenes:

Expand Down
1 change: 1 addition & 0 deletions packages/narrat/src/config/common-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ export const defaultScriptsConfig = [];
export const ScenesConfigSchema = Type.Object({
startMenuScene: Type.Optional(Type.String()),
gameScene: Type.Optional(Type.String()),
gameSplashScene: Type.Optional(Type.String()),
});

export type ScenesConfig = Static<typeof ScenesConfigSchema>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ test_multiline:
talk player idle $text

main:
jump dev_test
// jump dev_test
set_screen video
add_item book 1
jump quest_demo
Expand Down
9 changes: 8 additions & 1 deletion packages/narrat/src/stores/scenes-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,20 @@ export const useScenes = defineStore('scenes-store', {
return this.scenes[sceneId];
},
onEngineSplashFinished() {
this.changeScene('game-splash');
this.goToGameSplashScene();
},
finishedScene(sceneId: string) {
if (this.scenes[sceneId].onFinished) {
this.scenes[sceneId].onFinished!();
}
},
goToGameSplashScene() {
let destination = BuiltInScene.GameSplash as string;
if (getCommonConfig().scenes.gameSplashScene) {
destination = getCommonConfig().scenes.gameSplashScene!;
}
this.changeScene(destination);
},
goToStartMenuScene() {
let destination = BuiltInScene.StartMenu as string;
if (getCommonConfig().scenes.startMenuScene) {
Expand Down
4 changes: 3 additions & 1 deletion packages/narrat/src/utils/interact-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { getButtonConfig } from '@/config';
import { ScreenObjectState } from '@/stores/screen-objects-store';
import { isViewportElementClickable } from './viewport-utils';
import { useScreens } from '@/stores/screens-store';
import { useInputs } from '@/stores/inputs-store';

export interface RenderingState {
selected: boolean;
Expand Down Expand Up @@ -61,8 +62,9 @@ export function getRenderingStateForButton(
): RenderingState {
const buttonConfig = getButtonConfig(button);
const state = useScreens().getButtonState(button);
const input = useInputs().inputMode;
return {
selected,
selected: selected && input === 'gamepad',
clickable: useScreens().isButtonInteractible(button),
viewportClickable: isViewportElementClickable(buttonConfig)!,
transitioning,
Expand Down

0 comments on commit 80d1d90

Please sign in to comment.