Compare commits
3 Commits
5994a2d8f4
...
4da3c5ac06
| Author | SHA1 | Date | |
|---|---|---|---|
| 4da3c5ac06 | |||
| 31603d705a | |||
| b49619c110 |
18
examples/d20.sh
Normal file
18
examples/d20.sh
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
#!/usr/bin/env shrimp
|
||||||
|
# usage: dice <sides>
|
||||||
|
|
||||||
|
import math only=random
|
||||||
|
import list only=first
|
||||||
|
import str only=[replace starts-with?]
|
||||||
|
|
||||||
|
sides = $.args | first
|
||||||
|
sides ??= 20
|
||||||
|
|
||||||
|
if sides | starts-with? d:
|
||||||
|
sides = replace sides //\D// ''
|
||||||
|
end
|
||||||
|
|
||||||
|
sides = number sides
|
||||||
|
|
||||||
|
echo 'Rolling d$sides...'
|
||||||
|
random 1 sides | echo
|
||||||
|
|
@ -141,7 +141,7 @@ export class Tree {
|
||||||
|
|
||||||
// TODO: TEMPORARY SHIM
|
// TODO: TEMPORARY SHIM
|
||||||
class SyntaxNodeType {
|
class SyntaxNodeType {
|
||||||
constructor(public nodeType: NodeType) { }
|
constructor(public nodeType: NodeType, public isError: boolean) { }
|
||||||
|
|
||||||
is(other: string) {
|
is(other: string) {
|
||||||
return this.nodeType === other
|
return this.nodeType === other
|
||||||
|
|
@ -333,7 +333,7 @@ export class SyntaxNode {
|
||||||
}
|
}
|
||||||
|
|
||||||
get type(): SyntaxNodeType {
|
get type(): SyntaxNodeType {
|
||||||
return new SyntaxNodeType(this.#type)
|
return new SyntaxNodeType(this.#type, this.#isError)
|
||||||
}
|
}
|
||||||
|
|
||||||
set type(name: NodeType) {
|
set type(name: NodeType) {
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,10 @@ export const math = {
|
||||||
if (n < 0) throw new Error(`sqrt: cannot take square root of negative number ${n}`)
|
if (n < 0) throw new Error(`sqrt: cannot take square root of negative number ${n}`)
|
||||||
return Math.sqrt(n)
|
return Math.sqrt(n)
|
||||||
},
|
},
|
||||||
random: () => Math.random(),
|
random: (min = 0, max = 1) => {
|
||||||
|
if (min === 0 && max === 1) return Math.random()
|
||||||
|
return Math.floor(Math.random() * (max - min + 1)) + min
|
||||||
|
},
|
||||||
clamp: (n: number, min: number, max: number) => {
|
clamp: (n: number, min: number, max: number) => {
|
||||||
if (min > max) throw new Error(`clamp: min (${min}) must be less than or equal to max (${max})`)
|
if (min > max) throw new Error(`clamp: min (${min}) must be less than or equal to max (${max})`)
|
||||||
return Math.min(Math.max(n, min), max)
|
return Math.min(Math.max(n, min), max)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user