adding the class

This commit is contained in:
Yanick Champoux 2022-04-26 16:24:37 -04:00
parent f8df69a011
commit 82ca516b93
7 changed files with 117 additions and 6 deletions

View File

@ -3,16 +3,22 @@
version: "3" version: "3"
tasks: tasks:
schemas: fd -e yml -p ./schemas-yaml -x task schema SCHEMA='{}' schemas:
sources: [ 'schemas-yaml/*' ]
generates: [ 'schemas-json/*' ]
cmds:
- fd -e yml -p ./schemas-yaml -x task schema SCHEMA='{}'
schema: schema:
vars: vars:
TRANSFORM:
sh: |
echo {{.SCHEMA}} | \
perl -lnE's/yml$/pl/; s/^/.\//; say if -f $_'
DEST: DEST:
sh: echo {{.SCHEMA}} | perl -pe's/ya?ml/json/g' sh: echo {{.SCHEMA}} | perl -pe's/ya?ml/json/g'
sources: ["{{.SCHEMA}}"]
generates: ["{{.DEST}}"]
cmds: cmds:
- transerialize {{.SCHEMA}} {{.DEST}} - transerialize {{.SCHEMA}} {{.TRANSFORM}} {{.DEST}}
validate: validate:
silent: true silent: true
@ -23,7 +29,8 @@ tasks:
--errors=json \ --errors=json \
--verbose \ --verbose \
-c ajv-keywords \ -c ajv-keywords \
-s schemas-yaml/character.yml \ -r schemas-json/classes.json \
-s schemas-json/character.json \
-d {{.CLI_ARGS}} -d {{.CLI_ARGS}}
test: test:
deps: [ schemas ] deps: [ schemas ]

View File

@ -1,5 +1,8 @@
name: Verg-La name: Verg-La
player: Yanick player: Yanick
class:
generic: magician
subclass: cryomancer
statistics: statistics:
strength: 11 strength: 11
dexterity: 13 dexterity: 13

View File

@ -9,6 +9,9 @@
"$id" : "https://hyperboria.babyl.ca/character.json", "$id" : "https://hyperboria.babyl.ca/character.json",
"additionalProperties" : false, "additionalProperties" : false,
"properties" : { "properties" : {
"class" : {
"$ref" : "/classes.json"
},
"name" : { "name" : {
"type" : "string" "type" : "string"
}, },
@ -43,7 +46,8 @@
"required" : [ "required" : [
"name", "name",
"player", "player",
"statistics" "statistics",
"class"
], ],
"title" : "Hyperboria character sheet", "title" : "Hyperboria character sheet",
"type" : "object" "type" : "object"

66
schemas-json/classes.json Normal file
View File

@ -0,0 +1,66 @@
{
"$defs" : {
"fighter" : [
"barbarian",
"berserker",
"cataphract",
"hunstman",
"paladin",
"ranger",
"warlock"
],
"magician" : [
"cryomancer",
"illusionist",
"necromancer",
"pyromancer",
"witch"
]
},
"$id" : "https://hyperboria.babyl.ca/classes.json",
"oneOf" : [
{
"enum" : [
"fighter",
"magician"
]
},
{
"properties" : {
"generic" : {
"const" : "fighter"
},
"subclass" : {
"enum" : [
"barbarian",
"berserker",
"cataphract",
"hunstman",
"paladin",
"ranger",
"warlock"
]
}
},
"type" : "object"
},
{
"properties" : {
"generic" : {
"const" : "magician"
},
"subclass" : {
"enum" : [
"cryomancer",
"illusionist",
"necromancer",
"pyromancer",
"witch"
]
}
},
"type" : "object"
}
],
"title" : "Classes of characters for Hyperborea"
}

View File

@ -6,10 +6,12 @@ required:
- name - name
- player - player
- statistics - statistics
- class
properties: properties:
name: &string name: &string
type: string type: string
player: *string player: *string
class: { $ref: '/classes.json' }
statistics: statistics:
type: object type: object
allRequired: true allRequired: true

17
schemas-yaml/classes.pl Normal file
View File

@ -0,0 +1,17 @@
sub {
my $schema = $_->{oneOf} = [];
push @$schema, { enum => [ keys $_->{'$defs'}->%* ] };
for my $generic ( keys $_->{'$defs'}->%* ) {
push @$schema, {
type => 'object',
properties => {
generic => { const => $generic },
subclass => { enum => $_->{'$defs'}{$generic} }
}
}
}
return $_;
}

12
schemas-yaml/classes.yml Normal file
View File

@ -0,0 +1,12 @@
$id: https://hyperboria.babyl.ca/classes.json
title: Classes of characters for Hyperborea
$defs:
fighter:
- barbarian
- berserker
- cataphract
- hunstman
- paladin
- ranger
- warlock
magician: [cryomancer, illusionist, necromancer, pyromancer, witch]