Skip to content

Commit

Permalink
Fix for pm (#7)
Browse files Browse the repository at this point in the history
* fix: update sample dialog to use proper commands

* feat: can now add custom commands
  • Loading branch information
kenerwin88 authored Jan 11, 2023
1 parent ad35c98 commit 958e1d3
Show file tree
Hide file tree
Showing 25 changed files with 3,536 additions and 3,462 deletions.
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,38 @@ Functions are units of code that Yarn scripts can call to receive a value.
| item_count | item_count(itemName) | Returns the number of the given item the player has. |
| random_range | random_range(min, max) | Given a min and max, return a random number between them. |

## How to add custom commands?
This plugin was designed to be easily extensible. Let's say you'd like to add a new command
named `custom_hello`. Not only that, but we also want it to accept a parameter of WHO to say
hello to. Here's how you'd do it:

First, create your Yarn dialog file, exactly as you'd like it to be.

```yarn
title: SampleNode
---
Whatever other things you want to have happen.
<<custom_hello george>>
Other things...
===
```
Notice that "custom_hello" by default won't work, as that's not one of the commands built into
this plugin. So, let's add it.

Using a "script" in the event editor, or via your own plugins javascript code, add the following:
```js
const customGreeter = (_callingEventId, name) => {console.log("Hi " + name + "!")};
if (!pixelmapYarnSpinner.commands.get('custom_hello')) {
pixelmapYarnSpinner.addCommand('custom_hello', customGreeter);
}
```

The important part here is the `pixelmapYarnSpinner.addCommand` call. This is how you add a
new command to the plugin. The first parameter is the name of the command, and the second is
the function that will be called when the command is encountered in the Yarn dialog. The function
will be passed the calling event ID, followed by any parameters that were passed to the command.

Provided this is invoked BEFORE the Yarn dialog is loaded, the command will be available to use.

## Credits

Expand Down
1 change: 1 addition & 0 deletions build.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ generate('src/metadata.yaml').then((header) => {
require('esbuild')
.build({
logLevel: 'info',
globalName: 'pixelmapYarnSpinner',
entryPoints: ['src/index.ts'],
bundle: true,
sourcemap: true,
Expand Down
7 changes: 5 additions & 2 deletions data/Map002.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@
null,
{"id":1,"name":"EV001","note":"","pages":[{"conditions":{"actorId":1,"actorValid":false,"itemId":1,"itemValid":false,"selfSwitchCh":"A","selfSwitchValid":false,"switch1Id":1,"switch1Valid":false,"switch2Id":1,"switch2Valid":false,"variableId":1,"variableValid":false,"variableValue":0},"directionFix":false,"image":{"tileId":0,"characterName":"!Door2","direction":2,"pattern":0,"characterIndex":0},"list":[{"code":108,"indent":0,"parameters":["<Mini Label: SetLevel>"]},{"code":357,"indent":0,"parameters":["pixelmapYarnSpinner","yarn","Yarn Dialog",{"Yarn File Path":"dialog/teleport.yarn","Start At":"SetLevelTest"}]},{"code":657,"indent":0,"parameters":["Yarn File Path = dialog/teleport.yarn"]},{"code":657,"indent":0,"parameters":["Start At = SetLevelTest"]},{"code":0,"indent":0,"parameters":[]}],"moveFrequency":3,"moveRoute":{"list":[{"code":0,"parameters":[]}],"repeat":true,"skippable":false,"wait":false},"moveSpeed":3,"moveType":0,"priorityType":1,"stepAnime":false,"through":false,"trigger":0,"walkAnime":true}],"x":21,"y":3},
{"id":2,"name":"EV002","note":"","pages":[{"conditions":{"actorId":1,"actorValid":false,"itemId":1,"itemValid":false,"selfSwitchCh":"A","selfSwitchValid":false,"switch1Id":1,"switch1Valid":false,"switch2Id":1,"switch2Valid":false,"variableId":1,"variableValid":false,"variableValue":0},"directionFix":false,"image":{"tileId":0,"characterName":"SF_Actor1","direction":2,"pattern":2,"characterIndex":0},"list":[{"code":108,"indent":0,"parameters":["<Mini Label: Sprite Commands>"]},{"code":357,"indent":0,"parameters":["pixelmapYarnSpinner","yarn","Yarn Dialog",{"Yarn File Path":"dialog/spriteCommands.yarn","Start At":"SpriteCommands"}]},{"code":657,"indent":0,"parameters":["Yarn File Path = dialog/spriteCommands.yarn"]},{"code":657,"indent":0,"parameters":["Start At = SpriteCommands"]},{"code":0,"indent":0,"parameters":[]}],"moveFrequency":3,"moveRoute":{"list":[{"code":0,"parameters":[]}],"repeat":true,"skippable":false,"wait":false},"moveSpeed":3,"moveType":0,"priorityType":1,"stepAnime":false,"through":false,"trigger":0,"walkAnime":true}],"x":21,"y":5},
{"id":3,"name":"EV003","note":"","pages":[{"conditions":{"actorId":1,"actorValid":false,"itemId":1,"itemValid":false,"selfSwitchCh":"A","selfSwitchValid":false,"switch1Id":1,"switch1Valid":false,"switch2Id":1,"switch2Valid":false,"variableId":1,"variableValid":false,"variableValue":0},"directionFix":false,"image":{"tileId":0,"characterName":"Actor1","direction":2,"pattern":1,"characterIndex":2},"list":[{"code":108,"indent":0,"parameters":["<Mini Label: Text box changes>"]},{"code":357,"indent":0,"parameters":["pixelmapYarnSpinner","yarn","Yarn Dialog",{"Yarn File Path":"dialog/fisherman.yarn","Start At":"Greeting"}]},{"code":657,"indent":0,"parameters":["Yarn File Path = dialog/fisherman.yarn"]},{"code":657,"indent":0,"parameters":["Start At = Greeting"]},{"code":0,"indent":0,"parameters":[]}],"moveFrequency":3,"moveRoute":{"list":[{"code":0,"parameters":[]}],"repeat":true,"skippable":false,"wait":false},"moveSpeed":3,"moveType":0,"priorityType":1,"stepAnime":false,"through":false,"trigger":0,"walkAnime":true}],"x":21,"y":7},
{"id":3,"name":"EV003","note":"","pages":[{"conditions":{"actorId":1,"actorValid":false,"itemId":1,"itemValid":false,"selfSwitchCh":"A","selfSwitchValid":false,"switch1Id":1,"switch1Valid":false,"switch2Id":1,"switch2Valid":false,"variableId":1,"variableValid":false,"variableValue":0},"directionFix":false,"image":{"tileId":0,"characterName":"Actor1","direction":2,"pattern":1,"characterIndex":2},"list":[{"code":108,"indent":0,"parameters":["<Mini Label: Text box changes>"]},{"code":357,"indent":0,"parameters":["pixelmapYarnSpinner","yarn","Yarn Dialog",{"Yarn File Path":"dialog/cameraDemo.yarn","Start At":"CameraMain"}]},{"code":657,"indent":0,"parameters":["Yarn File Path = dialog/cameraDemo.yarn"]},{"code":657,"indent":0,"parameters":["Start At = CameraMain"]},{"code":0,"indent":0,"parameters":[]}],"moveFrequency":3,"moveRoute":{"list":[{"code":0,"parameters":[]}],"repeat":true,"skippable":false,"wait":false},"moveSpeed":3,"moveType":0,"priorityType":1,"stepAnime":false,"through":false,"trigger":0,"walkAnime":true}],"x":21,"y":7},
{"id":4,"name":"EV004","note":"","pages":[{"conditions":{"actorId":1,"actorValid":false,"itemId":1,"itemValid":false,"selfSwitchCh":"A","selfSwitchValid":false,"switch1Id":1,"switch1Valid":false,"switch2Id":1,"switch2Valid":false,"variableId":1,"variableValid":false,"variableValue":0},"directionFix":false,"image":{"tileId":0,"characterName":"Evil","direction":2,"pattern":0,"characterIndex":0},"list":[{"code":357,"indent":0,"parameters":["pixelmapYarnSpinner","yarn","Yarn Dialog",{"Yarn File Path":"dialog/addStuff.yarn","Start At":"AddStuff"}]},{"code":657,"indent":0,"parameters":["Yarn File Path = dialog/addStuff.yarn"]},{"code":657,"indent":0,"parameters":["Start At = AddStuff"]},{"code":108,"indent":0,"parameters":["<Mini Label: Add Stuff>"]},{"code":0,"indent":0,"parameters":[]}],"moveFrequency":3,"moveRoute":{"list":[{"code":0,"parameters":[]}],"repeat":true,"skippable":false,"wait":false},"moveSpeed":3,"moveType":0,"priorityType":1,"stepAnime":false,"through":false,"trigger":0,"walkAnime":true}],"x":21,"y":11},
{"id":5,"name":"EV005","note":"","pages":[{"conditions":{"actorId":1,"actorValid":false,"itemId":1,"itemValid":false,"selfSwitchCh":"A","selfSwitchValid":false,"switch1Id":1,"switch1Valid":false,"switch2Id":1,"switch2Valid":false,"variableId":1,"variableValid":false,"variableValue":0},"directionFix":false,"image":{"tileId":0,"characterName":"SF_Monster","direction":2,"pattern":0,"characterIndex":4},"list":[{"code":108,"indent":0,"parameters":["<Mini Label: FunctionTester>"]},{"code":357,"indent":0,"parameters":["pixelmapYarnSpinner","yarn","Yarn Dialog",{"Yarn File Path":"dialog/functionTester.yarn","Start At":"Hello"}]},{"code":657,"indent":0,"parameters":["Yarn File Path = dialog/functionTester.yarn"]},{"code":657,"indent":0,"parameters":["Start At = Hello"]},{"code":0,"indent":0,"parameters":[]}],"moveFrequency":3,"moveRoute":{"list":[{"code":0,"parameters":[]}],"repeat":true,"skippable":false,"wait":false},"moveSpeed":3,"moveType":0,"priorityType":1,"stepAnime":false,"through":false,"trigger":0,"walkAnime":true}],"x":21,"y":13},
{"id":6,"name":"EV006","note":"","pages":[{"conditions":{"actorId":1,"actorValid":false,"itemId":1,"itemValid":false,"selfSwitchCh":"A","selfSwitchValid":false,"switch1Id":1,"switch1Valid":false,"switch2Id":1,"switch2Valid":false,"variableId":1,"variableValid":false,"variableValue":0},"directionFix":false,"image":{"tileId":0,"characterName":"Nature","direction":2,"pattern":0,"characterIndex":0},"list":[{"code":357,"indent":0,"parameters":["pixelmapYarnSpinner","yarn","Yarn Dialog",{"Yarn File Path":"dialog/ken.yarn","Start At":"StardewMode"}]},{"code":657,"indent":0,"parameters":["Yarn File Path = dialog/ken.yarn"]},{"code":657,"indent":0,"parameters":["Start At = StardewMode"]},{"code":108,"indent":0,"parameters":["<Mini Label: Ken Test>"]},{"code":0,"indent":0,"parameters":[]}],"moveFrequency":3,"moveRoute":{"list":[{"code":0,"parameters":[]}],"repeat":true,"skippable":false,"wait":false},"moveSpeed":3,"moveType":0,"priorityType":1,"stepAnime":false,"through":false,"trigger":0,"walkAnime":true}],"x":8,"y":6},
{"id":7,"name":"EV007","note":"","pages":[{"conditions":{"actorId":1,"actorValid":false,"itemId":1,"itemValid":false,"selfSwitchCh":"A","selfSwitchValid":false,"switch1Id":1,"switch1Valid":false,"switch2Id":1,"switch2Valid":false,"variableId":1,"variableValid":false,"variableValue":0},"directionFix":false,"image":{"tileId":0,"characterName":"Nature","direction":2,"pattern":0,"characterIndex":0},"list":[{"code":357,"indent":0,"parameters":["pixelmapYarnSpinner","yarn","Yarn Dialog",{"Yarn File Path":"dialog/bocks.yarn","Start At":"Bocks_Start"}]},{"code":657,"indent":0,"parameters":["Yarn File Path = dialog/bocks.yarn"]},{"code":657,"indent":0,"parameters":["Start At = Bocks_Start"]},{"code":108,"indent":0,"parameters":["<Mini Label: Bocks Test>"]},{"code":355,"indent":0,"parameters":["$gamePlayer.playerOwnsTile = true;"]},{"code":0,"indent":0,"parameters":[]}],"moveFrequency":3,"moveRoute":{"list":[{"code":0,"parameters":[]}],"repeat":true,"skippable":false,"wait":false},"moveSpeed":3,"moveType":0,"priorityType":1,"stepAnime":false,"through":false,"trigger":0,"walkAnime":true}],"x":8,"y":9}
{"id":7,"name":"EV007","note":"","pages":[{"conditions":{"actorId":1,"actorValid":false,"itemId":1,"itemValid":false,"selfSwitchCh":"A","selfSwitchValid":false,"switch1Id":1,"switch1Valid":false,"switch2Id":1,"switch2Valid":false,"variableId":1,"variableValid":false,"variableValue":0},"directionFix":false,"image":{"tileId":0,"characterName":"People2","direction":2,"pattern":0,"characterIndex":0},"list":[{"code":357,"indent":0,"parameters":["pixelmapYarnSpinner","yarn","Yarn Dialog",{"Yarn File Path":"dialog/bocks.yarn","Start At":"Bocks_Start"}]},{"code":657,"indent":0,"parameters":["Yarn File Path = dialog/bocks.yarn"]},{"code":657,"indent":0,"parameters":["Start At = Bocks_Start"]},{"code":108,"indent":0,"parameters":["<Mini Label: Bocks Test>"]},{"code":355,"indent":0,"parameters":["$gamePlayer.playerOwnsTile = true;"]},{"code":0,"indent":0,"parameters":[]}],"moveFrequency":3,"moveRoute":{"list":[{"code":0,"parameters":[]}],"repeat":true,"skippable":false,"wait":false},"moveSpeed":3,"moveType":0,"priorityType":1,"stepAnime":false,"through":false,"trigger":0,"walkAnime":true}],"x":2,"y":10},
{"id":8,"name":"Monster1","note":"","pages":[{"conditions":{"actorId":1,"actorValid":false,"itemId":1,"itemValid":false,"selfSwitchCh":"A","selfSwitchValid":false,"switch1Id":1,"switch1Valid":false,"switch2Id":1,"switch2Valid":false,"variableId":1,"variableValid":false,"variableValue":0},"directionFix":false,"image":{"tileId":0,"characterName":"Monster","direction":2,"pattern":1,"characterIndex":1},"list":[{"code":0,"indent":0,"parameters":[]}],"moveFrequency":3,"moveRoute":{"list":[{"code":0,"parameters":[]}],"repeat":true,"skippable":false,"wait":false},"moveSpeed":3,"moveType":0,"priorityType":1,"stepAnime":false,"through":false,"trigger":0,"walkAnime":true}],"x":24,"y":5},
{"id":9,"name":"MovementMan","note":"","pages":[{"conditions":{"actorId":1,"actorValid":false,"itemId":1,"itemValid":false,"selfSwitchCh":"A","selfSwitchValid":false,"switch1Id":1,"switch1Valid":false,"switch2Id":1,"switch2Valid":false,"variableId":1,"variableValid":false,"variableValue":0},"directionFix":false,"image":{"tileId":0,"characterName":"Evil","direction":2,"pattern":1,"characterIndex":1},"list":[{"code":0,"indent":0,"parameters":[]}],"moveFrequency":3,"moveRoute":{"list":[{"code":1,"indent":null},{"code":1,"indent":null},{"code":0,"parameters":[]}],"repeat":true,"skippable":false,"wait":false},"moveSpeed":3,"moveType":0,"priorityType":1,"stepAnime":false,"through":false,"trigger":0,"walkAnime":true}],"x":25,"y":5},
{"id":10,"name":"EV010","note":"","pages":[{"conditions":{"actorId":1,"actorValid":false,"itemId":1,"itemValid":false,"selfSwitchCh":"A","selfSwitchValid":false,"switch1Id":1,"switch1Valid":false,"switch2Id":1,"switch2Valid":false,"variableId":1,"variableValid":false,"variableValue":0},"directionFix":false,"image":{"tileId":0,"characterName":"People1","direction":2,"pattern":1,"characterIndex":0},"list":[{"code":108,"indent":0,"parameters":["<Mini Label: CustomCommandDemo>"]},{"code":355,"indent":0,"parameters":["const customGreeter = (_callingEventId, name) => {console.log(\"Hi \" + name + \"!\")};"]},{"code":655,"indent":0,"parameters":["if (!pixelmapYarnSpinner.commands.get('custom_hello')) {"]},{"code":655,"indent":0,"parameters":[" pixelmapYarnSpinner.addCommand('custom_hello', customGreeter);"]},{"code":655,"indent":0,"parameters":["}"]},{"code":357,"indent":0,"parameters":["pixelmapYarnSpinner","yarn","Yarn Dialog",{"Yarn File Path":"dialog/customCommandDemo.yarn","Start At":"CustomCommandDemo_Start"}]},{"code":657,"indent":0,"parameters":["Yarn File Path = dialog/customCommandDemo.yarn"]},{"code":657,"indent":0,"parameters":["Start At = CustomCommandDemo_Start"]},{"code":0,"indent":0,"parameters":[]}],"moveFrequency":3,"moveRoute":{"list":[{"code":0,"parameters":[]}],"repeat":true,"skippable":false,"wait":false},"moveSpeed":3,"moveType":0,"priorityType":1,"stepAnime":false,"through":false,"trigger":0,"walkAnime":true}],"x":21,"y":21}
]
}
Loading

0 comments on commit 958e1d3

Please sign in to comment.