Skip to content

Commit

Permalink
v1.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
ChapelR committed Apr 21, 2020
1 parent 1a3b37e commit 16ecf93
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 91 deletions.
4 changes: 2 additions & 2 deletions dist/macro.min.js

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

4 changes: 2 additions & 2 deletions docs/changelog.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
## Release Versions

### v1.1.0
### v1.0.1

- **[Examples]** Added more examples:
- `(notify:)` A port of the CMFSC2 `<<notify>>` macro.
- `(macro:)` A widget-style macro for Harlowe by rachek64.
- `(macro:)` A widget-style macro passage system for Harlowe by rachek64.
- **[Docs]** Documented example macros.

### v1.0.0
Expand Down
1 change: 1 addition & 0 deletions docs/download/fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
'Articles' : 'articles',
'Clamp': 'clamp',
'Dialog' : 'dialog+css',
'Notify' : 'notify+css',
'Dice': 'dice',
'Hotkeys': 'hotkeys',
'Playtime': 'playtime',
Expand Down
67 changes: 65 additions & 2 deletions docs/examples/macro-passages.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,74 @@

By [rachek64](https://github.com/rachek64).

Description.
Allows you to run passages inline, similar to `(display:)`, but with no output and with the option of passing arguments to the passage, similar to SugarCube's widgets.

> **Get the Code**
>
> - [Minified](https://github.com/ChapelR/harlowe-macro-api/blob/master/examples/third-party/minified/macro-passages.min.js)
> - [Pretty](https://github.com/ChapelR/harlowe-macro-api/blob/master/examples/third-party/macro-passages.js)
Coming soon.
### Macro: `(macro:)`

Runs a macro passage, defined by adding the `macro` tag to a passage. If you add both the `macro` tag and the `auto-macro` tag, a first-class, named macro will be created.

#### Syntax

```
(macro: passage [, argsList])
```

#### Arguments

- `passage` ( *`string`* ) The name of a passage with the tag `macro`. The passage's code will be run with the given arguments.
- `args` ( *`any`* ) ( optional ) Arguments to be passed on to the passage, which may be accessed as an array using the temporary variable `_args`. Just list arguments separated by commas after the passage name.

#### Returns

Optionally returns the value given to the `_result` temporary variable, or nothing.

#### Examples

```
:: damage [macro]
<!-- reduces the player HP by the given number -->
(set: $player's hp to it - _args's 1st)
(if: $player's hp <= 0)[
(goto: 'game over')
]
:: some passage
The enemy attacks!
(macro: 'damage', $enemy's attack)
You take (print: $enemy's attack) damage and have (print: $player's hp) health remaining.
:: say-hi [macro auto-macro]
<!-- using the `auto-macro` tag makes a standalone custom macro! -->
(set: _result to 'Hi, ' + _args's 1st + '.')
:: some other passage
(alert: (say-hi: 'Bob')) <!-- alerts "Hi, Bob." -->
```

### Additional Usage Notes

* The entire macro-tagged passage should run at once (i.e., no `(prompt:)`, `(live:)`, or similar "delayed" commands) and they cannot display any output. This is suitable for code-only macros that perform complex calculations or automate repetitive tasks. If you need to print results, just return the results from the macro with `_result` and print it outside.
* No text is displayed while running the macro passage, nor can it have any
direct effect on the caller passage. The contents are rendered into a
dummy screen that is never shown on the page.
* This means you can nicely comment your macro with plain text. No need to use `{}`
or worry about line breaks or spacing.
* This also means no user input is possible. If you render a link to click,
it will never be able to be clicked. The macro will complete assuming the link
wasn't clicked.
* User input in general is not possible in macro-tagged passages, nor can you run
asynchronous commands like (alert:) that pause the passage until you interact
with them. No errors will happen, but the value in `_result` may not be
picked up properly if it was changed after the delaying command was used.
* Saving and loading from inside a macro is, in general, a terrible idea. Just don't do it.
* Argument type checking is not possible at this time. If a macro takes arguments,
thoroughly inspect `_args` before attempting to use them.
* Unfortunately, errors in macro passages are handled a bit oddly. Error details
are provided as best as possible, but so far as Harlowe is concerned the error
occurred in the caller passage. Check the dropdown in the error bubble for the
actual line that triggered the error.
38 changes: 36 additions & 2 deletions docs/examples/notify.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## Notify

Description.
Creates a quick user notification that rolls out from the top right of the screen, hangs for a minute, and rolls back in, useful for a quick note about status updates, achievements, or whatever else when a dialog box is a bit too much. Ported over from the similar CMFSC2 macro.

> - **Get the Code**
>
Expand All @@ -10,4 +10,38 @@ Description.
> - [Minified](https://github.com/ChapelR/harlowe-macro-api/blob/master/examples/minified/notify.min.css)
> - [Pretty](https://github.com/ChapelR/harlowe-macro-api/blob/master/examples/notify.css)
Coming soon.
### Macro: `(notify:)`

Creates and displays a quick notification and renders the content of the associated hook into it.

#### Syntax

```
(notify: [delay] [, classList])[ ... ]
```

#### Arguments

- `delay` ( *`time`* ) ( optional ) A CSS-style time value (e.g., `5s`, `500ms`) for controlling how long the notification should remain. A short animation plays before and after this delay. Defaults to two seconds.
- `classList` ( *`string`* | *`string array`* ) ( optional ) You may pass a single string of space separated class names (e.g. `"my-class another-class a-third-class"`), an array of strings, or simply list several different strings as arguments to the macro to have them added to the `#notify` element for styling. You must include a delay time to add classes

#### Returns

Nothing.

#### Examples

```
<!-- a two second, basic notification -->
(notify:)[Inventory updated.]
<!-- a ten second long notification with a custom class -->
(notify: '10s', 'my-class')[Achievement unlocked.]
<!-- a five second notification -->
(notify: '5000ms')[Gold earned.]
```

#### Note

Giving the player unlimited control over these notifications, or trying to show several at once or right after each other will cause them to trip over themselves as they try to animate, so try to keep them spaced out, and don't assign them to links or buttons you expect the player to press repeatedly.
82 changes: 0 additions & 82 deletions examples/call.js

This file was deleted.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "harlowe-macro-api",
"version": "1.0.0",
"version": "1.0.1",
"description": "Unofficial Macro API for Twine2/Harlowe.",
"main": "build.js",
"dependencies": {},
Expand Down

0 comments on commit 16ecf93

Please sign in to comment.