@3d-dice/fdp 中文文档教程

发布于 3年前 浏览 33 项目主页 更新于 3年前

FDP

Fantastic Dice Parser

这个模块只是提供了 @3d-dice/dice-roller-parser@3d-dice/骰子盒。 由于 dice-roller-parser 是另一个人的模块的分支,我不想在那个包中包含这个接口。

What it does

此模块允许使用 dice-box 进行更高级的掷骰。 Roll20 Dice Specification 中记录了所有支持的

How to use it

掷骰子库使用:

npm install @3d-dice/fdp

然后创建一个新的 dice-roller-parser 实例

import DiceParser from '@3d-dice/drp'

const DRP = new DiceParser()

DRP 类现在有方法来解析原始符号,处理重新滚动并计算 dice-box

<form id="dice-to-roll">
    <input id="input--notation" class="input" placeholder="2d20" autocomplete="off" />
</form>
const form = document.getElementById("dice-to-roll")
const notationInput = document.getElementById("input--notation")

const submitForm = (e) => {
  e.preventDefault();
    const notation = DRP.parseNotation(notationInput.value)
}

form.addEventListener("submit", submitForm)

Methods

parseNotation(string, default: '')

接受骰子字符串输入,对其进行解析并返回已解析输入的 JSON 表示形式。

示例:DRP.parseNotation('4d6')

[
    {
        "qty": 4,
        "sides": 6,
        "mods": [],
        "rolls": [
            {
                "sides": 6,
                "groupId": 0,
                "rollId": 0,
                "id": 0,
                "theme": "sunset",
                "result": 1
            },
            {
                "sides": 6,
                "groupId": 0,
                "rollId": 1,
                "id": 1,
                "theme": "sunset",
                "result": 3
            },
            {
                "sides": 6,
                "groupId": 0,
                "rollId": 2,
                "id": 2,
                "theme": "sunset",
                "result": 6
            },
            {
                "sides": 6,
                "groupId": 0,
                "rollId": 3,
                "id": 3,
                "theme": "sunset",
                "result": 6
            }
        ],
        "value": 16
    }
]

另请参阅:Just parse the value

handleRerolls(array, default:[])

此方法接受一个骰子数组(由 parseNotation 生成,由 dice-box 更新)并返回一个新的骰子数组需要重新滚动的对象。 可以产生重掷的掷骰示例包括爆炸、穿透和复合掷骰(例如:6d6!)。 还支持重新滚动和重新滚动一次符号(例如:2d12r1)。

Dice Object:

| 物业 | 类型 | 说明 | |-|-|-| |groupId|int|重投目标所属的组| |rollId|int 或 string|正在重新滚动的骰子的滚动 ID。 每次重投都会增加 .1| |side|int|重掷骰子的边数| |qty|int|要掷的骰子数。 这在重投时始终为 1,但 dice-box| 需要

示例:

[
    {
        "groupId": 0,
        "rollId": "2.1",
        "sides": 6,
        "qty": 1
    },
    {
        "groupId": 0,
        "rollId": "3.1",
        "sides": 6,
        "qty": 1
    }
]

parseFinalResults(array, default: [])

在所有掷和重掷完成后,您可以将结果对象传递给 parseFinalResults 以获取掷骰子的最终结果。 这通常发生在 dice-boxonRollComplete 回调方法中。

示例:

const results = DRP.parseFinalResults(results)

Putting it all together

Example HTML

Example JavaScript

Caveats

该模块没有做的一件事是提供用于为滚动符号字符串提供输入或显示最终结果的接口。 预计开发人员将创建自己的输入和输出或使用来自 @3d-dice/fui 的模块

FDP

Fantastic Dice Parser

This module simply provides an interface between @3d-dice/dice-roller-parser and @3d-dice/dice-box. Since dice-roller-parser is a fork of another person's module, I did not want to include this interface in that package.

What it does

This module allows for more advanced rolls with dice-box. All the rolls supported are documented at Roll20 Dice Specification

How to use it

Install the library using:

npm install @3d-dice/fdp

Then create a new instace of dice-roller-parser

import DiceParser from '@3d-dice/drp'

const DRP = new DiceParser()

The DRP class now has methods to parse raw notations, process re-rolls and compute the final results from dice-box

<form id="dice-to-roll">
    <input id="input--notation" class="input" placeholder="2d20" autocomplete="off" />
</form>
const form = document.getElementById("dice-to-roll")
const notationInput = document.getElementById("input--notation")

const submitForm = (e) => {
  e.preventDefault();
    const notation = DRP.parseNotation(notationInput.value)
}

form.addEventListener("submit", submitForm)

Methods

parseNotation(string, default: '')

Accepts a dice string input, parses it and returns a JSON representation of the parsed input.

Example: DRP.parseNotation('4d6')

[
    {
        "qty": 4,
        "sides": 6,
        "mods": [],
        "rolls": [
            {
                "sides": 6,
                "groupId": 0,
                "rollId": 0,
                "id": 0,
                "theme": "sunset",
                "result": 1
            },
            {
                "sides": 6,
                "groupId": 0,
                "rollId": 1,
                "id": 1,
                "theme": "sunset",
                "result": 3
            },
            {
                "sides": 6,
                "groupId": 0,
                "rollId": 2,
                "id": 2,
                "theme": "sunset",
                "result": 6
            },
            {
                "sides": 6,
                "groupId": 0,
                "rollId": 3,
                "id": 3,
                "theme": "sunset",
                "result": 6
            }
        ],
        "value": 16
    }
]

See also: Just parse the value

handleRerolls(array, default:[])

This method accepts an array of dice rolls (generated by parseNotation, updated by dice-box) and returns a new array of dice objects that need to be re-rolled. Examples of rolls that could generate rerolls include, exploding, penetrating, and compounding rolls (e.g.: 6d6!). Reroll and reroll-once notation is also supported (e.g.: 2d12r1).

Dice Object:

| Property | Type | Description | |-|-|-| |groupId|int|The group the reroll target belongs to| |rollId|int or string|The roll id of the die being rerolled. This will be incremented by .1 for every reroll made| |side|int|The number of sides the reroll die has| |qty|int|The number of dice to be rolled. This will always be 1 on rerolls but is needed by dice-box|

Example:

[
    {
        "groupId": 0,
        "rollId": "2.1",
        "sides": 6,
        "qty": 1
    },
    {
        "groupId": 0,
        "rollId": "3.1",
        "sides": 6,
        "qty": 1
    }
]

parseFinalResults(array, default: [])

After all rolls and rerolls have completed, you can pass the results object to parseFinalResults to get the final results of the dice roll. This typically happens inside dice-box's onRollComplete callback method.

Example:

const results = DRP.parseFinalResults(results)

Putting it all together

Example HTML

Example JavaScript

Caveats

One thing this modules does not do is provide the interface for providing an input for the roll notation string or displaying the final results. It is expected that the developer will create their own inputs and outputs or use modules from @3d-dice/fui

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文