From 1d7a77989088ae3f10b85c663d3f0f13ad7e8f4f Mon Sep 17 00:00:00 2001 From: lajbel Date: Thu, 14 Sep 2023 22:07:18 -0300 Subject: [PATCH] add autoskip to some actions --- docs/Basics.md | 46 +++++++++++++++++++++++++++++---------- package-lock.json | 14 ++++++------ package.json | 4 ++-- src/actions/audio.ts | 2 +- src/actions/background.ts | 2 +- src/actions/chapters.ts | 2 +- src/actions/character.ts | 2 +- src/actions/textbox.ts | 2 ++ src/game.ts | 2 +- src/types.ts | 2 +- 10 files changed, 51 insertions(+), 27 deletions(-) diff --git a/docs/Basics.md b/docs/Basics.md index 84c9a84..40e3473 100644 --- a/docs/Basics.md +++ b/docs/Basics.md @@ -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. @@ -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 @@ -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 @@ -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 @@ -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 @@ -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!")], }, }), -]); \ No newline at end of file +]); +``` diff --git a/package-lock.json b/package-lock.json index 5f212b6..ddfa180 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "1.0.0-beta-1", "license": "MIT", "dependencies": { - "kaboom": "^3000.1.6" + "kaboom": "^3000.0.15" }, "devDependencies": { "@types/node": "^18.14.0", @@ -1746,9 +1746,9 @@ "dev": true }, "node_modules/kaboom": { - "version": "3000.1.6", - "resolved": "https://registry.npmjs.org/kaboom/-/kaboom-3000.1.6.tgz", - "integrity": "sha512-0ZkfWBEiyrfusJgLBfno9OA3aeXxxPbAfWpkqUee2T4VasQZeibK8nqggOdzmp35UHGzeFAd7rrqYKkZZaXktA==" + "version": "3000.0.15", + "resolved": "https://registry.npmjs.org/kaboom/-/kaboom-3000.0.15.tgz", + "integrity": "sha512-tSSp7ixUWvKLflCelhQQ5+LsXVpdApPCQrtDjv/xLnEeA45D/fealLVfkPnKI24pqh5zYXfKtFHmFpe6W7MDDA==" }, "node_modules/levn": { "version": "0.4.1", @@ -3660,9 +3660,9 @@ "dev": true }, "kaboom": { - "version": "3000.1.6", - "resolved": "https://registry.npmjs.org/kaboom/-/kaboom-3000.1.6.tgz", - "integrity": "sha512-0ZkfWBEiyrfusJgLBfno9OA3aeXxxPbAfWpkqUee2T4VasQZeibK8nqggOdzmp35UHGzeFAd7rrqYKkZZaXktA==" + "version": "3000.0.15", + "resolved": "https://registry.npmjs.org/kaboom/-/kaboom-3000.0.15.tgz", + "integrity": "sha512-tSSp7ixUWvKLflCelhQQ5+LsXVpdApPCQrtDjv/xLnEeA45D/fealLVfkPnKI24pqh5zYXfKtFHmFpe6W7MDDA==" }, "levn": { "version": "0.4.1", diff --git a/package.json b/package.json index 09c8f8d..de5d98a 100644 --- a/package.json +++ b/package.json @@ -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", @@ -26,7 +26,7 @@ "README.md" ], "dependencies": { - "kaboom": "^3000.1.6" + "kaboom": "^3000.0.15" }, "devDependencies": { "@types/node": "^18.14.0", diff --git a/src/actions/audio.ts b/src/actions/audio.ts index 53c002c..a228c82 100644 --- a/src/actions/audio.ts +++ b/src/actions/audio.ts @@ -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, diff --git a/src/actions/background.ts b/src/actions/background.ts index faf1928..70fbdc5 100644 --- a/src/actions/background.ts +++ b/src/actions/background.ts @@ -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[] = []; diff --git a/src/actions/chapters.ts b/src/actions/chapters.ts index 8f7c8a2..473fe02 100644 --- a/src/actions/chapters.ts +++ b/src/actions/chapters.ts @@ -4,7 +4,7 @@ export function jump(name: string) { return createAction({ id: "jump", type: "normal", - autoskip: true, + autoSkip: true, start() { insertChapter(name); }, diff --git a/src/actions/character.ts b/src/actions/character.ts index 74fc92c..b391a57 100644 --- a/src/actions/character.ts +++ b/src/actions/character.ts @@ -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; diff --git a/src/actions/textbox.ts b/src/actions/textbox.ts index 5ad42e7..774eeae 100644 --- a/src/actions/textbox.ts +++ b/src/actions/textbox.ts @@ -97,6 +97,7 @@ export function choice( id: "choice", type: "normal", canSkip: false, + autoSkip: true, async start() { await addChoices(choices, setter); }, @@ -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); diff --git a/src/game.ts b/src/game.ts index 9debf7e..4cc76af 100644 --- a/src/game.ts +++ b/src/game.ts @@ -143,7 +143,7 @@ async function nextAction() { data.processingAction = false; data.currentAction++; - if (action.autoskip) nextAction(); + if (action.autoSkip) nextAction(); } } diff --git a/src/types.ts b/src/types.ts index 8e5773d..c94ebac 100644 --- a/src/types.ts +++ b/src/types.ts @@ -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 */