Skip to content

Commit

Permalink
add autoskip to some actions
Browse files Browse the repository at this point in the history
  • Loading branch information
lajbel committed Sep 15, 2023
1 parent a1a81f8 commit 1d7a779
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 27 deletions.
46 changes: 34 additions & 12 deletions docs/Basics.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ nav_order: 2
In this section, we will understand how Mandarina works from zero.

## Mandarina function

We start using the `mandarina()` function, this function takes care of create our base game, and can receive some options.
Also, `mandarina()` returns all the other mandarina functions, so you must save it in a variable.

Expand All @@ -23,7 +24,30 @@ const m = mandarina({

Now, we can start using mandarina.

## Loading assets

We can load assets in our game, like images, sounds, etc. It's necessary to load assets before starting the game, so we can use the `loadImage()` and `loadAudio()` functions.

Example game file tree

```bash
game.js
assets/
juizy.png
music.mp3
```

game.js:

```js
const m = mandarina();

m.loadImage("juizy", "assets/juizy.png");
m.loadSound("music", "assets/music.mp3");
```

## Chapters

The sections of your visual novel normally are defined by chapters, like the start chapter, the second chapter, etc. We use this system to define the parts of our novel.

```js
Expand Down Expand Up @@ -61,6 +85,7 @@ Now, when you start the game, you will see the text "Hello world!" in the textbo
See more about actions in the [Actions](/Actions.md) section.

## Characters

Characters are the people that appear in your visual novel. We should define our characters before our chapters. We will use the `character()` function, as parameter, it needs an `id`, a `display name` and we can define some extra options.

```js
Expand All @@ -73,12 +98,11 @@ m.character("j", "Juizy", {
Here, **Juizy** is our character represented by the `j` letter, now we can reference this character in actions, for example, in say.

```js
m.chapter("start", () => [
m.say("j", "Hello world!"),
]);
m.chapter("start", () => [m.say("j", "Hello world!")]);
```

## Variables

Variables are the values that we can use in our game. We can define variables in the our novel, and we can use them in actions.

```js
Expand All @@ -91,6 +115,7 @@ m.chapter("start", () => [
```

## Choices

Choices are the options that the player can choose. We can define choices in a chapter, and we can define as many choices as we want.

```js
Expand All @@ -99,15 +124,12 @@ m.chapter("start", () => [
m.say("j", "What's your favorite programming language?"),

m.choice({
"Javascript": {
actions: () => [
m.say("j", "Nice! I like Javascript too!"),
],
Javascript: {
actions: () => [m.say("j", "Nice! I like Javascript too!")],
},
"Python": {
actions: () => [
m.say("j", "Nice! I like Python too!"),
],
Python: {
actions: () => [m.say("j", "Nice! I like Python too!")],
},
}),
]);
]);
```
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"types": "./dist/types.d.ts",
"type": "module",
"scripts": {
"dev": "nodemon --watch ./src --watch ./example --exec \"npm run build && npm run example\" --ext \"ts\"",
"dev": "nodemon --watch ./src --watch ./example --exec \"npm run build && npm run build:example\" --ext \"ts\"",
"build": "node scripts/build.js",
"watch": "nodemon --watch ./src --exec \"npm run build\" --ext \"ts\"",
"build:example": "esbuild example/main.ts --bundle --sourcemap --outfile=example/game.js",
Expand All @@ -26,7 +26,7 @@
"README.md"
],
"dependencies": {
"kaboom": "^3000.1.6"
"kaboom": "^3000.0.15"
},
"devDependencies": {
"@types/node": "^18.14.0",
Expand Down
2 changes: 1 addition & 1 deletion src/actions/audio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export function playAudio(
id: "play_audio",
type: "audio",
volume: 0.5,
autoskip: true,
autoSkip: true,
start() {
audioPlay = k.play(audio, {
volume: this.volume,
Expand Down
2 changes: 1 addition & 1 deletion src/actions/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export function showBackground(background: string | KA.Color) {
return createAction({
id: "showBackground",
type: "visual",
autoskip: true,
autoSkip: true,
fade: false,
start() {
const comps: KA.Comp[] = [];
Expand Down
2 changes: 1 addition & 1 deletion src/actions/chapters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export function jump(name: string) {
return createAction({
id: "jump",
type: "normal",
autoskip: true,
autoSkip: true,
start() {
insertChapter(name);
},
Expand Down
2 changes: 1 addition & 1 deletion src/actions/character.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export function showCharacter(
return createAction({
id: "show_character",
type: "visual",
autoskip: true,
autoSkip: true,
fade: false,
start(this: VisualAction) {
const textbox = m._textbox;
Expand Down
2 changes: 2 additions & 0 deletions src/actions/textbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ export function choice(
id: "choice",
type: "normal",
canSkip: false,
autoSkip: true,
async start() {
await addChoices(choices, setter);
},
Expand All @@ -116,6 +117,7 @@ export function input(text: string, setter: (value: any) => void) {
id: "input",
type: "normal",
canSkip: false,
autoSkip: true,
async start() {
const textbox = m._textbox;
const inputText = await textbox?.getInput(text);
Expand Down
2 changes: 1 addition & 1 deletion src/game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ async function nextAction() {
data.processingAction = false;
data.currentAction++;

if (action.autoskip) nextAction();
if (action.autoSkip) nextAction();
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ export interface BaseAction {
/** Action's type. */
type: ActionType;
/** If action won't wait for an user interaction to continue to the next one. */
autoskip?: boolean;
autoSkip?: boolean;
/** If action is skippeable. (default to true) */
canSkip?: boolean;
/** If action was auto inserted */
Expand Down

0 comments on commit 1d7a779

Please sign in to comment.