Skip to content

Commit

Permalink
feat: Get skill check (#38)
Browse files Browse the repository at this point in the history
* new getSkillCheck functions

* changelog
  • Loading branch information
liana-p committed Feb 5, 2023
1 parent 0b16a7b commit 02b787e
Show file tree
Hide file tree
Showing 10 changed files with 84 additions and 14 deletions.
27 changes: 27 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,32 @@
# Narrat changelog

## [2.10.6] - New `get_skill_check` and `skill_check_result` functions

Those two new functions make it possible to access the data of a skill check.

- `get_skill_check` returns the skill check object for a given skill check label (contains `happened`, `succeeded` and `hidden`)
- `skill_check_result` returns the result of a skill check as `true` if succeeded or `false`

Example:

```narrat
test_skill_checks:
choice:
"test skill roll"
roll testSkillCheck agility 50 "Test this skill roll":
success:
"You succeed!"
failure:
"You fail!"
"no roll":
"hello"
var test (get_skill_check testSkillCheck)
log $test
log (skill_check_result testSkillCheck)
```

(See the logs in the js console after running this to see the skill check values appearing in it)

## [2.10.5] - Tooltip improvements

Tooltips now work inside the text of sprites in the viewport
Expand Down
4 changes: 2 additions & 2 deletions docs/.vitepress/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const config = {
items: [
{
text: 'All commands',
link: '/scripting/all-commands',
link: '/commands/all-commands',
},
{ text: 'Language Syntax', link: '/scripting/language-syntax' },
{ text: 'Functions', link: '/scripting/functions' },
Expand Down Expand Up @@ -88,7 +88,7 @@ const config = {
text: 'Scripting',
items: [
{
link: '/scripting/all-commands',
link: '/commands/all-commands',
text: 'All Commands Reference',
},
{ text: 'Example Script', link: '/examples/example-narrat-script' },
Expand Down
20 changes: 11 additions & 9 deletions docs/scripting/all-commands.md → docs/commands/all-commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,15 +124,17 @@ description: This page contains a list of all the existing narrat commands

#### Skills

| Command | Example | Description |
| ------------------------------------------- | ------------------------------------------------------- | ----------------------------------------------------------------- |
| [add_level](skills-commands/add-level.md) | `add_level agility 1` | Adds levels to a skill |
| [set_level](skills-commands/add-level-1.md) | `set_level agility 1` | Sets the level of a skill |
| [add_xp](skills-commands/add-xp.md) | `add_xp agility 10` | Adds experience to a skill |
| [get_level](skills-commands/get-level.md) | `get_level agility` | Gets the level of a skill |
| [get_xp](skills-commands/get-xp.md) | `get_xp agility` | Gets the experience of a skill |
| [roll](skills-commands/roll.md) | `roll mySkillCheck agility 50` // Returns true or false | Runs a skill check with a certain difficulty against a skill dice |
| [reset_roll](skills-commands/reset-roll.md) | `reset_roll mySkillCheck` | Resets a skill check |
| Command | Example | Description |
| ----------------------------------------------------------- | --------------------------------------------------------------- | --------------------------------------------------------------------------------------------- |
| [add_level](skills-commands/add-level.md) | `add_level agility 1` | Adds levels to a skill |
| [set_level](skills-commands/add-level-1.md) | `set_level agility 1` | Sets the level of a skill |
| [add_xp](skills-commands/add-xp.md) | `add_xp agility 10` | Adds experience to a skill |
| [get_level](skills-commands/get-level.md) | `get_level agility` | Gets the level of a skill |
| [get_xp](skills-commands/get-xp.md) | `get_xp agility` | Gets the experience of a skill |
| [roll](skills-commands/roll.md) | `roll mySkillCheck agility 50` // Returns true or false | Runs a skill check with a certain difficulty against a skill dice |
| [get_skill_check](skills-commands/get-skill-check.md) | `get_skill_check mySkillCheck` // Returns a skill check's state | Gets the result of a skill check (object with `happened`, `succeeded`, and `hidden` booleans) |
| [skill_check_result](skills-commands/skill-check-result.md) | `skill_check_result mySkillCheck` // Returns true or false | Gets the result of a skill check as boolean |
| [reset_roll](skills-commands/reset-roll.md) | `reset_roll mySkillCheck` | Resets a skill check |

#### Stats

Expand Down
2 changes: 1 addition & 1 deletion docs/commands/stats/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ title: Stats commands
description: This page explains the available stats commands in narrat
---

See [Stats functions list](/scripting/all-commands#stats)
See [Stats functions list](/commands/all-commands#stats)
2 changes: 1 addition & 1 deletion docs/guides/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,4 @@ It is now easy to make a game by editing the narrat scripts and config files!

## Commands Documentation

[All commands](/scripting/all-commands)
[All commands](/commands/all-commands)
14 changes: 14 additions & 0 deletions packages/narrat/examples/games/default/scripts/default.nar
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,20 @@ main:
"hello <span class='red'><i><b>world</i></b></span>"
jump test_sprites_click

test_skill_checks:
choice:
"test skill roll"
roll testSkillCheck agility 50 "Test this skill roll":
success:
"You succeed!"
failure:
"You fail!"
"no roll":
"hello"
var test (get_skill_check testSkillCheck)
log $test
log (skill_check_result testSkillCheck)

array_find_index_command:
var card1 (new Object)
set card1.name "A"
Expand Down
2 changes: 1 addition & 1 deletion packages/narrat/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "narrat",
"version": "2.10.5",
"version": "2.10.6",
"description": "narrat narrative engine",
"main": "dist/narrat.umd.js",
"module": "dist/narrat.es.js",
Expand Down
1 change: 1 addition & 0 deletions packages/narrat/src/utils/data-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ export function getModifiableDataPinia() {
const state = {
data: vm.data,
skills: skills.skills,
skillChecks: skills.skillChecks,
buttons: screens.buttons,
items: inventory.items,
quests: useQuests().quests,
Expand Down
4 changes: 4 additions & 0 deletions packages/narrat/src/vm/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import {
addLevelPlugin,
addXpPlugin,
getLevelPlugin,
getSkillCheckPlugin,
getSkillCheckResultPlugin,
getXpPlugin,
resetSkillCheck,
rollPlugin,
Expand Down Expand Up @@ -221,6 +223,8 @@ export function registerBaseCommands(vm: VM) {
vm.addCommand(addXpPlugin);
vm.addCommand(rollPlugin);
vm.addCommand(resetSkillCheck);
vm.addCommand(getSkillCheckPlugin);
vm.addCommand(getSkillCheckResultPlugin);
vm.addCommand(getLevelPlugin);
vm.addCommand(getXpPlugin);
// Text Fields
Expand Down
22 changes: 22 additions & 0 deletions packages/narrat/src/vm/commands/skill-commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,28 @@ export const rollPlugin = new CommandPlugin<RollArgs>(
},
);

export const getSkillCheckPlugin = new CommandPlugin<{
skillCheckId: string;
}>(
'get_skill_check',
[{ name: 'skillCheckId', type: 'string' }],
async (cmd) => {
return useSkills().getSkillCheck(cmd.options.skillCheckId);
},
);

// Write a skillCheckResult plugin to get the result of a skill check as boolean
export const getSkillCheckResultPlugin = new CommandPlugin<{
skillCheckId: string;
}>(
'skill_check_result',
[{ name: 'skillCheckId', type: 'string' }],
async (cmd) => {
const skillCheck = useSkills().getSkillCheck(cmd.options.skillCheckId);
return skillCheck.succeeded;
},
);

export const resetSkillCheck = new CommandPlugin<{ id: string }>(
'reset_roll',
[
Expand Down

0 comments on commit 02b787e

Please sign in to comment.