last bunch of props
This commit is contained in:
parent
c55abfb2df
commit
4f4d1ac3f2
@ -32,7 +32,11 @@ tasks:
|
||||
--data \
|
||||
-c ajv-keywords \
|
||||
-c ./src/sumOf.cjs \
|
||||
-c ./src/maxSpells.cjs \
|
||||
-r schemas-json/classes.json \
|
||||
-r schemas-json/languages.json \
|
||||
-r schemas-json/races.json \
|
||||
-r schemas-json/spells.json \
|
||||
-s schemas-json/character.json \
|
||||
-d {{.CLI_ARGS}}
|
||||
test:
|
||||
|
@ -14,3 +14,76 @@ statistics:
|
||||
intelligence: 18
|
||||
wisdom: 15
|
||||
charisma: 11
|
||||
gender: male
|
||||
age: 18
|
||||
height: 6'2"
|
||||
appearance: |
|
||||
Tall, skinny bloke clad in a white cloak.
|
||||
Looks like he could use some hot cocoa.
|
||||
alignment: Neutral
|
||||
experience:
|
||||
total: 17660
|
||||
log:
|
||||
- date: '2020-11-05'
|
||||
amount: 2500
|
||||
- date: '2020-12-10'
|
||||
amount: 500
|
||||
- date: '2021-01-21'
|
||||
amount: 1500
|
||||
- date: '2021-03-18'
|
||||
amount: 600
|
||||
- date: '2021-04-29'
|
||||
amount: 1000
|
||||
- date: '2021-05-13'
|
||||
amount: 400
|
||||
- date: '2021-06-10'
|
||||
amount: 2600
|
||||
- date: '2021-08-05'
|
||||
amount: 1000
|
||||
- date: '2021-08-26'
|
||||
amount: 560
|
||||
- date: '2021-09-02'
|
||||
amount: 700
|
||||
- date: '2021-09-30'
|
||||
amount: 1000
|
||||
- date: '2021-11-04'
|
||||
amount: 3300
|
||||
- date: '2022-02-10'
|
||||
amount: 1000
|
||||
- date: '2022-03-31'
|
||||
amount: 1000
|
||||
|
||||
spells:
|
||||
- Magic Ice Dart
|
||||
- Freezing Hands
|
||||
- Detect Magic
|
||||
- Identify
|
||||
- Ray of Enfeeblement
|
||||
|
||||
gear:
|
||||
- <hm>hand axe x2
|
||||
- <hm>silver dagger
|
||||
- <hm>short spear
|
||||
- backpack
|
||||
- bandages
|
||||
- blanket
|
||||
- beeswax candles x3
|
||||
- chalk
|
||||
- crampons
|
||||
- small hammer
|
||||
- ink and quill
|
||||
- bull's eye lantern
|
||||
- desc: lamp oil
|
||||
qty: 2
|
||||
- parchment x3
|
||||
- hard leather pouch
|
||||
- soft leather pouch
|
||||
- silk rope
|
||||
- large sack
|
||||
- iron spikes x12
|
||||
- tinderbox
|
||||
- wineskin (full)
|
||||
- writing stick
|
||||
- iron rations
|
||||
- spell book
|
||||
|
||||
|
@ -1,5 +1,36 @@
|
||||
{
|
||||
"$defs" : {
|
||||
"experience" : {
|
||||
"properties" : {
|
||||
"items" : {
|
||||
"properties" : {
|
||||
"amount" : {
|
||||
"type" : "number"
|
||||
},
|
||||
"date" : {
|
||||
"type" : "string"
|
||||
},
|
||||
"notes" : {
|
||||
"type" : "string"
|
||||
}
|
||||
},
|
||||
"type" : "object"
|
||||
},
|
||||
"log" : {
|
||||
"type" : "array"
|
||||
},
|
||||
"total" : {
|
||||
"sumOf" : {
|
||||
"list" : {
|
||||
"$data" : "1/log"
|
||||
},
|
||||
"map" : "amount"
|
||||
},
|
||||
"type" : "number"
|
||||
}
|
||||
},
|
||||
"type" : "object"
|
||||
},
|
||||
"health" : {
|
||||
"properties" : {
|
||||
"current" : {
|
||||
@ -41,12 +72,37 @@
|
||||
"$id" : "https://hyperboria.babyl.ca/character.json",
|
||||
"additionalProperties" : false,
|
||||
"properties" : {
|
||||
"age" : {
|
||||
"type" : "number"
|
||||
},
|
||||
"alignment" : {
|
||||
"type" : "string"
|
||||
},
|
||||
"appearance" : {
|
||||
"type" : "string"
|
||||
},
|
||||
"class" : {
|
||||
"$ref" : "/classes.json"
|
||||
},
|
||||
"experience" : {
|
||||
"$ref" : "#/$defs/experience"
|
||||
},
|
||||
"gender" : {
|
||||
"type" : "string"
|
||||
},
|
||||
"health" : {
|
||||
"$ref" : "#/$defs/health"
|
||||
},
|
||||
"height" : {
|
||||
"type" : "string"
|
||||
},
|
||||
"languages" : {
|
||||
"items" : {
|
||||
"$ref" : "/languages.json"
|
||||
},
|
||||
"minItems" : 1,
|
||||
"type" : "array"
|
||||
},
|
||||
"level" : {
|
||||
"minimum" : 1,
|
||||
"type" : "number"
|
||||
@ -57,6 +113,23 @@
|
||||
"player" : {
|
||||
"type" : "string"
|
||||
},
|
||||
"race" : {
|
||||
"$ref" : "/races.json"
|
||||
},
|
||||
"spells" : {
|
||||
"items" : {
|
||||
"$ref" : "/spells.json"
|
||||
},
|
||||
"maxSpells" : {
|
||||
"class" : {
|
||||
"$data" : "/class"
|
||||
},
|
||||
"level" : {
|
||||
"$data" : "/level"
|
||||
}
|
||||
},
|
||||
"type" : "array"
|
||||
},
|
||||
"statistics" : {
|
||||
"allRequired" : true,
|
||||
"properties" : {
|
||||
@ -88,7 +161,12 @@
|
||||
"statistics",
|
||||
"class",
|
||||
"level",
|
||||
"health"
|
||||
"health",
|
||||
"experience",
|
||||
"age",
|
||||
"height",
|
||||
"appearance",
|
||||
"alignment"
|
||||
],
|
||||
"title" : "Hyperboria character sheet",
|
||||
"type" : "object"
|
||||
|
8
schemas-json/languages.json
Normal file
8
schemas-json/languages.json
Normal file
@ -0,0 +1,8 @@
|
||||
{
|
||||
"$id" : "https://hyperboria.babyl.ca/languages.json",
|
||||
"enum" : [
|
||||
"Common",
|
||||
"Thracian"
|
||||
],
|
||||
"title" : "Languages spoken in Hyperboria"
|
||||
}
|
7
schemas-json/races.json
Normal file
7
schemas-json/races.json
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"$id" : "https://hyperboria.babyl.ca/races.json",
|
||||
"enum" : [
|
||||
"Viking"
|
||||
],
|
||||
"title" : "Character races"
|
||||
}
|
11
schemas-json/spells.json
Normal file
11
schemas-json/spells.json
Normal file
@ -0,0 +1,11 @@
|
||||
{
|
||||
"$id" : "https://hyperboria.babyl.ca/spells.json",
|
||||
"enum" : [
|
||||
"Magic Ice Dart",
|
||||
"Freezing Hands",
|
||||
"Detect Magic",
|
||||
"Identify",
|
||||
"Ray of Enfeeblement"
|
||||
],
|
||||
"title" : "List of known spells"
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
$id: https://hyperboria.babyl.ca/character.json
|
||||
title: Hyperboria character sheet
|
||||
type: object
|
||||
additionalProperties: false
|
||||
type: object
|
||||
required:
|
||||
- name
|
||||
- player
|
||||
@ -9,6 +9,11 @@ required:
|
||||
- class
|
||||
- level
|
||||
- health
|
||||
- experience
|
||||
- age
|
||||
- height
|
||||
- appearance
|
||||
- alignment
|
||||
properties:
|
||||
name: &string
|
||||
type: string
|
||||
@ -27,7 +32,45 @@ properties:
|
||||
charisma: *stat
|
||||
level: { type: number, minimum: 1 }
|
||||
health: { $ref: "#/$defs/health" }
|
||||
experience: { $ref: '#/$defs/experience' }
|
||||
gender: *string
|
||||
age: &number
|
||||
type: number
|
||||
height: *string
|
||||
appearance: *string
|
||||
alignment: *string
|
||||
race: { $ref: /races.json }
|
||||
languages:
|
||||
type: array
|
||||
minItems: 1
|
||||
items:
|
||||
$ref: /languages.json
|
||||
spells:
|
||||
type: array
|
||||
items: { $ref: /spells.json }
|
||||
maxSpells:
|
||||
class: { $data: /class }
|
||||
level: { $data: /level }
|
||||
gear: { $ref: '#/$defs/gear' }
|
||||
|
||||
$defs:
|
||||
gear:
|
||||
type: array
|
||||
items:
|
||||
oneOf:
|
||||
- *string
|
||||
- type: object
|
||||
properties:
|
||||
desc:
|
||||
type: string
|
||||
description: description of the equipment
|
||||
qty:
|
||||
type: number
|
||||
description: quantity of the item in the character's possession
|
||||
required: [ desc ]
|
||||
additionalProperties: false
|
||||
examples:
|
||||
- { desc: 'lamp oil', qty: 2 }
|
||||
statistic:
|
||||
type: number
|
||||
minimum: 1
|
||||
@ -43,6 +86,22 @@ $defs:
|
||||
log:
|
||||
type: array
|
||||
description: history of health rolls
|
||||
items: { type: number }
|
||||
items: &number { type: number }
|
||||
minItems: { $data: /level }
|
||||
maxItems: { $data: /level }
|
||||
experience:
|
||||
type: object
|
||||
properties:
|
||||
total:
|
||||
type: number
|
||||
sumOf:
|
||||
list: { $data: '1/log' }
|
||||
map: amount
|
||||
log:
|
||||
type: array
|
||||
items:
|
||||
type: object
|
||||
properties:
|
||||
date: *string
|
||||
amount: *number
|
||||
notes: *string
|
||||
|
6
schemas-yaml/languages.yml
Normal file
6
schemas-yaml/languages.yml
Normal file
@ -0,0 +1,6 @@
|
||||
---
|
||||
$id: https://hyperboria.babyl.ca/languages.json
|
||||
title: Languages spoken in Hyperboria
|
||||
enum:
|
||||
- Common
|
||||
- Thracian
|
5
schemas-yaml/races.yml
Normal file
5
schemas-yaml/races.yml
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
$id: https://hyperboria.babyl.ca/races.json
|
||||
title: Character races
|
||||
enum:
|
||||
- Viking
|
9
schemas-yaml/spells.yml
Normal file
9
schemas-yaml/spells.yml
Normal file
@ -0,0 +1,9 @@
|
||||
---
|
||||
$id: https://hyperboria.babyl.ca/spells.json
|
||||
title: List of known spells
|
||||
enum:
|
||||
- Magic Ice Dart
|
||||
- Freezing Hands
|
||||
- Detect Magic
|
||||
- Identify
|
||||
- Ray of Enfeeblement
|
30
src/maxSpells.cjs
Normal file
30
src/maxSpells.cjs
Normal file
@ -0,0 +1,30 @@
|
||||
const _ = require("lodash");
|
||||
const resolvePointer = require('./resolvePointer.cjs');
|
||||
|
||||
module.exports = (ajv) =>
|
||||
ajv.addKeyword({
|
||||
keyword: "maxSpells",
|
||||
validate: function validate(
|
||||
schema,
|
||||
data,
|
||||
_parent,
|
||||
{ rootData, instancePath }
|
||||
) {
|
||||
if (schema.class.$data) {
|
||||
schema.class = resolvePointer(rootData, instancePath, schema.class.$data);
|
||||
}
|
||||
|
||||
if( schema.class !== 'magician' && schema.class?.generic !== 'magician' && data.length ) {
|
||||
validate.errors = [
|
||||
{
|
||||
message: "non-magician can't have spells",
|
||||
},
|
||||
];
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
},
|
||||
$data: true,
|
||||
errors: true,
|
||||
});
|
13
src/resolvePointer.cjs
Normal file
13
src/resolvePointer.cjs
Normal file
@ -0,0 +1,13 @@
|
||||
const ptr = require("json-pointer");
|
||||
|
||||
module.exports = function resolvePointer(data, rootPath, relativePath) {
|
||||
if (relativePath[0] === "/") return ptr.get(data, relativePath);
|
||||
|
||||
const m = relativePath.match(/^(\d+)(.*)/);
|
||||
relativePath = m[2];
|
||||
for (let i = 0; i < parseInt(m[1]); i++) {
|
||||
rootPath = rootPath.replace(/\/[^\/]+$/, "");
|
||||
}
|
||||
|
||||
return ptr.get(data, rootPath + relativePath);
|
||||
}
|
@ -1,17 +1,6 @@
|
||||
const _ = require("lodash");
|
||||
const ptr = require("json-pointer");
|
||||
|
||||
function resolvePointer(data, rootPath, relativePath) {
|
||||
if (relativePath[0] === "/") return ptr.get(data, relativePath);
|
||||
|
||||
const m = relativePath.match(/^(\d+)(.*)/);
|
||||
relativePath = m[2];
|
||||
for (let i = 0; i < parseInt(m[1]); i++) {
|
||||
rootPath = rootPath.replace(/\/[^\/]+$/, "");
|
||||
}
|
||||
|
||||
return ptr.get(data, rootPath + relativePath);
|
||||
}
|
||||
const resolvePointer = require('./resolvePointer.cjs');
|
||||
|
||||
module.exports = (ajv) =>
|
||||
ajv.addKeyword({
|
||||
@ -26,7 +15,7 @@ module.exports = (ajv) =>
|
||||
list = resolvePointer(rootData, instancePath, list.$data);
|
||||
}
|
||||
|
||||
if (map) data = _.map(data, map);
|
||||
if (map) list = _.map(list, map);
|
||||
|
||||
if (_.sum(list) === total) return true;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user