-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathappendix_interactive.qmd
125 lines (82 loc) · 2.94 KB
/
appendix_interactive.qmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# Interactive tools
## Character Generation Helpers
### Character Abilities
```{ojs}
import {generalDice, calculateModifier} from "./custom.js"
viewof statrolls = Inputs.button("Roll Statistics", {reduce: () => [generalDice(3,6,0),generalDice(3,6,0),generalDice(3,6,0),generalDice(3,6,0),generalDice(3,6,0),generalDice(3,6,0)]}
)
```
| Ability | Value | Modifier |
|--------------|-----------------|------------------------------------|
| Strength | ${statrolls[0]} | ${calculateModifier(statrolls[0])} |
| Intelligence | ${statrolls[1]} | ${calculateModifier(statrolls[1])} |
| Wisdom | ${statrolls[2]} | ${calculateModifier(statrolls[2])} |
| Dexterity | ${statrolls[3]} | ${calculateModifier(statrolls[3])} |
| Constitution | ${statrolls[4]} | ${calculateModifier(statrolls[4])} |
| Charisma | ${statrolls[5]} | ${calculateModifier(statrolls[5])} |
### Starting Gold
```{ojs}
viewof goldRoll = Inputs.button("Roll Gold (3d6 x 10)", {value: 0, reduce: () => {
let temp = (10 * generalDice(3,6,0));
set (viewof startingGold, temp);
return temp}})
```
**Starting Gold**: ${goldRoll}
### Buy Equipment
```{ojs}
import { convertToGold } from "./custom.js"
function set(input, value) {
input.value = value;
input.dispatchEvent(new Event("input", {bubbles: true}));
}
viewof startingGold = Inputs.text({label: "Starting Gold: "})
spent = {
if (myarray.length != 0){
let pricesGP = myarray.map(x => x[1].split(" ")).map(x => convertToGold(Number(x[0]), x[1]))
let total = pricesGP.reduce ((x,y) => x + y)
return total
} else {return 0}
}
remainingGold = Number(startingGold) - spent
```
**Remaining Gold**: ${remainingGold.toFixed(1)} gp
Click to select. Use Ctrl (Cmd) or Shift to select multiple.
```{ojs}
data = {
const d = await FileAttachment("equipment.json").json()
return d
}
miscs = data[0].map( x => [x["Item"], x["Price"]] )
weapons = data[1].map( x => [x["Weapon"], x["Price"]])
armor = data[2].map( x => [x["Armor Type"], x["Price"]])
animals = data[3].map( x => [x["Item"], x["Price"]])
allItems = miscs.concat(weapons.concat(armor.concat(animals)))
```
```{ojs}
viewof search = {
let n = Inputs.search(allItems);
return n
}
```
```{ojs}
viewof items = Inputs.select(search, {multiple: true
, format: (x) => `${x[0]}, (${x[1]})`
} )
miscPrice = items.map(x => x[1])
miscItems = items.map(x => x[0])
```
```{ojs}
mutable myarray = []
viewof b = Inputs.button("add selected", {
reduce: () => mutable myarray = [...mutable myarray].concat(items) })
```
<br>
```{ojs}
viewof inventory = Inputs.select(myarray, {multiple:true
, format: (x) => `${x[0]}, (${x[1]})`
})
```
```{ojs}
viewof c = Inputs.button("remove selected", {
reduce: () => mutable myarray = [...mutable myarray].filter(item => !inventory.includes(item)) })
```