Skip to content

Commit

Permalink
Removed two bugs from diceboard and chancerollplugin
Browse files Browse the repository at this point in the history
  • Loading branch information
rajch committed Aug 8, 2024
1 parent 245a133 commit 05e8178
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 17 deletions.
19 changes: 2 additions & 17 deletions src/chancerollplugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { BBScannerPlugin } from "./plugin";
import './types'

const chanceRegEx = /(?:[Rr]oll|[Tt]hrow) (\S*?) di(?:c?)e\.(.*?)(?:\n|$)/
const actionRegEx = /If you roll (?:a )?(\d{1,2})( or(?: a)? | to |)(\d{0,2}),([^\.\n]*?)(?: [Tt]urn to (\d{1,3}))?\./g

export class ChanceRollPlugin extends BBScannerPlugin {
/** @type {DiceBoardPlugin} */
Expand Down Expand Up @@ -51,11 +52,6 @@ export class ChanceRollPlugin extends BBScannerPlugin {
let rowToShow
for (let i = 0; i < chanceroll.actions.length; i++) {
const action = chanceroll.actions[i]
// if (
// (!action.rangeEnd && rollResult == action.rangeStart)
// || (rollResult >= action.rangeStart && rollResult <= action.rangeEnd)
// || (rollResult == action.rangeStart || rollResult == action.rangeEnd)
// ) {
if (rollInRange(action, rollResult)) {
console.log(`Going to show ${JSON.stringify(action)}`)
rowToShow = view.content.querySelector(`p.chanceroll-result-${i}`)
Expand Down Expand Up @@ -111,7 +107,7 @@ export class ChanceRollPlugin extends BBScannerPlugin {
if (action.destination) {
result = result.trimEnd() + ` [[go to ${action.destination}|${action.destination}]]`
}
result = result + '</p>'
result = result.trimEnd() + '.</p>'
}

return input.replace(chanceRegEx, result)
Expand All @@ -127,15 +123,6 @@ export class ChanceRollPlugin extends BBScannerPlugin {
scan (passage) {
const passageBody = passage.body

// const phrase1 = /[Rr]oll\s{1}(\S*?)\s{1}di(c{0,1})e\./
// let match = passageBody.match(phrase1)

// if (!match) {
// const phrase2 = /[Tt]hrow\s{1}(\S*?)\s{1}di(c{0,1})e\./
// match = passageBody.match(phrase2)
// }


const match = passageBody.match(chanceRegEx)

if (!match) {
Expand All @@ -157,8 +144,6 @@ export class ChanceRollPlugin extends BBScannerPlugin {

let restOfParagraph = match[2]

const actionRegEx = /If you roll (?:a )?(\d{1,2})( or(?: a)? | to |)(\d{0,2}),([^\.\n]*?)(?: [Tt]urn to (\d{1,3}))?\./g

let destMatch
while ((destMatch = actionRegEx.exec(match[2])) !== null) {
const chanceAction = {
Expand Down
2 changes: 2 additions & 0 deletions src/diceboardplugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,8 @@ export class DiceBoardPlugin extends BBScannerPlugin {

const matchMap = {
"0": 0,
"1": 1,
"one": 1,
"2": 2,
"two": 2,
"3": 3,
Expand Down

0 comments on commit 05e8178

Please sign in to comment.